From 6a39bb75f7bfed5e9f95aa70712bdad8d6f7ffa6 Mon Sep 17 00:00:00 2001 From: Akumatic Date: Wed, 20 Jun 2018 02:55:37 +0200 Subject: [PATCH] moderation added --- extensions/moderation.py | 127 +++++++++++++++++++++++++++++++++++++++ settings.json | 3 +- 2 files changed, 129 insertions(+), 1 deletion(-) create mode 100644 extensions/moderation.py diff --git a/extensions/moderation.py b/extensions/moderation.py new file mode 100644 index 0000000..d60ac9c --- /dev/null +++ b/extensions/moderation.py @@ -0,0 +1,127 @@ +import discord, json, akuma +from discord.ext import commands + +modCommands = """```Possible Commands: + mod setJoinMessage +```""" + +adminCommands = """```Possible Commands: + admin addMod + admin rmMod +```""" + +ownerCommands = """```Possible Commands: + owner addAdmin + owner rmAdmin + owner load + owner unload + owner reload + ```""" + +class Moderation(): + def __init__(self, bot): + self.bot = bot + + @commands.command() + async def suggest(self, ctx, *, msg : str): + """Makes a suggestion to the moderation team. + + Planned: If there's no suggestionChannel specified, send a pm to the owner.""" + await ctx.message.delete() + e = discord.Embed(color=0x6428c8) + e.set_author(name=ctx.author, icon_url=ctx.author.avatar_url) + e.add_field(name="Suggestion", value=msg) + if(akuma.c["suggestionChannel"] != 0): + chan = self.bot.get_channel(akuma.c["suggestionChannel"]) + await chan.send(embed=e) + else: + await ctx.send(e) + + ### Mod Commands ### + @commands.group() + async def mod(self, ctx): + """Commands usable a Mod""" + if (ctx.author.id not in akuma.c["mods"]): + return + if ctx.invoked_subcommand is None: + await ctx.send(modCommands) + + @mod.command() + async def setJoinMessage(self, ctx, *, msg : str): + akuma.c["joinMessage"] = msg + akuma.writeJSON(akuma.c) + await ctx.send("Join Message sucessfully changed to: " + msg) + + ### Admin Commands ### + @commands.group() + async def admin(self, ctx): + """Commands usable by an Admin""" + if(ctx.author.id not in akuma.c["admins"]): + return + if ctx.invoked_subcommand is None: + await ctx.send(adminCommands) + + @admin.command() + async def addMod(self, ctx, id : int = None): + if (id == None): + await ctx.send("Missing id") + return + if(id not in akuma.c["mods"]): + akuma.c["mods"].append(id) + akuma.writeJSON(akuma.c) + await ctx.send("Added user id " + str(id) + " to mods") + else: + return await ctx.send("User is already a mod") + + @admin.command() + async def rmMod(self, ctx, id : int = None): + if (id == None): + return await ctx.send("Missing id") + if(id in akuma.c["mods"]): + if(id in akuma.c["admins"] and ctx.author.id != akuma.c["owner"]): + return await ctx.send("You can't remove this ID") + else: + akuma.c["mods"].remove(id) + akuma.writeJSON(akuma.c) + else: + return await ctx.send("User wasn't an admin") + + ### Owner Commands ### + @commands.group() + async def owner(self, ctx): + """Commands usable by the Owner""" + if (ctx.author.id not in akuma.c["owner"]): + return + if ctx.invoked_subcommand is None: + await ctx.send(ownerCommands) + + @owner.command() + async def addAdmin(self, ctx, id : int = None): + if (id == None): + return await ctx.send("Missing id") + if(id not in akuma.c["admins"]): + akuma.c["admins"].append(id) + await ctx.send("Added user ID " + str(id) + " to admins") + else: + return await ctx.send("User is already an admin") + if(id not in akuma.c["mods"]): + akuma.c["mods"].append(id) + await ctx.send("Added user id " + str(id) + " to mods") + else: + return await ctx.send("User is already a mod") + akuma.writeJSON(akuma.c) + + @owner.command() + async def rmAdmin(self, ctx, id : int = None): + if (id == None): + return await ctx.send("Missing id") + if(id in akuma.c["admins"]): + akuma.c["admins"].remove(id) + akuma.writeJSON(akuma.c) + await ctx.send("Removed user id " + str(id) + " from admins") + else: + return await ctx.send("User wasn't an admin") + +#Setup +def setup(bot): + bot.add_cog(Moderation(bot)) \ No newline at end of file diff --git a/settings.json b/settings.json index 704067e..c0240b6 100644 --- a/settings.json +++ b/settings.json @@ -7,7 +7,8 @@ "admins": [], "mods": [], "extensions": [ - "fun" + "fun", + "moderation" ], "joinMessage": "", "suggestionChannel": 0