Added user, reworked mod functions

This commit is contained in:
Akumatic 2018-06-20 16:56:25 +02:00
parent e9fa28aaed
commit e224c9a41a
3 changed files with 109 additions and 79 deletions

View File

@ -1,5 +1,6 @@
import discord, json, akuma import discord, json
from discord.ext import commands from discord.ext import commands
from akuma import c, writeJSON
modCommands = """```Possible Commands: modCommands = """```Possible Commands:
mod setJoinMessage <msg> mod setJoinMessage <msg>
@ -13,114 +14,127 @@ adminCommands = """```Possible Commands:
ownerCommands = """```Possible Commands: ownerCommands = """```Possible Commands:
owner addAdmin <id> owner addAdmin <id>
owner rmAdmin <id> owner rmAdmin <id>
owner load <ext>
owner unload <ext>
owner reload <ext>
```""" ```"""
class Moderation(): class Moderation():
def __init__(self, bot): def __init__(self, bot):
self.bot = bot self.bot = bot
@commands.command() #Groups
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() @commands.group()
async def mod(self, ctx): async def mod(self, ctx):
"""Commands usable a Mod""" """Commands usable a Mod"""
if (ctx.author.id not in akuma.c["mods"]): if (ctx.author.id not in c["mods"]):
return return
if ctx.invoked_subcommand is None: if ctx.invoked_subcommand is None:
await ctx.send(modCommands) 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() @commands.group()
async def admin(self, ctx): async def admin(self, ctx):
"""Commands usable by an Admin""" """Commands usable by an Admin"""
if(ctx.author.id not in akuma.c["admins"]): if(ctx.author.id not in c["admins"]):
return return
if ctx.invoked_subcommand is None: if ctx.invoked_subcommand is None:
await ctx.send(adminCommands) await ctx.send(adminCommands)
@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)
### Mod Commands ###
@mod.command()
async def setJoinMessage(self, ctx, *, msg : str):
c["joinMessage"] = msg
writeJSON(c)
await ctx.send("Join Message sucessfully changed to: " + msg)
### Admin Commands ###
@admin.command() @admin.command()
async def addMod(self, ctx, id : int = None): async def addMod(self, ctx, id : int = None):
if (id == None): if (id == None):
await ctx.send("Missing id") return await ctx.send("Missing id")
return user = ctx.guild.get_member(id)
if(id not in akuma.c["mods"]): if user is None:
akuma.c["mods"].append(id) return await ctx.send("User not Found")
akuma.writeJSON(akuma.c) #Add Mod Role to User
await ctx.send("Added user id " + str(id) + " to mods") if(c["modRole"] not in [r.name for r in user.roles]):
await user.add_roles(discord.utils.get(ctx.guild.roles, name=c["modRole"]))
await ctx.send("User " + user.name + " was added to " + c["modRole"])
else: else:
return await ctx.send("User is already a mod") return await ctx.send("User " + user.name + " is already in " + c["modRole"])
@admin.command() @admin.command()
async def rmMod(self, ctx, id : int = None): async def rmMod(self, ctx, id : int = None):
if (id == None): if (id == None):
return await ctx.send("Missing id") return await ctx.send("Missing id")
if(id in akuma.c["mods"]): user = ctx.guild.get_member(id)
if(id in akuma.c["admins"] and ctx.author.id != akuma.c["owner"]): 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(c["adminRole"] in [r.name for r in user.roles] and ctx.author.id != ctx.guild.owner.id):
return await ctx.send("You can't remove this ID") return await ctx.send("You can't remove this ID")
if(c["modRole"] in [r.name for r in user.roles]):
await user.remove_roles(discord.utils.get(ctx.guild.roles, name=c["modRole"]))
await ctx.send("User " + user.name + " was removed from " + c["modRole"])
else: else:
akuma.c["mods"].remove(id) return await ctx.send("User " + user.name + " wasn't in " + c["modRole"])
akuma.writeJSON(akuma.c)
else:
return await ctx.send("User wasn't an admin")
### Owner Commands ### ### Owner Commands ###
@commands.group() @owner.command()
async def owner(self, ctx): async def setModRole(self, ctx, msg : str):
"""Commands usable by the Owner""" if(msg not in [r.name for r in ctx.guild.roles]):
if (ctx.author.id not in akuma.c["owner"]): return await ctx.send("Role " + msg + " does not exist")
return c["modRole"] = msg
if ctx.invoked_subcommand is None: writeJSON(c)
await ctx.send(ownerCommands) 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")
c["adminRole"] = msg
writeJSON(c)
await ctx.send("Admin role set")
@owner.command() @owner.command()
async def addAdmin(self, ctx, id : int = None): async def addAdmin(self, ctx, id : int = None):
if (id == None): if (id == None):
return await ctx.send("Missing id") return await ctx.send("Missing id")
if(id not in akuma.c["admins"]): user = ctx.guild.get_member(id)
akuma.c["admins"].append(id) if user is None:
await ctx.send("Added user ID " + str(id) + " to admins") return await ctx.send("User not Found")
#Add Admin Role to User
if(c["adminRole"] not in [r.name for r in user.roles]):
await user.add_roles(discord.utils.get(ctx.guild.roles, name=c["adminRole"]))
await ctx.send("User " + user.name + " was added to " + c["adminRole"])
else: else:
return await ctx.send("User is already an admin") return await ctx.send("User " + user.name + " is already in " + c["adminRole"])
if(id not in akuma.c["mods"]): #Add Mod Role to User
akuma.c["mods"].append(id) if(c["modRole"] not in [r.name for r in user.roles]):
await ctx.send("Added user id " + str(id) + " to mods") await user.add_roles(discord.utils.get(ctx.guild.roles, name=c["modRole"]))
await ctx.send("User " + user.name + " was added to " + c["modRole"])
else: else:
return await ctx.send("User is already a mod") return await ctx.send("User " + user.name + " is already in " + c["modRole"])
akuma.writeJSON(akuma.c)
@owner.command() @owner.command()
async def rmAdmin(self, ctx, id : int = None): async def rmAdmin(self, ctx, id : int = None):
if (id == None): if (id == None):
return await ctx.send("Missing id") return await ctx.send("Missing id")
if(id in akuma.c["admins"]): user = ctx.guild.get_member(id)
akuma.c["admins"].remove(id) if user is None:
akuma.writeJSON(akuma.c) return await ctx.send("User not Found")
await ctx.send("Removed user id " + str(id) + " from admins") if (user.id == ctx.author.id):
return await ctx.send("You can't remove yourself from Admins")
if(c["adminRole"] in [r.name for r in user.roles]):
await user.remove_roles(discord.utils.get(ctx.guild.roles, name=c["adminRole"]))
await ctx.send("User " + user.name + " was removed from " + c["adminRole"])
else: else:
return await ctx.send("User wasn't an admin") return await ctx.send("User " + user.name + " wasn't in " + c["adminRole"])
#Setup #Setup
def setup(bot): def setup(bot):

31
extensions/user.py Normal file
View File

@ -0,0 +1,31 @@
from discord.ext import commands
from akuma import c
import discord
class User():
def __init__(self, bot):
self.bot = bot
@commands.command()
async def greetMe(self, ctx):
"""Prints the greeting text a user receives by joining the server"""
await ctx.send(c["joinMessage"])
@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(c["suggestionChannel"] != 0):
chan = self.bot.get_channel(c["suggestionChannel"])
await chan.send(embed=e)
else:
await ctx.send(e)
#Setup
def setup(bot):
bot.add_cog(User(bot))

View File

@ -1,15 +0,0 @@
{
"token": "",
"prefix": "~",
"description": "A Discord Bot written by Akuma#7346",
"game": "",
"owner": 0,
"admins": [],
"mods": [],
"extensions": [
"fun",
"moderation"
],
"joinMessage": "",
"suggestionChannel": 0
}