xtex
23ae1fb5f2
* build(deps): add matrix-nio * build(deps): update requirements.txt for matrix-nio * feat: add example config for matrix * feat: init matrix support * feat: do init sync to avoid receiving old messages * feat: store next sync batch with file * feat: parse matrix message * feat: check moderator permission * feat: redacting message * feat: toMessageChain for m.text and m.image * feat: drop m.notice messages * feat: sending messages * fix: power level fetching * fix: rich reply fallback stripping * style: less log * feat: guess image content type * fix: image upload * feat: sending audio * chore: add todo * chore: add todo * fix: use FinS.result to store room id As the spec, room_id is an opaque identifier, and at least all valid ASCII characters except '/' and ':' can be included in room_id. This means in some servers, '|' may be included in room_id. * fix: print RoomSendError * fix: public rooms with two user are regarded as DM * feat: resolving pm * fix: nio.ErrorResponse * feat: add post test * feat: pm post test * Revert "feat: pm post test" This reverts commit3688213c80
. * Revert "feat: add post test" This reverts commit259fcf54ca
. * feat: create TPM room * feat: send typing notifications * feat: leave empty room * feat: rich reply formatted fallback support * fix: import * fix: include body in formatted rich reply fallbacks * fix: escape line breaks in html * fix: <br/> tag * feat: improve matrix direct messaging * feat: parse m.emote as m.text * fix: command run blockingly * fix: message send error handle * fix: keep DM room * fix: reuse of DM rooms * feat: add error log * docs: add deploy guide for matrix * docs: add matrix to readme * docs: add more warning * style: remove explictly type declartion (poljar/matrix-nio#417) * feat: receive audio message * feat: standard rich-reply fallback for m.emote * chore: add matrix to bug report issues template
34 lines
1.1 KiB
Python
34 lines
1.1 KiB
Python
import os
|
|
from nio import AsyncClient, AsyncClientConfig
|
|
import urllib3
|
|
|
|
from config import Config
|
|
from core.logger import Logger
|
|
|
|
homeserver: str = Config('matrix_homeserver')
|
|
user: str = Config('matrix_user')
|
|
token: str = Config('matrix_token')
|
|
|
|
store_path = os.path.abspath('./matrix_store')
|
|
if not os.path.exists(store_path):
|
|
os.mkdir(store_path)
|
|
|
|
store_path_nio = os.path.join(store_path, 'nio')
|
|
if not os.path.exists(store_path_nio):
|
|
os.mkdir(store_path_nio)
|
|
|
|
store_path_next_batch = os.path.join(store_path, 'next_batch.txt')
|
|
|
|
|
|
if homeserver and user and token:
|
|
if homeserver.endswith('/'):
|
|
Logger.warn(f"The matrix_homeserver ends with a slash(/), and this may cause M_UNRECOGNIZED error")
|
|
homeserver_host = urllib3.util.parse_url(homeserver).host
|
|
bot: AsyncClient = AsyncClient(homeserver,
|
|
user,
|
|
device_id='AkariBot',
|
|
store_path=store_path_nio,
|
|
config=AsyncClientConfig(store_sync_tokens=True))
|
|
bot.access_token = token
|
|
else:
|
|
bot = False
|