-
Notifications
You must be signed in to change notification settings - Fork 6
/
telegramBot.py
103 lines (78 loc) · 3.3 KB
/
telegramBot.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
from telegram.ext import Updater, CommandHandler, MessageHandler, Filters, run_async
from GoogleMeet import *
# @run_async
# def restart(update, context):
# restart_message = context.bot.send_message(chat_id=update.message.chat_id, text="Restarting, Please wait!")
def start(update, context):
main()
update.message.reply_text('Starting the class')
# def startdb(update, context):
# conn = sqlite3.connect('checktt.db', check_same_thread=False)
# db = conn.cursor()
# update.message.reply_text('Connection with database established')
# def stopdb(update, context):
# conn.close()
# update.message.reply_text('Connection with database closed')
def help(update, context):
update.message.reply_text('/start : Start automatic session')
update.message.reply_text('/tt day s1 s2 s3 s4 s5 s6 : Change timetable for anyday')
update.message.reply_text('/dtt : Drop temp tables')
update.message.reply_text('/ctt : Create temp tables')
update.message.reply_text('/timetable : View current day timetable')
# update.message.reply_text('/startdb : Start connection with database')
# update.message.reply_text('/stopdb : Drop connection with database')
def ttChange(update, context):
conn = sqlite3.connect('checktt.db', check_same_thread=False)
db = conn.cursor()
data = update.message.text.split()
day = data[1]
s1 = data[2]
s2 = data[3]
s3 = data[4]
s4 = data[5]
s5 = data[6]
print(day, s1, s2, s3, s4, s5)
modifyTempTimeTable(day, s1, s2, s3, s4, s5)
update.message.reply_text('Time table modified')
subjects = printTimetable()
print(subjects)
day = datetime.datetime.now().strftime("%A")
text = ""+ subjects[0]+ " - "+ subjects[1]+ " - "+ subjects[2] + " - " + subjects[3] + " - " + subjects[4]
update.message.reply_text(day + " : "+ text)
sendDiscord("Time table modified")
conn.close()
def dtt(update, context):
conn = sqlite3.connect('checktt.db', check_same_thread=False)
db = conn.cursor()
dropTempTimeTable()
conn.close()
update.message.reply_text('Dropped all temp tables')
def ctt(update, context):
conn = sqlite3.connect('checktt.db', check_same_thread=False)
db = conn.cursor()
createTempTimeTable()
conn.close()
update.message.reply_text('Created all temp tables')
def timetable(update, context):
conn = conn = sqlite3.connect('checktt.db', check_same_thread=False)
db = conn.cursor()
subjects = printTimetable()
print(subjects)
day = datetime.datetime.now().strftime("%A")
text = ""+ subjects[0]+ " - "+ subjects[1]+ " - "+ subjects[2] + " - " + subjects[3] + " - " + subjects[4]
update.message.reply_text(day + " : "+ text)
conn.close()
updater = Updater(TELEGRAM_TOKEN, use_context=True)
# Get the dispatcher to register handlers
dp = updater.dispatcher
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("tt", ttChange))
dp.add_handler(CommandHandler("help", help))
dp.add_handler(CommandHandler("dtt", dtt))
dp.add_handler(CommandHandler("ctt", ctt))
dp.add_handler(CommandHandler("timetable", timetable))
# dp.add_handler(CommandHandler("startdb", startdb))
# dp.add_handler(CommandHandler("stopdb", stopdb))
# Start the Bot
updater.start_polling()
print("Start doing your thing!")