Steven Smith revised this gist . Go to revision
1 file changed, 33 insertions
dcirc.py(file created)
| @@ -0,0 +1,33 @@ | |||
| 1 | + | #!/usr/bin/env python3 | |
| 2 | + | import irc3 | |
| 3 | + | import websockets | |
| 4 | + | import asyncio | |
| 5 | + | import json | |
| 6 | + | ||
| 7 | + | @irc3.plugin | |
| 8 | + | class 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 | + | ||
| 27 | + | def 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 | + | ||
| 32 | + | if __name__ == "__main__": | |
| 33 | + | main() | |
Newer
Older