Skip to content

Commit

Permalink
Add human-readable version of permissions...
Browse files Browse the repository at this point in the history
... and deprecate _silent in i18n in favor of _locale=None
  • Loading branch information
AiroPi committed Dec 25, 2023
1 parent e9bcb33 commit a6a20e3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
56 changes: 56 additions & 0 deletions src/core/constants.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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"),
}
3 changes: 3 additions & 0 deletions src/core/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit a6a20e3

Please sign in to comment.