-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
87 additions
and
1 deletion.
There are no files selected for viewing
2 changes: 2 additions & 0 deletions
2
migrations/20231211023309_translate_to_english_enabled_by_default.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- Add migration script here | ||
ALTER TABLE guilds ALTER COLUMN translate SET DEFAULT true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use scripty_bot_utils::{checks::is_guild, Context, Error}; | ||
|
||
/// Automatically translate transcriptions to English? | ||
#[poise::command( | ||
prefix_command, | ||
slash_command, | ||
check = "is_guild", | ||
required_permissions = "MANAGE_GUILD", | ||
rename = "translate" | ||
)] | ||
pub async fn config_translate( | ||
ctx: Context<'_>, | ||
#[description = "Defaults to false"] translate: bool, | ||
) -> Result<(), Error> { | ||
let guild_id = ctx | ||
.guild_id() | ||
.map(|g| g.get()) | ||
.ok_or_else(Error::expected_guild)?; | ||
let resolved_language = | ||
scripty_i18n::get_resolved_language(ctx.author().id.get(), Some(guild_id)).await; | ||
|
||
if resolved_language.language != "en" { | ||
ctx.say(format_message!( | ||
resolved_language, | ||
"config-translate-not-english" | ||
)) | ||
.await?; | ||
return Ok(()); | ||
} | ||
|
||
sqlx::query!( | ||
"INSERT INTO guilds (guild_id, translate) VALUES ($1, $2) ON CONFLICT (guild_id) DO \ | ||
UPDATE SET translate = $2", | ||
guild_id as i64, | ||
translate | ||
) | ||
.execute(scripty_db::get_db()) | ||
.await?; | ||
|
||
ctx.say(format_message!( | ||
resolved_language, | ||
if translate { | ||
"config-translate-enabled" | ||
} else { | ||
"config-translate-disabled" | ||
} | ||
)) | ||
.await?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters