From a6a20e3ef9d2f6a7031eeff5bca783323c12aafe Mon Sep 17 00:00:00 2001 From: "airo.pi_" <47398145+AiroPi@users.noreply.github.com> Date: Mon, 25 Dec 2023 19:13:39 +0100 Subject: [PATCH] Add human-readable version of permissions... ... and deprecate _silent in i18n in favor of _locale=None --- src/core/constants.py | 56 +++++++++++++++++++++++++++++++++++++++++++ src/core/i18n.py | 3 +++ 2 files changed, 59 insertions(+) diff --git a/src/core/constants.py b/src/core/constants.py index abe3c1a..4374f9a 100644 --- a/src/core/constants.py +++ b/src/core/constants.py @@ -1,13 +1,18 @@ from __future__ import annotations import enum +from functools import partial from typing import TYPE_CHECKING, Self from discord.app_commands import TranslationContextLocation +from .i18n import _ + if TYPE_CHECKING: from ._types import Snowflake +_ = partial(_, _locale=None) + class Emoji(str): def __new__(cls, id: Snowflake) -> Self: @@ -138,3 +143,54 @@ def from_location(cls, location: TranslationContextLocation) -> TranslationConte TranslationContextLocation.group_description: TranslationContextLimits.GROUP_DESCRIPTION, } return translation_context_limits_bind.get(location) + + +# keys are from discord.Permissions, so some can defer from the discord API +# values are the version showed in the Discord UI. +human_permissions = { + "create_instant_invite": _("Create Invite"), + "kick_members": _("Kick Members"), + "ban_members": _("Ban Members"), + "administrator": _("Administrator"), + "manage_channels": _("Manage Channels"), + "manage_guild": _("Manage Server"), + "add_reactions": _("Add Reactions"), + "view_audit_log": _("View Audit Log"), + "priority_speaker": _("Priority Speaker"), + "stream": _("Video"), + "read_messages": _("View Channel"), + "send_messages": _("Send Messages"), + "send_tts_messages": _("Send Text-to-speech Messages"), + "manage_messages": _("Manage Messages"), + "embed_links": _("Embed Links"), + "attach_files": _("Attach Files"), + "read_message_history": _("Read Message History"), + "mention_everyone": _("Mention @everyone, @here and All Roles"), + "external_emojis": _("Use External Emojis"), + "view_guild_insights": _("View Guild Insights"), + "connect": _("Connect"), + "speak": _("Speak"), + "mute_members": _("Mute Members"), + "deafen_members": _("Deafen Members"), + "move_members": _("Move Members"), + "use_voice_activation": _("Use Voice Activity"), + "change_nickname": _("Change Nickname"), + "manage_nicknames": _("Manage Nicknames"), + "manage_roles": _("Manage Roles"), + "manage_webhooks": _("Manage Webhooks"), + "manage_expressions": _("Manage Expressions"), + "use_application_commands": _("Use Application Commands"), + "request_to_speak": _("Request to Speak"), + "manage_events": _("Manage Events"), + "manage_threads": _("Manage Threads"), + "create_public_threads": _("Create Public Threads"), + "create_private_threads": _("Create Private Threads"), + "external_stickers": _("Use External Stickers"), + "send_messages_in_threads": _("Send Messages in Threads"), + "use_embedded_activities": _("Use Activities"), + "moderate_members": _("Time out members"), + "use_soundboard": _("Use Soundboard"), + "create_expressions": _("Create Expressions"), + "use_external_sounds": _("Use External Sounds"), + "send_voice_messages": _("Send Voice Messages"), +} diff --git a/src/core/i18n.py b/src/core/i18n.py index b244d16..aa098c5 100644 --- a/src/core/i18n.py +++ b/src/core/i18n.py @@ -63,6 +63,9 @@ def i18n( _l: int = -1, # size limit **kwargs: Any, ) -> str: + if _silent: + logger.warning("Deprecated usage of _silent parameter in i18n function.") + _locale = None if _locale is MISSING: frame: FrameType | None = inspect.currentframe()