feat(gateway): add cache event handler stubs
This commit is contained in:
parent
e4f1957c75
commit
433603feaa
73
gateway/src/cache.rs
Normal file
73
gateway/src/cache.rs
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
use twilight_gateway::Event;
|
||||||
|
|
||||||
|
pub async fn handle_event<'a>(
|
||||||
|
event: Event,
|
||||||
|
rconn: redis::Client
|
||||||
|
) -> anyhow::Result<()> {
|
||||||
|
match event {
|
||||||
|
// todo: SaveDMChannelStub (?)
|
||||||
|
// todo: save user profiles for some reason (from message create, etc)
|
||||||
|
// todo(dotnet): remove relying on cache.OwnUserId
|
||||||
|
|
||||||
|
Event::GuildCreate(guild) => {
|
||||||
|
// save guild itself
|
||||||
|
// save all roles in guild
|
||||||
|
// save guild-role map
|
||||||
|
// save all channels in guild
|
||||||
|
// save all threads in guild (as channels lol)
|
||||||
|
// save guild-channel map
|
||||||
|
// save self guild member
|
||||||
|
|
||||||
|
// c# code also saves users in guildCreate.Members, but I'm pretty sure that doesn't have anything now because intents
|
||||||
|
}
|
||||||
|
Event::GuildUpdate(guild) => {
|
||||||
|
// save guild itself
|
||||||
|
}
|
||||||
|
Event::GuildDelete(guild) => {
|
||||||
|
// delete guild
|
||||||
|
// this probably should also delete all channels/roles/etc of the guild
|
||||||
|
}
|
||||||
|
Event::MemberUpdate(member) => {
|
||||||
|
// save self guild member
|
||||||
|
}
|
||||||
|
Event::ChannelCreate(channel) => {
|
||||||
|
// save channel
|
||||||
|
// update guild-channel map
|
||||||
|
}
|
||||||
|
Event::ChannelUpdate(channel) => {
|
||||||
|
// save channel
|
||||||
|
}
|
||||||
|
Event::ChannelDelete(channel) => {
|
||||||
|
// delete channel
|
||||||
|
// update guild-channel map
|
||||||
|
}
|
||||||
|
Event::RoleCreate(role) => {
|
||||||
|
// save role
|
||||||
|
// update guild-role map
|
||||||
|
}
|
||||||
|
Event::RoleUpdate(role) => {
|
||||||
|
// save role
|
||||||
|
}
|
||||||
|
Event::RoleDelete(role) => {
|
||||||
|
// delete role
|
||||||
|
// update guild-role map
|
||||||
|
}
|
||||||
|
Event::ThreadCreate(thread) => {
|
||||||
|
// save channel
|
||||||
|
// update guild-channel map
|
||||||
|
}
|
||||||
|
Event::ThreadUpdate(thread) => {
|
||||||
|
// save thread
|
||||||
|
}
|
||||||
|
Event::ThreadDelete(thread) => {
|
||||||
|
// delete channel
|
||||||
|
// update guild-channel map
|
||||||
|
}
|
||||||
|
Event::ThreadListSync(tls) => {
|
||||||
|
// save channels
|
||||||
|
}
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
@ -7,6 +7,8 @@ use tracing::info;
|
|||||||
use twilight_gateway::Event;
|
use twilight_gateway::Event;
|
||||||
use twilight_http::Client as HttpClient;
|
use twilight_http::Client as HttpClient;
|
||||||
|
|
||||||
|
use crate::cache;
|
||||||
|
|
||||||
lazy_static::lazy_static! {
|
lazy_static::lazy_static! {
|
||||||
static ref ALLOWED_EVENTS: Vec<&'static str> = [
|
static ref ALLOWED_EVENTS: Vec<&'static str> = [
|
||||||
"INTERACTION_CREATE",
|
"INTERACTION_CREATE",
|
||||||
@ -25,6 +27,8 @@ pub async fn handle_event<'a>(
|
|||||||
_db: Pool,
|
_db: Pool,
|
||||||
rconn: redis::Client
|
rconn: redis::Client
|
||||||
) -> anyhow::Result<()> {
|
) -> anyhow::Result<()> {
|
||||||
|
cache::handle_event(event.clone(), rconn.clone()).await?;
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
Event::GatewayInvalidateSession(resumable) => {
|
Event::GatewayInvalidateSession(resumable) => {
|
||||||
info!("shard {} session invalidated, resumable? {}", shard_id, resumable);
|
info!("shard {} session invalidated, resumable? {}", shard_id, resumable);
|
||||||
|
@ -9,6 +9,7 @@ use twilight_gateway::{
|
|||||||
};
|
};
|
||||||
use twilight_http::Client as HttpClient;
|
use twilight_http::Client as HttpClient;
|
||||||
|
|
||||||
|
mod cache;
|
||||||
mod config;
|
mod config;
|
||||||
mod evt;
|
mod evt;
|
||||||
mod db;
|
mod db;
|
||||||
@ -81,7 +82,7 @@ async fn init_gateway(
|
|||||||
if shard_count < 16 {
|
if shard_count < 16 {
|
||||||
scheme = ShardScheme::Auto;
|
scheme = ShardScheme::Auto;
|
||||||
} else {
|
} else {
|
||||||
let cluster_id = env::var("NOMAD_ALLOC_INDEX").or("0").parse::<u64>().unwrap();
|
let cluster_id = env::var("NOMAD_ALLOC_INDEX").or::<String>(Result::Ok("0".to_string())).unwrap().parse::<u64>().unwrap();
|
||||||
let first_shard_id = 16 * cluster_id;
|
let first_shard_id = 16 * cluster_id;
|
||||||
|
|
||||||
scheme = ShardScheme::try_from((first_shard_id..first_shard_id+16, shard_count)).unwrap();
|
scheme = ShardScheme::try_from((first_shard_id..first_shard_id+16, shard_count)).unwrap();
|
||||||
|
Loading…
Reference in New Issue
Block a user