From 1ed9252858bb475010d431bba274a286c50341cc Mon Sep 17 00:00:00 2001 From: Joey Hines Date: Fri, 14 Sep 2018 08:21:02 -0500 Subject: [PATCH] Band-aid solution for the register problem. Mods can now manually add players to the database. Mods can now search for players too. Also fixed a few small issues. --- geoffrey/Commands.py | 33 +++++++++++++++++++++++++++++++++ geoffrey/bot.py | 3 +++ geoffrey/cogs/Add_Commands.py | 2 +- geoffrey/cogs/Admin_Commands.py | 26 ++++++++++++++++++++++++++ geoffrey/tests/test_commands.py | 28 ++++++++++++++++++++++++++++ 5 files changed, 91 insertions(+), 1 deletion(-) diff --git a/geoffrey/Commands.py b/geoffrey/Commands.py index 4345d58..9af38c0 100644 --- a/geoffrey/Commands.py +++ b/geoffrey/Commands.py @@ -380,3 +380,36 @@ class Commands: raise e finally: session.close() + + def add_player(self, discord_uuid, mc_name): + session = self.interface.database.Session() + + try: + self.interface.find_player_by_discord_uuid(session, discord_uuid) + out = "is already in database." + except PlayerNotFound: + player = Player(mc_name, discord_id=discord_uuid) + self.interface.database.add_object(session, player) + + player = self.interface.find_player_by_discord_uuid(session, discord_uuid) + out = "has been added to the database with id {}".format(player.id) + + finally: + session.close() + + return out + + def find_player(self, discord_uuid): + session = self.interface.database.Session() + + try: + player = self.interface.find_player_by_discord_uuid(session, discord_uuid) + id = player.id + username = player.name + discord_uuid = player.discord_uuid + minecraft_uuid = player.mc_uuid + + finally: + session.close() + + return id, username, discord_uuid, minecraft_uuid diff --git a/geoffrey/bot.py b/geoffrey/bot.py index 5d01b8a..fe2a7b5 100644 --- a/geoffrey/bot.py +++ b/geoffrey/bot.py @@ -76,6 +76,9 @@ class GeoffreyBot(commands.Bot): logger.info("User %s, used command %s%s with context: %s", ctx.message.author, ctx.command, subcommand, ctx.args) + if ctx.invoked_with == 'help': + await ctx.send("{}, I sent you some help in the DMs.".format(ctx.message.author.mention)) + async def on_command_error(self, ctx, error): error_str = '' if hasattr(ctx, 'cog'): diff --git a/geoffrey/cogs/Add_Commands.py b/geoffrey/cogs/Add_Commands.py index 1cf39c4..5609468 100644 --- a/geoffrey/cogs/Add_Commands.py +++ b/geoffrey/cogs/Add_Commands.py @@ -61,7 +61,7 @@ class Add_Commands: @commands.cooldown(5, 60, commands.BucketType.user) async def add_shop(self, ctx, x_pos: int, z_pos: int, *args): """ - Adds your shop to the database. The name is shop optional if this your first shop + Adds your shop to the database. The name is optional if this your first shop ?add_shop [X Coordinate] [Z Coordinate] [Shop Name] """ diff --git a/geoffrey/cogs/Admin_Commands.py b/geoffrey/cogs/Admin_Commands.py index 832ce93..5dcaae4 100644 --- a/geoffrey/cogs/Admin_Commands.py +++ b/geoffrey/cogs/Admin_Commands.py @@ -129,6 +129,32 @@ class Admin_Commands: await self.bot.change_presence(activity=Game(status)) await ctx.send('{}, status has been changed'.format(ctx.message.author.mention)) + @mod.command(pass_context=True) + async def add_player(self, ctx, discord_uuid: str, mc_name: str): + """ + Manually add a player to the database + """ + str = self.bot.bot_commands.add_player(discord_uuid, mc_name) + await ctx.send('{}, user **{}** {}.' + .format(ctx.message.author.mention, mc_name, str)) + + @add_player.error + async def add_player_error(self, ctx, error): + await self.error(ctx, error) + + @mod.command(pass_context=True) + async def find_player(self, ctx, discord_uuid: str): + """ + Finds a player in the database + """ + id, username, discord_uuid, minecraft_uuid = self.bot.bot_commands.find_player(discord_uuid) + await ctx.send('Username: {}, id: {}, Discord UUID: {}, Minecraft UUID: {}' + .format(username, id, discord_uuid, minecraft_uuid)) + + @find_player.error + async def find_player_error(self, ctx, error): + await self.error(ctx, error) + def setup(bot): bot.add_cog(Admin_Commands(bot)) diff --git a/geoffrey/tests/test_commands.py b/geoffrey/tests/test_commands.py index 1fbf41f..595e362 100644 --- a/geoffrey/tests/test_commands.py +++ b/geoffrey/tests/test_commands.py @@ -1,4 +1,5 @@ import os +import time from unittest import TestCase from Commands import * @@ -259,3 +260,30 @@ class TestCommands(TestCase): self.assertRaises(PlayerNotFound, self.commands.add_shop, 0, 0, shop_name='test shop', discord_uuid='143072699567177728') + + def test_register_and_add(self): + + for i in range(0, 1000): + + time.sleep(10) + self.commands.register('BirbHD', '143072699567177728') + time.sleep(10) + self.commands.add_base(0, 0, "tmpB" + str(i), discord_uuid='143072699567177728') + + time.sleep(15) + self.commands.register('YMCA', '151081244824698880') + time.sleep(10) + + try: + self.commands.add_tunnel("North", i, discord_uuid='151081244824698880') + except: + False + + time.sleep(1) + self.commands.add_base(0, 0, "tmpY" + str(i), discord_uuid='151081244824698880') + + if "YMCA" not in self.commands.find("YMCA"): + self.fail() + + self.session = self.commands.interface.database.Session() + self.commands.interface.database.clear_all(self.session)