From 34f070192536ef1966348c517355762b5320ae3b Mon Sep 17 00:00:00 2001 From: angerstoner Date: Fri, 9 Nov 2018 16:16:15 +0100 Subject: [PATCH] first try with adding quotes by user input --- bro.txt | 0 schneiderbot.py | 57 +++++++++++++++++++++++++++++++++++++++---------- waack.txt | 1 + 3 files changed, 47 insertions(+), 11 deletions(-) create mode 100644 bro.txt create mode 100644 waack.txt diff --git a/bro.txt b/bro.txt new file mode 100644 index 0000000..e69de29 diff --git a/schneiderbot.py b/schneiderbot.py index a0f8de7..4695627 100755 --- a/schneiderbot.py +++ b/schneiderbot.py @@ -74,15 +74,9 @@ MODES = { "light" : HIDE_CATEGORIES_LIGHT, "full" : HIDE_CATEGORIES_FULL } - -# Enable logging -logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', - level=logging.INFO) - -logger = logging.getLogger(__name__) - -with open("stoll.txt", "r") as tmp_file: - STOLL = tmp_file.readlines() +STOLL = open("stoll.txt", "r+") +BRO = open("bro.txt", "r+") +WAACK = open("waack.txt", "r+") with open("manta.txt", "r") as tmp_file: MANTA = tmp_file.readlines() @@ -90,6 +84,25 @@ with open("manta.txt", "r") as tmp_file: with open("goodlife.txt", "r") as tmp_file: GOOD_LIFE = tmp_file.readlines() + +QUOTEPERSONS = { + "stoll" : "Dr. Axel Stoll", + "brosenne" : "Dr. Henrik Brosenne", + "waack" : "Dr. Stephan Waack" +} + +QUOTEFILES = { + "stoll" : STOLL, + "brosenne" : BRO, + "waack" : WAACK +} + +# Enable logging +logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', + level=logging.INFO) + +logger = logging.getLogger(__name__) + # Define a few command handlers. These usually take the two arguments bot and # update. Error handlers also receive the raised TelegramError object in error. def start(bot, update): @@ -182,6 +195,26 @@ def sudo(bot, update, args): else: update.message.reply_text("Unknown command") +def addquote(bot, update, args): + """for real""" + if not args : + update.message.reply_text("missing params") + return + person = args[0] + if person in QUOTEPERSONS: + quote = "" + quotefile = QUOTEFILES[person] + argslenght = len(args) + for argnum in range(1, argslenght): + quote += args[argnum] + if argnum != (argslenght - 1): + quote += " " + quotefile.write(quote + "\n") + reopen(quotefile) + update.message.reply_text("Added quote \"%s\" for %s" % (quote, QUOTEPERSONS[person])) + else: + update.message.reply_text("wrong params") + def sendCatDog(bot, update): """Best of both worlds!""" catdog = "https://upload.wikimedia.org/wikipedia/en/6/64/CatDog.jpeg" @@ -249,8 +282,8 @@ def mensa(bot, update, args): meal_line = "*%s*\n" % meal["category"] meal_line += meal["title"].strip() + "\n" - # Discord only allows up to 2000 chars per message - if len(message) + len(meal_line) > 2000: + # Telegram only allows up to 4096 chars per message + if len(message) + len(meal_line) > 4096: update.message.reply_text(message, parse_mode=ParseMode.MARKDOWN) message = meal_line + "\n" else: @@ -286,6 +319,8 @@ def main(): dp.add_handler(CommandHandler("manta", manta)) dp.add_handler(CommandHandler("goodlife", goodlife)) dp.add_handler(CommandHandler("mensa", mensa, pass_args=True)) + dp.add_handler(CommandHandler("addquote", addquote, pass_args=True)) +# dp.add_handler(CommandHandler("quote", quote, pass_args=True)) dp.add_handler(CommandHandler("sudo", sudo, pass_args=True)) dp.add_handler(CommandHandler("cat", sendCat)) dp.add_handler(CommandHandler("dog", sendDog)) diff --git a/waack.txt b/waack.txt new file mode 100644 index 0000000..d727e2f --- /dev/null +++ b/waack.txt @@ -0,0 +1 @@ +Problem damit? Ne!