cache
All checks were successful
Build / Build (push) Successful in 1m49s
Build / docker (push) Successful in 19s

This commit is contained in:
파링 2026-01-07 20:29:29 +09:00
parent e934da887f
commit 11f6f1edbf
Signed by: paring
SSH key fingerprint: SHA256:8uCHhCpn/gVOLEaTolmbub9kfM6XBxWkIWmHxUZoWWk
4 changed files with 26 additions and 3 deletions

2
Cargo.lock generated
View file

@ -1867,7 +1867,7 @@ dependencies = [
[[package]]
name = "serenity"
version = "0.12.4"
source = "git+https://github.com/serenity-rs/serenity?branch=next#c21fc6f5c94b72ce8c0a6ef8f7e343e87f080d09"
source = "git+https://github.com/paring-chan/serenity.git?branch=fix%2Freaction-cache-next#62962a31fe92ba45d6741c715082fd0a5f12f2a9"
dependencies = [
"aformat",
"arrayvec",

View file

@ -15,8 +15,9 @@ figment = { version = "0.10.19", features = ["toml", "env"] }
rhai = "1.23.6"
secrecy = { version = "0.10", features = ["serde"] }
serde = { version = "1.0.228", features = ["derive"] }
serenity = { git = "https://github.com/serenity-rs/serenity", branch = "next", features = [
serenity = { git = "https://github.com/paring-chan/serenity.git", branch = "fix/reaction-cache-next", features = [
"unstable",
"cache",
] }
sqlx = { version = "0.8.6", features = ["runtime-tokio", "postgres"] }
tokio = { version = "1.49.0", features = ["full"] }

View file

@ -205,6 +205,11 @@ impl Handler {
return Ok(());
}
debug!(
"cached message: {:?}",
ctx.cache.message(channel_id, message_id).as_deref()
);
let msg = channel_id
.message((ctx.cache(), ctx.http()), message_id)
.await?;
@ -225,6 +230,14 @@ impl Handler {
CloneBuilderMessage::from(msg.clone())
};
debug!(
"cached channel: {:?}",
ctx.cache
.guild(guild_id)
.as_ref()
.and_then(|x| x.channel(channel_id).clone())
);
let channel = channel_id
.to_channel((ctx.cache(), ctx.http()), Some(guild_id))
.await?;
@ -269,6 +282,11 @@ impl Handler {
.parse()
.context("unable to parse counter channel id")?;
debug!(
"cached counter msg: {:?}",
ctx.cache.message(chn_id, msg_id).as_deref()
);
let existing_message = chn_id.message((ctx.cache(), ctx.http()), msg_id).await?;
for comp in existing_message

View file

@ -11,6 +11,7 @@ use secrecy::ExposeSecret;
use serenity::{
Client,
all::{GatewayIntents, Token},
cache,
};
use sqlx::{migrate, postgres::PgPoolOptions};
use tracing::Level;
@ -53,18 +54,21 @@ async fn main() -> anyhow::Result<()> {
info!("migrated database");
let mut cache_settings = cache::Settings::default();
cache_settings.max_messages = 100;
let mut client = Client::builder(
Token::from_str(config.bot.token.expose_secret()).unwrap(),
GatewayIntents::GUILD_MESSAGES
| GatewayIntents::GUILD_MESSAGE_REACTIONS
| GatewayIntents::GUILDS
| GatewayIntents::GUILD_MESSAGES
| GatewayIntents::MESSAGE_CONTENT,
)
.event_handler(Arc::new(Handler {
db,
message_lock: Arc::new(DashMap::new()),
}))
.cache_settings(cache_settings)
.await
.expect("Err creating client");