mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-08 10:22:31 -05:00
started on multi server roles configuration
This commit is contained in:
17
cogs/utils/chat_formatting.py
Normal file
17
cogs/utils/chat_formatting.py
Normal file
@@ -0,0 +1,17 @@
|
||||
def bold(text):
|
||||
return "**"+str(text)+"**"
|
||||
|
||||
def italics(text):
|
||||
return "*"+str(text)+"*"
|
||||
|
||||
def strikethrough(text):
|
||||
return "~~"+str(text)+"~~"
|
||||
|
||||
def underline(text):
|
||||
return "__"+str(text)+"__"
|
||||
|
||||
def box(text):
|
||||
return "```"+str(text)+"```"
|
||||
|
||||
def inline(text):
|
||||
return "`"+str(text)+"`"
|
||||
@@ -13,8 +13,9 @@ import json
|
||||
try:
|
||||
with open("data/red/settings.json", "r") as f:
|
||||
settings = json.loads(f.read())
|
||||
except:
|
||||
settings = {"OWNER" : False, "ADMIN_ROLE" : False, "MOD_ROLE" : False}
|
||||
except Exception as e:
|
||||
print(e)
|
||||
settings = {"OWNER" : False, "default":{"ADMIN_ROLE" : False, "MOD_ROLE" : False}}
|
||||
|
||||
def is_owner_check(ctx):
|
||||
return ctx.message.author.id == settings["OWNER"]
|
||||
@@ -32,6 +33,17 @@ def is_owner():
|
||||
# the permissions required for them.
|
||||
# Of course, the owner will always be able to execute commands.
|
||||
|
||||
def save_bot_settings(bot_settings=settings):
|
||||
with open("data/red/settings.json", "w") as f:
|
||||
f.write(json.dumps(bot_settings,sort_keys=True,indent=4,separators=(',',':')))
|
||||
|
||||
def update_old_settings():
|
||||
mod = settings["MOD_ROLE"]
|
||||
admin = settings["ADMIN_ROLE"]
|
||||
del settings["MOD_ROLE"]
|
||||
del settings["ADMIN_ROLE"]
|
||||
settings["default"] = {"MOD_ROLE":mod,"ADMIN_ROLE":admin}
|
||||
|
||||
def check_permissions(ctx, perms):
|
||||
if is_owner_check(ctx):
|
||||
return True
|
||||
@@ -55,12 +67,30 @@ def role_or_permissions(ctx, check, **perms):
|
||||
|
||||
def mod_or_permissions(**perms):
|
||||
def predicate(ctx):
|
||||
return role_or_permissions(ctx, lambda r: r.name in (settings["MOD_ROLE"], settings["ADMIN_ROLE"]), **perms)
|
||||
if "default" not in settings:
|
||||
update_old_settings()
|
||||
if admin_or_permissions(**perms):
|
||||
return True
|
||||
sid = ctx.message.server.id
|
||||
if sid not in settings:
|
||||
mod_role = settings["default"]["MOD_ROLE"].lower()
|
||||
admin_role = settings["default"]["ADMIN_ROLE"].lower()
|
||||
else:
|
||||
mod_role = settings[sid]["MOD_ROLE"].lower()
|
||||
admin_role = settings[sid]["ADMIN_ROLE"].lower()
|
||||
return role_or_permissions(ctx, lambda r: r.name.lower() in (mod_role,admin_role), **perms)
|
||||
|
||||
return commands.check(predicate)
|
||||
|
||||
def admin_or_permissions(**perms):
|
||||
def predicate(ctx):
|
||||
return role_or_permissions(ctx, lambda r: r.name == settings["ADMIN_ROLE"], **perms)
|
||||
if "default" not in settings:
|
||||
update_old_settings()
|
||||
sid = ctx.message.server.id
|
||||
if sid not in settings:
|
||||
admin_role = settings["default"]["ADMIN_ROLE"]
|
||||
else:
|
||||
admin_role = settings[sid]["ADMIN_ROLE"]
|
||||
return role_or_permissions(ctx, lambda r: r.name.lower() == admin_role.lower(), **perms)
|
||||
|
||||
return commands.check(predicate)
|
||||
|
||||
Reference in New Issue
Block a user