From 76709cbdc7f3ce58ec9d1d54485218d6e2026e96 Mon Sep 17 00:00:00 2001 From: TolaMironcenko Date: Wed, 19 Oct 2022 22:44:32 +0700 Subject: [PATCH] initial commit --- .gitignore | 3 +++ README.md | 1 + bot.py | 5 +++++ changelocale.py | 11 +++++++++++ locale.py | 23 +++++++++++++++++++++++ main.py | 38 ++++++++++++++++++++++++++++++++++++++ requirements.txt | 7 +++++++ 7 files changed, 88 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 bot.py create mode 100644 changelocale.py create mode 100644 locale.py create mode 100644 main.py create mode 100644 requirements.txt diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1dc13fb --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*venv +*__pycache__ +*.idea diff --git a/README.md b/README.md new file mode 100644 index 0000000..9c8e0ce --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# FINANCE TELEGRAM BOT diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..5be2377 --- /dev/null +++ b/bot.py @@ -0,0 +1,5 @@ +import telebot + +TOKEN = '5123679189:AAHTMxCyOUwPSbaeof31m8SjRHVs4qKZci8' + +bot = telebot.TeleBot(TOKEN) \ No newline at end of file diff --git a/changelocale.py b/changelocale.py new file mode 100644 index 0000000..10470db --- /dev/null +++ b/changelocale.py @@ -0,0 +1,11 @@ +from bot import bot +import locale + + +def change_locale(message): + if message.text.split(' ')[0] == '/ru': + locale.LOCALE = 'ru' + bot.send_message(message.chat.id, 'Выбран русский язык') + elif message.text.split(' ')[0] == '/en': + locale.LOCALE = 'en' + bot.send_message(message.chat.id, 'Selected language: english') diff --git a/locale.py b/locale.py new file mode 100644 index 0000000..a9cb67d --- /dev/null +++ b/locale.py @@ -0,0 +1,23 @@ +LOCALE = 'ru' + +ru = { + 'help_message': + ''' +Привет я бот для управления твоими финансами и вот что я умею: +/help - показать этот список. +/ru - русский язык +/en - английский язык + ''', + 'error404_message': 'Я не могу это сделать.' +} + +en = { + 'help_message': + ''' +Hi i am finance bot and i can do this: +/help - open this list +/ru - russian language +/en - english language + ''', + 'error404_message': 'I can\'t do this.' +} diff --git a/main.py b/main.py new file mode 100644 index 0000000..283e90a --- /dev/null +++ b/main.py @@ -0,0 +1,38 @@ +from termcolor import cprint +from bot import bot +import locale +from changelocale import change_locale + + +def main_bot(messages): + for message in messages: + if message.text.split(' ')[0] == '/start' or message.text.split(' ')[0] == '/help': + mes = None + if locale.LOCALE == 'ru': + mes = locale.ru['help_message'] + elif locale.LOCALE == 'en': + mes = locale.en['help_message'] + bot.send_message(message.chat.id, mes) + elif message.text.split(' ')[0] == '/ru' or message.text.split(' ')[0] == '/en': + change_locale(message) + else: + mes = None + if locale.LOCALE == 'ru': + mes = locale.ru['error404_message'] + elif locale.LOCALE == 'en': + mes = locale.en['error404_message'] + bot.send_message(message.chat.id, mes) + + +bot.set_update_listener(main_bot) + +try: + bot.polling(none_stop=True) +except KeyboardInterrupt: + exit('byby\n') +except Exception as e: + cprint(str(e), 'red') + bot.polling(none_stop=True) + +while True: + pass diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..8ee58cb --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +certifi==2022.9.24 +charset-normalizer==2.1.1 +idna==3.4 +pyTelegramBotAPI==4.7.0 +requests==2.28.1 +termcolor==2.0.1 +urllib3==1.26.12