Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Pukimaa committed Dec 2, 2022
2 parents 67dcca7 + cfb64db commit 86d33f8
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 12 deletions.
4 changes: 2 additions & 2 deletions .gitmoji-changelogrc
Original file line number Diff line number Diff line change
@@ -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"
}
}
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

<a name="0.1.4"></a>
## 0.1.4 (2022-12-02)

### Added

- ✨ added autotranslate styles [[c490624](https://github.com/tako-discord/tako/commit/c490624334671808903e75b4529c22c52f7d9bb2)]


<a name="0.1.3"></a>
## 0.1.3 (2022-12-02)

Expand Down
67 changes: 58 additions & 9 deletions cogs/misc/autotranslate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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"
)
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions i18n/misc/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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}"

0 comments on commit 86d33f8

Please sign in to comment.