diff --git a/Commands.py b/Commands.py index 4ac2750..aba048f 100644 --- a/Commands.py +++ b/Commands.py @@ -311,4 +311,20 @@ class Commands: 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 diff --git a/Geoffrey.py b/Geoffrey.py index f8bec9f..79990d0 100644 --- a/Geoffrey.py +++ b/Geoffrey.py @@ -59,7 +59,7 @@ async def on_command_error(error, ctx): else: 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)) @@ -103,8 +103,11 @@ if __name__ == '__main__': except Exception as e: print('Failed to load extension {}, {}'.format(extension, e)) - bot.loop.create_task(username_update()) - bot.run(bot_config.token) + try: + bot.loop.create_task(username_update()) + bot.run(bot_config.token) + except TimeoutError: + print("Disconnected, is Discord offline?") diff --git a/Search_Commands.py b/Search_Commands.py index fea5609..2e8837a 100644 --- a/Search_Commands.py +++ b/Search_Commands.py @@ -122,6 +122,21 @@ class Search_Commands: except IndexError: 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): bot.add_cog(Search_Commands(bot)) diff --git a/test_commands.py b/test_commands.py index 3c89fbd..3df890d 100644 --- a/test_commands.py +++ b/test_commands.py @@ -222,3 +222,15 @@ class TestCommands(TestCase): self.assertRaises(LocationLookUpError, self.commands.delete_item, 'wood', None, 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() +