diff options
Diffstat (limited to 'control.py')
-rwxr-xr-x | control.py | 38 |
1 files changed, 22 insertions, 16 deletions
@@ -1,4 +1,4 @@ -#!/bin/python +#!/usr/bin/env python3 import datetime import sys @@ -71,41 +71,43 @@ def onMessage(chat, update): sender = getUser(update) log("[%s] %s" % (sender, message)) - if nick != config.USER: + if not nick.endswith("@" + config.USER): if trip == 'null': - toTG("[<b>%s</b>] %s" % (htmlescape(nick), htmlescape(message))) + toTG("<code>[{:7s}]|</code>{}".format(htmlescape(nick), htmlescape(message))) else: - toTG("[<b>%s</b>#%s] %s" % (htmlescape(nick), trip, htmlescape(message))) + toTG("<code>[{:7s}#{}]</code> {}".format(htmlescape(nick), trip, htmlescape(message))) def onJoin(chat, update): """Callback function handling users joining the channel.""" user = getUser(update) - log("# %s joined" % user) - toTG("# %s joined" % htmlescape(user)) + + log("* %s joined" % user) + toTG("<code>* %s joined</code>" % htmlescape(user)) def onLeave(chat, update): """Callback function handling users leaving the channel.""" user = getUser(update) - log("# %s left" % user) - toTG("# %s left" % htmlescape(user)) + + log("<code>%s</code> left" % user) + toTG("<code>* %s left</code>" % htmlescape(user)) def onEmote(chat, update): """Callback function handling users sending emotes to the channel.""" text = update["text"] - log("* %s" % text) - toTG("* %s" % htmlescape(text)) + log("<code>* %s</code>" % text) + toTG("<code>* %s</code>" % htmlescape(text)) def onInvite(chat, update): """Callback function handling users sending invite to the bot.""" user = update["from"] newChannel = update["invite"] - log(">>> %s invited you to hack.chat/?%s" % (user, newChannel)) - toTG(">>> %s invited you to hack.chat/?%s" % (htmlescape(user), htmlescape(newChannel))) + log(">>> <code>%s</code> invited you to hack.chat/?%s" % (user, newChannel)) + toTG(">>> <code>%s</code> invited you to hack.chat/?%s" % (htmlescape(user), htmlescape(newChannel))) def startHCBot(): """Starts the HC bot.""" global hcBot - bot = hackchat.HackChat(config.USER_AND_PASS, config.CHANNEL) + bot = hackchat.HackChat(config.USER_AND_PASS, config.SERVER, config.CHANNEL) bot.on_message += [onMessage] bot.on_join += [onJoin] bot.on_leave += [onLeave] @@ -137,16 +139,20 @@ def kill(): hcBot.ws.close() ### TG-Bot Config -def onTGMessage(text): +def onTGMessage(update): """Handles receiving messages from the Telegram bot. Currently, they are simple forwarded to the HC bot which will then send them""" - hcBot.send_message(text) + hcBot._send_packet({ + "cmd":"bridge", + "text":update.message.text, + "nick":update.message.from_user.username, + }) def toTG(s): """Handles sending messages to the Telegram bot. Currently, the TG bot will simply send - the message with Markdown parsing enabled.""" + the message with HTML parsing enabled.""" tgBot.send(s) def startTGBot(): |