forked from UNICT-DMI/FinderUniCT-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
58 lines (47 loc) · 1.76 KB
/
main.py
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
54
55
56
57
58
"""
main module
"""
from module.commands import start, report, help, register_conv_handler
from module.data import HELP, REPORT
from telegram import BotCommand, Update
from telegram.ext import filters, Application, ApplicationBuilder, CommandHandler, MessageHandler, ContextTypes
async def add_commands(app: Application) -> None:
"""
Adds a list of commands with their description to the bot
Args:
app (Application): the built application
"""
commands = [
BotCommand("start", "messaggio di benvenuto"),
BotCommand("help", "ricevi aiuto sui comandi"),
BotCommand("report", "segnala un problema"),
BotCommand("register", "procedura di registrazione")
]
await app.bot.set_my_commands(commands)
def add_handlers(app: Application) -> None:
"""
Adds all the handlers to the bot
Args:
app (Application): the built application
"""
async def chatid(update: Update, context: ContextTypes.DEFAULT_TYPE):
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=str(update.effective_chat.id)
)
handlers = [
CommandHandler("start", start, filters.ChatType.PRIVATE),
CommandHandler("chatid", chatid),
CommandHandler("help", help, filters.ChatType.PRIVATE),
MessageHandler(filters.Regex(HELP) & filters.ChatType.PRIVATE, help),
CommandHandler("report", report),
MessageHandler(filters.Regex(REPORT) & filters.ChatType.PRIVATE, report),
register_conv_handler()
]
app.add_handlers(handlers)
def main():
app = ApplicationBuilder().token("TOKEN").post_init(add_commands).build()
add_handlers(app)
app.run_polling()
if __name__ == "__main__":
main()