support months in sender

This commit is contained in:
jellywx 2022-02-01 23:41:28 +00:00
parent 05606dfec1
commit d62c8c95c2
3 changed files with 24 additions and 8 deletions

View File

@ -323,7 +323,7 @@ async fn look(ctx: &Context, invoke: &mut CommandInvoke, args: CommandOptions) {
.iter() .iter()
.map(|reminder| reminder.display(&flags, &timezone)) .map(|reminder| reminder.display(&flags, &timezone))
.fold(0, |t, r| t + r.len()) .fold(0, |t, r| t + r.len())
.div_ceil(&EMBED_DESCRIPTION_MAX_LENGTH); .div_ceil(EMBED_DESCRIPTION_MAX_LENGTH);
let pager = LookPager::new(flags, timezone); let pager = LookPager::new(flags, timezone);

View File

@ -3,7 +3,6 @@ pub(crate) mod pager;
use std::io::Cursor; use std::io::Cursor;
use chrono_tz::Tz; use chrono_tz::Tz;
use num_integer::Integer;
use rmp_serde::Serializer; use rmp_serde::Serializer;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serenity::{ use serenity::{
@ -79,7 +78,7 @@ impl ComponentDataModel {
.iter() .iter()
.map(|reminder| reminder.display(&flags, &pager.timezone)) .map(|reminder| reminder.display(&flags, &pager.timezone))
.fold(0, |t, r| t + r.len()) .fold(0, |t, r| t + r.len())
.div_ceil(&EMBED_DESCRIPTION_MAX_LENGTH); .div_ceil(EMBED_DESCRIPTION_MAX_LENGTH);
let channel_name = let channel_name =
if let Some(Channel::Guild(channel)) = channel_id.to_channel_cached(&ctx) { if let Some(Channel::Guild(channel)) = channel_id.to_channel_cached(&ctx) {

View File

@ -257,7 +257,8 @@ pub struct Reminder {
timezone: String, timezone: String,
restartable: bool, restartable: bool,
expires: Option<NaiveDateTime>, expires: Option<NaiveDateTime>,
interval: Option<u32>, interval_seconds: Option<u32>,
interval_months: Option<u32>,
avatar: Option<String>, avatar: Option<String>,
username: Option<String>, username: Option<String>,
@ -289,7 +290,8 @@ SELECT
reminders.`timezone` AS timezone, reminders.`timezone` AS timezone,
reminders.`restartable` AS restartable, reminders.`restartable` AS restartable,
reminders.`expires` AS expires, reminders.`expires` AS expires,
reminders.`interval` AS 'interval', reminders.`interval_seconds` AS 'interval_seconds',
reminders.`interval_months` AS 'interval_months',
reminders.`avatar` AS avatar, reminders.`avatar` AS avatar,
reminders.`username` AS username reminders.`username` AS username
@ -327,12 +329,27 @@ UPDATE channels SET webhook_id = NULL, webhook_token = NULL WHERE channel = ?
} }
async fn refresh(&self, pool: &MySqlPool) { async fn refresh(&self, pool: &MySqlPool) {
if let Some(interval) = self.interval { if self.interval_seconds.is_some() || self.interval_months.is_some() {
let now = Utc::now().naive_local(); let now = Utc::now().naive_local();
let mut updated_reminder_time = self.utc_time; let mut updated_reminder_time = self.utc_time;
while updated_reminder_time < now { if let Some(interval) = self.interval_months {
updated_reminder_time += Duration::seconds(interval as i64); let row = sqlx::query!(
"SELECT DATE_ADD(?, INTERVAL ? MONTH) AS new_time",
updated_reminder_time,
interval
)
.fetch_one(pool)
.await
.unwrap();
updated_reminder_time = row.new_time.unwrap();
}
if let Some(interval) = self.interval_seconds {
while updated_reminder_time < now {
updated_reminder_time += Duration::seconds(interval as i64);
}
} }
if self.expires.map_or(false, |expires| { if self.expires.map_or(false, |expires| {