-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbot.py
95 lines (74 loc) · 3.52 KB
/
bot.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
import os
import logging
from telegram import Update
from telegram.ext import Updater, CommandHandler, CallbackContext, PicklePersistence, MessageHandler
from telegram.ext import filters as Filters
from bot.commands import brao, random_photo, tonis, fire, odg, punti, simione, spesa, tecsone, tracker, vsv, ore_lab, custom_tags
from bot.jobs import scheduler
from bot.conversations import remindme
from bot.database.engine import engine
from bot.database.base import Base
from bot.database.session import Session
from bot.singleton import BOT
from bot.utils import escape, sudo
logger = logging.getLogger(__name__)
def start(update: Update, ctx: CallbackContext) -> None:
return brao.piacere(update, ctx)
@sudo
def info(update: Update, _: CallbackContext):
if update.message.reply_to_message is not None:
user = update.message.reply_to_message.from_user
chat_id = update.message.reply_to_message.chat_id
update.message.reply_markdown_v2(
f"full\_name\=`{escape(user.full_name)}` user\_id\=`{user.id}` chat\_id\=`{chat_id}`"
)
else:
user = update.effective_user
chat = update.effective_chat
update.message.reply_markdown_v2(f"user\_id\=`{user.id}` chat\_id\=`{chat.id}`")
def main() -> None:
Base.metadata.create_all(engine)
Session.configure(bind=engine)
persistance = PicklePersistence(filename="data/bot.pickle")
updater = Updater(os.environ["TOKEN"], persistence=persistance)
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(CommandHandler("info", info))
custom_tags.add_custom_tag(dispatcher, '@ct', custom_tags.custom_tag_ct)
custom_tags.add_custom_tag(dispatcher, '@drivers', custom_tags.custom_tag_drivers)
custom_tags.add_custom_tag(dispatcher, '@driver', custom_tags.custom_tag_drivers)
custom_tags.add_custom_tag(dispatcher, '@pm', custom_tags.custom_tag_pm)
custom_tags.add_custom_tag(dispatcher, '@hr', custom_tags.custom_tag_pm)
custom_tags.add_custom_tag(dispatcher, '@sw', custom_tags.custom_tag_sw)
custom_tags.add_custom_tag(dispatcher, '@hw', custom_tags.custom_tag_hw)
custom_tags.add_custom_tag(dispatcher, '@dmt', custom_tags.custom_tag_dmt)
custom_tags.add_custom_tag(dispatcher, '@mt', custom_tags.custom_tag_mt)
custom_tags.add_custom_tag(dispatcher, '@cm', custom_tags.custom_tag_cm)
custom_tags.add_custom_tag(dispatcher, '@mgt', custom_tags.custom_tag_mgt)
custom_tags.add_custom_tag(dispatcher, '@inlab', custom_tags.custom_tag_in_lab)
custom_tags.add_custom_tag(dispatcher, '@telemetry', custom_tags.custom_tag_wg_telemetry)
custom_tags.add_custom_tag(dispatcher, '@micro', custom_tags.custom_tag_wg_micro)
custom_tags.add_custom_tag(dispatcher, '@compositi', custom_tags.custom_tag_wg_composites)
custom_tags.add_custom_tag(dispatcher, '@powertrain', custom_tags.custom_tag_wg_powertrain)
remindme.register(dispatcher)
fire.register(dispatcher)
brao.register(dispatcher)
tonis.register(dispatcher)
odg.register(dispatcher)
punti.register(dispatcher)
simione.register(dispatcher)
tecsone.register(dispatcher)
tracker.register(dispatcher)
spesa.register(dispatcher)
vsv.register(dispatcher)
ore_lab.register(dispatcher)
random_photo.register(dispatcher)
custom_tags.register(dispatcher)
bot = dispatcher.bot
BOT.set(bot)
updater.start_polling()
scheduler.start()
updater.idle()
scheduler.shutdown()
if __name__ == "__main__":
main()