-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.py
91 lines (79 loc) · 2.85 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import logging
from telegram import Update
from telegram.ext import (
ApplicationBuilder,
CallbackContext,
CommandHandler,
MessageHandler,
filters
)
#
from components.fetch import fetch_token
from commands.source import source
from commands.getid import getID, getGroupID
from commands.history import history
from commands.certs import certs
from commands.juna import juna
from commands.remove import *
from commands.add import *
logger = logging.getLogger("UdeCursosBot")
logger.setLevel(logging.DEBUG)
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - (%(name)s) - [%(levelname)s] -- %(message)s')
console_handler.setFormatter(formatter)
logger.addHandler(console_handler)
logging.basicConfig(
filename="logs/console.log",
format="%(asctime)s - (%(name)s) - [%(levelname)s] -- %(message)s",
datefmt='%m/%d/%Y %I:%M:%S %p',
)
async def start(update: Update, context: CallbackContext):
logger.info(
f"{update.message.text} <- User @{update.effective_user.username} ({update.effective_user.first_name}) started the bot"
)
await context.bot.send_message(
chat_id=update.effective_chat.id,
text=(
"👋 ¡Hey, aquí UdeCursos Bot!\n\n"
"Todo listo para comenzar ✅\n"
"_Para obtener ayuda escribe /udecursos_ \n\n"
"No olvides visitarme en: [UdeCursos.study](https://udecursos.study/) 🔗 !"
),
parse_mode='Markdown'
)
if __name__ == "__main__":
logger.info("Starting bot...")
bot = (
ApplicationBuilder()
.token(fetch_token())
.build()
)
logger.info("Adding handlers...")
bot.add_handler(CommandHandler("start", start))
bot.add_handler(CommandHandler("source", source))
bot.add_handler(CommandHandler("myid", getID))
bot.add_handler(CommandHandler("groupid", getGroupID))
bot.add_handler(CommandHandler("certs", certs))
bot.add_handler(CommandHandler("history", history))
bot.add_handler(CommandHandler("juna", juna))
add_conv = ConversationHandler(
entry_points=[CommandHandler('add', add)],
states={
CERT_INFO: [MessageHandler(filters.TEXT, cert_info)],
ADD_CERT: [MessageHandler(filters.TEXT, cert_operation)]
},
fallbacks=[CommandHandler('cancel', cancel)]
)
remove_conv = ConversationHandler(
entry_points=[CommandHandler('remove', remove)],
states={
REMOVE_CONFIRM: [MessageHandler(filters.TEXT, remove_confirm)], # Pending Regex filter
REMOVE_CERT: [MessageHandler(filters.Regex("^(👍|❌)$"), remove_cert)]
},
fallbacks=[CommandHandler('cancel', cancel)]
)
bot.add_handler(add_conv)
bot.add_handler(remove_conv)
logger.info("Starting polling...")
bot.run_polling()