diff --git a/src/commands/moderation_cmds.rs b/src/commands/moderation_cmds.rs index b8bf321..ddb8345 100644 --- a/src/commands/moderation_cmds.rs +++ b/src/commands/moderation_cmds.rs @@ -581,8 +581,6 @@ pub fn show_macro_page(macros: &[CommandMacro], page: usize) -> Crea } struct Alias { - id: u32, - guild_id: u32, name: String, command: String, } @@ -601,7 +599,7 @@ pub async fn migrate_macro(ctx: Context<'_>) -> Result<(), Error> { let aliases = sqlx::query_as!( Alias, - "SELECT * FROM command_aliases WHERE guild_id = (SELECT id FROM guilds WHERE guild = ?)", + "SELECT name, command FROM command_aliases WHERE guild_id = (SELECT id FROM guilds WHERE guild = ?)", guild_id.0 ) .fetch_all(&mut transaction) diff --git a/src/commands/reminder_cmds.rs b/src/commands/reminder_cmds.rs index 5984c73..d9a27d2 100644 --- a/src/commands/reminder_cmds.rs +++ b/src/commands/reminder_cmds.rs @@ -10,7 +10,7 @@ use num_integer::Integer; use poise::{ serenity::{builder::CreateEmbed, model::channel::Channel}, serenity_prelude::{component::ButtonStyle, ReactionType}, - CreateReply, + CreateReply, Modal, }; use crate::{ @@ -36,7 +36,7 @@ use crate::{ }, time_parser::natural_parser, utils::{check_guild_subscription, check_subscription}, - Context, Error, + ApplicationContext, Context, Error, }; /// Pause all reminders on the current channel until a certain time or indefinitely @@ -548,6 +548,40 @@ pub async fn delete_timer( Ok(()) } +#[derive(poise::Modal)] +#[name = "Reminder"] +struct ContentModal { + #[name = "Content"] + #[placeholder = "Message..."] + #[paragraph] + #[max_length = 2000] + content: String, +} + +/// Create a new reminder with multiline content +#[poise::command( + slash_command, + rename = "multiline", + identifying_name = "remind_multiline", + default_member_permissions = "MANAGE_GUILD" +)] +pub async fn remind_multiline( + ctx: ApplicationContext<'_>, + #[description = "A description of the time to set the reminder for"] time: String, + #[description = "Channel or user mentions to set the reminder for"] channels: Option, + #[description = "(Patreon only) Time to wait before repeating the reminder. Leave blank for one-shot reminder"] + interval: Option, + #[description = "(Patreon only) For repeating reminders, the time at which the reminder will stop repeating"] + expires: Option, + #[description = "Set the TTS flag on the reminder message, similar to the /tts command"] + tts: Option, +) -> Result<(), Error> { + let data = ContentModal::execute(ctx).await?; + + create_reminder(Context::Application(ctx), time, data.content, channels, interval, expires, tts) + .await +} + /// Create a new reminder #[poise::command( slash_command, @@ -561,10 +595,22 @@ pub async fn remind( #[description = "Channel or user mentions to set the reminder for"] channels: Option, #[description = "(Patreon only) Time to wait before repeating the reminder. Leave blank for one-shot reminder"] interval: Option, - #[description = "(Patreon only) For repeating reminders, the time at which the reminder will stop sending"] + #[description = "(Patreon only) For repeating reminders, the time at which the reminder will stop repeating"] expires: Option, #[description = "Set the TTS flag on the reminder message, similar to the /tts command"] tts: Option, +) -> Result<(), Error> { + create_reminder(ctx, time, content, channels, interval, expires, tts).await +} + +async fn create_reminder( + ctx: Context<'_>, + time: String, + content: String, + channels: Option, + interval: Option, + expires: Option, + tts: Option, ) -> Result<(), Error> { if interval.is_none() && expires.is_some() { ctx.say("`expires` can only be used with `interval`").await?; diff --git a/src/event_handlers.rs b/src/event_handlers.rs index e7d0d57..e47585d 100644 --- a/src/event_handlers.rs +++ b/src/event_handlers.rs @@ -1,6 +1,5 @@ -use std::{collections::HashMap, env, sync::atomic::Ordering}; +use std::{collections::HashMap, env}; -use log::{error, info, warn}; use poise::{ serenity::{model::application::interaction::Interaction, utils::shard_id}, serenity_prelude as serenity, diff --git a/src/main.rs b/src/main.rs index a5ac64d..64e8267 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,7 +18,6 @@ use std::{ env, error::Error as StdError, fmt::{Debug, Display, Formatter}, - sync::atomic::AtomicBool, }; use chrono_tz::Tz; @@ -44,14 +43,14 @@ type Database = MySql; type Error = Box; type Context<'a> = poise::Context<'a, Data, Error>; +type ApplicationContext<'a> = poise::ApplicationContext<'a, Data, Error>; pub struct Data { database: Pool, http: reqwest::Client, recording_macros: RwLock>>, popular_timezones: Vec, - is_loop_running: AtomicBool, - broadcast: Sender<()>, + _broadcast: Sender<()>, } impl Debug for Data { @@ -135,6 +134,7 @@ async fn _main(tx: Sender<()>) -> Result<(), Box> { ..reminder_cmds::timer_base() }, reminder_cmds::remind(), + reminder_cmds::remind_multiline(), poise::Command { subcommands: vec![ poise::Command { @@ -229,8 +229,7 @@ async fn _main(tx: Sender<()>) -> Result<(), Box> { database, popular_timezones, recording_macros: Default::default(), - is_loop_running: AtomicBool::new(false), - broadcast: tx, + _broadcast: tx, }) }) })