Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a few new locales in english and french #53

Open
wants to merge 2 commits into
base: feat/version/3.27
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion suggestions/clunk2/edits.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async def update_suggestion_message(
suggestion: Suggestion,
bot: SuggestionsBot,
time_after: float = 10,
interaction : disnake.Interaction
):
if suggestion.suggestion_id in pending_edits:
log.debug("Ignoring already existing item %s", suggestion.suggestion_id)
Expand All @@ -32,7 +33,7 @@ async def update_suggestion_message(
try:
await MessageEditing(
bot, channel_id=suggestion.channel_id, message_id=suggestion.message_id
).edit(embed=await suggestion.as_embed(bot))
).edit(embed=await suggestion.as_embed(bot, interaction))
except (disnake.HTTPException, disnake.NotFound):
log.error("Failed to update suggestion %s", suggestion.suggestion_id)

Expand Down
4 changes: 2 additions & 2 deletions suggestions/cogs/suggestion_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ async def suggestion_up_vote(
ephemeral=True,
)

await update_suggestion_message(suggestion=suggestion, bot=self.bot)
await update_suggestion_message(suggestion=suggestion, bot=self.bot, interaction=inter)

@components.button_listener()
async def suggestion_down_vote(
Expand Down Expand Up @@ -146,7 +146,7 @@ async def suggestion_down_vote(
ephemeral=True,
)

await update_suggestion_message(suggestion=suggestion, bot=self.bot)
await update_suggestion_message(suggestion=suggestion, bot=self.bot, interaction=inter)
# log.debug("Member %s down voted suggestion %s", member_id, suggestion_id)

@commands.slash_command(
Expand Down
13 changes: 12 additions & 1 deletion suggestions/locales/en_GB.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,16 @@
"CONFIG_GET_INNER_IMAGES_IN_SUGGESTIONS_MESSAGE": "This guild {} have images in suggestions.",
"CONFIG_SUGGESTIONS_IMAGES_ENABLE_INNER_MESSAGE": "All new suggestions can include images.",
"CONFIG_SUGGESTIONS_IMAGES_DISABLE_INNER_MESSAGE": "All new suggestions cannot include images.",
"VIEW_VOTERS_INNER_EMBED_TITLE": "Viewing voters"
"VIEW_VOTERS_INNER_EMBED_TITLE": "Viewing voters",
"RESULTS_SO_FAR": "Results so far",
"EMBED_RESULTS": "Results",
"SUGGESTION": "Suggestion",
"SUBMITTER_NAME": "Submitter",
"SUBMITTER_ANONYMOUS": "Anonymous",
"SUBMITTER_ID": "Submitter ID",
"PAGE": "Page",
"THREAD_FOR_SUGGESTION": "Thread for suggestion",
"SUGGESTION_STATUS_APPROVED": "Approved",
"SUGGESTION_STATUS_REJECTED": "Rejected",
"SUGGESTION_STATUS_CHANGED_BY": "By"
}
13 changes: 12 additions & 1 deletion suggestions/locales/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,16 @@
"CONFIG_GET_INNER_IMAGES_IN_SUGGESTIONS_MESSAGE": "Cette guilde {} autoriser les images dans les suggestions.",
"CONFIG_SUGGESTIONS_IMAGES_ENABLE_INNER_MESSAGE": "Toutes les nouvelles suggestions peuvent inclure des images.",
"CONFIG_SUGGESTIONS_IMAGES_DISABLE_INNER_MESSAGE": "Toutes les nouvelles suggestions ne peuvent pas inclure d'images.",
"VIEW_VOTERS_INNER_EMBED_TITLE": "Affichage des votants"
"VIEW_VOTERS_INNER_EMBED_TITLE": "Affichage des votants",
"RESULTS_SO_FAR": "Résultats",
"EMBED_RESULTS": "Résultats",
"SUGGESTION": "Suggestion",
"SUBMITTER_NAME": "Créer par",
"SUBMITTER_ANONYMOUS": "Anonyme",
"SUBMITTER_ID": "ID du créateur",
"PAGE": "Page",
"THREAD_FOR_SUGGESTION": "Fil de suggestion",
"SUGGESTION_STATUS_APPROVED": "Approuvée",
"SUGGESTION_STATUS_REJECTED": "Rejetée",
"SUGGESTION_STATUS_CHANGED_BY": "Par"
}
11 changes: 6 additions & 5 deletions suggestions/objects/queued_suggestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Optional, TYPE_CHECKING, overload

from disnake import Embed
import disnake

from suggestions.exceptions import UnhandledError
from suggestions.objects import Suggestion
Expand Down Expand Up @@ -129,22 +130,22 @@ def as_dict(self) -> dict:

return data

async def as_embed(self, bot: SuggestionsBot) -> Embed:
async def as_embed(self, bot: SuggestionsBot, interaction: disnake.Interaction) -> Embed:
user = await bot.get_or_fetch_user(self.suggestion_author_id)
if self.is_anonymous:
submitter = "Anonymous"
submitter = bot.get_localized_string("SUBMITTER_ANONYMOUS", interaction)
else:
submitter = user.display_name

embed: Embed = Embed(
description=f"**Submitter**\n{submitter}\n\n"
f"**Suggestion**\n{self.suggestion}",
description=f"**{bot.get_localized_string('SUBMITTER_NAME', interaction)}**\n{submitter}\n\n"
f"**{bot.get_localized_string('SUGGESTION', interaction)}**\n{self.suggestion}",
colour=bot.colors.embed_color,
timestamp=self.created_at,
)
if not self.is_anonymous:
embed.set_thumbnail(user.display_avatar)
embed.set_footer(text=f"Submitter ID: {self.suggestion_author_id}")
embed.set_footer(text=f"{bot.get_localized_string('SUBMITTER_ID', interaction)}: {self.suggestion_author_id}")

if self.image_url:
embed.set_image(self.image_url)
Expand Down
44 changes: 22 additions & 22 deletions suggestions/objects/suggestion.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,20 +386,20 @@ def as_dict(self) -> dict:

return data

async def as_embed(self, bot: SuggestionsBot) -> Embed:
async def as_embed(self, bot: SuggestionsBot, interaction: disnake.Interaction) -> Embed:
user = await bot.get_or_fetch_user(self.suggestion_author_id)

if self.resolved_by:
return await self._as_resolved_embed(bot, user)
return await self._as_resolved_embed(bot, user, interaction)

if self.is_anonymous:
submitter = "Anonymous"
submitter = bot.get_localized_string("SUBMITTER_ANONYMOUS", interaction)
else:
submitter = user.display_name

embed: Embed = Embed(
description=f"**Submitter**\n{submitter}\n\n"
f"**Suggestion**\n{self.suggestion}",
description=f"**{bot.get_localized_string('SUBMITTER_NAME', interaction)}**\n{submitter}\n\n"
f"**{bot.get_localized_string('SUGGESTION', interaction)}**\n{self.suggestion}",
colour=self.color,
timestamp=bot.state.now,
)
Expand All @@ -416,33 +416,33 @@ async def as_embed(self, bot: SuggestionsBot) -> Embed:

if self.uses_views_for_votes:
results = (
f"**Results so far**\n{await bot.suggestion_emojis.default_up_vote()}: **{self.total_up_votes}**\n"
f"**{bot.get_localized_string('RESULTS_SO_FAR', interaction)}**\n{await bot.suggestion_emojis.default_up_vote()}: **{self.total_up_votes}**\n"
f"{await bot.suggestion_emojis.default_down_vote()}: **{self.total_down_votes}**"
)
embed.description += f"\n\n{results}"

return embed

async def _as_resolved_embed(
self, bot: SuggestionsBot, user: disnake.User
self, bot: SuggestionsBot, user: disnake.User, interaction: disnake.Interaction
) -> Embed:
results = (
f"**Results**\n{await bot.suggestion_emojis.default_up_vote()}: **{self.total_up_votes}**\n"
f"**{bot.get_localized_string('EMBED_RESULTS', interaction)}**\n{await bot.suggestion_emojis.default_up_vote()}: **{self.total_up_votes}**\n"
f"{await bot.suggestion_emojis.default_down_vote()}: **{self.total_down_votes}**"
)

if self.is_anonymous:
submitter = "Anonymous"
submitter = bot.get_localized_string('SUBMITTER_ANONYMOUS', interaction)
else:
submitter = f"<@{self.suggestion_author_id}>"
text = "Approved" if self.state == SuggestionState.approved else "Rejected"
text = bot.get_localized_string('SUGGESTION_STATUS_APPROVED', interaction) if self.state == SuggestionState.approved else bot.get_localized_string('SUGGESTION_STATUS_REJECTED', interaction)
resolved_by_text = (
"Anonymous" if self.anonymous_resolution else f"<@{self.resolved_by}>"
bot.get_localized_string('SUBMITTER_ANONYMOUS', interaction) if self.anonymous_resolution else f"<@{self.resolved_by}>"
)
embed = Embed(
description=f"{results}\n\n**Suggestion**\n{self.suggestion}\n\n"
f"**Submitter**\n{submitter}\n\n"
f"**{text} By**\n{resolved_by_text}\n\n",
description=f"{results}\n\n**{bot.get_localized_string('SUGGESTION', interaction)}**\n{self.suggestion}\n\n"
f"**{bot.get_localized_string('SUBMITTER_NAME', interaction)}**\n{submitter}\n\n"
f"**{text} {bot.get_localized_string('SUGGESTION_STATUS_CHANGED_BY', interaction)}**\n{resolved_by_text}\n\n",
colour=self.color,
timestamp=bot.state.now,
)
Expand Down Expand Up @@ -662,14 +662,14 @@ async def try_notify_user_of_decision(self, bot: SuggestionsBot):
except disnake.HTTPException:
log.debug("Failed to dm %s to tell them about their suggestion", user.id)

async def create_thread(self, message: disnake.Message):
async def create_thread(self, message: disnake.Message, bot: SuggestionsBot, locale: disnake.Locale):
"""Create a thread for this suggestion"""
if self.state != SuggestionState.pending:
raise ValueError(
"Cannot create a thread for suggestions which aren't pending."
)

await message.create_thread(name=f"Thread for suggestion {self.suggestion_id}")
await message.create_thread(name=f"{bot.get_locale('THREAD_FOR_SUGGESTION', locale)} {self.suggestion_id}")

async def update_vote_count(
self,
Expand All @@ -688,7 +688,7 @@ async def update_vote_count(
try:
await MessageEditing(
bot, channel_id=self.channel_id, message_id=self.message_id
).edit(embed=await self.as_embed(bot))
).edit(embed=await self.as_embed(bot, interaction))
except (disnake.HTTPException, disnake.NotFound):
await interaction.send(
embed=bot.error_embed(
Expand Down Expand Up @@ -722,7 +722,7 @@ async def edit_message_after_finalization(
message: disnake.Message = await channel.fetch_message(self.message_id)

try:
await message.edit(embed=await self.as_embed(bot), components=None)
await message.edit(embed=await self.as_embed(bot, interaction), components=None)
except disnake.Forbidden:
raise commands.MissingPermissions(
missing_permissions=[
Expand All @@ -749,7 +749,7 @@ async def edit_message_after_finalization(
)
try:
message: disnake.Message = await channel.send(
embed=await self.as_embed(bot)
embed=await self.as_embed(bot, interaction)
)
except disnake.Forbidden:
raise commands.MissingPermissions(
Expand Down Expand Up @@ -866,7 +866,7 @@ async def setup_initial_messages(
)
channel: disnake.TextChannel = cast(disnake.TextChannel, channel)
message: disnake.Message = await channel.send(
embed=await self.as_embed(bot),
embed=await self.as_embed(bot, interaction),
components=[
disnake.ui.Button(
emoji=await bot.suggestion_emojis.default_up_vote(),
Expand All @@ -893,7 +893,7 @@ async def setup_initial_messages(

if guild_config.threads_for_suggestions:
try:
await self.create_thread(message)
await self.create_thread(message, bot, interaction.locale)
except disnake.HTTPException:
log.debug(
"Failed to create a thread on suggestion %s",
Expand Down
2 changes: 1 addition & 1 deletion suggestions/qs_paginator.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def format_page(self) -> disnake.Embed:
await self.remove_current_page()
log.debug("Hit QueueImbalance")
else:
embed: disnake.Embed = await suggestion.as_embed(self.bot)
embed: disnake.Embed = await suggestion.as_embed(self.bot, self.original_interaction)
if suggestion.is_anonymous:
embed.set_footer(text=f"Page {self.current_page}/{self.total_pages}")
else:
Expand Down