mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-20 09:56:05 -05:00
[i18n] Pass over modlog, permissions, reports, streams, trivia, warnings
Signed-off-by: Toby Harradine <tobyharradine@gmail.com>
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
from typing import NamedTuple, Union, Optional
|
||||
from typing import NamedTuple, Union, Optional, cast, Type
|
||||
|
||||
from redbot.core import commands
|
||||
from redbot.core.i18n import Translator
|
||||
|
||||
_ = Translator("PermissionsConverters", __file__)
|
||||
|
||||
|
||||
class CogOrCommand(NamedTuple):
|
||||
@@ -18,39 +22,34 @@ class CogOrCommand(NamedTuple):
|
||||
return cls(type="COMMAND", name=cmd.qualified_name, obj=cmd)
|
||||
|
||||
raise commands.BadArgument(
|
||||
'Cog or command "{arg}" not found. Please note that this is case sensitive.'
|
||||
"".format(arg=arg)
|
||||
_(
|
||||
'Cog or command "{name}" not found. Please note that this is case sensitive.'
|
||||
).format(name=arg)
|
||||
)
|
||||
|
||||
|
||||
class RuleType:
|
||||
def RuleType(arg: str) -> bool:
|
||||
if arg.lower() in ("allow", "whitelist", "allowed"):
|
||||
return True
|
||||
if arg.lower() in ("deny", "blacklist", "denied"):
|
||||
return False
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@classmethod
|
||||
async def convert(cls, ctx: commands.Context, arg: str) -> bool:
|
||||
if arg.lower() in ("allow", "whitelist", "allowed"):
|
||||
return True
|
||||
if arg.lower() in ("deny", "blacklist", "denied"):
|
||||
return False
|
||||
|
||||
raise commands.BadArgument(
|
||||
'"{arg}" is not a valid rule. Valid rules are "allow" or "deny"'.format(arg=arg)
|
||||
)
|
||||
raise commands.BadArgument(
|
||||
_('"{arg}" is not a valid rule. Valid rules are "allow" or "deny"').format(arg=arg)
|
||||
)
|
||||
|
||||
|
||||
class ClearableRuleType:
|
||||
def ClearableRuleType(arg: str) -> Optional[bool]:
|
||||
if arg.lower() in ("allow", "whitelist", "allowed"):
|
||||
return True
|
||||
if arg.lower() in ("deny", "blacklist", "denied"):
|
||||
return False
|
||||
if arg.lower() in ("clear", "reset"):
|
||||
return None
|
||||
|
||||
# noinspection PyUnusedLocal
|
||||
@classmethod
|
||||
async def convert(cls, ctx: commands.Context, arg: str) -> Optional[bool]:
|
||||
if arg.lower() in ("allow", "whitelist", "allowed"):
|
||||
return True
|
||||
if arg.lower() in ("deny", "blacklist", "denied"):
|
||||
return False
|
||||
if arg.lower() in ("clear", "reset"):
|
||||
return None
|
||||
|
||||
raise commands.BadArgument(
|
||||
raise commands.BadArgument(
|
||||
_(
|
||||
'"{arg}" is not a valid rule. Valid rules are "allow" or "deny", or "clear" to '
|
||||
"remove the rule".format(arg=arg)
|
||||
)
|
||||
"remove the rule"
|
||||
).format(arg=arg)
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@ import asyncio
|
||||
import io
|
||||
import textwrap
|
||||
from copy import copy
|
||||
from typing import Union, Optional, Dict, List, Tuple, Any, Iterator, ItemsView
|
||||
from typing import Union, Optional, Dict, List, Tuple, Any, Iterator, ItemsView, cast
|
||||
|
||||
import discord
|
||||
import yaml
|
||||
@@ -287,9 +287,11 @@ class Permissions(commands.Cog):
|
||||
`<who_or_what>` is the user, channel, role or server the rule
|
||||
is for.
|
||||
"""
|
||||
# noinspection PyTypeChecker
|
||||
await self._add_rule(
|
||||
rule=allow_or_deny, cog_or_cmd=cog_or_command, model_id=who_or_what.id, guild_id=0
|
||||
rule=cast(bool, allow_or_deny),
|
||||
cog_or_cmd=cog_or_command,
|
||||
model_id=who_or_what.id,
|
||||
guild_id=0,
|
||||
)
|
||||
await ctx.send(_("Rule added."))
|
||||
|
||||
@@ -312,9 +314,8 @@ class Permissions(commands.Cog):
|
||||
|
||||
`<who_or_what>` is the user, channel or role the rule is for.
|
||||
"""
|
||||
# noinspection PyTypeChecker
|
||||
await self._add_rule(
|
||||
rule=allow_or_deny,
|
||||
rule=cast(bool, allow_or_deny),
|
||||
cog_or_cmd=cog_or_command,
|
||||
model_id=who_or_what.id,
|
||||
guild_id=ctx.guild.id,
|
||||
@@ -381,9 +382,10 @@ class Permissions(commands.Cog):
|
||||
`<cog_or_command>` is the cog or command to set the default
|
||||
rule for. This is case sensitive.
|
||||
"""
|
||||
# noinspection PyTypeChecker
|
||||
await self._set_default_rule(
|
||||
rule=allow_or_deny, cog_or_cmd=cog_or_command, guild_id=ctx.guild.id
|
||||
rule=cast(Optional[bool], allow_or_deny),
|
||||
cog_or_cmd=cog_or_command,
|
||||
guild_id=ctx.guild.id,
|
||||
)
|
||||
await ctx.send(_("Default set."))
|
||||
|
||||
@@ -403,9 +405,8 @@ class Permissions(commands.Cog):
|
||||
`<cog_or_command>` is the cog or command to set the default
|
||||
rule for. This is case sensitive.
|
||||
"""
|
||||
# noinspection PyTypeChecker
|
||||
await self._set_default_rule(
|
||||
rule=allow_or_deny, cog_or_cmd=cog_or_command, guild_id=GLOBAL
|
||||
rule=cast(Optional[bool], allow_or_deny), cog_or_cmd=cog_or_command, guild_id=GLOBAL
|
||||
)
|
||||
await ctx.send(_("Default set."))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user