mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-21 10:17:59 -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:
@@ -1,16 +1,15 @@
|
||||
from copy import copy
|
||||
from discord.ext import commands
|
||||
import asyncio
|
||||
import inspect
|
||||
import discord
|
||||
|
||||
from redbot.core import RedContext, Config, checks
|
||||
from redbot.core.i18n import CogI18n
|
||||
from redbot.core import Config, checks, commands
|
||||
from redbot.core.i18n import Translator
|
||||
|
||||
_ = CogI18n("Warnings", __file__)
|
||||
_ = Translator("Warnings", __file__)
|
||||
|
||||
|
||||
async def warning_points_add_check(config: Config, ctx: RedContext, user: discord.Member, points: int):
|
||||
async def warning_points_add_check(config: Config, ctx: commands.Context, user: discord.Member, points: int):
|
||||
"""Handles any action that needs to be taken or not based on the points"""
|
||||
guild = ctx.guild
|
||||
guild_settings = config.guild(guild)
|
||||
@@ -25,7 +24,7 @@ async def warning_points_add_check(config: Config, ctx: RedContext, user: discor
|
||||
await create_and_invoke_context(ctx, act["exceed_command"], user)
|
||||
|
||||
|
||||
async def warning_points_remove_check(config: Config, ctx: RedContext, user: discord.Member, points: int):
|
||||
async def warning_points_remove_check(config: Config, ctx: commands.Context, user: discord.Member, points: int):
|
||||
guild = ctx.guild
|
||||
guild_settings = config.guild(guild)
|
||||
act = {}
|
||||
@@ -39,10 +38,10 @@ async def warning_points_remove_check(config: Config, ctx: RedContext, user: dis
|
||||
await create_and_invoke_context(ctx, act["drop_command"], user)
|
||||
|
||||
|
||||
async def create_and_invoke_context(realctx: RedContext, command_str: str, user: discord.Member):
|
||||
async def create_and_invoke_context(realctx: commands.Context, command_str: str, user: discord.Member):
|
||||
m = copy(realctx.message)
|
||||
m.content = command_str.format(user=user.mention, prefix=realctx.prefix)
|
||||
fctx = await realctx.bot.get_context(m, cls=RedContext)
|
||||
fctx = await realctx.bot.get_context(m, cls=commands.Context)
|
||||
try:
|
||||
await realctx.bot.invoke(fctx)
|
||||
except (commands.CheckFailure, commands.CommandOnCooldown):
|
||||
@@ -69,7 +68,7 @@ def get_command_from_input(bot, userinput: str):
|
||||
return "{prefix}" + orig, None
|
||||
|
||||
|
||||
async def get_command_for_exceeded_points(ctx: RedContext):
|
||||
async def get_command_for_exceeded_points(ctx: commands.Context):
|
||||
"""Gets the command to be executed when the user is at or exceeding
|
||||
the points threshold for the action"""
|
||||
await ctx.send(
|
||||
@@ -102,7 +101,7 @@ async def get_command_for_exceeded_points(ctx: RedContext):
|
||||
return command
|
||||
|
||||
|
||||
async def get_command_for_dropping_points(ctx: RedContext):
|
||||
async def get_command_for_dropping_points(ctx: commands.Context):
|
||||
"""
|
||||
Gets the command to be executed when the user drops below the points
|
||||
threshold
|
||||
|
||||
@@ -1,21 +1,20 @@
|
||||
from collections import namedtuple
|
||||
|
||||
from discord.ext import commands
|
||||
import discord
|
||||
import asyncio
|
||||
|
||||
from redbot.cogs.warnings.helpers import warning_points_add_check, get_command_for_exceeded_points, \
|
||||
get_command_for_dropping_points, warning_points_remove_check
|
||||
from redbot.core import Config, modlog, checks
|
||||
from redbot.core import Config, modlog, checks, commands
|
||||
from redbot.core.bot import Red
|
||||
from redbot.core.context import RedContext
|
||||
from redbot.core.i18n import CogI18n
|
||||
from redbot.core.i18n import Translator, cog_i18n
|
||||
from redbot.core.utils.mod import is_admin_or_superior
|
||||
from redbot.core.utils.chat_formatting import warning, pagify
|
||||
|
||||
_ = CogI18n("Warnings", __file__)
|
||||
_ = Translator("Warnings", __file__)
|
||||
|
||||
|
||||
@cog_i18n(_)
|
||||
class Warnings:
|
||||
"""A warning system for Red"""
|
||||
|
||||
@@ -51,14 +50,14 @@ class Warnings:
|
||||
@commands.group()
|
||||
@commands.guild_only()
|
||||
@checks.guildowner_or_permissions(administrator=True)
|
||||
async def warningset(self, ctx: RedContext):
|
||||
async def warningset(self, ctx: commands.Context):
|
||||
"""Warning settings"""
|
||||
if ctx.invoked_subcommand is None:
|
||||
await ctx.send_help()
|
||||
|
||||
@warningset.command()
|
||||
@commands.guild_only()
|
||||
async def allowcustomreasons(self, ctx: RedContext, allowed: bool):
|
||||
async def allowcustomreasons(self, ctx: commands.Context, allowed: bool):
|
||||
"""Allow or disallow custom reasons for a warning"""
|
||||
guild = ctx.guild
|
||||
await self.config.guild(guild).allow_custom_reasons.set(allowed)
|
||||
@@ -69,14 +68,14 @@ class Warnings:
|
||||
@commands.group()
|
||||
@commands.guild_only()
|
||||
@checks.guildowner_or_permissions(administrator=True)
|
||||
async def warnaction(self, ctx: RedContext):
|
||||
async def warnaction(self, ctx: commands.Context):
|
||||
"""Action management"""
|
||||
if ctx.invoked_subcommand is None:
|
||||
await ctx.send_help()
|
||||
|
||||
@warnaction.command(name="add")
|
||||
@commands.guild_only()
|
||||
async def action_add(self, ctx: RedContext, name: str, points: int):
|
||||
async def action_add(self, ctx: commands.Context, name: str, points: int):
|
||||
"""Create an action to be taken at a specified point count
|
||||
Duplicate action names are not allowed"""
|
||||
guild = ctx.guild
|
||||
@@ -125,7 +124,7 @@ class Warnings:
|
||||
|
||||
@warnaction.command(name="del")
|
||||
@commands.guild_only()
|
||||
async def action_del(self, ctx: RedContext, action_name: str):
|
||||
async def action_del(self, ctx: commands.Context, action_name: str):
|
||||
"""Delete the point count action with the specified name"""
|
||||
guild = ctx.guild
|
||||
guild_settings = self.config.guild(guild)
|
||||
@@ -146,14 +145,14 @@ class Warnings:
|
||||
@commands.group()
|
||||
@commands.guild_only()
|
||||
@checks.guildowner_or_permissions(administrator=True)
|
||||
async def warnreason(self, ctx: RedContext):
|
||||
async def warnreason(self, ctx: commands.Context):
|
||||
"""Add reasons for warnings"""
|
||||
if ctx.invoked_subcommand is None:
|
||||
await ctx.send_help()
|
||||
|
||||
@warnreason.command(name="add")
|
||||
@commands.guild_only()
|
||||
async def reason_add(self, ctx: RedContext, name: str, points: int, *, description: str):
|
||||
async def reason_add(self, ctx: commands.Context, name: str, points: int, *, description: str):
|
||||
"""Add a reason to be available for warnings"""
|
||||
guild = ctx.guild
|
||||
|
||||
@@ -177,7 +176,7 @@ class Warnings:
|
||||
|
||||
@warnreason.command(name="del")
|
||||
@commands.guild_only()
|
||||
async def reason_del(self, ctx: RedContext, reason_name: str):
|
||||
async def reason_del(self, ctx: commands.Context, reason_name: str):
|
||||
"""Delete the reason with the specified name"""
|
||||
guild = ctx.guild
|
||||
guild_settings = self.config.guild(guild)
|
||||
@@ -190,7 +189,7 @@ class Warnings:
|
||||
@commands.command()
|
||||
@commands.guild_only()
|
||||
@checks.admin_or_permissions(ban_members=True)
|
||||
async def reasonlist(self, ctx: RedContext):
|
||||
async def reasonlist(self, ctx: commands.Context):
|
||||
"""List all configured reasons for warnings"""
|
||||
guild = ctx.guild
|
||||
guild_settings = self.config.guild(guild)
|
||||
@@ -210,7 +209,7 @@ class Warnings:
|
||||
@commands.command()
|
||||
@commands.guild_only()
|
||||
@checks.admin_or_permissions(ban_members=True)
|
||||
async def actionlist(self, ctx: RedContext):
|
||||
async def actionlist(self, ctx: commands.Context):
|
||||
"""List the actions to be taken at specific point values"""
|
||||
guild = ctx.guild
|
||||
guild_settings = self.config.guild(guild)
|
||||
@@ -232,7 +231,7 @@ class Warnings:
|
||||
@commands.command()
|
||||
@commands.guild_only()
|
||||
@checks.admin_or_permissions(ban_members=True)
|
||||
async def warn(self, ctx: RedContext, user: discord.Member, reason: str):
|
||||
async def warn(self, ctx: commands.Context, user: discord.Member, reason: str):
|
||||
"""Warn the user for the specified reason
|
||||
Reason must be a registered reason, or custom if custom reasons are allowed"""
|
||||
reason_type = {}
|
||||
@@ -276,7 +275,7 @@ class Warnings:
|
||||
|
||||
@commands.command()
|
||||
@commands.guild_only()
|
||||
async def warnings(self, ctx: RedContext, userid: int=None):
|
||||
async def warnings(self, ctx: commands.Context, userid: int=None):
|
||||
"""Show warnings for the specified user.
|
||||
If userid is None, show warnings for the person running the command
|
||||
Note that showing warnings for users other than yourself requires
|
||||
@@ -326,7 +325,7 @@ class Warnings:
|
||||
@commands.command()
|
||||
@commands.guild_only()
|
||||
@checks.admin_or_permissions(ban_members=True)
|
||||
async def unwarn(self, ctx: RedContext, user_id: int, warn_id: str):
|
||||
async def unwarn(self, ctx: commands.Context, user_id: int, warn_id: str):
|
||||
"""Removes the specified warning from the user specified"""
|
||||
guild = ctx.guild
|
||||
member = guild.get_member(user_id)
|
||||
@@ -347,7 +346,7 @@ class Warnings:
|
||||
await ctx.tick()
|
||||
|
||||
@staticmethod
|
||||
async def custom_warning_reason(ctx: RedContext):
|
||||
async def custom_warning_reason(ctx: commands.Context):
|
||||
"""Handles getting description and points for custom reasons"""
|
||||
to_add = {
|
||||
"points": 0,
|
||||
|
||||
Reference in New Issue
Block a user