From 7c8f135b790e17eaf005755e65041e2266eaf13c Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Sat, 20 Jan 2018 15:28:04 +0100 Subject: [PATCH] 3 --- bots.py | 2 ++ static/royal.css | 1 + telegrambot.py | 13 ++++++++++--- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/bots.py b/bots.py index e07276b5..7fa97f74 100644 --- a/bots.py +++ b/bots.py @@ -1,6 +1,7 @@ import multiprocessing import telegrambot import discordbot +import time discord_telegram_pipe = multiprocessing.Pipe() discord = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],), daemon=True) @@ -14,3 +15,4 @@ if __name__ == "__main__": print("Restarting Discord Bot...") discord = multiprocessing.Process(target=discordbot.process, args=(discord_telegram_pipe[0],), daemon=True) discord.start() + time.sleep(60) \ No newline at end of file diff --git a/static/royal.css b/static/royal.css index 051f5815..a2050f10 100644 --- a/static/royal.css +++ b/static/royal.css @@ -34,6 +34,7 @@ table.dota th { .dota-rank-medal-stars { position: relative; left: -32px; + margin-right: -32px; } .rl-rank-hidden { diff --git a/telegrambot.py b/telegrambot.py index 109cae32..1b5f9b49 100644 --- a/telegrambot.py +++ b/telegrambot.py @@ -49,6 +49,9 @@ def cmd_register(bot: Bot, update: Update): def cmd_discord(bot: Bot, update: Update): + if discord_connection is None: + bot.send_message(update.message.chat.id, "⚠ Il bot non è sincronizzato con Discord al momento.") + return discord_connection.send("/cv") server_members = discord_connection.recv() channels = {0:None} @@ -108,7 +111,7 @@ def cmd_discord(bot: Bot, update: Update): message += f" | 📡 [{member.game.name}]({member.game.url})" message += "\n" message += "\n" - bot.send_message(update.message.chat.id, message, disable_web_page_preview=True, parse_mode="Markdown") + bot.send_message(update.message.chat.id, message, disable_web_page_preview=True) def cmd_cast(bot: Bot, update: Update): @@ -141,10 +144,14 @@ def cmd_cast(bot: Bot, update: Update): def process(arg_discord_connection): print("Telegrambot starting...") - global discord_connection - discord_connection = arg_discord_connection + if arg_discord_connection is not None: + global discord_connection + discord_connection = arg_discord_connection u = Updater(config["Telegram"]["bot_token"]) u.dispatcher.add_handler(CommandHandler("register", cmd_register)) u.dispatcher.add_handler(CommandHandler("discord", cmd_discord)) u.dispatcher.add_handler(CommandHandler("cast", cmd_cast)) u.start_polling() + +if __name__ == "__main__": + process(None) \ No newline at end of file