feat: 支持Matrix access_token登录,配置AI模型接口

This commit is contained in:
2026-04-11 11:58:14 +08:00
parent c27fc8c02f
commit fd583132d7
8 changed files with 186 additions and 22 deletions
+12 -1
View File
@@ -19,6 +19,7 @@ class MatrixBot:
self.homeserver: str = ""
self.username: str = ""
self.password: str = ""
self.access_token: str = ""
self.is_running: bool = False
self.on_message_callback: Optional[Callable] = None
@@ -30,8 +31,9 @@ class MatrixBot:
self.homeserver = configs.get('matrix_homeserver', 'https://matrix.tphai.com')
self.username = configs.get('matrix_username', '')
self.password = configs.get('matrix_password', '')
self.access_token = configs.get('matrix_access_token', '')
if self.username and self.password:
if self.username and (self.password or self.access_token):
await self.connect()
finally:
db.close()
@@ -44,6 +46,15 @@ class MatrixBot:
try:
self.client = AsyncClient(self.homeserver, self.username)
# 如果有access_token,直接使用
if self.access_token:
self.client.access_token = self.access_token
logger.info(f"Matrix连接成功(使用token): {self.username}")
self.is_running = True
return True
# 否则使用密码登录
response = await self.client.login(self.password)
if isinstance(response, LoginResponse):