[i18n] Pass over modlog, permissions, reports, streams, trivia, warnings

Signed-off-by: Toby Harradine <tobyharradine@gmail.com>
This commit is contained in:
Toby Harradine
2018-10-05 17:37:26 +10:00
parent fa692ccc0b
commit 443f2ca556
10 changed files with 498 additions and 435 deletions

View File

@@ -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)
)

View File

@@ -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."))