42 lines
1.1 KiB
Python
Executable File
42 lines
1.1 KiB
Python
Executable File
import asyncio
|
|
import sys
|
|
import time
|
|
|
|
from room import Room
|
|
|
|
|
|
async def main():
|
|
config_path = sys.argv[1] if len(sys.argv) > 1 else "configs/config.yaml"
|
|
room = Room(config_path)
|
|
|
|
if not await room.login_to_matrix():
|
|
print("Failed to login")
|
|
return
|
|
|
|
# Initial sync establishes the next-batch; after this, listen from "now"
|
|
assert room.client is not None
|
|
await room.client.sync(timeout=room.config.initial_sync_timeout)
|
|
|
|
try:
|
|
while True:
|
|
listen_since_ms = int(time.time() * 1000)
|
|
|
|
# Wait for !gettitles before posting
|
|
await room.wait_for_gettitles(since_ms=listen_since_ms)
|
|
|
|
# Results commands leave the pending queue untouched.
|
|
room.read_db(only_unposted=True)
|
|
if room.posts:
|
|
await room.post_suggestions_individually()
|
|
room.update_last_post()
|
|
else:
|
|
await room.alert_post("No new title suggestions posted.")
|
|
await asyncio.sleep(room.config.post_loop_interval)
|
|
finally:
|
|
await room.close()
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|
|
|
|
|