diff --git a/.gitmoji-changelogrc b/.gitmoji-changelogrc
index 8fb23442..1edc2d32 100644
--- a/.gitmoji-changelogrc
+++ b/.gitmoji-changelogrc
@@ -1,7 +1,7 @@
{
"project": {
"name": "Tako",
- "description": "A m HAAAAALLLLLOOOOOO???????? ultipurpose Discord bot for everything",
- "version": "0.1.3"
+ "description": "A multipurpose Discord bot for everything",
+ "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)
diff --git a/cogs/misc/autotranslate.py b/cogs/misc/autotranslate.py
index 19e2ef7c..b9a72e18 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,41 @@ 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'])}%"
+ ),
+ )
+ await webhook.delete()
+ 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}"