From 05755774df9b1b02b0b074dab4f95da6ad8f2173 Mon Sep 17 00:00:00 2001 From: Cameron Bernhardt Date: Mon, 17 Jun 2019 12:17:46 -0700 Subject: [PATCH 1/4] Add thumbs up for drink commands --- bot.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 389b700..091bfeb 100644 --- a/bot.py +++ b/bot.py @@ -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] @@ -91,6 +91,7 @@ def process_message(self, author_id, ma, thread_id, thread_type): homie_increment(self, thread_id, thread_type, author_id) elif ma[1] == "drink": data.insert_drink(author_id, bottle_name=ma[2]) + self.reactToMessage(message_object.uid, '👍') elif ma[1] == "stats": verbose_list = ["-v", "full", "verbose", "--verbose"] if len(ma)>2 and ma[2] in verbose_list: From edadce09a5ad563a6395933b1ffaa06f09b73862 Mon Sep 17 00:00:00 2001 From: Cameron Bernhardt Date: Mon, 17 Jun 2019 12:25:19 -0700 Subject: [PATCH 2/4] Check for success --- bot.py | 4 ++-- data.py | 14 +++++++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/bot.py b/bot.py index 091bfeb..19bc070 100644 --- a/bot.py +++ b/bot.py @@ -90,8 +90,8 @@ def process_message(self, author_id, ma, thread_id, thread_type, message_object) 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]) - self.reactToMessage(message_object.uid, '👍') + if data.insert_drink(author_id, bottle_name=ma[2]): + self.reactToMessage(message_object.uid, '👍') elif ma[1] == "stats": verbose_list = ["-v", "full", "verbose", "--verbose"] if len(ma)>2 and ma[2] in verbose_list: diff --git a/data.py b/data.py index e98f182..5426d99 100644 --- a/data.py +++ b/data.py @@ -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) From d6e9d94cde8ed7d45c5dd735a1eb4e0f6672964c Mon Sep 17 00:00:00 2001 From: Cameron Bernhardt Date: Mon, 24 Jun 2019 16:40:42 -0700 Subject: [PATCH 3/4] Fixes and add to switch --- bot.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 19bc070..7b3a814 100644 --- a/bot.py +++ b/bot.py @@ -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 @@ -81,6 +81,7 @@ def process_message(self, author_id, ma, thread_id, thread_type, message_object) data.delete_bottle(ma[2], author_id) 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": @@ -91,7 +92,7 @@ def process_message(self, author_id, ma, thread_id, thread_type, message_object) homie_increment(self, thread_id, thread_type, author_id) elif ma[1] == "drink": if data.insert_drink(author_id, bottle_name=ma[2]): - self.reactToMessage(message_object.uid, '👍') + 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: From 31dada08a3ca2e11567013809a90e13e4071ea0c Mon Sep 17 00:00:00 2001 From: Cameron Bernhardt Date: Mon, 24 Jun 2019 16:42:40 -0700 Subject: [PATCH 4/4] Add to remove --- bot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/bot.py b/bot.py index 7b3a814..82a8e13 100644 --- a/bot.py +++ b/bot.py @@ -79,6 +79,7 @@ def process_message(self, author_id, ma, thread_id, thread_type, message_object) 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)