From 18008b33a597c8694835a76b8ae9d3e950c0e849 Mon Sep 17 00:00:00 2001 From: Hugo Botas Date: Wed, 27 Dec 2017 00:33:58 +0000 Subject: [PATCH 1/4] Added some python flavour --- bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot.py b/bot.py index 3c62fa5..9e948c8 100644 --- a/bot.py +++ b/bot.py @@ -85,8 +85,8 @@ def populate_settings(database): db_cursor.execute( 'SELECT name, value' ' FROM Settings') - for row in db_cursor.fetchall(): - settings[row[0]] = row[1] + global settings + settings = {row[0]: row[1] for row in db_cursor.fetchall()} def populate_parser_data(database): From f00d240902f5c65b8bcba50302b97ebf0a23e6db Mon Sep 17 00:00:00 2001 From: Hugo Botas Date: Wed, 27 Dec 2017 03:05:39 +0000 Subject: [PATCH 2/4] Minor Adjustments --- bot.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/bot.py b/bot.py index 9e948c8..a6ddf0a 100644 --- a/bot.py +++ b/bot.py @@ -99,17 +99,16 @@ def populate_parser_data(database): for row in db_cursor.fetchall(): if row[2] is None and row[1] is not None: triggers[re.compile(row[0])] = lambda message, text=row[1]: client.send_message(message.channel, text) - elif row[1] is None and row[2] is not None: + elif row[2] is not None: embed = discord.Embed() embed.set_image(url=row[2]) - triggers[re.compile(row[0])] = lambda message, embed=embed: client.send_message(message.channel, - embed=embed) - elif row[1] is not None and row[2] is not None: - embed = discord.Embed() - embed.set_image(url=row[2]) - triggers[re.compile(row[0])] = lambda message, text=row[1], embed=embed: client.send_message( - message.channel, - text, - embed=embed) + if row[1] is None: + triggers[re.compile(row[0])] = lambda message, embed=embed: client.send_message(message.channel, + embed=embed) + else: + triggers[re.compile(row[0])] = lambda message, text=row[1], embed=embed: client.send_message( + message.channel, + text, + embed=embed) else: print("Invalid row: " + str(row)) From 7a39d3919fc8809fdf0eef66c5311f2e0e2d5d94 Mon Sep 17 00:00:00 2001 From: Hugo Botas Date: Wed, 27 Dec 2017 15:03:15 +0000 Subject: [PATCH 3/4] Minor Adjustments in find_student --- clip/database.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/clip/database.py b/clip/database.py index 7c7a8f5..3cca9fa 100644 --- a/clip/database.py +++ b/clip/database.py @@ -550,16 +550,12 @@ def commit(self): self.lock.release() def find_student(self, name): - nice_try = escape(name) - query_string = '%' - for word in nice_try.split(): - query_string += (word + '%') - + query_string = "%{0}%".format("%".join(name.split())) self.lock.acquire() try: self.cursor.execute("SELECT internal_id, name, abbreviation " "FROM Students " - "WHERE name LIKE '{}'".format(query_string)) + "WHERE name LIKE '?'", (query_string, )) return set(self.cursor.fetchall()) finally: - self.lock.release() \ No newline at end of file + self.lock.release() From 7d8e3006a10815869c24e8ad4b0c18c73d7596a0 Mon Sep 17 00:00:00 2001 From: Hugo Botas Date: Wed, 27 Dec 2017 15:04:13 +0000 Subject: [PATCH 4/4] Typo in fetch_class_instances's finally block --- clip/database.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clip/database.py b/clip/database.py index 3cca9fa..7239fae 100644 --- a/clip/database.py +++ b/clip/database.py @@ -539,7 +539,7 @@ def fetch_class_instances(self): 'institution': instance[6] }) finally: - self.lock.acquire() + self.lock.release() return class_instances def commit(self):