-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.py
79 lines (49 loc) · 1.84 KB
/
admin.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
from telegram import Update, InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import CallbackContext
from pymongo import *
from credentials import *
from first_time import first_time, initiate_or_join
###
# commands
###
def start(update: Update, context: CallbackContext):
context.chat_data["state"] = "start"
context.chat_data.clear()
context.chat_data["user_id"] = str(update.message.from_user.id)
context.chat_data["tele_handle"] = str(update.message.from_user.username)
print("user_id: " + context.chat_data["user_id"])
print("tele_handle: " + context.chat_data["tele_handle"])
user_identification(update, context)
return
def help(update: Update, context: CallbackContext):
context.chat_data["state"] = "help"
update.message.reply_text(
"""
Available Commands:
/start - Start Study Buddy Telegram Bot
"""
)
return
def unknown_command(update: Update, context: CallbackContext):
context.chat_data["state"] = "unknown_command"
update.message.reply_text(
"Sorry \"%s\" is not a valid command" % update.message.text)
return
def unknown_text(update: Update, context: CallbackContext):
context.chat_data["state"] = "unknown_text"
update.message.reply_text(
"Sorry I can't recognize you , you said \"%s\". Please use /start to start again." % update.message.text)
return
###
# helper functions
###
def user_identification(update, context):
context.chat_data["state"] = "user_identification"
cursor = db.users.find_one({"user_id": context.chat_data["user_id"]})
if cursor == None:
first_time(update, context)
else:
update.message.reply_text(
"Welcome back " + context.chat_data["tele_handle"] + "! What do we have planned for this week?")
initiate_or_join(update, context)
return