From 8e00afaa45b18500e0661e83717bbb0dd24e2ce0 Mon Sep 17 00:00:00 2001 From: Misaki Date: Tue, 14 Nov 2023 18:45:52 +0100 Subject: [PATCH] vorberitung nach Chat GPT. Mimimimimimimimi bin Faul. --- bot.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/bot.py b/bot.py index 3fa920e..6f519f5 100644 --- a/bot.py +++ b/bot.py @@ -1 +1,47 @@ #Mau mau das wird der Funi Bot +from telegram.ext import Updater, CommandHandler, MessageHandler, Filters +import logging + +logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', + level=logging.INFO) +logger = logging.getLogger(__name__) + +def start(update, context): + """Send a message when the command /start is issued.""" + update.message.reply_text('Hallo! Ich bin dein Echo-Bot. Sende mir eine Nachricht und ich werde sie wiederholen.') + +def echo(update, context): + """Echo the user message.""" + update.message.reply_text(update.message.text) + +def error(update, context): + """Log Errors caused by Updates.""" + logger.warning('Update "%s" caused error "%s"', update, context.error) + +def main(): + """Start the bot.""" + # Ersetzen Sie 'YOUR_TOKEN' mit Ihrem Bot-Token + updater = Updater("6885365398:AAHhgMRbUGfeS0VzKRmJvjKxSHfi18xESC4", use_context=True) + + # Get the dispatcher to register handlers + dp = updater.dispatcher + + # on different commands - answer in Telegram + dp.add_handler(CommandHandler("start", start)) + + # on noncommand i.e message - echo the message on Telegram + dp.add_handler(MessageHandler(Filters.text, echo)) + + # log all errors + dp.add_error_handler(error) + + # Start the Bot + updater.start_polling() + + # Run the bot until you press Ctrl-C or the process receives SIGINT, + # SIGTERM or SIGABRT. This should be used most of the time, since + # start_polling() is non-blocking and will stop the bot gracefully. + updater.idle() + +if __name__ == '__main__': + main()