From 2d9bf1cfb9cc8d9c5b786e3d5e0bebe0e3a2236b Mon Sep 17 00:00:00 2001 From: profitroll Date: Sat, 3 May 2025 00:55:13 +0200 Subject: [PATCH] Introduced prefer_emojis for PycordGuild --- classes/pycord_guild.py | 3 +++ cogs/cog_config.py | 20 +++++++++++++++++++- cogs/cog_guess.py | 8 +++++--- locale/en-US.json | 6 +++++- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/classes/pycord_guild.py b/classes/pycord_guild.py index 5355976..1eb639f 100644 --- a/classes/pycord_guild.py +++ b/classes/pycord_guild.py @@ -26,6 +26,7 @@ class PycordGuild: channel_id: int | None category_id: int | None timezone: str + prefer_emojis: bool @classmethod async def from_id( @@ -145,6 +146,7 @@ class PycordGuild: "channel_id": self.channel_id, "category_id": self.category_id, "timezone": self.timezone, + "prefer_emojis": self.prefer_emojis, } # TODO Add documentation @@ -155,6 +157,7 @@ class PycordGuild: "channel_id": None, "category_id": None, "timezone": "UTC", + "prefer_emojis": False, } @staticmethod diff --git a/cogs/cog_config.py b/cogs/cog_config.py index c45d000..e22e7a9 100644 --- a/cogs/cog_config.py +++ b/cogs/cog_config.py @@ -43,7 +43,14 @@ class CogConfig(Cog): ), required=True, ) - @option("channel", description="Text channel for admin notifications", required=True) + @option( + "channel", + description=_("description", "commands", "config_set", "options", "channel"), + description_localizations=in_every_locale( + "description", "commands", "config_set", "options", "channel" + ), + required=True, + ) @option( "timezone", description=_("description", "commands", "config_set", "options", "timezone"), @@ -53,12 +60,21 @@ class CogConfig(Cog): autocomplete=basic_autocomplete(autocomplete_timezones), required=True, ) + @option( + "prefer_emojis", + description=_("description", "commands", "config_set", "options", "prefer_emojis"), + description_localizations=in_every_locale( + "description", "commands", "config_set", "options", "prefer_emojis" + ), + required=True, + ) async def command_config_set( self, ctx: ApplicationContext, category: CategoryChannel, channel: TextChannel, timezone: str, + prefer_emojis: bool, ) -> None: try: guild: PycordGuild = await self.bot.find_guild(ctx.guild.id) @@ -79,6 +95,7 @@ class CogConfig(Cog): channel_id=channel.id, category_id=category.id, timezone=str(timezone_parsed), + prefer_emojis=prefer_emojis, ) await ctx.respond(self.bot._("config_set", "messages", locale=ctx.locale)) @@ -131,6 +148,7 @@ class CogConfig(Cog): channel_id=guild.channel_id, category_id=guild.category_id, timezone=guild.timezone, + prefer_emojis=guild.prefer_emojis, ) ) diff --git a/cogs/cog_guess.py b/cogs/cog_guess.py index df2d2da..61b6785 100644 --- a/cogs/cog_guess.py +++ b/cogs/cog_guess.py @@ -65,9 +65,11 @@ class CogGuess(Cog): return if answer.lower() != stage.answer.lower(): - # TODO Make a nice message - # await ctx.respond("Provided answer is wrong.") - await ctx.respond(self.bot.config["emojis"]["guess_wrong"]) + await ctx.respond( + self.bot.config["emojis"]["guess_wrong"] + if guild.prefer_emojis + else self.bot._("guess_incorrect", "messages", locale=ctx.locale) + ) return next_stage_index = stage.sequence + 1 diff --git a/locale/en-US.json b/locale/en-US.json index 7e3ff12..ffcc0c2 100644 --- a/locale/en-US.json +++ b/locale/en-US.json @@ -6,7 +6,7 @@ "admin_user_completed_stage": "User **{display_name}** ({mention}) has completed the stage {stage_sequence} of the event **{event_name}**.", "config_reset": "Configuration has been reset. You can update it using `/config set`, otherwise no events can be held.", "config_set": "Configuration has been updated. You can review it anytime using `/config show`.", - "config_show": "**Guild config**\n\nChannel: <#{channel_id}>\nCategory: <#{category_id}>\nTimezone: `{timezone}`", + "config_show": "**Guild config**\n\nChannel: <#{channel_id}>\nCategory: <#{category_id}>\nTimezone: `{timezone}`\nPrefer emojis: `{prefer_emojis}`", "event_cancelled": "Event **{event_name}** was cancelled.", "event_created": "Event **{event_name}** has been created and will take place .", "event_dates_parsing_failed": "Could not parse start and end dates. Please, make sure these are provided in `DD.MM.YYYY HH:MM` format.", @@ -23,6 +23,7 @@ "event_start_past": "Start date must not be in the past", "event_updated": "Event **{event_name}** has been updated and will take place .", "guess_completed_event": "Congratulations! You have completed the event!", + "guess_incorrect": "Provided answer is wrong.", "guess_incorrect_channel": "Usage outside own event channel is not allowed.", "guess_incorrect_event": "Your event could not be found. Please, contact the administrator.", "guess_unregistered": "You have no ongoing events. You can register for events using the `/register` command.", @@ -67,6 +68,9 @@ }, "timezone": { "description": "Timezone in which events take place" + }, + "prefer_emojis": { + "description": "Prefer emojis over text messages where available" } } },