feat: the bot wasnt using any caching, this should make many operations far faster now
All checks were successful
On_Push / lint_fmt (push) Successful in 23s
/ check_lfs (push) Successful in 22s
On_Push / lint_clippy (push) Successful in 1m45s
On_Push / build (push) Successful in 1m46s
On_Push / deploy (push) Successful in 14s

This commit is contained in:
silver 2025-07-07 21:29:37 +01:00
parent 764e8cd620
commit b8ffd42184
Signed by: silver
GPG key ID: 36F93D61BAD3FD7D

View file

@ -1,13 +1,16 @@
pub mod commands;
use crate::commands::role_adder::tools::on_role_change;
use serenity::all::{ActivityData, Command, CommandDataOptionValue, CreateMessage, EditInteractionResponse, GuildMemberUpdateEvent, Interaction};
use serenity::model::guild::Member;
use serenity::all::{
ActivityData, Command, CommandDataOptionValue, CreateMessage, EditInteractionResponse, GuildId, GuildMemberUpdateEvent, Interaction,
};
use serenity::{
async_trait,
client::{Context, EventHandler},
gateway::ChunkGuildFilter,
model::{
gateway::{GatewayIntents, Ready},
guild::Member,
user::OnlineStatus,
},
Client,
@ -24,6 +27,14 @@ struct Handler;
#[async_trait]
impl EventHandler for Handler {
// this caches members of all servers teh bot is in
async fn cache_ready(&self, ctx: Context, guilds: Vec<GuildId>) {
for guild in guilds {
ctx.shard.chunk_guild(guild, Some(500), false, ChunkGuildFilter::None, None);
}
println!("Cache built successfully!");
}
// handles previously linked accounts joining the server
async fn guild_member_addition(&self, ctx: Context, new_member: Member) {
let db_lock = {
@ -281,6 +292,7 @@ async fn main() {
// Build our client.
let mut client = Client::builder(&config.discord_token, intents)
.event_handler(Handler {})
.cache_settings(serenity::cache::Settings::default())
.await
.expect("Error creating client");