aboutsummaryrefslogtreecommitdiffstats
path: root/control.py
diff options
context:
space:
mode:
authorTim Schmidt <tim.schmidt@ewe.net>2018-12-15 12:30:48 +0100
committerTim Schmidt <tim.schmidt@ewe.net>2018-12-15 12:30:48 +0100
commitd2b83008c9e6ec9226bac71ca79bfa2f3c999d46 (patch)
treee26289c7ece76ef98aa523bac0459e2d048f4bcc /control.py
parentdisabled debug logging (diff)
downloadhchat-tg-bridge-d2b83008c9e6ec9226bac71ca79bfa2f3c999d46.tar.gz
hchat-tg-bridge-d2b83008c9e6ec9226bac71ca79bfa2f3c999d46.zip
HC: added emote and invite, TG: switched to HTML
Diffstat (limited to 'control.py')
-rwxr-xr-xcontrol.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/control.py b/control.py
index f2ae5f3..0ccc421 100755
--- a/control.py
+++ b/control.py
@@ -7,6 +7,7 @@ import threading
import traceback
import signal
import logging
+import html
# Custom scripts
import hackchatcustom as hackchat
@@ -41,6 +42,9 @@ def mdescape(s):
s = s.replace(x, "\\" + x)
return s
+def htmlescape(s):
+ return html.escape(s)
+
### HV-Bot
def getUser(update):
"""Convenience function that extracts a nick and tripcode (if any) from
@@ -69,21 +73,34 @@ def onMessage(chat, update):
log("[%s] %s" % (sender, message))
if nick != config.USER:
if trip == 'null':
- toTG("\\[*%s*] %s" % (mdescape(nick), mdescape(message)))
+ toTG("[<b>%s</b>] %s" % (htmlescape(nick), htmlescape(message)))
else:
- toTG("\\[*%s*#%s] %s" % (mdescape(nick), trip, mdescape(message)))
+ toTG("[<b>%s</b>#%s] %s" % (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" % mdescape(user))
+ toTG("# %s joined" % htmlescape(user))
def onLeave(chat, update):
"""Callback function handling users leaving the channel."""
user = getUser(update)
log("# %s left" % user)
- toTG("# %s left" % mdescape(user))
+ toTG("# %s left" % 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))
+
+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)))
def startHCBot():
"""Starts the HC bot."""
@@ -92,6 +109,8 @@ def startHCBot():
bot.on_message += [onMessage]
bot.on_join += [onJoin]
bot.on_leave += [onLeave]
+ bot.on_emote += [onEmote]
+ bot.on_invite += [onInvite]
hcBot = bot
bot.run()
@@ -156,7 +175,7 @@ def cmdOnline(bot, update):
users = list(hcBot.online_users)
users.sort()
tgBot.send("Users online:\n%s" %
- mdescape(", ".join(users)))
+ htmlescape(", ".join(users)))
### Common