54 lines
1.4 KiB
Python
54 lines
1.4 KiB
Python
# main.py
|
|
|
|
import asyncio
|
|
from services.matrix_service import MatrixService
|
|
|
|
|
|
async def command_listener(matrix_service):
|
|
while True:
|
|
print("Command Menu:")
|
|
print("1. Send Message")
|
|
print("q. Quit")
|
|
user_input = input("Enter command: ")
|
|
|
|
if user_input == "1":
|
|
message = input("Enter message to send: ")
|
|
await matrix_service.send_message(message)
|
|
print("Message sent!")
|
|
elif user_input == "q":
|
|
print("Exiting command listener...")
|
|
break
|
|
else:
|
|
print("Invalid command. Please try again.")
|
|
|
|
|
|
async def main():
|
|
matrix_service = MatrixService()
|
|
|
|
try:
|
|
# 登录(会自动加入配置的所有房间)
|
|
await matrix_service.login()
|
|
|
|
# 先进行一次同步以确保房间状态正确
|
|
print("正在同步房间状态...")
|
|
await matrix_service.client.sync()
|
|
|
|
# 启动同步任务
|
|
sync_task = asyncio.create_task(matrix_service.sync())
|
|
|
|
# 等待同步任务完成(实际上会一直运行)
|
|
await sync_task
|
|
|
|
except KeyboardInterrupt:
|
|
print("\n正在关闭服务...")
|
|
await matrix_service.close()
|
|
except Exception as e:
|
|
print(f"发生错误: {e}")
|
|
await matrix_service.close()
|
|
finally:
|
|
await matrix_service.close()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|