Fixed some commands allowing empty names

doc_update
Joey Hines 2018-07-27 19:02:41 -05:00
parent 91999322ec
commit b6ccaeac6e
1 changed files with 29 additions and 24 deletions

View File

@ -4,7 +4,6 @@ from BotErrors import *
from MinecraftAccountInfoGrabber import * from MinecraftAccountInfoGrabber import *
from itertools import zip_longest from itertools import zip_longest
from BotConfig import * from BotConfig import *
import time
import threading import threading
command_prefix = '?' command_prefix = '?'
@ -37,7 +36,7 @@ async def on_command_error(error, ctx):
if isinstance(error, commands.CommandNotFound): if isinstance(error, commands.CommandNotFound):
error_str = 'Command not found, ding dongs like you can use ?help to see all the commands this bot can do.' error_str = 'Command not found, ding dongs like you can use ?help to see all the commands this bot can do.'
elif isinstance(error, commands.UserInputError): elif isinstance(error, commands.UserInputError):
error_str = 'Invalid syntax for {} you ding dong, please read ?help {}.'\ error_str = 'Invalid syntax for **{}** you ding dong, please read ?help {}.'\
.format(ctx.invoked_with, ctx.invoked_with) .format(ctx.invoked_with, ctx.invoked_with)
elif isinstance(error.original, UsernameLookupFailed): elif isinstance(error.original, UsernameLookupFailed):
error_str = error.original.__doc__ error_str = error.original.__doc__
@ -89,10 +88,8 @@ async def addbase(ctx, x_pos: int, z_pos: int, * args):
The name is optional. The name is optional.
?addbase [X Coordinate] [Y Coordinate] [Z Coordinate] [Base Name] ?addbase [X Coordinate] [Y Coordinate] [Z Coordinate] [Base Name]
''' '''
if len(args) > 0:
name = ' '.join(args) name = get_name(args)
else:
name = None
try: try:
base = bot_commands.addbase(x_pos, z_pos, base_name=name, discord_uuid=ctx.message.author.id) base = bot_commands.addbase(x_pos, z_pos, base_name=name, discord_uuid=ctx.message.author.id)
@ -115,10 +112,8 @@ async def addshop(ctx, x_pos: int, z_pos: int, *args):
The name is optional. The name is optional.
?addshop [X Coordinate] [Y Coordinate] [Z Coordinate] [Shop Name] ?addshop [X Coordinate] [Y Coordinate] [Z Coordinate] [Shop Name]
''' '''
if len(args) > 0:
name = ' '.join(args) name = get_name(args)
else:
name = None
try: try:
shop = bot_commands.addshop(x_pos, z_pos, shop_str=name, discord_uuid=ctx.message.author.id) shop = bot_commands.addshop(x_pos, z_pos, shop_str=name, discord_uuid=ctx.message.author.id)
@ -141,10 +136,7 @@ async def addtunnel(ctx, tunnel_color: str, tunnel_number: int, *args):
?tunnel [Tunnel Color] [Tunnel Number] [Location Name] ?tunnel [Tunnel Color] [Tunnel Number] [Location Name]
''' '''
try: try:
if len(args) > 0: location_name = get_name(args)
location_name = ' '.join(args)
else:
location_name = None
bot_commands.addtunnel(tunnel_color, tunnel_number, discord_uuid=ctx.message.author.id, location_name=location_name) bot_commands.addtunnel(tunnel_color, tunnel_number, discord_uuid=ctx.message.author.id, location_name=location_name)
await bot.say('{}, your tunnel has been added to the database'.format(ctx.message.author.mention)) await bot.say('{}, your tunnel has been added to the database'.format(ctx.message.author.mention))
@ -168,7 +160,11 @@ async def find(ctx, * args):
?find [Search] ?find [Search]
''' '''
try: try:
search = ' '.join(args) search = get_name(args)
if search is None:
raise commands.UserInputError
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))
@ -196,7 +192,11 @@ async def delete(ctx, * args):
?delete [Location name] ?delete [Location name]
''' '''
try: try:
name = ' '.join(args) loc = get_name(args)
if loc is None:
raise commands.UserInputError
bot_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):
@ -251,10 +251,7 @@ async def additem(ctx, item_name: str, quantity: int, diamond_price: int, * args
?additem [Item Name] [Quantity] [Price] [Shop name] ?additem [Item Name] [Quantity] [Price] [Shop name]
''' '''
try: try:
if len(args) > 0: shop_name = get_name(args)
shop_name = ' '.join(args)
else:
shop_name = None
bot_commands.additem(item_name, quantity, diamond_price, shop_name=shop_name, bot_commands.additem(item_name, quantity, diamond_price, shop_name=shop_name,
discord_uuid=ctx.message.author.id) discord_uuid=ctx.message.author.id)
@ -294,12 +291,12 @@ async def info(ctx, * args):
?info [Location Name] ?info [Location Name]
''' '''
try: try:
if len(args) > 0: loc = get_name(args)
name = ' '.join(args)
else: if loc is None:
raise commands.UserInputError raise commands.UserInputError
info_str = bot_commands.info(name) info_str = bot_commands.info(loc)
await bot.say(info_str) await bot.say(info_str)
except IndexError: except IndexError:
await bot.say('{}, no locations in the database match {}.'.format(ctx.message.author.mention, name)) await bot.say('{}, no locations in the database match {}.'.format(ctx.message.author.mention, name))
@ -307,6 +304,13 @@ async def info(ctx, * args):
# Helper Functions ************************************************************ # Helper Functions ************************************************************
def get_name(args):
if len(args) > 0:
name = ' '.join(args)
else:
name = None
return name
def get_nickname(discord_user): def get_nickname(discord_user):
if discord_user.nick is None: if discord_user.nick is None:
@ -356,3 +360,4 @@ update_user_names(bot_commands)
bot.run(TOKEN) bot.run(TOKEN)