From 517cb21f149d0e8a26c3dbdddfe0551536309b96 Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Tue, 16 Oct 2018 17:22:11 -0500 Subject: [PATCH] Fixed issue where entering an empty string would cause issues --- geoffrey/BotErrors.py | 3 +++ geoffrey/Commands.py | 19 ++++++++++++++++++- geoffrey/bot.py | 2 ++ geoffrey/tests/test_commands.py | 6 +++--- geoffrey/tests/test_geoffreyDatabase.py | 6 +++--- geoffrey/tests/test_get_nickname.py | 2 +- geoffrey/tests/test_minecraftInfoGrabber.py | 2 +- geoffrey/tests/test_stress.py | 6 +++--- 8 files changed, 34 insertions(+), 12 deletions(-) diff --git a/geoffrey/BotErrors.py b/geoffrey/BotErrors.py index 8ab3146..a375263 100644 --- a/geoffrey/BotErrors.py +++ b/geoffrey/BotErrors.py @@ -77,3 +77,6 @@ class NoLocationsInDatabase(DataBaseError): class FuckyWucky: """You made one.""" + +class EmptryString(DataBaseError): + """Empty string provided""" diff --git a/geoffrey/Commands.py b/geoffrey/Commands.py index 0e1dfb2..b989a0f 100644 --- a/geoffrey/Commands.py +++ b/geoffrey/Commands.py @@ -10,6 +10,11 @@ def list_to_string(loc_list, str_format='{}\n{}'): return loc_string +def checkIfEmpty(str): + if len(str) == 0: + raise EmptryString + + class Commands: def __init__(self, bot_config, debug=False): self.bot_config = bot_config @@ -69,6 +74,8 @@ class Commands: elif base_name is None: raise EntryNameNotUniqueError + checkIfEmpty(base_name) + base = self.interface.add_loc(session, player, base_name, x_pos, z_pos, loc_type=Base) base_str = base.__str__() @@ -89,6 +96,7 @@ class Commands: elif shop_name is None: raise EntryNameNotUniqueError + checkIfEmpty(shop_name) shop = self.interface.add_loc(session, player, shop_name, x_pos, z_pos, loc_type=Shop) shop_name = shop.__str__() @@ -107,6 +115,7 @@ class Commands: loc = self.get_location(session, player, name=location_name) location_name = loc.name + checkIfEmpty(location_name) tunnel = self.interface.add_tunnel(session, player, tunnel_direction, tunnel_number, location_name) tunnel_info = tunnel.__str__() @@ -118,6 +127,7 @@ class Commands: def find(self, search): limit = 25 session = self.interface.database.Session() + checkIfEmpty(search) try: locations = self.interface.search_all_fields(session, search, limit) locations_string = '' @@ -137,8 +147,8 @@ class Commands: return locations_string def delete(self, name, discord_uuid=None, mc_uuid=None): - session = self.interface.database.Session() + checkIfEmpty(name) try: player = self.get_player(session, discord_uuid, mc_uuid) self.interface.delete_location(session, player, name) @@ -160,6 +170,7 @@ class Commands: def add_item(self, item_name, quantity, diamond_price, shop_name=None, discord_uuid=None, mc_uuid=None): session = self.interface.database.Session() + checkIfEmpty(item_name) try: player = self.get_player(session, discord_uuid, mc_uuid) @@ -176,6 +187,10 @@ class Commands: session = self.interface.database.Session() try: + + if len(item_name) == 0: + raise EmptryString + shop_list = self.interface.find_top_shops_selling_item(session, item_name) if len(shop_list) == 0: @@ -199,6 +214,8 @@ class Commands: def info(self, location_name): session = self.interface.database.Session() try: + if len(location_name) == 0: + raise EmptryString loc = self.interface.find_location_by_name_closest_match(session, location_name).full_str(self.bot_config) finally: diff --git a/geoffrey/bot.py b/geoffrey/bot.py index ca0cb54..02006be 100644 --- a/geoffrey/bot.py +++ b/geoffrey/bot.py @@ -103,6 +103,8 @@ class GeoffreyBot(commands.Bot): elif isinstance(error.original, OperationalError): await self.send_error_message('Error connecting to the MySQL server, is it offline?') error_str = 'Database connection issue, looks like some admin has to fix something.'.format() + elif isinstance(error.original, EmptryString): + error_str = 'Do not not pass empty string to Geoffrey. Ding dong.' elif isinstance(error, commands.CommandOnCooldown): return elif isinstance(error, commands.UserInputError): diff --git a/geoffrey/tests/test_commands.py b/geoffrey/tests/test_commands.py index 2c017b6..e36b47e 100644 --- a/geoffrey/tests/test_commands.py +++ b/geoffrey/tests/test_commands.py @@ -1,10 +1,10 @@ import os from unittest import TestCase -from Commands import * -from BotConfig import get_config +from geoffrey.Commands import * +from geoffrey.BotConfig import get_config -zerohd = 'birbhd' +zerohd = 'zerohd' class TestCommands(TestCase): def setUp(self): diff --git a/geoffrey/tests/test_geoffreyDatabase.py b/geoffrey/tests/test_geoffreyDatabase.py index e71ab81..e707cf3 100644 --- a/geoffrey/tests/test_geoffreyDatabase.py +++ b/geoffrey/tests/test_geoffreyDatabase.py @@ -1,10 +1,10 @@ import os from unittest import TestCase -from DatabaseInterface import * -from BotConfig import * +from geoffrey.DatabaseInterface import * +from geoffrey.BotConfig import * -zerohd = 'BirbHD' +zerohd = 'zerohd' class TestGeoffreyDatabase(TestCase): diff --git a/geoffrey/tests/test_get_nickname.py b/geoffrey/tests/test_get_nickname.py index ea040eb..0e2684b 100644 --- a/geoffrey/tests/test_get_nickname.py +++ b/geoffrey/tests/test_get_nickname.py @@ -1,6 +1,6 @@ from unittest import TestCase -from DiscordHelperFunctions import get_nickname +from geoffrey.DiscordHelperFunctions import get_nickname class TestGet_nickname(TestCase): diff --git a/geoffrey/tests/test_minecraftInfoGrabber.py b/geoffrey/tests/test_minecraftInfoGrabber.py index 41bf5cc..19d65f4 100644 --- a/geoffrey/tests/test_minecraftInfoGrabber.py +++ b/geoffrey/tests/test_minecraftInfoGrabber.py @@ -1,6 +1,6 @@ from unittest import TestCase -from MinecraftAccountInfoGrabber import * +from geoffrey.MinecraftAccountInfoGrabber import * class TestMinecraftInfoGrabber(TestCase): diff --git a/geoffrey/tests/test_stress.py b/geoffrey/tests/test_stress.py index c83ca55..36aabeb 100644 --- a/geoffrey/tests/test_stress.py +++ b/geoffrey/tests/test_stress.py @@ -1,8 +1,8 @@ from unittest import TestCase import os -from Commands import * -from BotConfig import get_config -from MinecraftAccountInfoGrabber import * +from geoffrey.Commands import * +from geoffrey.BotConfig import get_config +from Mgeoffrey.inecraftAccountInfoGrabber import * from time import sleep