Add suggestion command

late-submissions
Elnu 2 years ago
parent edfb01d154
commit 9063017a48

@ -329,3 +329,48 @@ async fn imageDelete(ctx: &Context, msg: &Message, mut args: Args) -> CommandRes
.await?;
Ok(())
}
#[command]
#[allow(non_snake_case)]
async fn suggest(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
let guild_data = get_guild_data();
let channel = ChannelId(
guild_data["suggestionChannel"]
.as_str()
.unwrap()
.parse::<u64>()
.unwrap(),
);
// User::accent_colour is only available via the REST API
// If we just do msg.author.accent_colour here, we will get None
let accent_color = ctx.http
.get_user(*msg.author.id.as_u64())
.await.unwrap()
.accent_colour;
channel.send_message(&ctx.http, |m| {
m.allowed_mentions(|am| {
am.empty_parse();
am
});
m.embed(|e| {
let username = format!("{}#{}", msg.author.name, msg.author.discriminator);
e.title("New suggestion");
e.description(format!("{}\n\n[See original message]({}) ({})", args.rest(), msg.link(), msg.guild(&ctx).unwrap().name));
let mut author = serenity::builder::CreateEmbedAuthor::default();
author
.icon_url(format!("https://cdn.discordapp.com/avatars/{}/{}.webp", msg.author.id, msg.author.avatar.as_ref().unwrap()))
.name(username)
.url(format!("https://discord.com/users/{}", msg.author.id));
e.set_author(author);
if let Some(accent_color) = accent_color {
e.color(accent_color);
}
e
});
m
})
.await
.unwrap();
msg.reply(&ctx.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?;
Ok(())
}

@ -57,6 +57,24 @@ async fn setSubmissionChannel(ctx: &Context, msg: &Message) -> CommandResult {
Ok(())
}
#[command]
#[owners_only]
#[allow(non_snake_case)]
async fn setSuggestionChannel(ctx: &Context, msg: &Message) -> CommandResult {
let channel = msg.channel_id.as_u64().to_string();
let mut guild_data = get_guild_data();
guild_data["suggestionChannel"] = channel.into();
set_guild_data(guild_data);
msg.reply(
&ctx.http,
format!(
"Submission channel set to <#{}>.",
msg.channel_id
),
).await?;
Ok(())
}
#[command]
#[owners_only]
#[allow(non_snake_case)]

@ -53,7 +53,9 @@ impl EventHandler for Handler {
help,
sleep,
setSubmissionChannel,
setSuggestionChannel,
setAnnouncementRole,
suggest,
announce,
announceChallenge
)]

Loading…
Cancel
Save