2018-08-12 19:00:04 +00:00
|
|
|
from discord import Game
|
2018-08-05 22:20:37 +00:00
|
|
|
from discord.ext import commands
|
2018-08-12 19:00:04 +00:00
|
|
|
|
2018-08-21 20:36:51 +00:00
|
|
|
from geoffrey.BotErrors import *
|
2018-09-12 21:29:28 +00:00
|
|
|
from geoffrey.DiscordHelperFunctions import get_name
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
|
2018-08-30 16:34:19 +00:00
|
|
|
def check_mod(user, admin_users):
|
2018-08-11 16:20:40 +00:00
|
|
|
try:
|
|
|
|
for role in user.roles:
|
2018-09-12 21:11:56 +00:00
|
|
|
if str(role.id) in admin_users:
|
2018-08-11 16:20:40 +00:00
|
|
|
return True
|
|
|
|
except AttributeError:
|
|
|
|
raise NotOnServerError
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
2018-08-05 22:20:37 +00:00
|
|
|
class Admin_Commands:
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
Commands for cool people only.
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
|
2018-09-12 21:11:56 +00:00
|
|
|
async def error(self, ctx, error):
|
2018-09-13 16:25:40 +00:00
|
|
|
error_str = ""
|
|
|
|
|
|
|
|
if hasattr(error, "original"):
|
|
|
|
if isinstance(error.original, PlayerNotFound):
|
|
|
|
error_str = 'that player is not in the database.'
|
|
|
|
elif isinstance(error.original, DeleteEntryError) or isinstance(error.original, LocationLookUpError):
|
|
|
|
error_str = 'that player does not have a location by that name.'
|
|
|
|
|
|
|
|
if error_str is "":
|
2018-08-12 15:32:35 +00:00
|
|
|
error_str = 'the bot encountered the following error: {}'.format(error.__str__())
|
2018-08-11 16:20:40 +00:00
|
|
|
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, {}'.format(ctx.message.author.mention, error_str))
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
@commands.command(pass_context=True)
|
|
|
|
async def test(self, ctx):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-05 22:20:37 +00:00
|
|
|
Checks if the bot is alive.
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-30 16:34:19 +00:00
|
|
|
if check_mod(ctx.message.author, self.bot.admin_users):
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('I\'m here you ding dong')
|
2018-08-05 22:20:37 +00:00
|
|
|
else:
|
|
|
|
raise NoPermissionError
|
|
|
|
|
2018-08-11 16:20:40 +00:00
|
|
|
@commands.group(pass_context=True)
|
|
|
|
async def mod(self, ctx):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-11 18:46:03 +00:00
|
|
|
Bot moderation tools.
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-30 16:34:19 +00:00
|
|
|
if check_mod(ctx.message.author, self.bot.admin_users):
|
2018-08-11 16:20:40 +00:00
|
|
|
if ctx.invoked_subcommand is None:
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, invalid sub-command for command **mod**.'.format(ctx.message.author.mention))
|
2018-08-11 16:20:40 +00:00
|
|
|
else:
|
|
|
|
raise NoPermissionError
|
|
|
|
|
|
|
|
@mod.command(pass_context=True)
|
|
|
|
async def delete(self, ctx, discord_uuid: str, location_name: str):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-12 15:32:35 +00:00
|
|
|
Deletes a location in the database.
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-30 16:34:19 +00:00
|
|
|
self.bot.bot_commands.delete(location_name, discord_uuid=discord_uuid)
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, **{}** has been deleted.'.format(ctx.message.author.mention, location_name))
|
2018-08-11 16:20:40 +00:00
|
|
|
|
|
|
|
@delete.error
|
2018-09-12 21:11:56 +00:00
|
|
|
async def delete_error(self, ctx, error):
|
|
|
|
await self.error(ctx, error)
|
2018-08-11 16:20:40 +00:00
|
|
|
|
|
|
|
@mod.command(pass_context=True)
|
2018-08-11 18:46:03 +00:00
|
|
|
async def edit_name(self, ctx, discord_uuid: str, new_name: str, current_name: str):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-11 18:46:03 +00:00
|
|
|
Edits the name of a location in the database.
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-30 16:34:19 +00:00
|
|
|
self.bot.bot_commands.edit_name(new_name, current_name, discord_uuid=discord_uuid)
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, **{}** has been rename to **{}**.'.format(ctx.message.author.mention, current_name,
|
2018-09-13 16:25:40 +00:00
|
|
|
new_name))
|
2018-08-11 16:20:40 +00:00
|
|
|
|
2018-08-11 18:46:03 +00:00
|
|
|
@edit_name.error
|
2018-09-12 21:11:56 +00:00
|
|
|
async def edit_error(self, ctx, error):
|
|
|
|
await self.error(ctx, error)
|
2018-08-11 16:20:40 +00:00
|
|
|
|
|
|
|
@mod.command(pass_context=True)
|
|
|
|
async def update_mc_uuid(self, ctx, discord_uuid: str, mc_uuid: str):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-09-13 16:25:40 +00:00
|
|
|
Updates a user's MC UUID
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-30 16:34:19 +00:00
|
|
|
self.bot.bot_commands.update_mc_uuid(discord_uuid, mc_uuid)
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, **{}** has been updated.'.format(ctx.message.author.mention, discord_uuid))
|
2018-08-11 16:20:40 +00:00
|
|
|
|
|
|
|
@update_mc_uuid.error
|
2018-09-12 21:11:56 +00:00
|
|
|
async def update_mc_uuid_error(self, ctx, error):
|
|
|
|
await self.error(ctx, error)
|
2018-08-11 16:20:40 +00:00
|
|
|
|
|
|
|
@mod.command(pass_context=True)
|
2018-09-13 16:25:40 +00:00
|
|
|
async def update_discord_uuid(self, ctx, new_discord_uuid: str, current_discord_uuid: str):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-09-13 16:25:40 +00:00
|
|
|
Updates a user's Discord UUID
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-30 16:34:19 +00:00
|
|
|
self.bot.bot_commands.update_mc_uuid(current_discord_uuid, new_discord_uuid)
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, user **{}** has been updated.'.format(ctx.message.author.mention, current_discord_uuid))
|
2018-08-11 16:20:40 +00:00
|
|
|
|
|
|
|
@update_discord_uuid.error
|
2018-09-12 21:11:56 +00:00
|
|
|
async def update_discord_uuid_error(self, ctx, error):
|
|
|
|
await self.error(ctx, error)
|
2018-08-11 16:20:40 +00:00
|
|
|
|
|
|
|
@mod.command(pass_context=True)
|
2018-08-11 18:46:03 +00:00
|
|
|
async def update_mc_name(self, ctx, discord_uuid: str):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-09-13 16:25:40 +00:00
|
|
|
Updates a user's MC name to the current name on the MC UUID
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-30 16:34:19 +00:00
|
|
|
self.bot.bot_commands.update_mc_name(discord_uuid)
|
2018-09-12 21:11:56 +00:00
|
|
|
await ctx.send('{}, user **{}**\'s MC name has update.'.format(ctx.message.author.mention, discord_uuid))
|
2018-08-11 16:20:40 +00:00
|
|
|
|
|
|
|
@update_mc_name.error
|
2018-09-12 21:11:56 +00:00
|
|
|
async def update_mc_name_error(self, ctx, error):
|
|
|
|
await self.error(ctx, error)
|
2018-08-11 16:20:40 +00:00
|
|
|
|
2018-08-11 18:46:03 +00:00
|
|
|
@mod.command(pass_context=True)
|
2018-09-12 21:29:28 +00:00
|
|
|
async def status(self, ctx, *args):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-09-13 16:25:40 +00:00
|
|
|
Updates "playing [game]" status of the bot
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-09-12 21:29:28 +00:00
|
|
|
status = get_name(args)
|
2018-09-12 21:11:56 +00:00
|
|
|
await self.bot.change_presence(activity=Game(status))
|
|
|
|
await ctx.send('{}, status has been changed'.format(ctx.message.author.mention))
|
2018-08-11 16:20:40 +00:00
|
|
|
|
2018-09-14 13:21:02 +00:00
|
|
|
@mod.command(pass_context=True)
|
|
|
|
async def add_player(self, ctx, discord_uuid: str, mc_name: str):
|
|
|
|
"""
|
|
|
|
Manually add a player to the database
|
|
|
|
"""
|
2018-09-21 12:27:32 +00:00
|
|
|
try:
|
|
|
|
db_id = self.bot.bot_commands.add_player(discord_uuid, mc_name)
|
|
|
|
await ctx.send('{}, user **{}** been added to the data base with id {}.'.format(ctx.message.author.mention,
|
|
|
|
mc_name, db_id))
|
|
|
|
except PlayerInDBError:
|
|
|
|
await ctx.send('{}, user **{}** is already in the database.'.format(ctx.message.author.mention, mc_name))
|
2018-09-14 13:21:02 +00:00
|
|
|
|
|
|
|
@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
|
|
|
|
"""
|
2018-09-21 12:27:32 +00:00
|
|
|
try:
|
|
|
|
db_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, db_id, discord_uuid, minecraft_uuid))
|
|
|
|
except PlayerNotFound:
|
|
|
|
await ctx.send('That player is not in the database...')
|
2018-09-14 13:21:02 +00:00
|
|
|
|
|
|
|
@find_player.error
|
|
|
|
async def find_player_error(self, ctx, error):
|
|
|
|
await self.error(ctx, error)
|
|
|
|
|
2018-08-10 02:25:55 +00:00
|
|
|
|
2018-08-05 22:20:37 +00:00
|
|
|
def setup(bot):
|
2018-08-11 23:02:50 +00:00
|
|
|
bot.add_cog(Admin_Commands(bot))
|