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-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-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-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-08-11 16:20:40 +00:00
|
|
|
new_name))
|
|
|
|
|
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-08-12 15:32:35 +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)
|
|
|
|
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-12 15:32:35 +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-08-12 15:32:35 +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)
|
|
|
|
async def status(self, ctx, status: str):
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
2018-08-12 15:32:35 +00:00
|
|
|
Updates "playing [game]" status of the bot.
|
2018-08-11 23:02:50 +00:00
|
|
|
"""
|
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-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))
|