Restrict reminder selection to one-per-guild during fetch loop

This commit is contained in:
jude 2022-07-28 19:19:46 +01:00
parent 03f08f0a18
commit 2781f2923e
8 changed files with 23 additions and 14 deletions

View File

@ -38,7 +38,7 @@ async fn _initialize(ctx: Context, pool: impl Executor<'_, Database = Database>
let reminders = sender::Reminder::fetch_reminders(pool).await; let reminders = sender::Reminder::fetch_reminders(pool).await;
if reminders.len() > 0 { if reminders.len() > 0 {
info!("Preparing to send {} reminders.", reminders.len()); println!("Preparing to send {} reminders.", reminders.len());
for reminder in reminders { for reminder in reminders {
reminder.send(pool, ctx.clone()).await; reminder.send(pool, ctx.clone()).await;

View File

@ -292,6 +292,16 @@ INNER JOIN
ON ON
reminders.channel_id = channels.id reminders.channel_id = channels.id
WHERE 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()"#, reminders.`utc_time` < NOW()"#,
) )
.fetch_all(pool) .fetch_all(pool)

View File

@ -9,7 +9,7 @@ use chrono_tz::Tz;
use num_integer::Integer; use num_integer::Integer;
use poise::{ use poise::{
serenity::{builder::CreateEmbed, model::channel::Channel}, serenity::{builder::CreateEmbed, model::channel::Channel},
serenity_prelude::{ButtonStyle, ReactionType}, serenity_prelude::{component::ButtonStyle, ReactionType},
CreateReply, CreateReply,
}; };

View File

@ -9,11 +9,11 @@ use poise::{
builder::CreateEmbed, builder::CreateEmbed,
client::Context, client::Context,
model::{ model::{
channel::Channel, application::interaction::{
interactions::{
message_component::MessageComponentInteraction, InteractionResponseType, message_component::MessageComponentInteraction, InteractionResponseType,
MessageFlags,
}, },
prelude::InteractionApplicationCommandCallbackDataFlags, channel::Channel,
}, },
}, },
serenity_prelude as serenity, serenity_prelude as serenity,
@ -260,7 +260,7 @@ WHERE guilds.guild = ?",
r.kind(InteractionResponseType::ChannelMessageWithSource) r.kind(InteractionResponseType::ChannelMessageWithSource)
.interaction_response_data(|d| { .interaction_response_data(|d| {
d.flags( d.flags(
InteractionApplicationCommandCallbackDataFlags::EPHEMERAL, MessageFlags::EPHEMERAL,
) )
.content("Only the user who performed the command can use these components") .content("Only the user who performed the command can use these components")
}) })
@ -314,7 +314,7 @@ WHERE guilds.guild = ?",
r.kind(InteractionResponseType::ChannelMessageWithSource) r.kind(InteractionResponseType::ChannelMessageWithSource)
.interaction_response_data(|d| { .interaction_response_data(|d| {
d.flags( d.flags(
InteractionApplicationCommandCallbackDataFlags::EPHEMERAL, MessageFlags::EPHEMERAL,
) )
.content("Only the user who performed the command can use these components") .content("Only the user who performed the command can use these components")
}) })

View File

@ -1,8 +1,6 @@
// todo split pager out into a single struct // todo split pager out into a single struct
use chrono_tz::Tz; use chrono_tz::Tz;
use poise::serenity::{ use poise::serenity::{builder::CreateComponents, model::application::component::ButtonStyle};
builder::CreateComponents, model::interactions::message_component::ButtonStyle,
};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use serde_repr::*; use serde_repr::*;

View File

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

View File

@ -1,5 +1,5 @@
use poise::serenity::model::{ use poise::serenity::model::{
id::GuildId, interactions::application_command::ApplicationCommandInteractionDataOption, application::interaction::application_command::CommandDataOption, id::GuildId,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -19,7 +19,7 @@ pub struct RecordedCommand<U, E> {
#[serde(default = "default_none::<U, E>")] #[serde(default = "default_none::<U, E>")]
pub action: Option<Func<U, E>>, pub action: Option<Func<U, E>>,
pub command_name: String, pub command_name: String,
pub options: Vec<ApplicationCommandInteractionDataOption>, pub options: Vec<CommandDataOption>,
} }
pub struct CommandMacro<U, E> { pub struct CommandMacro<U, E> {

View File

@ -5,6 +5,7 @@ use poise::{
model::id::{GuildId, UserId}, model::id::{GuildId, UserId},
}, },
serenity_prelude as serenity, serenity_prelude as serenity,
serenity_prelude::interaction::MessageFlags,
}; };
use crate::{ use crate::{
@ -102,6 +103,6 @@ pub fn send_as_initial_response(
}); });
} }
if ephemeral { if ephemeral {
f.flags(serenity::InteractionApplicationCommandCallbackDataFlags::EPHEMERAL); f.flags(MessageFlags::EPHEMERAL);
} }
} }