mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-07 11:48:55 -05:00
[Permissions] Allow for multiple IDs in permissions rule commands. (#2448)
Use `commands.Greedy` to apply multiple rules at once. closes #2214
This commit is contained in:
parent
0f9501f93a
commit
30af83aa6a
@ -278,7 +278,7 @@ class Permissions(commands.Cog):
|
|||||||
ctx: commands.Context,
|
ctx: commands.Context,
|
||||||
allow_or_deny: RuleType,
|
allow_or_deny: RuleType,
|
||||||
cog_or_command: CogOrCommand,
|
cog_or_command: CogOrCommand,
|
||||||
who_or_what: GlobalUniqueObjectFinder,
|
who_or_what: commands.Greedy[GlobalUniqueObjectFinder],
|
||||||
):
|
):
|
||||||
"""Add a global rule to a command.
|
"""Add a global rule to a command.
|
||||||
|
|
||||||
@ -287,13 +287,13 @@ class Permissions(commands.Cog):
|
|||||||
`<cog_or_command>` is the cog or command to add the rule to.
|
`<cog_or_command>` is the cog or command to add the rule to.
|
||||||
This is case sensitive.
|
This is case sensitive.
|
||||||
|
|
||||||
`<who_or_what>` is the user, channel, role or server the rule
|
`<who_or_what>` is one or more users, channels or roles the rule is for.
|
||||||
is for.
|
|
||||||
"""
|
"""
|
||||||
|
for w in who_or_what:
|
||||||
await self._add_rule(
|
await self._add_rule(
|
||||||
rule=cast(bool, allow_or_deny),
|
rule=cast(bool, allow_or_deny),
|
||||||
cog_or_cmd=cog_or_command,
|
cog_or_cmd=cog_or_command,
|
||||||
model_id=who_or_what.id,
|
model_id=w.id,
|
||||||
guild_id=0,
|
guild_id=0,
|
||||||
)
|
)
|
||||||
await ctx.send(_("Rule added."))
|
await ctx.send(_("Rule added."))
|
||||||
@ -306,7 +306,7 @@ class Permissions(commands.Cog):
|
|||||||
ctx: commands.Context,
|
ctx: commands.Context,
|
||||||
allow_or_deny: RuleType,
|
allow_or_deny: RuleType,
|
||||||
cog_or_command: CogOrCommand,
|
cog_or_command: CogOrCommand,
|
||||||
who_or_what: GuildUniqueObjectFinder,
|
who_or_what: commands.Greedy[GuildUniqueObjectFinder],
|
||||||
):
|
):
|
||||||
"""Add a rule to a command in this server.
|
"""Add a rule to a command in this server.
|
||||||
|
|
||||||
@ -315,12 +315,13 @@ class Permissions(commands.Cog):
|
|||||||
`<cog_or_command>` is the cog or command to add the rule to.
|
`<cog_or_command>` is the cog or command to add the rule to.
|
||||||
This is case sensitive.
|
This is case sensitive.
|
||||||
|
|
||||||
`<who_or_what>` is the user, channel or role the rule is for.
|
`<who_or_what>` is one or more users, channels or roles the rule is for.
|
||||||
"""
|
"""
|
||||||
|
for w in who_or_what:
|
||||||
await self._add_rule(
|
await self._add_rule(
|
||||||
rule=cast(bool, allow_or_deny),
|
rule=cast(bool, allow_or_deny),
|
||||||
cog_or_cmd=cog_or_command,
|
cog_or_cmd=cog_or_command,
|
||||||
model_id=who_or_what.id,
|
model_id=w.id,
|
||||||
guild_id=ctx.guild.id,
|
guild_id=ctx.guild.id,
|
||||||
)
|
)
|
||||||
await ctx.send(_("Rule added."))
|
await ctx.send(_("Rule added."))
|
||||||
@ -331,19 +332,17 @@ class Permissions(commands.Cog):
|
|||||||
self,
|
self,
|
||||||
ctx: commands.Context,
|
ctx: commands.Context,
|
||||||
cog_or_command: CogOrCommand,
|
cog_or_command: CogOrCommand,
|
||||||
who_or_what: GlobalUniqueObjectFinder,
|
who_or_what: commands.Greedy[GlobalUniqueObjectFinder],
|
||||||
):
|
):
|
||||||
"""Remove a global rule from a command.
|
"""Remove a global rule from a command.
|
||||||
|
|
||||||
`<cog_or_command>` is the cog or command to remove the rule
|
`<cog_or_command>` is the cog or command to remove the rule
|
||||||
from. This is case sensitive.
|
from. This is case sensitive.
|
||||||
|
|
||||||
`<who_or_what>` is the user, channel, role or server the rule
|
`<who_or_what>` is one or more users, channels or roles the rule is for.
|
||||||
is for.
|
|
||||||
"""
|
"""
|
||||||
await self._remove_rule(
|
for w in who_or_what:
|
||||||
cog_or_cmd=cog_or_command, model_id=who_or_what.id, guild_id=GLOBAL
|
await self._remove_rule(cog_or_cmd=cog_or_command, model_id=w.id, guild_id=GLOBAL)
|
||||||
)
|
|
||||||
await ctx.send(_("Rule removed."))
|
await ctx.send(_("Rule removed."))
|
||||||
|
|
||||||
@commands.guild_only()
|
@commands.guild_only()
|
||||||
@ -353,18 +352,18 @@ class Permissions(commands.Cog):
|
|||||||
self,
|
self,
|
||||||
ctx: commands.Context,
|
ctx: commands.Context,
|
||||||
cog_or_command: CogOrCommand,
|
cog_or_command: CogOrCommand,
|
||||||
*,
|
who_or_what: commands.Greedy[GlobalUniqueObjectFinder],
|
||||||
who_or_what: GuildUniqueObjectFinder,
|
|
||||||
):
|
):
|
||||||
"""Remove a server rule from a command.
|
"""Remove a server rule from a command.
|
||||||
|
|
||||||
`<cog_or_command>` is the cog or command to remove the rule
|
`<cog_or_command>` is the cog or command to remove the rule
|
||||||
from. This is case sensitive.
|
from. This is case sensitive.
|
||||||
|
|
||||||
`<who_or_what>` is the user, channel or role the rule is for.
|
`<who_or_what>` is one or more users, channels or roles the rule is for.
|
||||||
"""
|
"""
|
||||||
|
for w in who_or_what:
|
||||||
await self._remove_rule(
|
await self._remove_rule(
|
||||||
cog_or_cmd=cog_or_command, model_id=who_or_what.id, guild_id=ctx.guild.id
|
cog_or_cmd=cog_or_command, model_id=w.id, guild_id=ctx.guild.id
|
||||||
)
|
)
|
||||||
await ctx.send(_("Rule removed."))
|
await ctx.send(_("Rule removed."))
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user