This commit is contained in:
git-bruh 2020-11-30 21:14:34 +05:30
parent edf6f10ed0
commit bdc333292e
No known key found for this signature in database
GPG key ID: E1475C50075ADCE6

22
main.py
View file

@ -1,4 +1,3 @@
import asyncio
import discord import discord
import re import re
import json import json
@ -48,6 +47,7 @@ class MatrixClient(object):
homeserver = config["homeserver"] homeserver = config["homeserver"]
username = config["username"] username = config["username"]
password = config["password"] password = config["password"]
timeout = 30000
global matrix_client global matrix_client
@ -55,9 +55,8 @@ class MatrixClient(object):
matrix_logger.info(await matrix_client.login(password)) matrix_logger.info(await matrix_client.login(password))
# Sync once to avoid acting on old messages
matrix_logger.info("Doing initial sync.") matrix_logger.info("Doing initial sync.")
await matrix_client.sync(30000) await matrix_client.sync(timeout)
# Set up event callbacks # Set up event callbacks
callbacks = Callbacks() callbacks = Callbacks()
@ -71,6 +70,11 @@ class MatrixClient(object):
matrix_client.add_ephemeral_callback( matrix_client.add_ephemeral_callback(
callbacks.typing_callback, EphemeralEvent) callbacks.typing_callback, EphemeralEvent)
matrix_logger.info("Syncing forever.")
await matrix_client.sync_forever(timeout=timeout)
await matrix_client.close()
async def message_send(self, message, reply_id=None, edit_id=None): async def message_send(self, message, reply_id=None, edit_id=None):
content = { content = {
"msgtype": "m.text", "msgtype": "m.text",
@ -128,9 +132,7 @@ class DiscordClient(discord.Client):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
matrix_logger.info("Syncing forever.") self.bg_task = self.loop.create_task(MatrixClient().create())
self.bg_task = self.loop.create_task(
matrix_client.sync_forever(timeout=30000))
async def on_ready(self): async def on_ready(self):
print(f"Logged in as {self.user}") print(f"Logged in as {self.user}")
@ -324,12 +326,12 @@ class Process(object):
return message return message
async def main(): def main():
intents = discord.Intents.default() intents = discord.Intents.default()
intents.members = True intents.members = True
await MatrixClient().create() DiscordClient(intents=intents).run(config["token"])
await DiscordClient(intents=intents).start(config["token"])
if __name__ == "__main__": if __name__ == "__main__":
asyncio.run(main()) main()