aboutsummaryrefslogtreecommitdiffstats
path: root/control.py
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2020-04-20 00:25:07 +0200
committerNao Pross <naopross@thearcway.org>2020-04-20 00:25:07 +0200
commit92401488df871b15e747515472a797bececcc728 (patch)
tree61d4721d1750eb8e52f65dcc3c9d414b98e297aa /control.py
parentHC: added emote and invite, TG: switched to HTML (diff)
downloadhchat-tg-bridge-92401488df871b15e747515472a797bececcc728.tar.gz
hchat-tg-bridge-92401488df871b15e747515472a797bececcc728.zip
Add custom server ip, and custom bridge command
Diffstat (limited to 'control.py')
-rwxr-xr-xcontrol.py38
1 files changed, 22 insertions, 16 deletions
diff --git a/control.py b/control.py
index 0ccc421..f70a8e1 100755
--- a/control.py
+++ b/control.py
@@ -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():