-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMoodBot.py
More file actions
86 lines (71 loc) · 2.58 KB
/
Copy pathMoodBot.py
File metadata and controls
86 lines (71 loc) · 2.58 KB
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
from backend import addMessage, addUser, getHistory, respondedForToday, userExists, getLatestMood
import telebot
from pprint import pprint # pprint for a prettier print
from pymongo import MongoClient
from datetime import datetime
import config
# The DB Url
mongoDBUrl = "mongodb+srv://MoodBot:MoodBot%40HackTheNorth@mooddiary.dcals.mongodb.net/MoodBot?retryWrites=true&w=majority"
client = MongoClient(mongoDBUrl)
db=client.admin
serverStatusResult=db.command("serverStatus")
pprint("Connected to the server")
user_trial = client.MoodDiaryUsers.Users.find_one({'chatId':"1234"})
print(user_trial)
bot = telebot.TeleBot(config.bot['token'], parse_mode="HTML")
isAwaitingMessage = False
# def brodcastMessage(message):
# for user in db:
# chatId = user.chatId
# bot.send_message(chat_id, message)
# Returning Help Message
def sendHelpMessage():
print("Helping!")
return "Helping!"
# Handling /start command
@bot.message_handler(commands=['start'])
def send_welcome(message):
if not userExists(message, client):
addUser(message, client)
bot.reply_to(message, "Howdy, how are you doing?")
# Handling /message command
@bot.message_handler(commands=['message'])
def send_enter_message(message):
if not userExists(message, client):
bot.reply_to(message, "Please enter /start first")
elif respondedForToday(message, client):
bot.reply_to(message, "You have already sent a response for today. See you tomorrow!")
else:
addMessage(message, client)
bot.reply_to(message, "You response for the day has been recorded!")
# Handling /help command
@bot.message_handler(commands=['help'])
def send_help_message(message):
bot.reply_to(message, sendHelpMessage())
# @bot.message_handler(commands=['mood'])
# def send_mood_message(message):
# bot.reply_to(message, getLatestMood(message, client))
@bot.message_handler(commands=['view'])
def send_view_message(message):
records = getHistory(message, client)
bot.reply_to(message, records)
# Handling unknown commands
@bot.message_handler(func=lambda message: True)
def echo_all(message):
global isAwaitingMessage
if isAwaitingMessage:
isAwaitingMessage = False
else:
bot.reply_to(message, "Invalid Command!")
# Main Method
def main():
bot.polling()
#send a daily reminder to all users
while(True):
now = datetime.datetime.now()
current_time = now.strftime("%H:%M:%S")
if current_time=='00:00:00':
print("the start of a new day")
# brodcastMessage("Good morning")
if __name__ == '__main__':
main()