-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
139 lines (115 loc) · 4.19 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from telegram.ext import CommandHandler, MessageHandler, Filters, CallbackQueryHandler
import data
from bot import updater, dp
from config.auth import admin_ids, group_id, debug
from commands.acronym import desiglar, siglar, glosario, confirm_siglar
from commands.admin import get_log, prohibir
from commands.counter import contador, sumar, restar
from commands.list import lista, agregar, quitar, editar, deslistar
from commands.response import start, tup, gracias, weekly_poll, reply_hello
from commands.summary import resumir, noticia, confirm_resumir
from commands.text import slashear, uwuspeech, repetir, distancia
from commands.gpt import reply_gpt, reply_fill, desigliar
from commands.stats import stats, stats_detail
from commands.weather import weather, enable_weather
def add_command(command: str | list[str], callback: callable, **kwargs):
"""
Helper: Adds a command with one or more aliases to the dispatcher.
"""
if isinstance(command, list):
for c in command:
dp.add_handler(CommandHandler(c, callback, **kwargs))
else:
dp.add_handler(CommandHandler(command, callback, **kwargs))
def receive_message(update, context):
"""
Receives a message and stores it in the database.
This doesn't receive messages from the bot itself.
"""
author_id = update.message.from_user.id
author_username = update.message.from_user.username
if update.message.forward_from:
author_id = update.message.forward_from.id
author_username = update.message.forward_from.username
elif update.message.forward_sender_name:
author_id = 0
author_username = update.message.forward_sender_name
if update.message.text is not None:
data.Messages.add(
update.message.message_id,
update.message.date,
author_id,
author_username,
update.message.text,
(
update.message.reply_to_message.message_id
if update.message.reply_to_message
else None
),
)
def main():
data.init()
# Acronym
add_command("desiglar", desiglar)
add_command("siglar", siglar)
dp.add_handler(CallbackQueryHandler(confirm_siglar, pattern="siglar:.*"))
add_command("glosario", glosario)
# Admin
add_command("get_log", get_log, filters=Filters.user(admin_ids))
add_command("prohibir", prohibir)
# Counter
add_command("contador", contador)
add_command(["sumar", "incrementar"], sumar)
add_command(["restar", "decrementar"], restar)
# List
add_command(["lista", "listar"], lista)
add_command("agregar", agregar)
add_command("quitar", quitar)
add_command("editar", editar)
add_command(["deslistar", "cerrar"], deslistar)
# Text
add_command(["uwuspeech", "uwuspeak", "uwuizar", "uwu"], uwuspeech)
add_command("slashear", slashear)
add_command("repetir", repetir)
add_command("distancia", distancia)
# Response
add_command("tup", tup)
add_command("start", start)
add_command(["gracias", "garcias"], gracias)
add_command("asistencia", weekly_poll)
add_command("hello", reply_hello)
# AI
add_command("gpt", reply_gpt)
add_command("gb", reply_fill)
add_command("desigliar", desigliar)
# Summary
add_command("resumir", resumir)
add_command(["noticia", "noticias", "quepaso"], noticia)
# Weather
add_command("habilitar_clima", enable_weather)
# Stats
add_command("stats", stats)
add_command("stats_detail", stats_detail)
dp.add_handler(
CallbackQueryHandler(confirm_resumir, pattern=".*(confirm|cancel)_summary.*")
)
# Message handler to store messages in the database.
dp.add_handler(
MessageHandler(
(
(
Filters.text
& Filters.chat_type.groups
& Filters.chat(chat_id=group_id)
)
if not debug
else Filters.text
),
receive_message,
),
group=1,
) # Group must be != 0 so it doesn't conflict with command handlers.
updater.start_polling()
updater.idle()
if __name__ == "__main__":
main()