deek->irc just werks(tm)
This commit is contained in:
parent
fb537538aa
commit
62f0d2389c
20
main.py
20
main.py
|
@ -1,6 +1,7 @@
|
|||
import requests, websockets, asyncio, json, re, threading, time
|
||||
from ircked.bot import irc_bot
|
||||
from ircked.message import *
|
||||
import traceback
|
||||
|
||||
class bird_inst():
|
||||
def __init__(self, endpoint, httpendpoint, config):
|
||||
|
@ -11,6 +12,7 @@ class bird_inst():
|
|||
self.headers = None
|
||||
self.irc = irc_bot(nick=self.config["irc_nick"])
|
||||
self.irc.connect_register(self.config["irc_serb"], self.config["irc_port"])
|
||||
self.send_queue = []
|
||||
|
||||
def irc_handler(msg, ctx):
|
||||
#print("<><><><>", str(msg))
|
||||
|
@ -22,7 +24,7 @@ class bird_inst():
|
|||
message.manual(":"+msg.parameters[0], "PRIVMSG", [msg.prefix[1:].split("!")[0], ":\x01dorfl bot\x01"]).send(ctx.socket)
|
||||
if msg.command == "PRIVMSG" and ("py-ctcp" not in msg.prefix):
|
||||
pm = privmsg.parse(msg)
|
||||
self.send_post(pm.fr+": "+pm.bod)
|
||||
self.send_post(pm.fr.split("!")[0]+": "+pm.bod)
|
||||
threading.Thread(target=self.irc.run, kwargs={"event_handler": irc_handler}, daemon=True).start()
|
||||
def auth(self, name, passwd):
|
||||
h = {
|
||||
|
@ -39,6 +41,7 @@ class bird_inst():
|
|||
print("running main loop")
|
||||
async with websockets.connect(self.endpoint, extra_headers=self.headers) as self.ws:
|
||||
print(self.ws)
|
||||
asyncio.get_event_loop().create_task(self._send_post())
|
||||
while True:
|
||||
data = json.loads(await self.ws.recv())
|
||||
print(">>>", data)
|
||||
|
@ -51,19 +54,27 @@ class bird_inst():
|
|||
def handle_files(self, ctx):
|
||||
self.irc.sendraw(privmsg.build(self.config["irc_nick"], self.config["irc_chan"], ctx["name"]+": "+ctx["data"]["message"]).msg)
|
||||
for f in ctx["data"]["files"]:
|
||||
self.irc.sendraw(privmsg.build(self.config["irc_nick"], self.config["irc_chan"], f"({ctx['name']} uploaded file: {self.httpendpoint}/{f['name']}").msg)
|
||||
self.irc.sendraw(privmsg.build(self.config["irc_nick"], self.config["irc_chan"], f"({ctx['name']} uploaded file: {self.httpendpoint}/storage/files/{f['name']})").msg)
|
||||
def handle_exit(self, ctx): pass
|
||||
def handle_enter(self, ctx): pass
|
||||
def handle_userLoaded(self, ctx): pass
|
||||
def send_post(self, msg):
|
||||
if self.ws is None: return
|
||||
print(msg)
|
||||
self.send_queue.append(msg)
|
||||
#loop = asyncio.new_event_loop()
|
||||
#asyncio.set_event_loop(loop)
|
||||
#loop.create_task(self.send_post(pm.bod))
|
||||
#loop.run_forever()
|
||||
#pass#await self.ws.send(json.dumps({"type": "message", "message": msg}))
|
||||
|
||||
async def _send_post(self):
|
||||
while True:
|
||||
for msg in self.send_queue:
|
||||
await self.ws.send(json.dumps({"type": "message", "data": {"message": msg}}))
|
||||
self.send_queue.remove(msg)
|
||||
print("shipped", msg)
|
||||
await asyncio.sleep(.5)
|
||||
print("blab")
|
||||
cfg = json.loads(open("config.json", "r").read())
|
||||
bi = bird_inst("wss://deekchat.ml/ws", "https://deekchat.ml", cfg)
|
||||
print("yes hello birdchat here")
|
||||
|
@ -73,5 +84,6 @@ while True:
|
|||
except KeyboardInterrupt:
|
||||
break
|
||||
except Exception as e:
|
||||
print(e)
|
||||
print("yo ur shits broken", e)
|
||||
print(traceback.format_exc())
|
||||
continue
|
Loading…
Reference in New Issue