Fixed error handling for tunnels and dims
parent
a13e1c9af2
commit
cc1324c5bb
|
@ -33,5 +33,11 @@ class DatabaseValueError(DataBaseError):
|
||||||
class ItemNotFound(DataBaseError):
|
class ItemNotFound(DataBaseError):
|
||||||
'''No item matches found in database'''
|
'''No item matches found in database'''
|
||||||
|
|
||||||
|
class InvalidDimError(DataBaseError):
|
||||||
|
"""Invalid dimension name"""
|
||||||
|
|
||||||
|
class InvalidTunnelError(DataBaseError):
|
||||||
|
"""Invalid tunnel name"""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,6 @@ class GeoffreyDatabase:
|
||||||
except:
|
except:
|
||||||
session.rollback()
|
session.rollback()
|
||||||
|
|
||||||
|
|
||||||
def query_by_filter(self, session, obj_type, * args):
|
def query_by_filter(self, session, obj_type, * args):
|
||||||
filter_value = self.combine_filter(args)
|
filter_value = self.combine_filter(args)
|
||||||
return session.query(obj_type).filter(filter_value).all()
|
return session.query(obj_type).filter(filter_value).all()
|
||||||
|
@ -79,6 +78,7 @@ class GeoffreyDatabase:
|
||||||
def combine_filter(self, filter_value):
|
def combine_filter(self, filter_value):
|
||||||
return expression.and_(filter_value[0])
|
return expression.and_(filter_value[0])
|
||||||
|
|
||||||
|
|
||||||
class TunnelDirection(enum.Enum):
|
class TunnelDirection(enum.Enum):
|
||||||
North = 'green'
|
North = 'green'
|
||||||
East = 'blue'
|
East = 'blue'
|
||||||
|
@ -97,7 +97,7 @@ class TunnelDirection(enum.Enum):
|
||||||
elif check_similarity(TunnelDirection.West.value, arg):
|
elif check_similarity(TunnelDirection.West.value, arg):
|
||||||
return TunnelDirection.West
|
return TunnelDirection.West
|
||||||
else:
|
else:
|
||||||
raise ValueError
|
raise InvalidTunnelError
|
||||||
|
|
||||||
|
|
||||||
class Dimension(enum.Enum):
|
class Dimension(enum.Enum):
|
||||||
|
@ -114,7 +114,7 @@ class Dimension(enum.Enum):
|
||||||
elif check_similarity(Dimension.end.value, arg):
|
elif check_similarity(Dimension.end.value, arg):
|
||||||
return Dimension.end
|
return Dimension.end
|
||||||
else:
|
else:
|
||||||
raise ValueError
|
raise InvalidDimError
|
||||||
|
|
||||||
|
|
||||||
class Player(SQL_Base):
|
class Player(SQL_Base):
|
||||||
|
|
19
Geoffrey.py
19
Geoffrey.py
|
@ -133,7 +133,7 @@ async def tunnel(ctx, tunnel_color: str, tunnel_number: int, *args):
|
||||||
'''
|
'''
|
||||||
Adds your tunnel to the database.
|
Adds your tunnel to the database.
|
||||||
The location name is optional. If the location has a tunnel, it is updated.
|
The location name is optional. If the location has a tunnel, it is updated.
|
||||||
?addtunnel [Tunnel Color] [Tunnel_Number] [Location Name]
|
?tunnel [Tunnel Color] [Tunnel Number] [Location Name]
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
if len(args) > 0:
|
if len(args) > 0:
|
||||||
|
@ -150,22 +150,25 @@ async def tunnel(ctx, tunnel_color: str, tunnel_number: int, *args):
|
||||||
except LocationLookUpError:
|
except LocationLookUpError:
|
||||||
await bot.say('{}, you do not have a location called **{}**.'.format(
|
await bot.say('{}, you do not have a location called **{}**.'.format(
|
||||||
ctx.message.author.mention, args[0]))
|
ctx.message.author.mention, args[0]))
|
||||||
except ValueError:
|
except TunnelInitError:
|
||||||
raise commands.UserInputError
|
await bot.say('{}, invalid tunnel color.'.format(ctx.message.author.mention))
|
||||||
|
except InvalidTunnelError:
|
||||||
|
await bot.say('{}, {} is an invalid tunnel color.'.format(ctx.message.author.mention, tunnel_color))
|
||||||
|
|
||||||
|
|
||||||
@bot.command(pass_context=True)
|
@bot.command(pass_context=True)
|
||||||
async def find(ctx, search: str):
|
async def find(ctx, * args):
|
||||||
'''
|
'''
|
||||||
Finds all the locations and tunnels matching the search term
|
Finds all the locations and tunnels matching the search term
|
||||||
?find [Search]
|
?find [Search]
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
|
search = ' '.join(args)
|
||||||
result = bot_commands.find(search)
|
result = bot_commands.find(search)
|
||||||
|
|
||||||
await bot.say('{}, The following entries match **{}**:\n{}'.format(ctx.message.author.mention, search, result))
|
await bot.say('{}, The following entries match **{}**:\n{}'.format(ctx.message.author.mention, search, result))
|
||||||
except LocationLookUpError:
|
except LocationLookUpError:
|
||||||
await bot.say('{}, no matches **{}** were found in the database'.format(ctx.message.author.mention, search))
|
await bot.say('{}, no matches to **{}** were found in the database'.format(ctx.message.author.mention, search))
|
||||||
|
|
||||||
@bot.command(pass_context=True)
|
@bot.command(pass_context=True)
|
||||||
async def delete(ctx, * args):
|
async def delete(ctx, * args):
|
||||||
|
@ -175,7 +178,7 @@ async def delete(ctx, * args):
|
||||||
'''
|
'''
|
||||||
try:
|
try:
|
||||||
name = ' '.join(args)
|
name = ' '.join(args)
|
||||||
commands.delete(name, discord_uuid=ctx.message.author.id)
|
bot_commands.delete(name, discord_uuid=ctx.message.author.id)
|
||||||
await bot.say('{}, your location named **{}** has been deleted.'.format(ctx.message.author.mention, name))
|
await bot.say('{}, your location named **{}** has been deleted.'.format(ctx.message.author.mention, name))
|
||||||
except (DeleteEntryError, PlayerNotFound):
|
except (DeleteEntryError, PlayerNotFound):
|
||||||
await bot.say('{}, you do not have a location named **{}**.'.format(ctx.message.author.mention, name))
|
await bot.say('{}, you do not have a location named **{}**.'.format(ctx.message.author.mention, name))
|
||||||
|
@ -216,8 +219,8 @@ async def findaround(ctx, x_pos: int, z_pos: int, * args):
|
||||||
else:
|
else:
|
||||||
await bot.say('{}, there are no locations within {} blocks of that point'
|
await bot.say('{}, there are no locations within {} blocks of that point'
|
||||||
.format(ctx.message.author.mention, radius))
|
.format(ctx.message.author.mention, radius))
|
||||||
except ValueError:
|
except InvalidDimError:
|
||||||
raise commands.UserInputError
|
await bot.say('{}, {} is an invalid dimension.'.format(ctx.message.author.mention, dimension))
|
||||||
|
|
||||||
|
|
||||||
@bot.command(pass_context=True)
|
@bot.command(pass_context=True)
|
||||||
|
|
Loading…
Reference in New Issue