2018-08-05 22:20:37 +00:00
|
|
|
from discord.ext import commands
|
|
|
|
from BotErrors import *
|
2018-08-11 16:20:40 +00:00
|
|
|
from BotConfig import bot_config
|
2018-08-11 21:07:33 +00:00
|
|
|
from bot import bot_commands
|
2018-08-11 18:46:03 +00:00
|
|
|
from discord import Game
|
2018-08-05 22:20:37 +00:00
|
|
|
|
|
|
|
|
2018-08-11 16:20:40 +00:00
|
|
|
def check_mod(user):
|
|
|
|
try:
|
|
|
|
for role in user.roles:
|
|
|
|
if role.id == bot_config.bot_mod:
|
|
|
|
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-08-11 16:20:40 +00:00
|
|
|
async def error(self, error, ctx):
|
2018-08-11 18:46:03 +00:00
|
|
|
if isinstance(error, PlayerNotFound):
|
2018-08-11 16:20:40 +00:00
|
|
|
error_str = 'that player is not in the database.'
|
2018-08-11 18:46:03 +00:00
|
|
|
elif isinstance(error, DeleteEntryError):
|
2018-08-11 16:20:40 +00:00
|
|
|
error_str = 'that player does not have a location by that name.'
|
|
|
|
else:
|
2018-08-11 18:46:03 +00:00
|
|
|
error_str = 'the bot encountered the following error: *{}*'.format(error.__str__())
|
2018-08-11 16:20:40 +00:00
|
|
|
|
|
|
|
await self.bot.send_message(ctx.message.channel, '{}, {}'.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-11 16:20:40 +00:00
|
|
|
if check_mod(ctx.message.author):
|
2018-08-05 22:20:37 +00:00
|
|
|
await self.bot.say('I\'m here you ding dong')
|
|
|
|
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-11 16:20:40 +00:00
|
|
|
if check_mod(ctx.message.author):
|
|
|
|
if ctx.invoked_subcommand is None:
|
|
|
|
await self.bot.say('{}, invalid sub-command for command **mod**.'.format(ctx.message.author.mention))
|
|
|
|
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-11 18:46:03 +00:00
|
|
|
Deletes a location in the database/
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-11 16:20:40 +00:00
|
|
|
bot_commands.delete(location_name, discord_uuid=discord_uuid)
|
|
|
|
await self.bot.say('{}, **{}** has been deleted.'.format(ctx.message.author.mention, location_name))
|
|
|
|
|
|
|
|
@delete.error
|
|
|
|
async def delete_error(self, error, ctx):
|
|
|
|
await self.error(error, ctx)
|
|
|
|
|
|
|
|
@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-11 16:20:40 +00:00
|
|
|
bot_commands.edit_name(new_name, current_name, discord_uuid=discord_uuid)
|
|
|
|
await self.bot.say('{}, **{}** has been rename to **{}**.'.format(ctx.message.author.mention, current_name,
|
|
|
|
new_name))
|
|
|
|
|
2018-08-11 18:46:03 +00:00
|
|
|
@edit_name.error
|
2018-08-11 16:20:40 +00:00
|
|
|
async def edit_error(self, error, ctx):
|
|
|
|
await self.error(error, ctx)
|
|
|
|
|
|
|
|
@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-08-11 18:46:03 +00:00
|
|
|
Updates a user's MC UUID
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-11 16:20:40 +00:00
|
|
|
bot_commands.update_mc_uuid(discord_uuid, mc_uuid)
|
|
|
|
await self.bot.say('{}, **{}** has been updated.'.format(ctx.message.author.mention, discord_uuid))
|
|
|
|
|
|
|
|
@update_mc_uuid.error
|
|
|
|
async def update_mc_uuid_error(self, error, ctx):
|
|
|
|
await self.error(error, ctx)
|
|
|
|
|
|
|
|
@mod.command(pass_context=True)
|
|
|
|
async def update_discord_uuid(self, ctx, current_discord_uuid: str, new_discord_uuid: str):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-11 18:46:03 +00:00
|
|
|
Updates a user's Discord UUID
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-11 16:20:40 +00:00
|
|
|
bot_commands.update_mc_uuid(current_discord_uuid, new_discord_uuid)
|
|
|
|
await self.bot.say('{}, user **{}** has been updated.'.format(ctx.message.author.mention, current_discord_uuid))
|
|
|
|
|
|
|
|
@update_discord_uuid.error
|
|
|
|
async def update_discord_uuid_error(self, error, ctx):
|
|
|
|
await self.error(error, ctx)
|
|
|
|
|
|
|
|
@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-08-11 18:46:03 +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-11 18:46:03 +00:00
|
|
|
bot_commands.update_mc_name(discord_uuid)
|
|
|
|
await self.bot.say('{}, 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
|
|
|
|
async def update_mc_name_error(self, error, ctx):
|
|
|
|
await self.error(error, ctx)
|
|
|
|
|
2018-08-11 18:46:03 +00:00
|
|
|
@mod.command(pass_context=True)
|
|
|
|
async def status(self, ctx, status: str):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-11 18:46:03 +00:00
|
|
|
Updates playing game status of the bot
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-11 18:46:03 +00:00
|
|
|
await self.bot.change_presence(game=Game(name=status))
|
|
|
|
await self.bot.say('{}, status has been changed'.format(ctx.message.author.mention))
|
2018-08-11 16:20:40 +00:00
|
|
|
|
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))
|