Просмотр исходного кода

Should work now with those commands. Just need to add checks to custom commands.

tags/v1.1.0
roxie 6 лет назад
Родитель
Сommit
cf75202cef
3 измененных файлов: 28 добавлений и 15 удалений
  1. +11
    -0
      checks.py
  2. +16
    -14
      cogs/settings.py
  3. +1
    -1
      config/servers.json

+ 11
- 0
checks.py Просмотреть файл

@@ -5,6 +5,17 @@ from config.server_config import ServerConfig
def is_bot_owner():
return commands.check(lambda ctx: ctx.message.author.id == load_config.owner)

def is_owner_or_admin():
def predicate(ctx):
if ctx.message.author.id == load_config.owner:
return True
else:
for role in ctx.message.author.roles:
if role.id in ServerConfig().load_config()[ctx.message.server.id]["perm_roles"]["admin"]:
return True
return False
return commands.check(predicate)

def is_nfsw_enabled():
return commands.check(lambda ctx: ServerConfig().load_config()[ctx.message.server.id]["nsfw"]["enabled"] == 1)


+ 16
- 14
cogs/settings.py Просмотреть файл

@@ -149,40 +149,42 @@ class Settings():
self.con.update_config(self.servers)
return await self.bot.say("Muted role set to '{}'".format(role.name))

@group(pass_context=True, hidden=True)
@checks.is_bot_owner()
@group(pass_context=True)
@checks.is_owner_or_admin()
async def add(self, ctx):
"OWNER OR ADMIN ONLY: Adds to lists like admin roles."
if ctx.invoked_subcommand is None:
return await self.bot.say('Missing Argument')

@add.command(pass_context=True, hidden=True)
async def adminrole(self, ctx, *, role: discord.Role = None):
@add.command(pass_context=True, aliases=["adminrole"])
async def addadminrole(self, ctx, *, role: discord.Role = None):
self.servers = self.con.load_config()
if role.id not in self.servers[ctx.message.server.id]["perm_roles"]["admin"]:
self.servers[ctx.message.server.id]["perm_roles"]["admin"].append(role.id)
self.con.update_config(self.servers)
return await self.bot.say("'{}' has been added to the Admin role list.".format(role.name))
else:
return await self.bot.say("'{}' is already in the list.")
return await self.bot.say("'{}' is already in the list.".format(role.name))

@add.command(pass_context=True, hidden=True)
async def modrole(self, ctx, *, role: discord.Role = None):
@add.command(pass_context=True, aliases=["modrole"])
async def addmodrole(self, ctx, *, role: discord.Role = None):
self.servers = self.con.load_config()
if role.id not in self.servers[ctx.message.server.id]["perm_roles"]["mod"]:
self.servers[ctx.message.server.id]["perm_roles"]["mod"].append(role.id)
self.con.update_config(self.servers)
return await self.bot.say("'{}' has been added to the Mod role list.".format(role.name))
else:
return await self.bot.say("'{}' is already in the list.")
return await self.bot.say("'{}' is already in the list.".format(role.name))

@group(pass_context=True, hidden=True)
@checks.is_bot_owner()
@group(pass_context=True)
@checks.is_owner_or_admin()
async def remove(self, ctx):
"OWNER OR ADMIN ONLY: Removes things like admin roles."
if ctx.invoked_subcommand is None:
return await self.bot.say('Missing Argument')

@remove.command(pass_context=True, hidden=True)
async def adminrole(self, ctx, *, role: discord.Role = None):
@remove.command(pass_context=True, aliases=["adminrole"])
async def readminrole(self, ctx, *, role: discord.Role = None):
self.servers = self.con.load_config()
try:
self.servers[ctx.message.server.id]["perm_roles"]["admin"].remove(role.id)
@@ -191,8 +193,8 @@ class Settings():
self.con.update_config(self.servers)
return await self.bot.say("'{}' has been removed from the Admin role list.".format(role.name))

@remove.command(pass_context=True, hidden=True)
async def modrole(self, ctx, *, role: discord.Role = None):
@remove.command(pass_context=True, aliases=["modrole"])
async def remodrole(self, ctx, *, role: discord.Role = None):
self.servers = self.con.load_config()
try:
self.servers[ctx.message.server.id]["perm_roles"]["mod"].remove(role.id)

+ 1
- 1
config/servers.json Просмотреть файл

@@ -1 +1 @@
{"304048071963312130": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "hellow", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "mute": {"role": "", "admin-role": []}, "nsfw": {"enabled": 0}, "admin_role": {"role": ""}, "custom_commands": {"0": {"test": "\"testedit\"", "hello": "<:tingles:346838411639914506>", "benis": "\ud83c\udd71enis", "sophie": "<@136619052994002944>", "myra": "<@342213251372941312>", "roxieee": "<@!142735312626515979>", "customs": "\"\ud83d\udec3\"", "zzz": "\ud83d\udca4", "lewd!": "\ud83d\udea8 lewd! \ud83d\udea8"}, "1": {}}, "perm_roles": {"admin": ["308082456743903233"], "mod": ["307330606348632064"]}}}
{"304048071963312130": {"greets": {"enabled": 0, "welcome-channel": "", "member-role": "", "custom-message": "hellow", "default-message": "Be sure to read the rules."}, "goodbyes": {"enabled": 0, "goodbye-channel": ""}, "self_assign": {"enabled": 0, "roles": []}, "twitch": {"enabled": 0, "twitch-channel": "", "whitelist": {"enabled": 0, "list": []}}, "mute": {"role": "", "admin-role": []}, "nsfw": {"enabled": 0}, "admin_role": {"role": ""}, "custom_commands": {"0": {"test": "\"testedit\"", "hello": "<:tingles:346838411639914506>", "benis": "\ud83c\udd71enis", "sophie": "<@136619052994002944>", "myra": "<@342213251372941312>", "roxieee": "<@!142735312626515979>", "customs": "\"\ud83d\udec3\"", "zzz": "\ud83d\udca4", "lewd!": "\ud83d\udea8 lewd! \ud83d\udea8"}, "1": {}}, "perm_roles": {"admin": ["308082456743903233", "308083509866659850"], "mod": ["307330606348632064"]}}}

Загрузка…
Отмена
Сохранить