Fixed issue where entering an empty string would cause issues
parent
219c993989
commit
517cb21f14
|
@ -77,3 +77,6 @@ class NoLocationsInDatabase(DataBaseError):
|
||||||
|
|
||||||
class FuckyWucky:
|
class FuckyWucky:
|
||||||
"""You made one."""
|
"""You made one."""
|
||||||
|
|
||||||
|
class EmptryString(DataBaseError):
|
||||||
|
"""Empty string provided"""
|
||||||
|
|
|
@ -10,6 +10,11 @@ def list_to_string(loc_list, str_format='{}\n{}'):
|
||||||
return loc_string
|
return loc_string
|
||||||
|
|
||||||
|
|
||||||
|
def checkIfEmpty(str):
|
||||||
|
if len(str) == 0:
|
||||||
|
raise EmptryString
|
||||||
|
|
||||||
|
|
||||||
class Commands:
|
class Commands:
|
||||||
def __init__(self, bot_config, debug=False):
|
def __init__(self, bot_config, debug=False):
|
||||||
self.bot_config = bot_config
|
self.bot_config = bot_config
|
||||||
|
@ -69,6 +74,8 @@ class Commands:
|
||||||
elif base_name is None:
|
elif base_name is None:
|
||||||
raise EntryNameNotUniqueError
|
raise EntryNameNotUniqueError
|
||||||
|
|
||||||
|
checkIfEmpty(base_name)
|
||||||
|
|
||||||
base = self.interface.add_loc(session, player, base_name, x_pos, z_pos, loc_type=Base)
|
base = self.interface.add_loc(session, player, base_name, x_pos, z_pos, loc_type=Base)
|
||||||
|
|
||||||
base_str = base.__str__()
|
base_str = base.__str__()
|
||||||
|
@ -89,6 +96,7 @@ class Commands:
|
||||||
elif shop_name is None:
|
elif shop_name is None:
|
||||||
raise EntryNameNotUniqueError
|
raise EntryNameNotUniqueError
|
||||||
|
|
||||||
|
checkIfEmpty(shop_name)
|
||||||
shop = self.interface.add_loc(session, player, shop_name, x_pos, z_pos, loc_type=Shop)
|
shop = self.interface.add_loc(session, player, shop_name, x_pos, z_pos, loc_type=Shop)
|
||||||
|
|
||||||
shop_name = shop.__str__()
|
shop_name = shop.__str__()
|
||||||
|
@ -107,6 +115,7 @@ class Commands:
|
||||||
loc = self.get_location(session, player, name=location_name)
|
loc = self.get_location(session, player, name=location_name)
|
||||||
location_name = loc.name
|
location_name = loc.name
|
||||||
|
|
||||||
|
checkIfEmpty(location_name)
|
||||||
tunnel = self.interface.add_tunnel(session, player, tunnel_direction, tunnel_number, location_name)
|
tunnel = self.interface.add_tunnel(session, player, tunnel_direction, tunnel_number, location_name)
|
||||||
tunnel_info = tunnel.__str__()
|
tunnel_info = tunnel.__str__()
|
||||||
|
|
||||||
|
@ -118,6 +127,7 @@ class Commands:
|
||||||
def find(self, search):
|
def find(self, search):
|
||||||
limit = 25
|
limit = 25
|
||||||
session = self.interface.database.Session()
|
session = self.interface.database.Session()
|
||||||
|
checkIfEmpty(search)
|
||||||
try:
|
try:
|
||||||
locations = self.interface.search_all_fields(session, search, limit)
|
locations = self.interface.search_all_fields(session, search, limit)
|
||||||
locations_string = ''
|
locations_string = ''
|
||||||
|
@ -137,8 +147,8 @@ class Commands:
|
||||||
return locations_string
|
return locations_string
|
||||||
|
|
||||||
def delete(self, name, discord_uuid=None, mc_uuid=None):
|
def delete(self, name, discord_uuid=None, mc_uuid=None):
|
||||||
|
|
||||||
session = self.interface.database.Session()
|
session = self.interface.database.Session()
|
||||||
|
checkIfEmpty(name)
|
||||||
try:
|
try:
|
||||||
player = self.get_player(session, discord_uuid, mc_uuid)
|
player = self.get_player(session, discord_uuid, mc_uuid)
|
||||||
self.interface.delete_location(session, player, name)
|
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):
|
def add_item(self, item_name, quantity, diamond_price, shop_name=None, discord_uuid=None, mc_uuid=None):
|
||||||
session = self.interface.database.Session()
|
session = self.interface.database.Session()
|
||||||
|
checkIfEmpty(item_name)
|
||||||
try:
|
try:
|
||||||
player = self.get_player(session, discord_uuid, mc_uuid)
|
player = self.get_player(session, discord_uuid, mc_uuid)
|
||||||
|
|
||||||
|
@ -176,6 +187,10 @@ class Commands:
|
||||||
session = self.interface.database.Session()
|
session = self.interface.database.Session()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
|
if len(item_name) == 0:
|
||||||
|
raise EmptryString
|
||||||
|
|
||||||
shop_list = self.interface.find_top_shops_selling_item(session, item_name)
|
shop_list = self.interface.find_top_shops_selling_item(session, item_name)
|
||||||
|
|
||||||
if len(shop_list) == 0:
|
if len(shop_list) == 0:
|
||||||
|
@ -199,6 +214,8 @@ class Commands:
|
||||||
def info(self, location_name):
|
def info(self, location_name):
|
||||||
session = self.interface.database.Session()
|
session = self.interface.database.Session()
|
||||||
try:
|
try:
|
||||||
|
if len(location_name) == 0:
|
||||||
|
raise EmptryString
|
||||||
loc = self.interface.find_location_by_name_closest_match(session,
|
loc = self.interface.find_location_by_name_closest_match(session,
|
||||||
location_name).full_str(self.bot_config)
|
location_name).full_str(self.bot_config)
|
||||||
finally:
|
finally:
|
||||||
|
|
|
@ -103,6 +103,8 @@ class GeoffreyBot(commands.Bot):
|
||||||
elif isinstance(error.original, OperationalError):
|
elif isinstance(error.original, OperationalError):
|
||||||
await self.send_error_message('Error connecting to the MySQL server, is it offline?')
|
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()
|
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):
|
elif isinstance(error, commands.CommandOnCooldown):
|
||||||
return
|
return
|
||||||
elif isinstance(error, commands.UserInputError):
|
elif isinstance(error, commands.UserInputError):
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import os
|
import os
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from Commands import *
|
from geoffrey.Commands import *
|
||||||
from BotConfig import get_config
|
from geoffrey.BotConfig import get_config
|
||||||
|
|
||||||
zerohd = 'birbhd'
|
zerohd = 'zerohd'
|
||||||
|
|
||||||
class TestCommands(TestCase):
|
class TestCommands(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
import os
|
import os
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from DatabaseInterface import *
|
from geoffrey.DatabaseInterface import *
|
||||||
from BotConfig import *
|
from geoffrey.BotConfig import *
|
||||||
|
|
||||||
zerohd = 'BirbHD'
|
zerohd = 'zerohd'
|
||||||
|
|
||||||
|
|
||||||
class TestGeoffreyDatabase(TestCase):
|
class TestGeoffreyDatabase(TestCase):
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from DiscordHelperFunctions import get_nickname
|
from geoffrey.DiscordHelperFunctions import get_nickname
|
||||||
|
|
||||||
|
|
||||||
class TestGet_nickname(TestCase):
|
class TestGet_nickname(TestCase):
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from MinecraftAccountInfoGrabber import *
|
from geoffrey.MinecraftAccountInfoGrabber import *
|
||||||
|
|
||||||
|
|
||||||
class TestMinecraftInfoGrabber(TestCase):
|
class TestMinecraftInfoGrabber(TestCase):
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
import os
|
import os
|
||||||
from Commands import *
|
from geoffrey.Commands import *
|
||||||
from BotConfig import get_config
|
from geoffrey.BotConfig import get_config
|
||||||
from MinecraftAccountInfoGrabber import *
|
from Mgeoffrey.inecraftAccountInfoGrabber import *
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue