Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/tako-discord/tako
Browse files Browse the repository at this point in the history
  • Loading branch information
Pukimaa committed Dec 13, 2022
2 parents ccdaef9 + 64a9fe8 commit 61d6a68
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 24 deletions.
10 changes: 5 additions & 5 deletions cogs/errors/_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ async def on_app_command_error(
self.bot,
i18n.t("errors.bot_missing_perms_title", locale=language),
i18n.t("errors.bot_missing_perms", perms=fmt, locale=language),
interaction.guild.id
interaction.guild.id,
)
return await interaction.response.send_message(
embed=embed, file=file, ephemeral=True
Expand All @@ -52,7 +52,7 @@ async def on_app_command_error(
self.bot,
i18n.t("errors.user_missing_perms_title", locale=language),
i18n.t("errors.user_missing_perms", perms=fmt, locale=language),
interaction.guild.id
interaction.guild.id,
)
return await interaction.response.send_message(
embed=embed, file=file, ephemeral=True
Expand All @@ -63,7 +63,7 @@ async def on_app_command_error(
self.bot,
i18n.t("errors.cooldown_title", locale=language),
i18n.t("errors.cooldown", perms=fmt, locale=language),
interaction.guild.id
interaction.guild.id,
)
return await interaction.response.send_message(
embed=embed, file=file, ephemeral=True
Expand All @@ -75,7 +75,7 @@ async def on_app_command_error(
self.bot,
i18n.t("errors.no_pm_title", locale=language),
i18n.t("errors.no_pm", perms=fmt, locale=language),
interaction.guild.id
interaction.guild.id,
)
return await interaction.response.send_message(
embed=embed, file=file, ephemeral=True
Expand All @@ -89,7 +89,7 @@ async def on_app_command_error(
self.bot,
i18n.t("errors.check_failure_title", locale=language),
i18n.t("errors.check_failure", perms=fmt, locale=language),
interaction.guild.id
interaction.guild.id,
)
return await interaction.response.send_message(
embed=embed, file=file, ephemeral=True
Expand Down
60 changes: 45 additions & 15 deletions cogs/misc/autotranslate.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,14 @@ async def on_message(self, message: discord.Message):
if message.attachments:
for attachment in message.attachments:
bytes = await attachment.read()
attachments.append({
"bytes": bytes,
"spoiler": attachment.is_spoiler(),
"filename": attachment.filename,
"description": attachment.description
})
attachments.append(
{
"bytes": bytes,
"spoiler": attachment.is_spoiler(),
"filename": attachment.filename,
"description": attachment.description,
}
)
size = 0
boost_level = message.guild.premium_tier if hasattr(message, "guild") else 0
size_limit = 8000000
Expand All @@ -136,7 +138,14 @@ async def on_message(self, message: discord.Message):
attachment_removed = True
continue
attachment_bytes = io.BytesIO(attachment["bytes"])
new_attachments.append(discord.File(attachment_bytes, spoiler=attachment["spoiler"], filename=attachment["filename"], description=attachment["description"]))
new_attachments.append(
discord.File(
attachment_bytes,
spoiler=attachment["spoiler"],
filename=attachment["filename"],
description=attachment["description"],
)
)
attachments = new_attachments
headers = {
"accept": "application/json",
Expand All @@ -163,7 +172,13 @@ async def on_message(self, message: discord.Message):
message.guild.id,
)
guild_language = get_language(self.bot, message.guild.id)
too_large_embed, too_large_file = error_embed(self.bot, i18n.t("errors.too_large_title", locale=guild_language), i18n.t("errors.too_large", locale=guild_language), message.guild.id, style="warning")
too_large_embed, too_large_file = error_embed(
self.bot,
i18n.t("errors.too_large_title", locale=guild_language),
i18n.t("errors.too_large", locale=guild_language),
message.guild.id,
style="warning",
)
if confidence >= data["confidence"]:
return
webhook_id = None
Expand All @@ -181,7 +196,7 @@ async def on_message(self, message: discord.Message):
await webhook.send(
username=f"{message.author.display_name} ({data['language']}{guild_language})",
avatar_url=message.author.display_avatar.url,
files = attachments,
files=attachments,
embed=discord.Embed(
description=await translate(
message.content, guild_language
Expand All @@ -198,7 +213,12 @@ async def on_message(self, message: discord.Message):
message.author.mention,
embed=too_large_embed,
file=too_large_file,
allowed_mentions=discord.AllowedMentions(everyone=False, users=[message.author], roles=False, replied_user=False),
allowed_mentions=discord.AllowedMentions(
everyone=False,
users=[message.author],
roles=False,
replied_user=False,
),
)
return
if attachment_removed:
Expand All @@ -211,7 +231,7 @@ async def on_message(self, message: discord.Message):
await webhook.send(
username=f"{message.author.display_name} ({data['language']}{guild_language})",
avatar_url=message.author.display_avatar.url,
files = attachments,
files=attachments,
content=await translate(
message.content, guild_language
),
Expand All @@ -223,7 +243,12 @@ async def on_message(self, message: discord.Message):
message.author.mention,
embed=too_large_embed,
file=too_large_file,
allowed_mentions=discord.AllowedMentions(everyone=False, users=[message.author], roles=False, replied_user=False),
allowed_mentions=discord.AllowedMentions(
everyone=False,
users=[message.author],
roles=False,
replied_user=False,
),
)
return
if attachment_removed:
Expand All @@ -243,14 +268,19 @@ async def on_message(self, message: discord.Message):
).replace("\n", "\n> ")
+ f"\n\n` {data['language']}{guild_language} | {round(data['confidence'])} `",
allowed_mentions=discord.AllowedMentions.none(),
files = attachments,
files=attachments,
)
if attachment_removed:
await message.channel.send(
message.author.mention,
embed=too_large_embed,
file=too_large_file,
allowed_mentions=discord.AllowedMentions(everyone=False, users=[message.author], roles=False, replied_user=False),
allowed_mentions=discord.AllowedMentions(
everyone=False,
users=[message.author],
roles=False,
replied_user=False,
),
)
await message.delete()
return
Expand All @@ -262,7 +292,7 @@ async def on_message(self, message: discord.Message):
+ f"\n\n` {data['language']}{guild_language} | {round(data['confidence'])} `",
allowed_mentions=discord.AllowedMentions.none(),
mention_author=False,
files = attachments,
files=attachments,
)
if attachment_removed:
await message.reply(
Expand Down
23 changes: 19 additions & 4 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,14 @@ async def balance_embed(
return embed, file


def error_embed(bot, title: str, description: str, guild_id: int, footer: str = None, style: str = "error"):
def error_embed(
bot,
title: str,
description: str,
guild_id: int,
footer: str = None,
style: str = "error",
):
"""tuple[:class:`discord.Embed`, :class:`discord.File`]: Returns an error embed and a file for it's Thumbnail.
The first value is the embed and the second value is the file.
Expand All @@ -262,16 +269,24 @@ def error_embed(bot, title: str, description: str, guild_id: int, footer: str =
footer: :class:`str` = "An error occured"
The footer of the embed. (Mostly just the translation of "An error occured")
style: :class:`str` = "error"
The style of the embed. (Either 'error' or 'warning')
The style of the embed. (Either 'error' or 'warning')
"""
match style:
case "error":
file = discord.File("assets/alert.png", filename="thumbnail.png")
if not footer:
footer = i18n.t("errors.error_occured", locale=get_language(bot, guild_id)) if not footer else footer
footer = (
i18n.t("errors.error_occured", locale=get_language(bot, guild_id))
if not footer
else footer
)
case _:
file = discord.File("assets/warning.png", filename="thumbnail.png")
footer = i18n.t("errors.warning_occured", locale=get_language(bot, guild_id)) if not footer else footer
footer = (
i18n.t("errors.warning_occured", locale=get_language(bot, guild_id))
if not footer
else footer
)
embed = discord.Embed(
title=f"**{title}**",
description=description,
Expand Down

0 comments on commit 61d6a68

Please sign in to comment.