Added ?me command
parent
cc0ea90241
commit
dac4516285
16
Commands.py
16
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
|
||||
|
||||
|
|
|
@ -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?")
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in New Issue