feat: the bot wasnt using any caching, this should make many operations far faster now
This commit is contained in:
parent
764e8cd620
commit
b8ffd42184
1 changed files with 14 additions and 2 deletions
16
src/main.rs
16
src/main.rs
|
@ -1,13 +1,16 @@
|
||||||
pub mod commands;
|
pub mod commands;
|
||||||
|
|
||||||
use crate::commands::role_adder::tools::on_role_change;
|
use crate::commands::role_adder::tools::on_role_change;
|
||||||
use serenity::all::{ActivityData, Command, CommandDataOptionValue, CreateMessage, EditInteractionResponse, GuildMemberUpdateEvent, Interaction};
|
use serenity::all::{
|
||||||
use serenity::model::guild::Member;
|
ActivityData, Command, CommandDataOptionValue, CreateMessage, EditInteractionResponse, GuildId, GuildMemberUpdateEvent, Interaction,
|
||||||
|
};
|
||||||
use serenity::{
|
use serenity::{
|
||||||
async_trait,
|
async_trait,
|
||||||
client::{Context, EventHandler},
|
client::{Context, EventHandler},
|
||||||
|
gateway::ChunkGuildFilter,
|
||||||
model::{
|
model::{
|
||||||
gateway::{GatewayIntents, Ready},
|
gateway::{GatewayIntents, Ready},
|
||||||
|
guild::Member,
|
||||||
user::OnlineStatus,
|
user::OnlineStatus,
|
||||||
},
|
},
|
||||||
Client,
|
Client,
|
||||||
|
@ -24,6 +27,14 @@ struct Handler;
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl EventHandler for Handler {
|
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
|
// handles previously linked accounts joining the server
|
||||||
async fn guild_member_addition(&self, ctx: Context, new_member: Member) {
|
async fn guild_member_addition(&self, ctx: Context, new_member: Member) {
|
||||||
let db_lock = {
|
let db_lock = {
|
||||||
|
@ -281,6 +292,7 @@ async fn main() {
|
||||||
// Build our client.
|
// Build our client.
|
||||||
let mut client = Client::builder(&config.discord_token, intents)
|
let mut client = Client::builder(&config.discord_token, intents)
|
||||||
.event_handler(Handler {})
|
.event_handler(Handler {})
|
||||||
|
.cache_settings(serenity::cache::Settings::default())
|
||||||
.await
|
.await
|
||||||
.expect("Error creating client");
|
.expect("Error creating client");
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue