mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-12-21 16:52:31 -05:00
[V3 i18n] Internationalise help for commands and cogs (#1143)
* Framework for internationalised command help * Translator for class docstring of cog * Remove references to old context module * Use CogManagerUI as PoC * Replace all references to RedContext * Rename CogI18n object to avoid confusion * Update docs * Update i18n docs. * Store translators in list instead of dict * Change commands module to package, updated refs in cogs * Updated docs and more references in cogs * Resolve syntax error * Update from merge
This commit is contained in:
@@ -16,13 +16,12 @@ from distutils.version import StrictVersion
|
||||
import aiohttp
|
||||
import discord
|
||||
import pkg_resources
|
||||
from discord.ext import commands
|
||||
|
||||
from redbot.core import __version__
|
||||
from redbot.core import checks
|
||||
from redbot.core import i18n
|
||||
from redbot.core import rpc
|
||||
from redbot.core.context import RedContext
|
||||
from redbot.core import commands
|
||||
from .utils import TYPE_CHECKING
|
||||
from .utils.chat_formatting import pagify, box, inline
|
||||
|
||||
@@ -39,9 +38,10 @@ OWNER_DISCLAIMER = ("⚠ **Only** the person who is hosting Red should be "
|
||||
"system.** ⚠")
|
||||
|
||||
|
||||
_ = i18n.CogI18n("Core", __file__)
|
||||
_ = i18n.Translator("Core", __file__)
|
||||
|
||||
|
||||
@i18n.cog_i18n(_)
|
||||
class Core:
|
||||
"""Commands related to core functions"""
|
||||
def __init__(self, bot):
|
||||
@@ -52,7 +52,7 @@ class Core:
|
||||
rpc.add_method('core', self.rpc_reload)
|
||||
|
||||
@commands.command()
|
||||
async def info(self, ctx: RedContext):
|
||||
async def info(self, ctx: commands.Context):
|
||||
"""Shows info about Red"""
|
||||
author_repo = "https://github.com/Twentysix26"
|
||||
org_repo = "https://github.com/Cog-Creators"
|
||||
@@ -103,7 +103,7 @@ class Core:
|
||||
await ctx.send("I need the `Embed links` permission to send this")
|
||||
|
||||
@commands.command()
|
||||
async def uptime(self, ctx: RedContext):
|
||||
async def uptime(self, ctx: commands.Context):
|
||||
"""Shows Red's uptime"""
|
||||
since = ctx.bot.uptime.strftime("%Y-%m-%d %H:%M:%S")
|
||||
passed = self.get_bot_uptime()
|
||||
@@ -112,7 +112,7 @@ class Core:
|
||||
passed, since
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
def get_bot_uptime(self, *, brief=False):
|
||||
# Courtesy of Danny
|
||||
now = datetime.datetime.utcnow()
|
||||
@@ -134,7 +134,7 @@ class Core:
|
||||
return fmt.format(d=days, h=hours, m=minutes, s=seconds)
|
||||
|
||||
@commands.group()
|
||||
async def embedset(self, ctx: RedContext):
|
||||
async def embedset(self, ctx: commands.Context):
|
||||
"""
|
||||
Commands for toggling embeds on or off.
|
||||
|
||||
@@ -157,7 +157,7 @@ class Core:
|
||||
|
||||
@embedset.command(name="global")
|
||||
@checks.is_owner()
|
||||
async def embedset_global(self, ctx: RedContext):
|
||||
async def embedset_global(self, ctx: commands.Context):
|
||||
"""
|
||||
Toggle the global embed setting.
|
||||
|
||||
@@ -175,7 +175,7 @@ class Core:
|
||||
|
||||
@embedset.command(name="guild")
|
||||
@checks.guildowner_or_permissions(administrator=True)
|
||||
async def embedset_guild(self, ctx: RedContext, enabled: bool=None):
|
||||
async def embedset_guild(self, ctx: commands.Context, enabled: bool=None):
|
||||
"""
|
||||
Toggle the guild's embed setting.
|
||||
|
||||
@@ -200,7 +200,7 @@ class Core:
|
||||
)
|
||||
|
||||
@embedset.command(name="user")
|
||||
async def embedset_user(self, ctx: RedContext, enabled: bool=None):
|
||||
async def embedset_user(self, ctx: commands.Context, enabled: bool=None):
|
||||
"""
|
||||
Toggle the user's embed setting.
|
||||
|
||||
@@ -412,7 +412,7 @@ class Core:
|
||||
"""Reloads packages"""
|
||||
|
||||
cognames = [c.strip() for c in cog_name.split(' ')]
|
||||
|
||||
|
||||
for c in cognames:
|
||||
ctx.bot.unload_extension(c)
|
||||
|
||||
@@ -428,7 +428,7 @@ class Core:
|
||||
except RuntimeError:
|
||||
notfound_packages.append(inline(c))
|
||||
|
||||
for spec, name in cogspecs:
|
||||
for spec, name in cogspecs:
|
||||
try:
|
||||
self.cleanup_and_refresh_modules(spec.name)
|
||||
await ctx.bot.load_extension(spec)
|
||||
@@ -489,7 +489,7 @@ class Core:
|
||||
except:
|
||||
pass
|
||||
await ctx.bot.shutdown()
|
||||
|
||||
|
||||
@commands.command(name="restart")
|
||||
@checks.is_owner()
|
||||
async def _restart(self, ctx, silently: bool=False):
|
||||
@@ -776,26 +776,26 @@ class Core:
|
||||
await ctx.send(_("You have been set as owner."))
|
||||
else:
|
||||
await ctx.send(_("Invalid token."))
|
||||
|
||||
|
||||
@_set.command()
|
||||
@checks.is_owner()
|
||||
async def token(self, ctx, token: str):
|
||||
"""Change bot token."""
|
||||
|
||||
if not isinstance(ctx.channel, discord.DMChannel):
|
||||
|
||||
|
||||
try:
|
||||
await ctx.message.delete()
|
||||
except discord.Forbidden:
|
||||
pass
|
||||
|
||||
|
||||
await ctx.send(
|
||||
_("Please use that command in DM. Since users probably saw your token,"
|
||||
" it is recommended to reset it right now. Go to the following link and"
|
||||
" select `Reveal Token` and `Generate a new token?`."
|
||||
"\n\nhttps://discordapp.com/developers/applications/me/{}").format(self.bot.user.id))
|
||||
return
|
||||
|
||||
|
||||
await ctx.bot.db.token.set(token)
|
||||
await ctx.send("Token set. Restart me.")
|
||||
|
||||
@@ -834,7 +834,7 @@ class Core:
|
||||
|
||||
@commands.command()
|
||||
@checks.is_owner()
|
||||
async def listlocales(self, ctx: RedContext):
|
||||
async def listlocales(self, ctx: commands.Context):
|
||||
"""
|
||||
Lists all available locales
|
||||
|
||||
@@ -1051,7 +1051,7 @@ class Core:
|
||||
await ctx.send(_("User has been removed from whitelist."))
|
||||
else:
|
||||
await ctx.send(_("User was not in the whitelist."))
|
||||
|
||||
|
||||
@whitelist.command(name='clear')
|
||||
async def whitelist_clear(self, ctx):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user