-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean_bot_template.py
More file actions
53 lines (41 loc) · 1.72 KB
/
clean_bot_template.py
File metadata and controls
53 lines (41 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
from telegram import Update, BotCommand
from telegram.ext import (
Application,
CommandHandler,
ContextTypes,
filters
)
async def start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
"""start template"""
pass
async def command1(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
pass
async def command2(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
pass
# Функция для регистрации команд в BotFather
async def post_init(application: Application) -> None:
bot_commands = [
BotCommand("start", "Начало работы с ботом")
]
await application.bot.set_my_commands(bot_commands)
def main() -> None:
""""""
# создаем приложение
application = Application.builder().token(os.getenv("BOT_TOKEN")).post_init(post_init).build()
# добавляем обработчики
application.add_handler(CommandHandler("start", start))
application.add_handler(CommandHandler("command1", command1))
application.add_handler(CommandHandler("command2", command2))
# можно добавить отдельные обработки чего угодно
# сообщения, но не команды
## application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
# местоположения
## application.add_handler(MessageHandler(filters.LOCATION, location))
# изображения
## application.add_handler(MessageHandler(filters.ATTACHMENT, attachment))
# и тд
# Запускаем до нажатия Ctrl-C
application.run_polling(allowed_updates=Update.ALL_TYPES)
if __name__ == "__main__":
main()