From ade4a3a92b89f314501a11d0185df9f62e2ac789 Mon Sep 17 00:00:00 2001 From: swee Date: Wed, 1 Jan 2025 16:58:53 -0800 Subject: [PATCH] Update sweebridge.py --- sweebridge.py | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/sweebridge.py b/sweebridge.py index db95b8f..6356644 100644 --- a/sweebridge.py +++ b/sweebridge.py @@ -1,5 +1,5 @@ # Modules for the system, these should be pre-installed with Python. -import json, os, sys, traceback, time, threading, requests, socket, subprocess +import json, os, sys, traceback, time, threading, requests, socket, subprocess, nio, asyncio from sys import argv # Modules for platforms import guilded, discord @@ -212,9 +212,12 @@ def ircsession(platform:str, sock:bot_irc): time.sleep(2) sys.exit() elif "QUIT" in text: - if guilded_enable: hook(gilwebhook, json={"content": nick + " Has quit for reason \"" + " ".join(text.split(" ")[2:])[1:] + "\"", "username": "SweeBridge IRC", "avatar_url": "https://git.swee.codes/swee/SweeBridge/raw/branch/main/logos/sweebridge-" + platform + ".png"}) - if discord_enable: hook(discwebhook, json={"content": nick + " Has quit for reason \"" + " ".join(text.split(" ")[2:])[1:] + "\"", "username": "SweeBridge IRC", "avatar_url": "https://git.swee.codes/swee/SweeBridge/raw/branch/main/logos/sweebridge-" + platform + ".png"}) - update(channel_irc, sock) + for key, value in userlist.items(): + if nick in value: + target = targets[platform][key] + if guilded_enable: hook(gilwebhook, json={"content": nick + " Has quit for reason \"" + " ".join(text.split(" ")[2:])[1:] + "\"", "username": "SweeBridge IRC", "avatar_url": "https://git.swee.codes/swee/SweeBridge/raw/branch/main/logos/sweebridge-" + platform + ".png"}) + if discord_enable: hook(discwebhook, json={"content": nick + " Has quit for reason \"" + " ".join(text.split(" ")[2:])[1:] + "\"", "username": "SweeBridge IRC", "avatar_url": "https://git.swee.codes/swee/SweeBridge/raw/branch/main/logos/sweebridge-" + platform + ".png"}) + update(channel_irc, sock) elif "JOIN" in text: channel_irc = text.split(" ")[2] target = targets[platform][channel_irc] @@ -526,6 +529,22 @@ intents.members = True client2 = MyClient(intents=intents) guild = threading.Thread(target=client.run, args=[os.getenv("GuildedToken")], daemon=True) disc = threading.Thread(target=client2.run, args=[os.getenv("DiscordToken")], daemon=True) +async def matrixSession(): + Mtrix = nio.AsyncClient(os.getenv("MatrixHomeserver"), os.getenv("MatrixUsername")) + Mtrix.access_token = os.getenv("MatrixToken") + Mtrix.user_id = os.getenv("MatrixUsername") + while True: + try: + await Mtrix.load_store() + sync = await Mtrix.sync(30000) + finally: + Mtrix.close() + + +def runMatrix() + asyncio.run(matrixSession()) +matrix = threading.Thread(target=runMatrix) +matrix.start() irc1.start() guild.start() disc.start()