Akuma-Matata/extensions/moderation.py

141 lines
5.9 KiB
Python
Raw Normal View History

import discord
2018-06-20 02:55:37 +02:00
from discord.ext import commands
from akuma import s, c, writeServer
2018-06-20 02:55:37 +02:00
modCommands = """```Possible Commands:
mod setJoinMessage <msg>
```"""
adminCommands = """```Possible Commands:
admin addMod <id>
admin rmMod <id>
```"""
ownerCommands = """```Possible Commands:
owner addAdmin <id>
owner rmAdmin <id>
```"""
class Moderation():
def __init__(self, bot):
self.bot = bot
2018-06-20 16:56:25 +02:00
#Groups
2018-06-20 02:55:37 +02:00
@commands.group()
async def mod(self, ctx):
"""Commands usable a Mod"""
if (s[str(ctx.guild.id)]["modRole"] not in [r.name for r in ctx.author.roles]):
2018-06-20 02:55:37 +02:00
return
if ctx.invoked_subcommand is None:
await ctx.send(modCommands)
@commands.group()
async def admin(self, ctx):
"""Commands usable by an Admin"""
if(s[str(ctx.guild.id)]["adminRole"] not in [r.name for r in ctx.author.roles]):
2018-06-20 02:55:37 +02:00
return
if ctx.invoked_subcommand is None:
await ctx.send(adminCommands)
2018-06-20 16:56:25 +02:00
@commands.group()
async def owner(self, ctx):
"""Commands usable by the Owner"""
if (ctx.author.id != ctx.guild.owner.id):
return
if ctx.invoked_subcommand is None:
await ctx.send(ownerCommands)
2018-06-20 02:55:37 +02:00
2018-06-20 16:56:25 +02:00
### Mod Commands ###
@mod.command()
async def setJoinMessage(self, ctx, *, msg : str):
s[str(ctx.guild.id)]["joinMessage"] = msg
writeServer(s)
2018-06-20 16:56:25 +02:00
await ctx.send("Join Message sucessfully changed to: " + msg)
### Admin Commands ###
2018-06-20 02:55:37 +02:00
@admin.command()
async def addMod(self, ctx, id : int = None):
if (id == None):
2018-06-20 16:56:25 +02:00
return await ctx.send("Missing id")
user = ctx.guild.get_member(id)
if user is None:
return await ctx.send("User not Found")
#Add Mod Role to User
if(s[str(ctx.guild.id)]["modRole"] not in [r.name for r in user.roles]):
await user.add_roles(discord.utils.get(ctx.guild.roles, name=s[str(ctx.guild.id)]["modRole"]))
await ctx.send("User " + user.name + " was added to " + s[str(ctx.guild.id)]["modRole"])
2018-06-20 02:55:37 +02:00
else:
return await ctx.send("User " + user.name + " is already in " + s[str(ctx.guild.id)]["modRole"])
2018-06-20 02:55:37 +02:00
@admin.command()
async def rmMod(self, ctx, id : int = None):
if (id == None):
return await ctx.send("Missing id")
2018-06-20 16:56:25 +02:00
user = ctx.guild.get_member(id)
if user is None:
return await ctx.send("User not Found")
if (user.id == ctx.author.id):
return await ctx.send("You can't remove yourself from Mods")
if(s[str(ctx.guild.id)]["adminRole"] in [r.name for r in user.roles] and ctx.author.id != ctx.guild.owner.id):
2018-06-20 16:56:25 +02:00
return await ctx.send("You can't remove this ID")
if(s[str(ctx.guild.id)]["modRole"] in [r.name for r in user.roles]):
await user.remove_roles(discord.utils.get(ctx.guild.roles, name=s[str(ctx.guild.id)]["modRole"]))
await ctx.send("User " + user.name + " was removed from " + s[str(ctx.guild.id)]["modRole"])
2018-06-20 02:55:37 +02:00
else:
return await ctx.send("User " + user.name + " wasn't in " + s[str(ctx.guild.id)]["modRole"])
2018-06-20 02:55:37 +02:00
### Owner Commands ###
2018-06-20 16:56:25 +02:00
@owner.command()
async def setModRole(self, ctx, msg : str):
if(msg not in [r.name for r in ctx.guild.roles]):
return await ctx.send("Role " + msg + " does not exist")
s[str(ctx.guild.id)]["modRole"] = msg
writeServer(s)
2018-06-20 16:56:25 +02:00
await ctx.send("Mod role set")
@owner.command()
async def setAdminRole(self, ctx, msg : str):
if(msg not in [r.name for r in ctx.guild.roles]):
return await ctx.send("Role " + msg + " does not exist")
s[str(ctx.guild.id)]["adminRole"] = msg
writeServer(s)
2018-06-20 16:56:25 +02:00
await ctx.send("Admin role set")
2018-06-20 02:55:37 +02:00
@owner.command()
async def addAdmin(self, ctx, id : int = None):
if (id == None):
return await ctx.send("Missing id")
2018-06-20 16:56:25 +02:00
user = ctx.guild.get_member(id)
if user is None:
return await ctx.send("User not Found")
#Add Admin Role to User
if(s[str(ctx.guild.id)]["adminRole"] not in [r.name for r in user.roles]):
await user.add_roles(discord.utils.get(ctx.guild.roles, name=s[str(ctx.guild.id)]["adminRole"]))
await ctx.send("User " + user.name + " was added to " + s[str(ctx.guild.id)]["adminRole"])
2018-06-20 02:55:37 +02:00
else:
return await ctx.send("User " + user.name + " is already in " + s[str(ctx.guild.id)]["adminRole"])
2018-06-20 16:56:25 +02:00
#Add Mod Role to User
if(s[str(ctx.guild.id)]["modRole"] not in [r.name for r in user.roles]):
await user.add_roles(discord.utils.get(ctx.guild.roles, name=s[str(ctx.guild.id)]["modRole"]))
await ctx.send("User " + user.name + " was added to " + s[str(ctx.guild.id)]["modRole"])
2018-06-20 02:55:37 +02:00
else:
return await ctx.send("User " + user.name + " is already in " + s[str(ctx.guild.id)]["modRole"])
2018-06-20 02:55:37 +02:00
@owner.command()
async def rmAdmin(self, ctx, id : int = None):
if (id == None):
return await ctx.send("Missing id")
2018-06-20 16:56:25 +02:00
user = ctx.guild.get_member(id)
if user is None:
return await ctx.send("User not Found")
if (user.id == ctx.author.id):
return await ctx.send("You can't remove yourself from Admins")
if(s[str(ctx.guild.id)]["adminRole"] in [r.name for r in user.roles]):
await user.remove_roles(discord.utils.get(ctx.guild.roles, name=s[str(ctx.guild.id)]["adminRole"]))
await ctx.send("User " + user.name + " was removed from " + s[str(ctx.guild.id)]["adminRole"])
2018-06-20 02:55:37 +02:00
else:
return await ctx.send("User " + user.name + " wasn't in " + s[str(ctx.guild.id)]["adminRole"])
2018-06-20 02:55:37 +02:00
#Setup
def setup(bot):
bot.add_cog(Moderation(bot))