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 {
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)

View File

@ -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<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
#[poise::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 = "(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 sending"]
#[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> {
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> {
if interval.is_none() && expires.is_some() {
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::{
serenity::{model::application::interaction::Interaction, utils::shard_id},
serenity_prelude as serenity,

View File

@ -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<dyn std::error::Error + Send + Sync>;
type Context<'a> = poise::Context<'a, Data, Error>;
type ApplicationContext<'a> = poise::ApplicationContext<'a, Data, Error>;
pub struct Data {
database: Pool<Database>,
http: reqwest::Client,
recording_macros: RwLock<HashMap<(GuildId, UserId), CommandMacro<Data, Error>>>,
popular_timezones: Vec<Tz>,
is_loop_running: AtomicBool,
broadcast: Sender<()>,
_broadcast: Sender<()>,
}
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::remind(),
reminder_cmds::remind_multiline(),
poise::Command {
subcommands: vec![
poise::Command {
@ -229,8 +229,7 @@ async fn _main(tx: Sender<()>) -> Result<(), Box<dyn StdError + Send + Sync>> {
database,
popular_timezones,
recording_macros: Default::default(),
is_loop_running: AtomicBool::new(false),
broadcast: tx,
_broadcast: tx,
})
})
})