Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thumbs up for "drink", "switch", and "remove" commands #12

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import sys

from fbchat import Client, log
from fbchat.models import Message, ThreadType
from fbchat.models import Message, ThreadType, MessageReaction

import data

Expand Down Expand Up @@ -44,12 +44,12 @@ def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs)
ma = messageText.split() # message array

if ma[0].lower() == "physics":
process_message(self, author_id, ma, thread_id, thread_type)
process_message(self, author_id, ma, thread_id, thread_type, message_object)
elif messageText == client.fetchThreadInfo(thread_id)[thread_id].emoji:
homie_increment(self, thread_id, thread_type, author_id)
super(HydroBot, self).onMessage(author_id=author_id, message_object=message_object, thread_id=thread_id, thread_type=thread_type, **kwargs)

def process_message(self, author_id, ma, thread_id, thread_type):
def process_message(self, author_id, ma, thread_id, thread_type, message_object):
if author_id != self.uid:
print(ma)
user = self.fetchUserInfo(author_id)[author_id]
Expand Down Expand Up @@ -79,8 +79,10 @@ def process_message(self, author_id, ma, thread_id, thread_type):
data.insert_bottle(ma[2], ma[3], author_id)
elif ma[1] == "remove":
data.delete_bottle(ma[2], author_id)
self.reactToMessage(message_object.uid, MessageReaction.YES)
elif ma[1] == "switch":
data.switch_bottle(ma[2], author_id)
self.reactToMessage(message_object.uid, MessageReaction.YES)
elif ma[1] == "rename":
pass
elif ma[1] == "list":
Expand All @@ -90,7 +92,8 @@ def process_message(self, author_id, ma, thread_id, thread_type):
elif ma[1] == "increment" or ma[1] == "inc":
homie_increment(self, thread_id, thread_type, author_id)
elif ma[1] == "drink":
data.insert_drink(author_id, bottle_name=ma[2])
if data.insert_drink(author_id, bottle_name=ma[2]):
self.reactToMessage(message_object.uid, MessageReaction.YES)
elif ma[1] == "stats":
verbose_list = ["-v", "full", "verbose", "--verbose"]
if len(ma)>2 and ma[2] in verbose_list:
Expand Down
14 changes: 9 additions & 5 deletions data.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ def insert_drink(homie_fb_id, bottle_name=None):
bottle_entry = execute_statement("SELECT * FROM bottles WHERE homie_fb_id = %s AND bottle_name = %s;", args=(homie_fb_id, bottle_name), ret=True)
bottle_id = bottle_entry[0][0]

# Adds a drink event with the currently selected bottle id
add_drink_sql = """INSERT INTO drinks (homie_fb_id, bottle_id) VALUES(%s, %s);"""
execute_statement(add_drink_sql, (homie_fb_id, bottle_id))
# Updates the total number of drink events logged by that bottle
execute_statement("UPDATE bottles set num_drinks = num_drinks+1 WHERE homie_fb_id = %s AND bottle_id = %s;", args=(homie_fb_id, bottle_id))
if bottle_id:
# Adds a drink event with the currently selected bottle id
add_drink_sql = """INSERT INTO drinks (homie_fb_id, bottle_id) VALUES(%s, %s);"""
execute_statement(add_drink_sql, (homie_fb_id, bottle_id))
# Updates the total number of drink events logged by that bottle
execute_statement("UPDATE bottles set num_drinks = num_drinks+1 WHERE homie_fb_id = %s AND bottle_id = %s;", args=(homie_fb_id, bottle_id))
return True
else:
return False

def insert_homie(homie_fb_id, homie_name):
insert_bottle("NULL", "0", homie_fb_id)
Expand Down