diff options
Diffstat (limited to 'cogs/admin.py')
-rwxr-xr-x | cogs/admin.py | 143 |
1 files changed, 95 insertions, 48 deletions
diff --git a/cogs/admin.py b/cogs/admin.py index 3cb7ff8..3a6299f 100755 --- a/cogs/admin.py +++ b/cogs/admin.py @@ -1,7 +1,6 @@ from discord.ext import commands import discord import asyncio -import subprocess import json import git import os @@ -12,30 +11,35 @@ class Admin(commands.Cog): async def is_mod(ctx): return ctx.author.guild_permissions.manage_channels - + + async def is_botmaster(ctx): + return ctx.author.id in ctx.bot.config[str(ctx.message.guild.id)]["bot_masters"] + @commands.command(aliases=['deleteEverything'], hidden=True) - @commands.check(is_mod) - async def purge(self, ctx, password): - if password == "MaxCantBeTrusted": - async for msg in ctx.channel.history(): - await msg.delete() + @commands.check(is_botmaster) + async def purge(self, ctx): + await ctx.message.channel.purge(limit=500) @commands.command(aliases=['quit'], hidden=True) - @commands.check(is_mod) - async def forceexit(self, ctx, password): - if password == "abort": - ctx.message.delete() - exit() + @commands.check(is_botmaster) + async def forceexit(self, ctx): + await ctx.send('Self Destructing') + await ctx.bot.close() @commands.command() @commands.check(is_mod) async def pull(self, ctx): + """Update the bot from github""" g = git.cmd.Git(os.getcwd()) - await ctx.send(f"Probably pulled.\n```bash\n{g.pull()}```") + try: + await ctx.send(f"Probably pulled.\n```bash\n{g.pull()}```") + except git.exc.GitCommandError as e: + await ctx.send(f"An error has occured when pulling```bash\n{e}```") @commands.command(aliases=['addcommand', 'newcommand']) @commands.check(is_mod) async def setcommand(self, ctx, command, *, message): + """Add a new simple command""" self.bot.custom_commands[ctx.prefix + command] = message with open('custom_commands.json', 'w') as f: json.dump(self.bot.custom_commands, f, indent=4) @@ -45,20 +49,20 @@ class Admin(commands.Cog): @commands.command(aliases=['deletecommand']) @commands.check(is_mod) async def removecommand(self, ctx, command): + """Remove a simple command""" del self.bot.custom_commands[ctx.prefix + command] with open('custom_commands.json', 'w') as f: json.dump(self.bot.custom_commands, f, indent=4) await ctx.send(f"Removed command {command}") - - - @commands.check(is_mod) + @commands.command(name='reload', hidden=True, usage='<extension>') + @commands.check(is_mod) async def _reload(self, ctx, ext): """Reloads an extension""" try: self.bot.reload_extension(f'cogs.{ext}') - await ctx.send(f'The extension {ext} was realoaded!') # Oceanlight told me too + await ctx.send(f'The extension {ext} was reloaded!') except commands.ExtensionNotFound: await ctx.send(f'The extension {ext} doesn\'t exist.') except commands.ExtensionNotLoaded: @@ -68,9 +72,9 @@ class Admin(commands.Cog): except commands.ExtensionFailed: await ctx.send(f'Some unknown error happened while trying to reload extension {ext} (check logs)') self.bot.logger.exception(f'Failed to reload extension {ext}:') - - @commands.check(is_mod) + @commands.command(name='load', hidden=True, usage='<extension>') + @commands.check(is_mod) async def _load(self, ctx, ext): """Loads an extension""" try: @@ -86,8 +90,8 @@ class Admin(commands.Cog): await ctx.send(f'Some unknown error happened while trying to reload extension {ext} (check logs)') self.bot.logger.exception(f'Failed to reload extension {ext}:') - @commands.check(is_mod) @commands.command(name='unload', hidden=True, usage='<extension>') + @commands.check(is_mod) async def _unload(self, ctx, ext): """Loads an extension""" try: @@ -101,27 +105,14 @@ class Admin(commands.Cog): await ctx.send(f'Some unknown error happened while trying to reload extension {ext} (check logs)') self.bot.logger.exception(f'Failed to unload extension {ext}:') - """ - @commands.command() - @commands.check(is_mod) - async def connect(self, ctx): - await ctx.author.voice.channel.connect() - await ctx.send(f"Joined channel {ctx.author.voice.channel.name}") - - @commands.command() - @commands.check(is_mod) - async def disconnect(self, ctx): - await ctx.voice_client.disconnect() - await ctx.send(f"Left channel {ctx.author.voice.channel.name}") - """ - @commands.command() @commands.check(is_mod) async def clear(self, ctx, number): + """Mass delete messages""" await ctx.message.channel.purge(limit=int(number)+1, check=None, before=None, after=None, around=None, oldest_first=False, bulk=True) - @commands.check(is_mod) @commands.command() + @commands.check(is_mod) async def mute(self, ctx, members: commands.Greedy[discord.Member]=False, mute_minutes: int = 0, *, reason: str = "absolutely no reason"): @@ -130,11 +121,11 @@ class Admin(commands.Cog): if not members: await ctx.send("You need to name someone to mute") return - elif type(members)=="str": - members = self.bot.get_user(int(user)) + elif type(members)==str: + members = [self.bot.get_user(int(members))] #muted_role = discord.utils.find(ctx.guild.roles, name="Muted") - muted_role = ctx.guild.get_role(707707894694412371) + muted_role = ctx.guild.get_role(int(self.bot.config[str(ctx.message.guild.id)]["mute_role"])) for member in members: if self.bot.user == member: # what good is a muted bot? embed = discord.Embed(title = "You can't mute me, I'm an almighty bot") @@ -148,31 +139,59 @@ class Admin(commands.Cog): for member in members: await member.remove_roles(muted_role, reason = "time's up ") - @commands.check(is_mod) @commands.command() + @commands.check(is_mod) async def unmute(self, ctx, members: commands.Greedy[discord.Member]): + """Remove the muted role""" if not members: await ctx.send("You need to name someone to unmute") return - elif type(members)=="str": + elif type(members)==str: members = self.bot.get_user(int(user)) - muted_role = ctx.guild.get_role(707707894694412371) + muted_role = ctx.guild.get_role(int(self.bot.config[str(ctx.message.guild.id)]["mute_role"])) for i in members: await i.remove_roles(muted_role) await ctx.send("{0.mention} has been unmuted by {1.mention}".format(i, ctx.author)) @commands.command() - @commands.check(is_mod) - async def logs(self, ctx, *, password): - if password == "beep boop": - await ctx.message.delete() - file = discord.File("discord.log") - await ctx.send(file=file) + @commands.check(is_botmaster) + async def ban(self, ctx, members: commands.Greedy[discord.Member]=False, + ban_minutes: int = 0, + *, reason: str = "absolutely no reason"): + """Mass ban members with an optional mute_minutes parameter to time it""" + + if not members: + await ctx.send("You need to name someone to ban") + return + elif type(members)==str: + members = [self.bot.get_user(int(members))] + for member in members: + if self.bot.user == member: # what good is a muted bot? + embed = discord.Embed(title = "You can't ban me, I'm an almighty bot") + await ctx.send(embed = embed) + continue + await member.send(f"You have been banned from {ctx.guild.name} for {mute_minutes} minutes because: ```{reason}```") + await ctx.guild.ban(member, reason=reason, delete_message_days=0) + await ctx.send("{0.mention} has been banned by {1.mention} for *{2}*".format(member, ctx.author, reason)) - @commands.command(aliases=['ban'], hidden=True) + if mute_minutes > 0: + await asyncio.sleep(ban_minutes * 60) + for member in members: + await ctx.guild.unban(member, reason="Time is up") + + @commands.command() + @commands.check(is_botmaster) + async def logs(self, ctx): + """Send the discord.log file""" + await ctx.message.delete() + file = discord.File("discord.log") + await ctx.send(file=file) + + @commands.command(hidden=True) @commands.check(is_mod) async def blacklist(self, ctx, members: commands.Greedy[discord.Member]=None): + """Ban someone from using the bot""" if not members: await ctx.send("You need to name someone to blacklist") return @@ -190,6 +209,34 @@ class Admin(commands.Cog): json.dump(self.bot.blacklist, f, indent=4) await ctx.send(f"{i} has been blacklisted.") + @commands.command() + @commands.check(is_mod) + async def activity(self, ctx, *, activity=None): + """Change the bot's activity""" + if activity: + game = discord.Game(activity) + else: + activity = "Mining away" + game = discord.Game(activity) + await self.bot.change_presence(activity=game) + await ctx.send(f"Activity changed to {activity}") + + @commands.command() + @commands.check(is_botmaster) + async def setvar(self, ctx, key, *, value): + """Set a config variable, ***use with caution**""" + with open('config.json', 'w') as f: + if value[0] == '[' and value[len(value)-1] == ']': + value = list(map(int, value[1:-1].split(','))) + self.bot.config[str(ctx.message.guild.id)][key] = value + json.dump(self.bot.config, f, indent=4) + + @commands.command() + @commands.check(is_mod) + async def printvar(self, ctx, key): + """Print a config variable, use for testing""" + await ctx.send(self.bot.config[str(ctx.message.guild.id)][key]) + def setup(bot): bot.add_cog(Admin(bot)) |