From c490624334671808903e75b4529c22c52f7d9bb2 Mon Sep 17 00:00:00 2001 From: boloped <53911231+boloped@users.noreply.github.com> Date: Fri, 2 Dec 2022 22:06:10 +0100 Subject: [PATCH 1/4] =?UTF-8?q?=E2=9C=A8=20added=20autotranslate=20styles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/misc/autotranslate.py | 62 ++++++++++++++++++++++++++++++++------ helper.py | 2 +- i18n/misc/en.yml | 1 + 3 files changed, 55 insertions(+), 10 deletions(-) diff --git a/cogs/misc/autotranslate.py b/cogs/misc/autotranslate.py index 19e2ef7c..3d9dcac9 100644 --- a/cogs/misc/autotranslate.py +++ b/cogs/misc/autotranslate.py @@ -4,6 +4,7 @@ import config from discord import app_commands from discord.ext import commands +from discord.app_commands import Choice from utils import get_language, translate @@ -28,6 +29,32 @@ async def auto_translate(self, interaction: discord.Interaction, value: bool): ephemeral=True, ) + @app_commands.command(description="Set the style of the auto trandlated message") + @app_commands.describe(style="The style of the auto translated message") + @app_commands.checks.has_permissions(manage_guild=True) + @app_commands.choices( + style=[ + Choice(name="Default", value="default"), + Choice(name="Webhook", value="webhook"), + ] + ) + async def auto_translate_reply_style( + self, interaction: discord.Interaction, style: str + ): + await self.bot.db_pool.execute( + "INSERT INTO guilds (guild_id, auto_translate_reply_style) VALUES ($1, $2) ON CONFLICT(guild_id) DO UPDATE SET auto_translate_reply_style = $2", + interaction.guild.id, + style, + ) + return await interaction.response.send_message( + i18n.t( + "misc.auto_translate_reply_style_set", + style=style, + locale=get_language(self.bot, interaction.guild.id), + ), + ephemeral=True, + ) + @app_commands.command( description="Adjust the confidence threshold for auto translate" ) @@ -74,19 +101,36 @@ async def on_message(self, message: discord.Message): "SELECT auto_translate_confidence FROM guilds WHERE guild_id = $1", message.guild.id, ) + reply_style = await self.bot.db_pool.fetchval( + "SELECT auto_translate_reply_style FROM guilds WHERE guild_id = $1", + message.guild.id, + ) guild_language = get_language(self.bot, message.guild.id) if confidence >= data["confidence"]: return if data["language"] != guild_language: try: - await message.reply( - "> " - + ( - await translate(message.content, guild_language) - ).replace("\n", "\n> ") - + f"\n\n` {data['language']} ➜ {guild_language} | {round(data['confidence'])} `", - allowed_mentions=discord.AllowedMentions.none(), - mention_author=False, - ) + if reply_style == "webhook": + webhook = await message.channel.create_webhook( + name="AutoTranslate" + ) + await webhook.send( + username=f"{message.author.display_name} ({data['language']} ➜ {guild_language})", + avatar_url=message.author.avatar.url, + embed=discord.Embed( + description=await translate(message.content, guild_language), + color=0x2F3136 + ).set_footer(text=f"Confidence: {round(data['confidence'])}%") + ) + else: + await message.reply( + "> " + + ( + await translate(message.content, guild_language) + ).replace("\n", "\n> ") + + f"\n\n` {data['language']} ➜ {guild_language} | {round(data['confidence'])} `", + allowed_mentions=discord.AllowedMentions.none(), + mention_author=False, + ) except discord.Forbidden: return diff --git a/helper.py b/helper.py index 85f98e0e..b6526c0b 100644 --- a/helper.py +++ b/helper.py @@ -72,7 +72,7 @@ async def main(): INSERT INTO badges (name, emoji, description) VALUES ('Translator', '🌐', 'Users who translated this bot receive this badge') ON CONFLICT DO NOTHING; INSERT INTO badges (name, emoji, description) VALUES ('Core Developer', '🧑‍💻', 'Users who are the core developers from the the bot') ON CONFLICT DO NOTHING; CREATE TABLE IF NOT EXISTS channels (channel_id BIGINT PRIMARY KEY, crosspost BOOLEAN NOT NULL); - CREATE TABLE IF NOT EXISTS guilds (guild_id BIGINT PRIMARY KEY, banned_games TEXT ARRAY, join_roles_user BIGINT ARRAY, join_roles_bot BIGINT ARRAY, language TEXT, reaction_translate BOOLEAN, auto_translate BOOLEAN DEFAULT FALSE, color TEXT, auto_translate_confidence INTEGER DEFAULT 50); + CREATE TABLE IF NOT EXISTS guilds (guild_id BIGINT PRIMARY KEY, banned_games TEXT ARRAY, join_roles_user BIGINT ARRAY, join_roles_bot BIGINT ARRAY, language TEXT, reaction_translate BOOLEAN, auto_translate BOOLEAN DEFAULT FALSE, color TEXT, auto_translate_confidence INTEGER DEFAULT 50, auto_translate_reply_style TEXT); CREATE EXTENSION IF NOT EXISTS "uuid-ossp"; CREATE TABLE IF NOT EXISTS tags (id uuid DEFAULT uuid_generate_v4() PRIMARY KEY, name TEXT, content TEXT, thumbnail TEXT, image TEXT, footer TEXT, embed BOOLEAN DEFAULT TRUE, guild_id BIGINT); CREATE TABLE IF NOT EXISTS users (user_id BIGINT PRIMARY KEY, wallet BIGINT DEFAULT 1000, bank BIGINT DEFAULT 0, last_meme TEXT); diff --git a/i18n/misc/en.yml b/i18n/misc/en.yml index ece6702f..9f792464 100644 --- a/i18n/misc/en.yml +++ b/i18n/misc/en.yml @@ -31,3 +31,4 @@ en: auto_translate_activated: "✅ Autotranslate is now activated" auto_translate_deactivated: "❌ Autotranslate is now deactivated" auto_translate_confidence_set: "Confidence Threshold is now set to %{value}%" + auto_translate_reply_style_set: "Autotranslate reply style is now set to %{style}" From 6ea2e6b108edf34a122311152af3656b6cedb682 Mon Sep 17 00:00:00 2001 From: github-actions Date: Fri, 2 Dec 2022 21:06:36 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=9A=A8=20Linting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/misc/autotranslate.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/cogs/misc/autotranslate.py b/cogs/misc/autotranslate.py index 3d9dcac9..dc7c80b0 100644 --- a/cogs/misc/autotranslate.py +++ b/cogs/misc/autotranslate.py @@ -118,9 +118,13 @@ async def on_message(self, message: discord.Message): username=f"{message.author.display_name} ({data['language']} ➜ {guild_language})", avatar_url=message.author.avatar.url, embed=discord.Embed( - description=await translate(message.content, guild_language), - color=0x2F3136 - ).set_footer(text=f"Confidence: {round(data['confidence'])}%") + description=await translate( + message.content, guild_language + ), + color=0x2F3136, + ).set_footer( + text=f"Confidence: {round(data['confidence'])}%" + ), ) else: await message.reply( From 48eb52c92eb4b1b99fa0b8a189a26427f210658d Mon Sep 17 00:00:00 2001 From: boloped <53911231+boloped@users.noreply.github.com> Date: Fri, 2 Dec 2022 22:24:08 +0100 Subject: [PATCH 3/4] =?UTF-8?q?=F0=9F=A9=B9=20fixed=20the=20webhook=20syle?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cogs/misc/autotranslate.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cogs/misc/autotranslate.py b/cogs/misc/autotranslate.py index 3d9dcac9..f0da580e 100644 --- a/cogs/misc/autotranslate.py +++ b/cogs/misc/autotranslate.py @@ -122,6 +122,7 @@ async def on_message(self, message: discord.Message): color=0x2F3136 ).set_footer(text=f"Confidence: {round(data['confidence'])}%") ) + await webhook.delete() else: await message.reply( "> " From cfb64db3cb16f4206c9ca23947d21d3f0ddc2b82 Mon Sep 17 00:00:00 2001 From: Pukimaa Date: Fri, 2 Dec 2022 23:34:33 +0100 Subject: [PATCH 4/4] =?UTF-8?q?=F0=9F=94=96=200.1.4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitmoji-changelogrc | 2 +- CHANGELOG.md | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/.gitmoji-changelogrc b/.gitmoji-changelogrc index c96a4f86..1edc2d32 100644 --- a/.gitmoji-changelogrc +++ b/.gitmoji-changelogrc @@ -2,6 +2,6 @@ "project": { "name": "Tako", "description": "A multipurpose Discord bot for everything", - "version": "0.1.3" + "version": "0.1.4" } } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index f9edb347..87ab5199 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog + +## 0.1.4 (2022-12-02) + +### Added + +- ✨ added autotranslate styles [[c490624](https://github.com/tako-discord/tako/commit/c490624334671808903e75b4529c22c52f7d9bb2)] + + ## 0.1.3 (2022-12-02)