Fixed issue where entering an empty string would cause issues

doc_update
Joey Hines 2018-10-16 17:22:11 -05:00
parent 219c993989
commit 517cb21f14
8 changed files with 34 additions and 12 deletions

View File

@ -77,3 +77,6 @@ class NoLocationsInDatabase(DataBaseError):
class FuckyWucky:
"""You made one."""
class EmptryString(DataBaseError):
"""Empty string provided"""

View File

@ -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:

View File

@ -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):

View File

@ -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):

View File

@ -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):

View File

@ -1,6 +1,6 @@
from unittest import TestCase
from DiscordHelperFunctions import get_nickname
from geoffrey.DiscordHelperFunctions import get_nickname
class TestGet_nickname(TestCase):

View File

@ -1,6 +1,6 @@
from unittest import TestCase
from MinecraftAccountInfoGrabber import *
from geoffrey.MinecraftAccountInfoGrabber import *
class TestMinecraftInfoGrabber(TestCase):

View File

@ -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