Added ?me command

doc_update
Joey Hines 2018-08-10 18:03:30 -05:00
parent cc0ea90241
commit dac4516285
4 changed files with 49 additions and 3 deletions

View File

@ -311,4 +311,20 @@ class Commands:
return shop_str return shop_str
def me(self, discord_uuid=None, mc_uuid=None):
session = self.interface.database.Session()
try:
player = self.get_player(session, discord_uuid=discord_uuid, mc_uuid=mc_uuid)
loc_list = self.interface.find_location_by_owner(session, player)
if len(loc_list) == 0:
raise PlayerNotFound
loc_str = list_to_string(loc_list)
finally:
session.close()
return loc_str

View File

@ -59,7 +59,7 @@ async def on_command_error(error, ctx):
else: else:
error_str = bad_error_message.format(ctx.invoked_with, error) error_str = bad_error_message.format(ctx.invoked_with, error)
bot.send_message(ctx.message.channel, '{} **Error Running Command:** {}'.format(ctx.message.author.mention, await bot.send_message(ctx.message.channel, '{} **Error Running Command:** {}'.format(ctx.message.author.mention,
error_str)) error_str))
@ -103,8 +103,11 @@ if __name__ == '__main__':
except Exception as e: except Exception as e:
print('Failed to load extension {}, {}'.format(extension, e)) print('Failed to load extension {}, {}'.format(extension, e))
bot.loop.create_task(username_update()) try:
bot.run(bot_config.token) bot.loop.create_task(username_update())
bot.run(bot_config.token)
except TimeoutError:
print("Disconnected, is Discord offline?")

View File

@ -122,6 +122,21 @@ class Search_Commands:
except IndexError: except IndexError:
await self.bot.say('{}, no locations in the database match **{}**.'.format(ctx.message.author.mention, loc)) await self.bot.say('{}, no locations in the database match **{}**.'.format(ctx.message.author.mention, loc))
@commands.command(pass_context=True)
async def me(self, ctx):
'''
Displays all your locations in the database
?me
'''
try:
loc_str = bot_commands.me(discord_uuid=ctx.message.author.id)
await self.bot.say('{}, here are your locations in the database: {}'.format(ctx.message.author.mention,
loc_str))
except PlayerNotFound:
await self.bot.say('{}, you don\'t have any locations in the database.'.format(ctx.message.author.mention))
def setup(bot): def setup(bot):
bot.add_cog(Search_Commands(bot)) bot.add_cog(Search_Commands(bot))

View File

@ -222,3 +222,15 @@ class TestCommands(TestCase):
self.assertRaises(LocationLookUpError, self.commands.delete_item, 'wood', None, self.assertRaises(LocationLookUpError, self.commands.delete_item, 'wood', None,
discord_uuid='143072699567177728') discord_uuid='143072699567177728')
def test_me(self):
self.commands.register('ZeroHD', '143072699567177728')
self.commands.add_shop(0, 0, shop_name='test shop', discord_uuid='143072699567177728')
result = self.commands.me(discord_uuid='143072699567177728')
if 'test shop' in result:
pass
else:
self.fail()