-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
62 lines (48 loc) · 2.35 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
from telegram.ext import Updater
from telegram.ext import CommandHandler, CallbackQueryHandler, MessageHandler, Filters
import telegram
import json
from sqlalchemy import func
from database import engine, Thought, create_tables
from thoughtmanager import ThoughtManager
from tips import tip, button
from informations import welcomemsg, helpmsg
from pushNotifications import add_notification_handler, remove_notification_handler
from telegram.ext import MessageHandler, Filters
"""
HELP
The Updater class continuously fetches new updates from telegram and passes them on to the Dispatcher class.
If you create an Updater object, it will create a Dispatcher for you and link them together with a Queue.
You can then register handlers of different types in the Dispatcher,
which will sort the updates fetched by the Updater according to the handlers you registered,
and deliver them to a callback function that you defined.
"""
# Init
with open("token.json", "r") as file:
data = json.load(file)
updater = Updater(token=data["bot_token"], use_context=True)
dispatcher = updater.dispatcher
tm = ThoughtManager()
if not engine.dialect.has_table(engine, "thoughts"):
create_tables()
# # Def a method that only sends a message
# def start(update, context):
# context.bot.send_message(chat_id=update.effective_chat.id, text="QuarantinTips!")
# Attach the method to a handler
# The bot executes the method everytime it receives the \start command
updater.dispatcher.add_handler(CommandHandler("start", welcomemsg))
dispatcher.add_handler(CommandHandler("help", helpmsg))
updater.dispatcher.add_handler(CommandHandler('tip', tip))
updater.dispatcher.add_handler(CallbackQueryHandler(button))
updater.dispatcher.add_handler(CommandHandler('pensiero', tm.thought_handler))
updater.dispatcher.add_handler(CommandHandler('listapensieri', tm.get_thoughts_list))
updater.dispatcher.add_handler(CommandHandler('pensierorandom', tm.get_random_though))
updater.dispatcher.add_handler(CommandHandler('promemoriagiornaliero', add_notification_handler))
updater.dispatcher.add_handler(CommandHandler('cancellapromemoria', remove_notification_handler))
# start_handler = CommandHandler('start', start)
# dispatcher.add_handler(start_handler)
# Start the bot
updater.start_polling()
# Run the bot until the user presses Ctrl-C or the process receives SIGINT,
# SIGTERM or SIGABRT
updater.idle()