Last active 1482102528

A non-working attempt at an integration between IRC and the AirDC web ui's hub chat

dcirc.py Raw
1#!/usr/bin/env python3
2import irc3
3import websockets
4import asyncio
5import json
6
7@irc3.plugin
8class DCIRC:
9 requires = ["irc3.plugins.command"]
10
11 def __init__(self, bot):
12 self.bot = bot
13 self.bot.loop.create_task(self.websocket("wss://localhost:5601"))
14
15 async def websocket(self, uri):
16 headers = {"Cookie": ""}
17 websocket = websockets.client.connect(uri, extra_headers=headers)
18 await websocket.send(json.dumps({"path":"session/v0/socket","method":"POST","data":{"authorization":""},"callback_id":1}))
19 while True:
20 msg = json.loads(await websocket.recv())
21 if "event" in msg and msg["event"] == "hub_message":
22 n = msg["data"]["from"]["nick"]
23 msg["data"]["from"]["nick"] = n[0] + "\u200b" + n[1:]
24 self.bot.privmsg(self.bot.config["autojoins"][0],
25 "<{from[nick]}> {text}".format(**msg["data"]))
26
27def main():
28 config = dict(nick="", autojoins=[""], host="irc..net", port=6667, includes=["irc3.plugins.core", "irc3.plugins.command", __name__])
29 bot = irc3.IrcBot.from_config(config)
30 bot.run(forever=True)
31
32if __name__ == "__main__":
33 main()
34