mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-20 18:06:08 -05:00
[i18n] User-facing string pass over admin, alias and audio
This commit is contained in:
@@ -14,26 +14,30 @@ log = logging.getLogger("red.admin")
|
||||
|
||||
_ = Translator("Admin", __file__)
|
||||
|
||||
GENERIC_FORBIDDEN = _(
|
||||
# The following are all lambdas to allow us to fetch the translation
|
||||
# during runtime, without having to copy the large strings everywhere
|
||||
# in the code.
|
||||
|
||||
generic_forbidden = lambda: _(
|
||||
"I attempted to do something that Discord denied me permissions for."
|
||||
" Your command failed to successfully complete."
|
||||
)
|
||||
|
||||
HIERARCHY_ISSUE = _(
|
||||
hierarchy_issue = lambda: _(
|
||||
"I tried to add {role.name} to {member.display_name} but that role"
|
||||
" is higher than my highest role in the Discord hierarchy so I was"
|
||||
" unable to successfully add it. Please give me a higher role and "
|
||||
"try again."
|
||||
)
|
||||
|
||||
USER_HIERARCHY_ISSUE = _(
|
||||
user_hierarchy_issue = lambda: _(
|
||||
"I tried to add {role.name} to {member.display_name} but that role"
|
||||
" is higher than your highest role in the Discord hierarchy so I was"
|
||||
" unable to successfully add it. Please get a higher role and "
|
||||
"try again."
|
||||
)
|
||||
|
||||
RUNNING_ANNOUNCEMENT = _(
|
||||
running_announcement = lambda: _(
|
||||
"I am already announcing something. If you would like to make a"
|
||||
" different announcement please use `{prefix}announce cancel`"
|
||||
" first."
|
||||
@@ -42,6 +46,7 @@ RUNNING_ANNOUNCEMENT = _(
|
||||
|
||||
@cog_i18n(_)
|
||||
class Admin(commands.Cog):
|
||||
"""A collection of server administration utilities."""
|
||||
def __init__(self, config=Config):
|
||||
super().__init__()
|
||||
self.conf = config.get_conf(self, 8237492837454039, force_registration=True)
|
||||
@@ -101,9 +106,9 @@ class Admin(commands.Cog):
|
||||
await member.add_roles(role)
|
||||
except discord.Forbidden:
|
||||
if not self.pass_hierarchy_check(ctx, role):
|
||||
await self.complain(ctx, HIERARCHY_ISSUE, role=role, member=member)
|
||||
await self.complain(ctx, hierarchy_issue(), role=role, member=member)
|
||||
else:
|
||||
await self.complain(ctx, GENERIC_FORBIDDEN)
|
||||
await self.complain(ctx, generic_forbidden())
|
||||
else:
|
||||
await ctx.send(
|
||||
_("I successfully added {role.name} to {member.display_name}").format(
|
||||
@@ -116,9 +121,9 @@ class Admin(commands.Cog):
|
||||
await member.remove_roles(role)
|
||||
except discord.Forbidden:
|
||||
if not self.pass_hierarchy_check(ctx, role):
|
||||
await self.complain(ctx, HIERARCHY_ISSUE, role=role, member=member)
|
||||
await self.complain(ctx, hierarchy_issue(), role=role, member=member)
|
||||
else:
|
||||
await self.complain(ctx, GENERIC_FORBIDDEN)
|
||||
await self.complain(ctx, generic_forbidden())
|
||||
else:
|
||||
await ctx.send(
|
||||
_("I successfully removed {role.name} from {member.display_name}").format(
|
||||
@@ -132,8 +137,8 @@ class Admin(commands.Cog):
|
||||
async def addrole(
|
||||
self, ctx: commands.Context, rolename: discord.Role, *, user: MemberDefaultAuthor = None
|
||||
):
|
||||
"""
|
||||
Adds a role to a user.
|
||||
"""Add a role to a user.
|
||||
|
||||
If user is left blank it defaults to the author of the command.
|
||||
"""
|
||||
if user is None:
|
||||
@@ -142,7 +147,7 @@ class Admin(commands.Cog):
|
||||
# noinspection PyTypeChecker
|
||||
await self._addrole(ctx, user, rolename)
|
||||
else:
|
||||
await self.complain(ctx, USER_HIERARCHY_ISSUE, member=ctx.author, role=rolename)
|
||||
await self.complain(ctx, user_hierarchy_issue(), member=ctx.author, role=rolename)
|
||||
|
||||
@commands.command()
|
||||
@commands.guild_only()
|
||||
@@ -150,8 +155,8 @@ class Admin(commands.Cog):
|
||||
async def removerole(
|
||||
self, ctx: commands.Context, rolename: discord.Role, *, user: MemberDefaultAuthor = None
|
||||
):
|
||||
"""
|
||||
Removes a role from a user.
|
||||
"""Remove a role from a user.
|
||||
|
||||
If user is left blank it defaults to the author of the command.
|
||||
"""
|
||||
if user is None:
|
||||
@@ -160,38 +165,40 @@ class Admin(commands.Cog):
|
||||
# noinspection PyTypeChecker
|
||||
await self._removerole(ctx, user, rolename)
|
||||
else:
|
||||
await self.complain(ctx, USER_HIERARCHY_ISSUE)
|
||||
await self.complain(ctx, user_hierarchy_issue())
|
||||
|
||||
@commands.group()
|
||||
@commands.guild_only()
|
||||
@checks.admin_or_permissions(manage_roles=True)
|
||||
async def editrole(self, ctx: commands.Context):
|
||||
"""Edits roles settings"""
|
||||
"""Edit role settings."""
|
||||
pass
|
||||
|
||||
@editrole.command(name="colour", aliases=["color"])
|
||||
async def editrole_colour(
|
||||
self, ctx: commands.Context, role: discord.Role, value: discord.Colour
|
||||
):
|
||||
"""Edits a role's colour
|
||||
"""Edit a role's colour.
|
||||
|
||||
Use double quotes if the role contains spaces.
|
||||
Colour must be in hexadecimal format.
|
||||
\"http://www.w3schools.com/colors/colors_picker.asp\"
|
||||
[Online colour picker](http://www.w3schools.com/colors/colors_picker.asp)
|
||||
|
||||
Examples:
|
||||
!editrole colour \"The Transistor\" #ff0000
|
||||
!editrole colour Test #ff9900"""
|
||||
`[p]editrole colour "The Transistor" #ff0000`
|
||||
`[p]editrole colour Test #ff9900`
|
||||
"""
|
||||
author = ctx.author
|
||||
reason = "{}({}) changed the colour of role '{}'".format(author.name, author.id, role.name)
|
||||
|
||||
if not self.pass_user_hierarchy_check(ctx, role):
|
||||
await self.complain(ctx, USER_HIERARCHY_ISSUE)
|
||||
await self.complain(ctx, user_hierarchy_issue())
|
||||
return
|
||||
|
||||
try:
|
||||
await role.edit(reason=reason, color=value)
|
||||
except discord.Forbidden:
|
||||
await self.complain(ctx, GENERIC_FORBIDDEN)
|
||||
await self.complain(ctx, generic_forbidden())
|
||||
else:
|
||||
log.info(reason)
|
||||
await ctx.send(_("Done."))
|
||||
@@ -199,11 +206,13 @@ class Admin(commands.Cog):
|
||||
@editrole.command(name="name")
|
||||
@checks.admin_or_permissions(administrator=True)
|
||||
async def edit_role_name(self, ctx: commands.Context, role: discord.Role, *, name: str):
|
||||
"""Edits a role's name
|
||||
"""Edit a role's name.
|
||||
|
||||
Use double quotes if the role or the name contain spaces.
|
||||
|
||||
Examples:
|
||||
!editrole name \"The Transistor\" Test"""
|
||||
`[p]editrole name \"The Transistor\" Test`
|
||||
"""
|
||||
author = ctx.message.author
|
||||
old_name = role.name
|
||||
reason = "{}({}) changed the name of role '{}' to '{}'".format(
|
||||
@@ -211,13 +220,13 @@ class Admin(commands.Cog):
|
||||
)
|
||||
|
||||
if not self.pass_user_hierarchy_check(ctx, role):
|
||||
await self.complain(ctx, USER_HIERARCHY_ISSUE)
|
||||
await self.complain(ctx, user_hierarchy_issue())
|
||||
return
|
||||
|
||||
try:
|
||||
await role.edit(reason=reason, name=name)
|
||||
except discord.Forbidden:
|
||||
await self.complain(ctx, GENERIC_FORBIDDEN)
|
||||
await self.complain(ctx, generic_forbidden())
|
||||
else:
|
||||
log.info(reason)
|
||||
await ctx.send(_("Done."))
|
||||
@@ -225,9 +234,7 @@ class Admin(commands.Cog):
|
||||
@commands.group(invoke_without_command=True)
|
||||
@checks.is_owner()
|
||||
async def announce(self, ctx: commands.Context, *, message: str):
|
||||
"""
|
||||
Announces a message to all servers the bot is in.
|
||||
"""
|
||||
"""Announce a message to all servers the bot is in."""
|
||||
if not self.is_announcing():
|
||||
announcer = Announcer(ctx, message, config=self.conf)
|
||||
announcer.start()
|
||||
@@ -237,14 +244,12 @@ class Admin(commands.Cog):
|
||||
await ctx.send(_("The announcement has begun."))
|
||||
else:
|
||||
prefix = ctx.prefix
|
||||
await self.complain(ctx, RUNNING_ANNOUNCEMENT, prefix=prefix)
|
||||
await self.complain(ctx, running_announcement(), prefix=prefix)
|
||||
|
||||
@announce.command(name="cancel")
|
||||
@checks.is_owner()
|
||||
async def announce_cancel(self, ctx):
|
||||
"""
|
||||
Cancels a running announce.
|
||||
"""
|
||||
"""Cancel a running announce."""
|
||||
try:
|
||||
self.__current_announcer.cancel()
|
||||
except AttributeError:
|
||||
@@ -256,9 +261,7 @@ class Admin(commands.Cog):
|
||||
@commands.guild_only()
|
||||
@checks.guildowner_or_permissions(administrator=True)
|
||||
async def announce_channel(self, ctx, *, channel: discord.TextChannel = None):
|
||||
"""
|
||||
Changes the channel on which the bot makes announcements.
|
||||
"""
|
||||
"""Change the channel to which the bot makes announcements."""
|
||||
if channel is None:
|
||||
channel = ctx.channel
|
||||
await self.conf.guild(ctx.guild).announce_channel.set(channel.id)
|
||||
@@ -271,9 +274,7 @@ class Admin(commands.Cog):
|
||||
@commands.guild_only()
|
||||
@checks.guildowner_or_permissions(administrator=True)
|
||||
async def announce_ignore(self, ctx):
|
||||
"""
|
||||
Toggles whether the announcements will ignore the current server.
|
||||
"""
|
||||
"""Toggle announcements being enabled this server."""
|
||||
ignored = await self.conf.guild(ctx.guild).announce_ignore()
|
||||
await self.conf.guild(ctx.guild).announce_ignore.set(not ignored)
|
||||
|
||||
@@ -309,8 +310,9 @@ class Admin(commands.Cog):
|
||||
@commands.guild_only()
|
||||
@commands.group(invoke_without_command=True)
|
||||
async def selfrole(self, ctx: commands.Context, *, selfrole: SelfRole):
|
||||
"""
|
||||
Add a role to yourself that server admins have configured as user settable.
|
||||
"""Add a role to yourself.
|
||||
|
||||
Server admins must have configured the role as user settable.
|
||||
|
||||
NOTE: The role is case sensitive!
|
||||
"""
|
||||
@@ -319,8 +321,7 @@ class Admin(commands.Cog):
|
||||
|
||||
@selfrole.command(name="remove")
|
||||
async def selfrole_remove(self, ctx: commands.Context, *, selfrole: SelfRole):
|
||||
"""
|
||||
Removes a selfrole from yourself.
|
||||
"""Remove a selfrole from yourself.
|
||||
|
||||
NOTE: The role is case sensitive!
|
||||
"""
|
||||
@@ -330,8 +331,7 @@ class Admin(commands.Cog):
|
||||
@selfrole.command(name="add")
|
||||
@checks.admin_or_permissions(manage_roles=True)
|
||||
async def selfrole_add(self, ctx: commands.Context, *, role: discord.Role):
|
||||
"""
|
||||
Add a role to the list of available selfroles.
|
||||
"""Add a role to the list of available selfroles.
|
||||
|
||||
NOTE: The role is case sensitive!
|
||||
"""
|
||||
@@ -344,8 +344,7 @@ class Admin(commands.Cog):
|
||||
@selfrole.command(name="delete")
|
||||
@checks.admin_or_permissions(manage_roles=True)
|
||||
async def selfrole_delete(self, ctx: commands.Context, *, role: SelfRole):
|
||||
"""
|
||||
Removes a role from the list of available selfroles.
|
||||
"""Remove a role from the list of available selfroles.
|
||||
|
||||
NOTE: The role is case sensitive!
|
||||
"""
|
||||
@@ -362,7 +361,7 @@ class Admin(commands.Cog):
|
||||
selfroles = await self._valid_selfroles(ctx.guild)
|
||||
fmt_selfroles = "\n".join(["+ " + r.name for r in selfroles])
|
||||
|
||||
msg = _("Available Selfroles:\n{selfroles}").format(selfroles=fmt_selfroles)
|
||||
msg = _("Available Selfroles: {selfroles}").format(selfroles=fmt_selfroles)
|
||||
await ctx.send(box(msg, "diff"))
|
||||
|
||||
async def _serverlock_check(self, guild: discord.Guild) -> bool:
|
||||
@@ -379,9 +378,7 @@ class Admin(commands.Cog):
|
||||
@commands.command()
|
||||
@checks.is_owner()
|
||||
async def serverlock(self, ctx: commands.Context):
|
||||
"""
|
||||
Locks a bot to its current servers only.
|
||||
"""
|
||||
"""Lock a bot to its current servers only."""
|
||||
serverlocked = await self.conf.serverlocked()
|
||||
await self.conf.serverlocked.set(not serverlocked)
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@ import asyncio
|
||||
|
||||
import discord
|
||||
from redbot.core import commands
|
||||
from redbot.core.i18n import Translator
|
||||
|
||||
_ = Translator("Announcer", __file__)
|
||||
|
||||
|
||||
class Announcer:
|
||||
@@ -63,7 +66,9 @@ class Announcer:
|
||||
try:
|
||||
await channel.send(self.message)
|
||||
except discord.Forbidden:
|
||||
await bot_owner.send("I could not announce to server: {}".format(g.id))
|
||||
await bot_owner.send(
|
||||
_("I could not announce to server: {server.id}").format(server=g)
|
||||
)
|
||||
await asyncio.sleep(0.5)
|
||||
|
||||
self.active = False
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import discord
|
||||
from redbot.core import commands
|
||||
from redbot.core.i18n import Translator
|
||||
|
||||
_ = Translator("AdminConverters", __file__)
|
||||
|
||||
|
||||
class MemberDefaultAuthor(commands.Converter):
|
||||
@@ -19,7 +22,7 @@ class SelfRole(commands.Converter):
|
||||
async def convert(self, ctx: commands.Context, arg: str) -> discord.Role:
|
||||
admin = ctx.command.instance
|
||||
if admin is None:
|
||||
raise commands.BadArgument("Admin is not loaded.")
|
||||
raise commands.BadArgument(_("The Admin cog is not loaded."))
|
||||
|
||||
conf = admin.conf
|
||||
selfroles = await conf.guild(ctx.guild).selfroles()
|
||||
@@ -28,5 +31,5 @@ class SelfRole(commands.Converter):
|
||||
role = await role_converter.convert(ctx, arg)
|
||||
|
||||
if role.id not in selfroles:
|
||||
raise commands.BadArgument("The provided role is not a valid selfrole.")
|
||||
raise commands.BadArgument(_("The provided role is not a valid selfrole."))
|
||||
return role
|
||||
|
||||
Reference in New Issue
Block a user