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.
parent
135aabb248
commit
1ed9252858
|
@ -380,3 +380,36 @@ class Commands:
|
||||||
raise e
|
raise e
|
||||||
finally:
|
finally:
|
||||||
session.close()
|
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
|
||||||
|
|
|
@ -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,
|
logger.info("User %s, used command %s%s with context: %s", ctx.message.author, ctx.command, subcommand,
|
||||||
ctx.args)
|
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):
|
async def on_command_error(self, ctx, error):
|
||||||
error_str = ''
|
error_str = ''
|
||||||
if hasattr(ctx, 'cog'):
|
if hasattr(ctx, 'cog'):
|
||||||
|
|
|
@ -61,7 +61,7 @@ class Add_Commands:
|
||||||
@commands.cooldown(5, 60, commands.BucketType.user)
|
@commands.cooldown(5, 60, commands.BucketType.user)
|
||||||
async def add_shop(self, ctx, x_pos: int, z_pos: int, *args):
|
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]
|
?add_shop [X Coordinate] [Z Coordinate] [Shop Name]
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
@ -129,6 +129,32 @@ class Admin_Commands:
|
||||||
await self.bot.change_presence(activity=Game(status))
|
await self.bot.change_presence(activity=Game(status))
|
||||||
await ctx.send('{}, status has been changed'.format(ctx.message.author.mention))
|
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):
|
def setup(bot):
|
||||||
bot.add_cog(Admin_Commands(bot))
|
bot.add_cog(Admin_Commands(bot))
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import os
|
import os
|
||||||
|
import time
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from Commands import *
|
from Commands import *
|
||||||
|
@ -259,3 +260,30 @@ class TestCommands(TestCase):
|
||||||
|
|
||||||
self.assertRaises(PlayerNotFound, self.commands.add_shop, 0, 0, shop_name='test shop',
|
self.assertRaises(PlayerNotFound, self.commands.add_shop, 0, 0, shop_name='test shop',
|
||||||
discord_uuid='143072699567177728')
|
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)
|
||||||
|
|
Loading…
Reference in New Issue