Skip to content
This repository has been archived by the owner on Jul 15, 2024. It is now read-only.

Commit

Permalink
feat: handle unnecessary data
Browse files Browse the repository at this point in the history
  • Loading branch information
KagChi committed Feb 1, 2024
1 parent af92714 commit e850bf6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
17 changes: 10 additions & 7 deletions src/Listeners/Caches/Guilds/GuildCreateListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,28 +30,24 @@ export class GuildCreateListener extends Listener {
}
}
await this.store.redis.incrby(GenKey(RedisKey.USER_KEY, RedisKey.COUNT), payload.data.d.members.length - alreadyExists);
payload.data.d.members = [];
}

if (stateChannels) {
for (const channel of payload.data.d.channels) {
await this.store.redis.set(GenKey(RedisKey.CHANNEL_KEY, channel.id, payload.data.d.id), JSON.stringify(channel));
}
payload.data.d.channels = [];
}

if (stateRoles) {
for (const role of payload.data.d.roles) {
await this.store.redis.set(GenKey(RedisKey.ROLE_KEY, role.id, payload.data.d.id), JSON.stringify(role));
}
payload.data.d.roles = [];
}

if (stateVoices) {
for (const voice of payload.data.d.voice_states) {
await this.store.redis.set(GenKey(RedisKey.VOICE_KEY, voice.user_id, payload.data.d.id), JSON.stringify(voice));
}
payload.data.d.voice_states = [];
}

if (stateEmojis) {
Expand All @@ -60,19 +56,26 @@ export class GuildCreateListener extends Listener {
await this.store.redis.set(GenKey(RedisKey.EMOJI_KEY, emoji.id, payload.data.d.id), JSON.stringify(emoji));
}
}
payload.data.d.emojis = [];
}

if (statePresences) {
for (const presence of payload.data.d.presences) {
await this.store.redis.set(GenKey(RedisKey.PRESENCE_KEY, presence.user.id, payload.data.d.id), JSON.stringify(presence));
}
payload.data.d.presences = [];
}

const key = GenKey(RedisKey.GUILD_KEY, payload.data.d.id);
const exists = await this.store.redis.exists(key);
await this.store.redis.set(key, JSON.stringify(payload.data.d));
await this.store.redis.set(key, JSON.stringify({
...payload.data.d,
members: [],
voice_states: [],
emojis: [],
presences: [],
channels: [],
stickers: [],
soundboards: []
}));

if (exists === 0) await this.store.redis.incr(GenKey(RedisKey.GUILD_KEY, RedisKey.COUNT));

Expand Down
10 changes: 9 additions & 1 deletion src/Listeners/Caches/Voices/VoiceStateUpdateListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ export class VoiceStateUpdateListener extends Listener {
if (stateVoices) {
if (payload.data.d.channel_id) {
const key = GenKey(RedisKey.VOICE_KEY, payload.data.d.user_id, payload.data.d.guild_id);
await this.store.redis.set(key, JSON.stringify(payload.data.d));
await this.store.redis.set(key, JSON.stringify({
...payload.data.d,
member: payload.data.d.member
? {
...payload.data.d.member,
roles: []
}
: null
}));
await this.store.redis.sadd(GenKey(RedisKey.VOICE_KEY, RedisKey.LIST, payload.data.d.guild_id), key);
} else {
const key = GenKey(RedisKey.VOICE_KEY, payload.data.d.user_id, payload.data.d.guild_id);
Expand Down

0 comments on commit e850bf6

Please sign in to comment.