From 641b58adb2a56806a92a67b637ba529b0762cda9 Mon Sep 17 00:00:00 2001 From: MateussssZ Date: Thu, 25 Apr 2024 17:13:22 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=A3=20=D0=BC=D0=B5=D0=BD=D1=8F=20=D1=82?= =?UTF-8?q?=D1=80=D0=B0=D0=B1=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + run_todobot.py | 4 +++ todobot/__init__.py | 0 todobot/bot.py | 73 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 run_todobot.py create mode 100644 todobot/__init__.py create mode 100644 todobot/bot.py diff --git a/.gitignore b/.gitignore index ab12272..b845209 100644 --- a/.gitignore +++ b/.gitignore @@ -356,3 +356,4 @@ dmypy.json # Cython debug symbols cython_debug/ +todobot/config.py diff --git a/run_todobot.py b/run_todobot.py new file mode 100644 index 0000000..9200781 --- /dev/null +++ b/run_todobot.py @@ -0,0 +1,4 @@ +from todobot.bot import main + +if __name__ == '__main__': + main() \ No newline at end of file diff --git a/todobot/__init__.py b/todobot/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/todobot/bot.py b/todobot/bot.py new file mode 100644 index 0000000..ce127ab --- /dev/null +++ b/todobot/bot.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python +# pylint: disable=unused-argument +# This program is dedicated to the public domain under the CC0 license. + +""" +Simple Bot to reply to Telegram messages. + +First, a few handler functions are defined. Then, those functions are passed to +the Application and registered at their respective places. +Then, the bot is started and runs until we press Ctrl-C on the command line. + +Usage: +Basic Echobot example, repeats messages. +Press Ctrl-C on the command line or send a signal to the process to stop the +bot. +""" + +import logging + +from telegram import ForceReply, Update +from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters + +from config import DefenceFromSkam + +# Enable logging +logging.basicConfig( + format="%(asctime)s - %(name)s - %(levelname)s - %(message)s", level=logging.INFO +) +# set higher logging level for httpx to avoid all GET and POST requests being logged +logging.getLogger("httpx").setLevel(logging.WARNING) + +logger = logging.getLogger(__name__) + + +# Define a few command handlers. These usually take the two arguments update and +# context. +async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + """Send a message when the command /start is issued.""" + user = update.effective_user + await update.message.reply_html( + rf"Салам вацок!", + reply_markup=ForceReply(selective=True), + ) + + +async def help_command(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + """Send a message when the command /help is issued.""" + await update.message.reply_text("Вацок, ты вообще перестал чувствовать.. Почувствуй!") + + +async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + """Echo the user message.""" + await update.message.reply_text(update.message.text) + + +def main() -> None: + """Start the bot.""" + # Create the Application and pass it your bot's token. + application = Application.builder().token(DefenceFromSkam).build() + + # on different commands - answer in Telegram + application.add_handler(CommandHandler("start", start)) + application.add_handler(CommandHandler("help", help_command)) + + # on non command i.e message - echo the message on Telegram + application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo)) + + # Run the bot until the user presses Ctrl-C + application.run_polling(allowed_updates=Update.ALL_TYPES) + + +if __name__ == "__main__": + main() \ No newline at end of file From 70b38f8ce1535313ad8187e34793449f8cbaf29f Mon Sep 17 00:00:00 2001 From: MateussssZ Date: Thu, 25 Apr 2024 17:20:44 +0300 Subject: [PATCH 2/2] Fix problem --- todobot/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/todobot/bot.py b/todobot/bot.py index ce127ab..72ac9d8 100644 --- a/todobot/bot.py +++ b/todobot/bot.py @@ -20,7 +20,7 @@ from telegram import ForceReply, Update from telegram.ext import Application, CommandHandler, ContextTypes, MessageHandler, filters -from config import DefenceFromSkam +from todobot.config import DefenceFromSkam # Enable logging logging.basicConfig(