From 92401488df871b15e747515472a797bececcc728 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 20 Apr 2020 00:25:07 +0200 Subject: Add custom server ip, and custom bridge command --- control.py | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) (limited to 'control.py') 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("[%s] %s" % (htmlescape(nick), htmlescape(message))) + toTG("[{:7s}]|{}".format(htmlescape(nick), htmlescape(message))) else: - toTG("[%s#%s] %s" % (htmlescape(nick), trip, htmlescape(message))) + toTG("[{:7s}#{}] {}".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("* %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" % htmlescape(user)) + + log("%s left" % 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)) + 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))) + 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.""" 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(): -- cgit v1.2.1