From 2781f2923e8f962fce612941c762265364c9246e Mon Sep 17 00:00:00 2001 From: jude Date: Thu, 28 Jul 2022 19:19:46 +0100 Subject: [PATCH] Restrict reminder selection to one-per-guild during fetch loop --- postman/src/lib.rs | 2 +- postman/src/sender.rs | 10 ++++++++++ src/commands/reminder_cmds.rs | 2 +- src/component_models/mod.rs | 10 +++++----- src/component_models/pager.rs | 4 +--- src/event_handlers.rs | 2 +- src/models/command_macro.rs | 4 ++-- src/utils.rs | 3 ++- 8 files changed, 23 insertions(+), 14 deletions(-) diff --git a/postman/src/lib.rs b/postman/src/lib.rs index a378dcf..f63b604 100644 --- a/postman/src/lib.rs +++ b/postman/src/lib.rs @@ -38,7 +38,7 @@ async fn _initialize(ctx: Context, pool: impl Executor<'_, Database = Database> let reminders = sender::Reminder::fetch_reminders(pool).await; if reminders.len() > 0 { - info!("Preparing to send {} reminders.", reminders.len()); + println!("Preparing to send {} reminders.", reminders.len()); for reminder in reminders { reminder.send(pool, ctx.clone()).await; diff --git a/postman/src/sender.rs b/postman/src/sender.rs index 433ecad..78ddc67 100644 --- a/postman/src/sender.rs +++ b/postman/src/sender.rs @@ -292,6 +292,16 @@ INNER JOIN ON reminders.channel_id = channels.id WHERE + reminders.id IN ( + SELECT + MIN(reminders.id) + FROM reminders + INNER JOIN + channels + ON reminders.channel_id = channels.id + WHERE reminders.`utc_time` < NOW() + GROUP BY channels.guild_id + ) AND reminders.`utc_time` < NOW()"#, ) .fetch_all(pool) diff --git a/src/commands/reminder_cmds.rs b/src/commands/reminder_cmds.rs index 5d24ccb..639d625 100644 --- a/src/commands/reminder_cmds.rs +++ b/src/commands/reminder_cmds.rs @@ -9,7 +9,7 @@ use chrono_tz::Tz; use num_integer::Integer; use poise::{ serenity::{builder::CreateEmbed, model::channel::Channel}, - serenity_prelude::{ButtonStyle, ReactionType}, + serenity_prelude::{component::ButtonStyle, ReactionType}, CreateReply, }; diff --git a/src/component_models/mod.rs b/src/component_models/mod.rs index a738034..b8e8598 100644 --- a/src/component_models/mod.rs +++ b/src/component_models/mod.rs @@ -9,11 +9,11 @@ use poise::{ builder::CreateEmbed, client::Context, model::{ - channel::Channel, - interactions::{ + application::interaction::{ message_component::MessageComponentInteraction, InteractionResponseType, + MessageFlags, }, - prelude::InteractionApplicationCommandCallbackDataFlags, + channel::Channel, }, }, serenity_prelude as serenity, @@ -260,7 +260,7 @@ WHERE guilds.guild = ?", r.kind(InteractionResponseType::ChannelMessageWithSource) .interaction_response_data(|d| { d.flags( - InteractionApplicationCommandCallbackDataFlags::EPHEMERAL, + MessageFlags::EPHEMERAL, ) .content("Only the user who performed the command can use these components") }) @@ -314,7 +314,7 @@ WHERE guilds.guild = ?", r.kind(InteractionResponseType::ChannelMessageWithSource) .interaction_response_data(|d| { d.flags( - InteractionApplicationCommandCallbackDataFlags::EPHEMERAL, + MessageFlags::EPHEMERAL, ) .content("Only the user who performed the command can use these components") }) diff --git a/src/component_models/pager.rs b/src/component_models/pager.rs index e82ff58..fcef2fd 100644 --- a/src/component_models/pager.rs +++ b/src/component_models/pager.rs @@ -1,8 +1,6 @@ // todo split pager out into a single struct use chrono_tz::Tz; -use poise::serenity::{ - builder::CreateComponents, model::interactions::message_component::ButtonStyle, -}; +use poise::serenity::{builder::CreateComponents, model::application::component::ButtonStyle}; use serde::{Deserialize, Serialize}; use serde_repr::*; diff --git a/src/event_handlers.rs b/src/event_handlers.rs index 3937d22..2b7b339 100644 --- a/src/event_handlers.rs +++ b/src/event_handlers.rs @@ -2,7 +2,7 @@ use std::{collections::HashMap, env, sync::atomic::Ordering}; use log::{error, info, warn}; use poise::{ - serenity::{model::interactions::Interaction, utils::shard_id}, + serenity::{model::application::interaction::Interaction, utils::shard_id}, serenity_prelude as serenity, }; diff --git a/src/models/command_macro.rs b/src/models/command_macro.rs index 08b314e..ff26a0f 100644 --- a/src/models/command_macro.rs +++ b/src/models/command_macro.rs @@ -1,5 +1,5 @@ use poise::serenity::model::{ - id::GuildId, interactions::application_command::ApplicationCommandInteractionDataOption, + application::interaction::application_command::CommandDataOption, id::GuildId, }; use serde::{Deserialize, Serialize}; @@ -19,7 +19,7 @@ pub struct RecordedCommand { #[serde(default = "default_none::")] pub action: Option>, pub command_name: String, - pub options: Vec, + pub options: Vec, } pub struct CommandMacro { diff --git a/src/utils.rs b/src/utils.rs index ecdef54..14805ab 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -5,6 +5,7 @@ use poise::{ model::id::{GuildId, UserId}, }, serenity_prelude as serenity, + serenity_prelude::interaction::MessageFlags, }; use crate::{ @@ -102,6 +103,6 @@ pub fn send_as_initial_response( }); } if ephemeral { - f.flags(serenity::InteractionApplicationCommandCallbackDataFlags::EPHEMERAL); + f.flags(MessageFlags::EPHEMERAL); } }