[Core] Guild scoped I18n (#3896)

* Guild I18n

Never again!

* Finish off guild scoped i18n

* Black formatting

* Added guild only flags.

* Fix missing import.

* Added listing of guild i18n settings

* Added API support

* Added API support... properly!

* Added API support... for realsies!

* Auto-translate create_cases instances

You're welcome cog creators! Jack talked me into this!

* Fix get_regional_format to actually return properly

* Cleanup `set showsettings`

* Style pass

* Update redbot/core/core_commands.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* Update redbot/core/events.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* Update redbot/core/core_commands.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* Fix missing import

* Improve caching

* Removal of unneeded function

* Fix some naming

* IDFK anymore...

* Reformat

* Update redbot/core/settings_caches.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* Update redbot/core/settings_caches.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* Update redbot/core/settings_caches.py

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* Remove line number

* Fix global sets

* Set contextual locale manually where needed

* Reports cog is wonderful...

* Update redbot/core/core_commands.py

Co-authored-by: Draper <27962761+Drapersniper@users.noreply.github.com>

* Set contextual locale manually where needed in Mutes cog

* s

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
Co-authored-by: Draper <27962761+Drapersniper@users.noreply.github.com>
This commit is contained in:
Kowlin
2020-10-26 17:59:11 +01:00
committed by GitHub
parent 7bb6e60c52
commit 2413c6abd3
13 changed files with 341 additions and 36 deletions

View File

@@ -170,7 +170,7 @@ class Alias(commands.Cog):
for p in prefixes:
if content.startswith(p):
return p
raise ValueError(_("No prefix found."))
raise ValueError("No prefix found.")
async def call_alias(self, message: discord.Message, prefix: str, alias: AliasEntry):
new_message = copy(message)

View File

@@ -6,7 +6,7 @@ from pathlib import Path
import discord
import lavalink
from redbot.core.i18n import Translator
from redbot.core.i18n import Translator, set_contextual_locales_from_guild
from ...errors import DatabaseError, TrackEnqueueError
from ..abc import MixinMeta
from ..cog_utils import CompositeMetaClass
@@ -31,6 +31,7 @@ class LavalinkEvents(MixinMeta, metaclass=CompositeMetaClass):
guild_id = self.rgetattr(guild, "id", None)
if not guild:
return
await set_contextual_locales_from_guild(self.bot, guild)
current_requester = self.rgetattr(current_track, "requester", None)
current_stream = self.rgetattr(current_track, "is_stream", None)
current_length = self.rgetattr(current_track, "length", None)

View File

@@ -5,7 +5,7 @@ from typing import Union, Set, Literal
from redbot.core import checks, Config, modlog, commands
from redbot.core.bot import Red
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.i18n import Translator, cog_i18n, set_contextual_locales_from_guild
from redbot.core.utils import AsyncIter
from redbot.core.utils.chat_formatting import pagify, humanize_list
@@ -396,6 +396,8 @@ class Filter(commands.Cog):
if await self.bot.is_automod_immune(message):
return
await set_contextual_locales_from_guild(self.bot, message.guild)
await self.check_filter(message)
@commands.Cog.listener()
@@ -429,6 +431,8 @@ class Filter(commands.Cog):
if not guild_data["filter_names"]:
return
await set_contextual_locales_from_guild(self.bot, guild)
if await self.filter_hits(member.display_name, member.guild):
name_to_use = guild_data["filter_default_name"]

View File

@@ -151,6 +151,9 @@ class Events(MixinMeta):
# As are anyone configured to be
if await self.bot.is_automod_immune(message):
return
await i18n.set_contextual_locales_from_guild(self.bot, message.guild)
deleted = await self.check_duplicates(message)
if not deleted:
await self.check_mention_spam(message)

View File

@@ -194,6 +194,7 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
guild = self.bot.get_guild(g_id)
if guild is None or await self.bot.cog_disabled_in_guild(self, guild):
continue
await i18n.set_contextual_locales_from_guild(self.bot, guild)
for u_id in self._server_mutes[guild.id]:
if self._server_mutes[guild.id][u_id]["until"] is None:
continue
@@ -295,6 +296,7 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
for guild_id, users in multiple_mutes.items():
guild = self.bot.get_guild(guild_id)
await i18n.set_contextual_locales_from_guild(self.bot, guild)
for user, channels in users.items():
if len(channels) > 1:
task_name = f"server-unmute-channels-{guild_id}-{user}"
@@ -461,6 +463,7 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
a = set(after.roles)
roles_removed = list(b - a)
roles_added = list(a - b)
await i18n.set_contextual_locales_from_guild(self.bot, guild)
if mute_role in roles_removed:
# send modlog case for unmute and remove from cache
if guild.id not in self._server_mutes:
@@ -511,6 +514,7 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
"""
if await self.bot.cog_disabled_in_guild(self, after.guild):
return
await i18n.set_contextual_locales_from_guild(self.bot, after.guild)
if after.id in self._channel_mutes:
before_perms: Dict[int, Dict[str, Optional[bool]]] = {
o.id: {name: attr for name, attr in p} for o, p in before.overwrites.items()
@@ -569,6 +573,7 @@ class Mutes(VoiceMutes, commands.Cog, metaclass=CompositeMetaClass):
# user to globally rate limit the bot therefore we are not
# going to support re-muting users via channel overwrites
return
await i18n.set_contextual_locales_from_guild(self.bot, guild)
if guild.id in self._server_mutes:
if member.id in self._server_mutes[guild.id]:
role = guild.get_role(mute_role)

View File

@@ -11,7 +11,7 @@ from redbot.core.utils import AsyncIter
from redbot.core.utils.chat_formatting import pagify, box
from redbot.core.utils.antispam import AntiSpam
from redbot.core.bot import Red
from redbot.core.i18n import Translator, cog_i18n
from redbot.core.i18n import Translator, cog_i18n, set_contextual_locales_from_guild
from redbot.core.utils.predicates import MessagePredicate
from redbot.core.utils.tunnel import Tunnel
@@ -346,8 +346,10 @@ class Reports(commands.Cog):
if t is None:
return
guild = t[0][0]
tun = t[1]["tun"]
if payload.user_id in [x.id for x in tun.members]:
await set_contextual_locales_from_guild(self.bot, guild)
await tun.react_close(
uid=payload.user_id, message=_("{closer} has closed the correspondence")
)
@@ -365,6 +367,7 @@ class Reports(commands.Cog):
to_remove.append(k)
continue
await set_contextual_locales_from_guild(self.bot, guild)
topic = _("Re: ticket# {ticket_number} in {guild.name}").format(
ticket_number=ticket_number, guild=guild
)
@@ -376,6 +379,7 @@ class Reports(commands.Cog):
for key in to_remove:
if tun := self.tunnel_store.pop(key, None):
guild, ticket = key
await set_contextual_locales_from_guild(self.bot, guild)
await tun["tun"].close_because_disabled(
_(
"Correspondence about ticket# {ticket_number} in "

View File

@@ -1,7 +1,7 @@
import discord
from redbot.core.bot import Red
from redbot.core import checks, commands, Config
from redbot.core.i18n import cog_i18n, Translator
from redbot.core.i18n import cog_i18n, Translator, set_contextual_locales_from_guild
from redbot.core.utils._internal_utils import send_to_owners_with_prefix_replaced
from redbot.core.utils.chat_formatting import escape, pagify
@@ -714,6 +714,9 @@ class Streams(commands.Cog):
ignore_reruns = await self.config.guild(channel.guild).ignore_reruns()
if ignore_reruns and is_rerun:
continue
await set_contextual_locales_from_guild(self.bot, channel.guild)
mention_str, edited_roles = await self._get_mention_str(
channel.guild, channel
)