From 980a8d2a9cc409cf11e4119d77c454e6b60d547a Mon Sep 17 00:00:00 2001 From: jude Date: Tue, 15 Sep 2020 15:13:41 +0100 Subject: [PATCH] write interval to db. validate interval --- src/commands/reminder_cmds.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/commands/reminder_cmds.rs b/src/commands/reminder_cmds.rs index 04add6f..07f0c19 100644 --- a/src/commands/reminder_cmds.rs +++ b/src/commands/reminder_cmds.rs @@ -754,6 +754,13 @@ async fn create_reminder( if content.len() == 0 { Err(ReminderError::NotEnoughArgs) } + // todo replace numbers with configurable values + else if interval.map_or(false, |inner| inner < 800) { + Err(ReminderError::ShortInterval) + } + else if interval.map_or(false, |inner| inner > 60*60*24*365*50) { + Err(ReminderError::LongInterval) + } else { match time_parser.timestamp() { Ok(time) => { @@ -774,12 +781,12 @@ INSERT INTO messages (content) VALUES (?) sqlx::query!( " -INSERT INTO reminders (uid, message_id, channel_id, time, method, set_by) VALUES +INSERT INTO reminders (uid, message_id, channel_id, time, `interval`, method, set_by) VALUES (?, (SELECT id FROM messages WHERE content = ? ORDER BY id DESC LIMIT 1), - ?, ?, 'remind', + ?, ?, ?, 'remind', (SELECT id FROM users WHERE user = ? LIMIT 1)) - ", generate_uid(), content, db_channel_id, time as u32, user_id) + ", generate_uid(), content, db_channel_id, time as u32, interval, user_id) .execute(pool) .await .unwrap();