mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-22 02:37:57 -05:00
[Core] Multiple mod admin roles (#2783)
* Adds Schema versioning - Adds Migration tool - Adds tool to migrate to allow multiple admin and mod roles - Supports Multiple mod and admin roles * Ensures migration is run prior to cog load and connection to discord * Updates to not rely on singular mod/admin role id * Update requires logic for multiple mod/admin roles * Add new commands for managing mod/admin roles * Feedback Update strings Update docstrings Add aliases * Use snowflakelist * paginate * Change variable name * Fix mistake * handle settings view fix * Fix name error * I'm bad at Ux * style fix
This commit is contained in:
@@ -33,7 +33,7 @@ from redbot.core import (
|
||||
i18n,
|
||||
)
|
||||
from .utils.predicates import MessagePredicate
|
||||
from .utils.chat_formatting import humanize_timedelta, pagify, box, inline
|
||||
from .utils.chat_formatting import humanize_timedelta, pagify, box, inline, humanize_list
|
||||
|
||||
from .commands.requires import PrivilegeLevel
|
||||
|
||||
@@ -705,15 +705,17 @@ class Core(commands.Cog, CoreLogic):
|
||||
if ctx.invoked_subcommand is None:
|
||||
if ctx.guild:
|
||||
guild = ctx.guild
|
||||
admin_role = (
|
||||
guild.get_role(await ctx.bot.db.guild(ctx.guild).admin_role()) or "Not set"
|
||||
)
|
||||
mod_role = (
|
||||
guild.get_role(await ctx.bot.db.guild(ctx.guild).mod_role()) or "Not set"
|
||||
admin_role_ids = await ctx.bot.db.guild(ctx.guild).admin_role()
|
||||
admin_role_names = [r.name for r in guild.roles if r.id in admin_role_ids]
|
||||
admin_roles_str = (
|
||||
humanize_list(admin_role_names) if admin_role_names else "Not Set."
|
||||
)
|
||||
mod_role_ids = await ctx.bot.db.guild(ctx.guild).mod_role()
|
||||
mod_role_names = [r.name for r in guild.roles if r.id in mod_role_ids]
|
||||
mod_roles_str = humanize_list(mod_role_names) if mod_role_names else "Not Set."
|
||||
prefixes = await ctx.bot.db.guild(ctx.guild).prefix()
|
||||
guild_settings = _("Admin role: {admin}\nMod role: {mod}\n").format(
|
||||
admin=admin_role, mod=mod_role
|
||||
guild_settings = _("Admin roles: {admin}\nMod roles: {mod}\n").format(
|
||||
admin=admin_roles_str, mod=mod_roles_str
|
||||
)
|
||||
else:
|
||||
guild_settings = ""
|
||||
@@ -734,23 +736,60 @@ class Core(commands.Cog, CoreLogic):
|
||||
guild_settings=guild_settings,
|
||||
locale=locale,
|
||||
)
|
||||
await ctx.send(box(settings))
|
||||
for page in pagify(settings):
|
||||
await ctx.send(box(page))
|
||||
|
||||
@_set.command()
|
||||
@checks.guildowner()
|
||||
@commands.guild_only()
|
||||
async def adminrole(self, ctx: commands.Context, *, role: discord.Role):
|
||||
"""Sets the admin role for this server"""
|
||||
await ctx.bot.db.guild(ctx.guild).admin_role.set(role.id)
|
||||
await ctx.send(_("The admin role for this guild has been set."))
|
||||
async def addadminrole(self, ctx: commands.Context, *, role: discord.Role):
|
||||
"""
|
||||
Adds an admin role for this guild.
|
||||
"""
|
||||
async with ctx.bot.db.guild(ctx.guild).admin_role() as roles:
|
||||
if role.id in roles:
|
||||
return await ctx.send(_("This role is already an admin role."))
|
||||
roles.append(role.id)
|
||||
await ctx.send(_("That role is now considered an admin role."))
|
||||
|
||||
@_set.command()
|
||||
@checks.guildowner()
|
||||
@commands.guild_only()
|
||||
async def modrole(self, ctx: commands.Context, *, role: discord.Role):
|
||||
"""Sets the mod role for this server"""
|
||||
await ctx.bot.db.guild(ctx.guild).mod_role.set(role.id)
|
||||
await ctx.send(_("The mod role for this guild has been set."))
|
||||
async def addmodrole(self, ctx: commands.Context, *, role: discord.Role):
|
||||
"""
|
||||
Adds a mod role for this guild.
|
||||
"""
|
||||
async with ctx.bot.db.guild(ctx.guild).mod_role() as roles:
|
||||
if role.id in roles:
|
||||
return await ctx.send(_("This role is already a mod role."))
|
||||
roles.append(role.id)
|
||||
await ctx.send(_("That role is now considered a mod role."))
|
||||
|
||||
@_set.command(aliases=["remadmindrole", "deladminrole", "deleteadminrole"])
|
||||
@checks.guildowner()
|
||||
@commands.guild_only()
|
||||
async def removeadminrole(self, ctx: commands.Context, *, role: discord.Role):
|
||||
"""
|
||||
Removes an admin role for this guild.
|
||||
"""
|
||||
async with ctx.bot.db.guild(ctx.guild).admin_role() as roles:
|
||||
if role.id not in roles:
|
||||
return await ctx.send(_("That role was not an admin role to begin with."))
|
||||
roles.remove(role.id)
|
||||
await ctx.send(_("That role is no longer considered an admin role."))
|
||||
|
||||
@_set.command(aliases=["remmodrole", "delmodrole", "deletemodrole"])
|
||||
@checks.guildowner()
|
||||
@commands.guild_only()
|
||||
async def removemodrole(self, ctx: commands.Context, *, role: discord.Role):
|
||||
"""
|
||||
Removes a mod role for this guild.
|
||||
"""
|
||||
async with ctx.bot.db.guild(ctx.guild).mod_role() as roles:
|
||||
if role.id not in roles:
|
||||
return await ctx.send(_("That role was not a mod role to begin with."))
|
||||
roles.remove(role.id)
|
||||
await ctx.send(_("That role is no longer considered a mod role."))
|
||||
|
||||
@_set.command(aliases=["usebotcolor"])
|
||||
@checks.guildowner()
|
||||
|
||||
Reference in New Issue
Block a user