Added command for multiline reminders

This commit is contained in:
jude 2022-09-07 18:27:13 +01:00
parent c799d10727
commit 8dd7dc6409
4 changed files with 55 additions and 13 deletions

View File

@ -581,8 +581,6 @@ pub fn show_macro_page<U, E>(macros: &[CommandMacro<U, E>], page: usize) -> Crea
} }
struct Alias { struct Alias {
id: u32,
guild_id: u32,
name: String, name: String,
command: String, command: String,
} }
@ -601,7 +599,7 @@ pub async fn migrate_macro(ctx: Context<'_>) -> Result<(), Error> {
let aliases = sqlx::query_as!( let aliases = sqlx::query_as!(
Alias, 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 guild_id.0
) )
.fetch_all(&mut transaction) .fetch_all(&mut transaction)

View File

@ -10,7 +10,7 @@ use num_integer::Integer;
use poise::{ use poise::{
serenity::{builder::CreateEmbed, model::channel::Channel}, serenity::{builder::CreateEmbed, model::channel::Channel},
serenity_prelude::{component::ButtonStyle, ReactionType}, serenity_prelude::{component::ButtonStyle, ReactionType},
CreateReply, CreateReply, Modal,
}; };
use crate::{ use crate::{
@ -36,7 +36,7 @@ use crate::{
}, },
time_parser::natural_parser, time_parser::natural_parser,
utils::{check_guild_subscription, check_subscription}, utils::{check_guild_subscription, check_subscription},
Context, Error, ApplicationContext, Context, Error,
}; };
/// Pause all reminders on the current channel until a certain time or indefinitely /// Pause all reminders on the current channel until a certain time or indefinitely
@ -548,6 +548,40 @@ pub async fn delete_timer(
Ok(()) 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<String>,
#[description = "(Patreon only) Time to wait before repeating the reminder. Leave blank for one-shot reminder"]
interval: Option<String>,
#[description = "(Patreon only) For repeating reminders, the time at which the reminder will stop repeating"]
expires: Option<String>,
#[description = "Set the TTS flag on the reminder message, similar to the /tts command"]
tts: Option<bool>,
) -> 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 /// Create a new reminder
#[poise::command( #[poise::command(
slash_command, slash_command,
@ -561,10 +595,22 @@ pub async fn remind(
#[description = "Channel or user mentions to set the reminder for"] channels: Option<String>, #[description = "Channel or user mentions to set the reminder for"] channels: Option<String>,
#[description = "(Patreon only) Time to wait before repeating the reminder. Leave blank for one-shot reminder"] #[description = "(Patreon only) Time to wait before repeating the reminder. Leave blank for one-shot reminder"]
interval: Option<String>, interval: Option<String>,
#[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<String>, expires: Option<String>,
#[description = "Set the TTS flag on the reminder message, similar to the /tts command"] #[description = "Set the TTS flag on the reminder message, similar to the /tts command"]
tts: Option<bool>, tts: Option<bool>,
) -> Result<(), Error> {
create_reminder(ctx, time, content, channels, interval, expires, tts).await
}
async fn create_reminder(
ctx: Context<'_>,
time: String,
content: String,
channels: Option<String>,
interval: Option<String>,
expires: Option<String>,
tts: Option<bool>,
) -> Result<(), Error> { ) -> Result<(), Error> {
if interval.is_none() && expires.is_some() { if interval.is_none() && expires.is_some() {
ctx.say("`expires` can only be used with `interval`").await?; ctx.say("`expires` can only be used with `interval`").await?;

View File

@ -1,6 +1,5 @@
use std::{collections::HashMap, env, sync::atomic::Ordering}; use std::{collections::HashMap, env};
use log::{error, info, warn};
use poise::{ use poise::{
serenity::{model::application::interaction::Interaction, utils::shard_id}, serenity::{model::application::interaction::Interaction, utils::shard_id},
serenity_prelude as serenity, serenity_prelude as serenity,

View File

@ -18,7 +18,6 @@ use std::{
env, env,
error::Error as StdError, error::Error as StdError,
fmt::{Debug, Display, Formatter}, fmt::{Debug, Display, Formatter},
sync::atomic::AtomicBool,
}; };
use chrono_tz::Tz; use chrono_tz::Tz;
@ -44,14 +43,14 @@ type Database = MySql;
type Error = Box<dyn std::error::Error + Send + Sync>; type Error = Box<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>; type Context<'a> = poise::Context<'a, Data, Error>;
type ApplicationContext<'a> = poise::ApplicationContext<'a, Data, Error>;
pub struct Data { pub struct Data {
database: Pool<Database>, database: Pool<Database>,
http: reqwest::Client, http: reqwest::Client,
recording_macros: RwLock<HashMap<(GuildId, UserId), CommandMacro<Data, Error>>>, recording_macros: RwLock<HashMap<(GuildId, UserId), CommandMacro<Data, Error>>>,
popular_timezones: Vec<Tz>, popular_timezones: Vec<Tz>,
is_loop_running: AtomicBool, _broadcast: Sender<()>,
broadcast: Sender<()>,
} }
impl Debug for Data { impl Debug for Data {
@ -135,6 +134,7 @@ async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> {
..reminder_cmds::timer_base() ..reminder_cmds::timer_base()
}, },
reminder_cmds::remind(), reminder_cmds::remind(),
reminder_cmds::remind_multiline(),
poise::Command { poise::Command {
subcommands: vec![ subcommands: vec![
poise::Command { poise::Command {
@ -229,8 +229,7 @@ async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> {
database, database,
popular_timezones, popular_timezones,
recording_macros: Default::default(), recording_macros: Default::default(),
is_loop_running: AtomicBool::new(false), _broadcast: tx,
broadcast: tx,
}) })
}) })
}) })