From 15d6a679c504c16104bcff9a94cf8d35e82b16d7 Mon Sep 17 00:00:00 2001 From: Cameron Bernhardt Date: Tue, 25 Jun 2019 16:37:13 -0700 Subject: [PATCH] Add resize command --- bot.py | 3 +++ data.py | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/bot.py b/bot.py index 389b700..fed7dad 100644 --- a/bot.py +++ b/bot.py @@ -70,6 +70,7 @@ def process_message(self, author_id, ma, thread_id, thread_type): physics switch [name] - switch your current bottle to the bottle with [name] physics drink [name] - logs a single drink with bottle [name], does not change current bottle physics rename [name] [newname] - NOT WORKING +physics resize [name] [newsize] - gives bottle [name] a new size [newsize] (this affects all past drink events) physics list - shows all of your bottles physics decrement - remove the last drink event {} - tap emoji to log a drink, uses your current bottle @@ -83,6 +84,8 @@ def process_message(self, author_id, ma, thread_id, thread_type): data.switch_bottle(ma[2], author_id) elif ma[1] == "rename": pass + elif ma[1] == "resize": + data.resize_bottle(ma[2], ma[3], author_id) elif ma[1] == "list": get_homie_bottles(self, thread_id, thread_type, author_id) elif ma[1] == "decrement" or ma[1] == "dec": diff --git a/data.py b/data.py index e98f182..6026667 100644 --- a/data.py +++ b/data.py @@ -117,6 +117,11 @@ def get_bottle(homie_fb_id): def insert_bottle(name, size, homie_fb_id): new_bottle_sql = """INSERT INTO bottles (homie_fb_id, bottle_name, bottle_size, num_drinks) VALUES(%s, %s, %s, %s);""" return execute_statement(new_bottle_sql, [homie_fb_id, name, size, 0]) + +def resize_bottle(name, size, homie_fb_id): + bottle_entry = execute_statement("SELECT * FROM bottles WHERE homie_fb_id = %s AND bottle_name = %s;", args=(homie_fb_id, name), ret=True) + bottle_id = bottle_entry[0][0] + return execute_statement("UPDATE bottles SET bottle_size = %s WHERE bottle_id = %s", (size, bottle_id)) def delete_bottle(name, homie_fb_id): bottle_entry = execute_statement("SELECT * FROM bottles WHERE homie_fb_id = %s AND bottle_name = %s;", args=(homie_fb_id, name), ret=True)