From 865b642ac94430556a5512ab9cdf89a666049792 Mon Sep 17 00:00:00 2001 From: yen Date: Sun, 13 Apr 2025 11:37:48 +0200 Subject: [PATCH] fix --- requirements.txt | 1 + seshsecretary.py | 39 ++++++++++++++++++++------------------- 2 files changed, 21 insertions(+), 19 deletions(-) create mode 100644 requirements.txt diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..201cacf --- /dev/null +++ b/requirements.txt @@ -0,0 +1 @@ +python-telegram-bot==22.0 diff --git a/seshsecretary.py b/seshsecretary.py index d8f3af2..07b95ca 100755 --- a/seshsecretary.py +++ b/seshsecretary.py @@ -1,6 +1,7 @@ #!/usr/bin/python -from telegram.ext import Updater, CommandHandler, filters +from telegram import Update +from telegram.ext import Application, CommandHandler, filters import os from random import randrange import sys @@ -8,7 +9,8 @@ import sys SAVED_PATH = '/var/lib/seshsecretary/saved.txt' CHATIDS_PATH = '/var/lib/seshsecretary/chatids.txt' -def _list(update, context): + +async def _list(update, context): chat_id = update.effective_chat.id if not check_chat_id(chat_id): @@ -19,11 +21,11 @@ def _list(update, context): for line in f: response += line.split()[0] + "\n" if response == "": - context.bot.send_message(chat_id, "Ingen gemte beskeder :(", 'MARKDOWN') + await context.bot.send_message(chat_id, "Ingen gemte beskeder :(", 'MARKDOWN') else: - context.bot.send_message(chat_id, response, 'MARKDOWN') + await context.bot.send_message(chat_id, response, 'MARKDOWN') -def random(update, context): +async def random(update, context): chat_id = update.effective_chat.id if not check_chat_id(chat_id): @@ -34,9 +36,9 @@ def random(update, context): message = lines[randrange(len(lines))] message_id = message.split()[1] from_chat_id = message.split()[2] - context.bot.forward_message(chat_id, from_chat_id, message_id) + await context.bot.forward_message(chat_id, from_chat_id, message_id) -def get(update, context): +async def get(update, context): chat_id = update.effective_chat.id if not check_chat_id(chat_id): @@ -52,12 +54,12 @@ def get(update, context): break if message_id == "": - update.message.reply_text( + await update.message.reply_text( "{} findes ik!".format(name)) else: - context.bot.forward_message(chat_id, from_chat_id, message_id) + await context.bot.forward_message(chat_id, from_chat_id, message_id) -def save(update, context): +async def save(update, context): chat_id = update.effective_chat.id if not check_chat_id(chat_id): @@ -74,9 +76,9 @@ def save(update, context): if cont: with open(SAVED_PATH, "a") as f: f.write(name + " " + str(message_id) + " " + str(chat_id) + "\n") - update.message.reply_text(name + " er gemt!") + await update.message.reply_text(name + " er gemt!") else: - update.message.reply_text(name + " findes allerede :(") + await update.message.reply_text(name + " findes allerede :(") def main(): if not os.path.isfile(SAVED_PATH): @@ -88,15 +90,14 @@ def main(): if token is None: sys.exit("Missing environment variable: SESHSECRETARY_TOKEN") - updater = Updater(token, use_context=True) + application = Application.builder().token(token).build() - updater.dispatcher.add_handler(CommandHandler("list", _list)) - updater.dispatcher.add_handler(CommandHandler("get", get)) - updater.dispatcher.add_handler(CommandHandler("random", random)) - updater.dispatcher.add_handler(CommandHandler("save", save, filters.REPLY)) + application.add_handler(CommandHandler("list", _list)) + application.add_handler(CommandHandler("get", get)) + application.add_handler(CommandHandler("random", random)) + application.add_handler(CommandHandler("save", save, filters.REPLY)) - updater.start_polling() - updater.idle() + application.run_polling(allowed_updates=Update.ALL_TYPES) def check_chat_id(chatid): with open(CHATIDS_PATH) as f: