Skip to content

Commit

Permalink
feat(translate): show link to original message
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanccn committed Nov 22, 2023
1 parent 75b6099 commit 323943f
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/commands/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ struct GoogleTranslateResponse {
#[poise::command(context_menu_command = "Translate", guild_only)]
pub async fn translate(ctx: Context<'_>, message: serenity::Message) -> Result<()> {
ctx.defer().await?;
let serenity::Message { content, .. } = message;

if content.is_empty() {
if message.content.is_empty() {
ctx.send(
CreateReply::new().embed(
serenity::CreateEmbed::new()
Expand All @@ -47,7 +46,7 @@ pub async fn translate(ctx: Context<'_>, message: serenity::Message) -> Result<(
.append_pair("dt", "t")
.append_pair("dj", "1")
.append_pair("source", "input")
.append_pair("q", &content);
.append_pair("q", &message.content);

let resp = crate::reqwest_client::HTTP.get(api_url).send().await?;

Expand All @@ -59,16 +58,20 @@ pub async fn translate(ctx: Context<'_>, message: serenity::Message) -> Result<(
.collect::<String>();

ctx.send(
CreateReply::new().embed(
serenity::CreateEmbed::new()
.title("Translation")
.description(&translation)
.color(0x34d399)
.footer(serenity::CreateEmbedFooter::new(format!(
"{} → en",
data.src
))),
),
CreateReply::new()
.embed(
serenity::CreateEmbed::new()
.title("Translation")
.description(&translation)
.color(0x34d399)
.footer(serenity::CreateEmbedFooter::new(format!(
"{} → en",
data.src
))),
)
.components(vec![serenity::CreateActionRow::Buttons(vec![
serenity::CreateButton::new_link(message.link()).label("Original message"),
])]),
)
.await?;

Expand Down

0 comments on commit 323943f

Please sign in to comment.