From 61973f617d3e02d49ea3e23dac052b076ff2c513 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Thu, 24 Nov 2022 17:35:49 -0800 Subject: [PATCH] Fix suggestions --- src/commands/challenge.rs | 28 +++++++++++++++++----------- src/main.rs | 2 +- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/commands/challenge.rs b/src/commands/challenge.rs index 9ac5742..45388a4 100644 --- a/src/commands/challenge.rs +++ b/src/commands/challenge.rs @@ -3,7 +3,7 @@ use serde_json::Map; use crate::serenity; use crate::Error; -use crate::{Context, PrefixContext}; +use crate::Context; use poise::command; use slug::slugify; @@ -418,10 +418,13 @@ pub async fn imagedelete(ctx: Context<'_>, number: i32) -> Result<(), Error> { // TODO: make also slash command #[command( prefix_command, + slash_command, + ephemeral, description_localized("en-US", "Make a suggestion for future challenge prompts!") )] pub async fn suggest( - ctx: PrefixContext<'_>, + ctx: Context<'_>, + #[rest] #[description = "Suggestion text. Please include passage and source."] suggestion: String, ) -> Result<(), Error> { let guild_data = get_guild_data(); @@ -434,16 +437,16 @@ pub async fn suggest( ); // User::accent_colour is only available via the REST API // If we just do msg.author.accent_colour here, we will get None - let author = &ctx.msg.author; + let author = &ctx.author(); let accent_color = ctx - .discord + .discord() .http .get_user(*author.id.as_u64()) .await .unwrap() .accent_colour; channel - .send_message(&ctx.discord.http, |m| { + .send_message(&ctx.discord().http, |m| { m.allowed_mentions(|am| { am.empty_parse(); am @@ -451,11 +454,14 @@ pub async fn suggest( m.embed(|e| { let username = format!("{}#{}", author.name, author.discriminator); e.title("New suggestion"); - e.description(format!( - "{}\n\n[See original message]({})", - suggestion, - ctx.msg.link(), - )); + e.description(if let Context::Prefix(ctx) = ctx { + format!( + "{suggestion}\n\n[See original message]({})", + ctx.msg.link(), + ) + } else { + suggestion + }); let mut embed_author = serenity::builder::CreateEmbedAuthor::default(); embed_author .icon_url(get_avatar(&author)) @@ -471,6 +477,6 @@ pub async fn suggest( }) .await .unwrap(); - ctx.msg.reply(&ctx.discord.http, "Suggestion sent! Thank you for making a suggestion. If it is chosen to be used in a future challenge, you will be mentioned in the challenge description!").await?; + ctx.say("Suggestion sent! Thank you for making a suggestion. If it is chosen to be used in a future challenge, you will be mentioned in the challenge description!").await?; Ok(()) } diff --git a/src/main.rs b/src/main.rs index 2643a2a..cb5100a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,7 +5,7 @@ use std::env; type Error = Box; type Context<'a> = poise::Context<'a, Data, Error>; -type PrefixContext<'a> = poise::PrefixContext<'a, Data, Error>; +// type PrefixContext<'a> = poise::PrefixContext<'a, Data, Error>; // User data, which is stored and accessible in all command invocations pub struct Data {}