fix(mentionhelp): default to English on locale lookup failure, use Polish only for pl locales
This commit is contained in:
@@ -1,17 +1,30 @@
|
||||
import discord
|
||||
from redbot.core import commands
|
||||
from redbot.core.i18n import get_locale_from_guild
|
||||
|
||||
|
||||
class MentionHelp(commands.Cog):
|
||||
def __init__(self, bot):
|
||||
self.bot = bot
|
||||
|
||||
def build_help_embed(self, message, prefix_text, main_prefix):
|
||||
@staticmethod
|
||||
def _is_polish_locale(locale: str) -> bool:
|
||||
if not isinstance(locale, str):
|
||||
return False
|
||||
return locale.lower().startswith("pl")
|
||||
|
||||
def build_help_embed(self, message, main_prefix, locale):
|
||||
is_polish = self._is_polish_locale(locale)
|
||||
title = "Pomoc" if is_polish else "Help"
|
||||
description = (
|
||||
f"Użyj `{main_prefix}help`, aby zobaczyć wszystkie komendy bota."
|
||||
if is_polish
|
||||
else f"Use `{main_prefix}help` to see all bot commands."
|
||||
)
|
||||
|
||||
embed = discord.Embed(
|
||||
title="Pomoc",
|
||||
description=(
|
||||
f"Użyj `{main_prefix}help`, aby zobaczyć wszystkie komendy bota."
|
||||
),
|
||||
title=title,
|
||||
description=description,
|
||||
color=0xEB459E
|
||||
)
|
||||
|
||||
@@ -58,7 +71,12 @@ class MentionHelp(commands.Cog):
|
||||
|
||||
visible_prefixes = [p for p in prefixes if not p.startswith("<@")]
|
||||
main_prefix = visible_prefixes[0] if visible_prefixes else prefixes[0]
|
||||
prefix_text = ", ".join(visible_prefixes) if visible_prefixes else ", ".join(prefixes)
|
||||
try:
|
||||
locale = await get_locale_from_guild(self.bot, message.guild)
|
||||
except Exception:
|
||||
locale = "en-US"
|
||||
if not isinstance(locale, str) or not locale.strip():
|
||||
locale = "en-US"
|
||||
|
||||
embed = self.build_help_embed(message, prefix_text, main_prefix)
|
||||
embed = self.build_help_embed(message, main_prefix, locale)
|
||||
await message.channel.send(embed=embed)
|
||||
|
||||
Reference in New Issue
Block a user