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

Commit

Permalink
feat: add more caches (#330)
Browse files Browse the repository at this point in the history
* fix: typo on progress bar

* feat: cache key

---------

Co-authored-by: Vann-Dev <[email protected]>
  • Loading branch information
KagChi and Vann-Dev committed Feb 12, 2024
1 parent c29f12a commit e865f7b
Show file tree
Hide file tree
Showing 12 changed files with 243 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/Listeners/Caches/Channels/ChannelCreateListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export class ChannelCreateListener extends Listener {
if (stateChannels) {
await this.store.drizzle.insert(channels).values({
id: payload.data.d.id,
name: payload.data.d.name,
name: payload.data.d.name
}).onConflictDoUpdate({
target: channels.id,
set: {
Expand Down
18 changes: 16 additions & 2 deletions src/Listeners/Caches/GuildMembers/GuildMemberAddListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ export class GuildMemberAddListener extends Listener {
globalName: payload.data.d.user?.global_name ?? null,
avatar: payload.data.d.user?.avatar ?? null,
bot: payload.data.d.user?.bot ?? false,
flags: payload.data.d.user?.flags
flags: payload.data.d.user?.flags,
accentColor: payload.data.d.user?.accent_color,
avatarDecoration: payload.data.d.user?.avatar_decoration,
banner: payload.data.d.user?.banner,
locale: payload.data.d.user?.locale,
mfaEnabled: payload.data.d.user?.mfa_enabled,
premiumType: payload.data.d.user?.premium_type,
publicFlags: payload.data.d.user?.public_flags
}).onConflictDoNothing({ target: users.id });
}

Expand All @@ -36,7 +43,14 @@ export class GuildMemberAddListener extends Listener {
}) ?? await this.store.drizzle.insert(members).values({
id: payload.data.d.user!.id,
avatar: payload.data.d.avatar,
flags: payload.data.d.flags
flags: payload.data.d.flags,
communicationDisabledUntil: payload.data.d.premium_since,
deaf: payload.data.d.deaf,
joinedAt: payload.data.d.joined_at,
mute: payload.data.d.mute,
nick: payload.data.d.nick,
pending: payload.data.d.pending,
premiumSince: payload.data.d.premium_since
}).onConflictDoNothing({ target: members.id })
.returning({ id: members.id })
.then(x => x[0]);
Expand Down
24 changes: 22 additions & 2 deletions src/Listeners/Caches/GuildMembers/GuildMemberUpdateListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,33 @@ export class GuildMemberUpdateListener extends Listener {
public async run(payload: { data: GatewayGuildMemberUpdateDispatch; shardId: number; }): Promise<void> {
if (stateUsers) {
await this.store.drizzle.update(users).set({
username: payload.data.d.user.username
username: payload.data.d.user.username,
accentColor: payload.data.d.user.accent_color,
avatar: payload.data.d.user.avatar,
avatarDecoration: payload.data.d.user.avatar_decoration,
banner: payload.data.d.user.banner,
bot: payload.data.d.user.bot,
discriminator: payload.data.d.user.discriminator,
flags: payload.data.d.user.flags,
globalName: payload.data.d.user.global_name,
locale: payload.data.d.user.locale,
mfaEnabled: payload.data.d.user.mfa_enabled,
premiumType: payload.data.d.user.premium_type,
publicFlags: payload.data.d.user.public_flags
}).where(eq(users.id, payload.data.d.user.id));
}

if (stateMembers) {
await this.store.drizzle.update(members).set({
avatar: payload.data.d.avatar
avatar: payload.data.d.avatar,
communicationDisabledUntil: payload.data.d.premium_since,
deaf: payload.data.d.deaf,
flags: payload.data.d.flags,
joinedAt: payload.data.d.joined_at,
mute: payload.data.d.mute,
nick: payload.data.d.nick,
pending: payload.data.d.pending,
premiumSince: payload.data.d.premium_since
}).where(eq(members.id, payload.data.d.user.id));
}

Expand Down
20 changes: 18 additions & 2 deletions src/Listeners/Caches/GuildMembers/GuildMembersChunkListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,29 @@ export class GuildMembersChunkListener extends Listener {
globalName: member.user?.global_name ?? null,
avatar: member.user?.avatar ?? null,
bot: member.user?.bot ?? false,
flags: member.user?.flags
flags: member.user?.flags,
accentColor: member.user?.accent_color,
avatarDecoration: member.user?.avatar_decoration,
banner: member.user?.banner,
locale: member.user?.locale,
mfaEnabled: member.user?.mfa_enabled,
premiumType: member.user?.premium_type,
publicFlags: member.user?.public_flags
}).onConflictDoNothing({ target: users.id });
}

if (stateMembers) {
await this.store.drizzle.insert(members).values({
id: member.user!.id
id: member.user!.id,
avatar: member.avatar,
communicationDisabledUntil: member.premium_since,
deaf: member.deaf,
flags: member.flags,
joinedAt: member.joined_at,
mute: member.mute,
nick: member.nick,
pending: member.pending,
premiumSince: member.premium_since
}).onConflictDoNothing({ target: users.id });
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/Listeners/Caches/GuildRoles/GuildRoleCreateListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export class GuildRoleCreateListener extends Listener {
name: payload.data.d.role.name,
permissions: payload.data.d.role.permissions,
position: payload.data.d.role.position,
color: payload.data.d.role.color
color: payload.data.d.role.color,
hoist: payload.data.d.role.hoist
});
}
await this.store.amqp.publish(RabbitMQ.GATEWAY_QUEUE_SEND, RoutingKey(clientId, payload.shardId), Buffer.from(JSON.stringify(payload.data)));
Expand Down
6 changes: 5 additions & 1 deletion src/Listeners/Caches/GuildRoles/GuildRoleUpdateListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ export class GuildRoleUpdateListener extends Listener {
public async run(payload: { data: GatewayGuildRoleUpdateDispatch; shardId: number; }): Promise<void> {
if (stateRoles) {
await this.store.drizzle.update(roles).set({
name: payload.data.d.role.name
name: payload.data.d.role.name,
permissions: payload.data.d.role.permissions,
position: payload.data.d.role.position,
color: payload.data.d.role.color,
hoist: payload.data.d.role.hoist
}).where(eq(roles.id, payload.data.d.role.id));
}

Expand Down
50 changes: 40 additions & 10 deletions src/Listeners/Caches/Guilds/GuildCreateListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class GuildCreateListener extends Listener {
preferredLocale: payload.data.d.preferred_locale,
maxVideoChannelUsers: payload.data.d.max_video_channel_users,
permissions: payload.data.d.permissions,
premiumBoostingBarEnabled: payload.data.d.premium_progress_bar_enabled,
premiumProgressBarEnabled: payload.data.d.premium_progress_bar_enabled,
safetyAlertChannelId: payload.data.d.safety_alerts_channel_id,
splash: payload.data.d.splash,
systemChannelFlags: payload.data.d.system_channel_flags
Expand Down Expand Up @@ -91,7 +91,7 @@ export class GuildCreateListener extends Listener {
preferredLocale: payload.data.d.preferred_locale,
maxVideoChannelUsers: payload.data.d.max_video_channel_users,
permissions: payload.data.d.permissions,
premiumBoostingBarEnabled: payload.data.d.premium_progress_bar_enabled,
premiumProgressBarEnabled: payload.data.d.premium_progress_bar_enabled,
safetyAlertChannelId: payload.data.d.safety_alerts_channel_id,
splash: payload.data.d.splash,
systemChannelFlags: payload.data.d.system_channel_flags
Expand All @@ -105,14 +105,16 @@ export class GuildCreateListener extends Listener {
name: role.name,
permissions: role.permissions,
position: role.position,
color: role.color
color: role.color,
hoist: role.hoist
}).onConflictDoUpdate({
target: roles.id,
set: {
name: role.name,
permissions: role.permissions,
position: role.position,
color: role.color
color: role.color,
hoist: role.hoist
}
});

Expand All @@ -132,7 +134,9 @@ export class GuildCreateListener extends Listener {
globalName: member.user?.global_name ?? null,
avatar: member.user?.avatar ?? null,
bot: member.user?.bot ?? false,
flags: member.user?.flags
flags: member.user?.flags,
premiumType: member.user?.premium_type,
publicFlags: member.user?.public_flags
}).onConflictDoUpdate({
target: users.id,
set: {
Expand All @@ -141,7 +145,9 @@ export class GuildCreateListener extends Listener {
globalName: member.user?.global_name ?? null,
avatar: member.user?.avatar ?? null,
bot: member.user?.bot ?? false,
flags: member.user?.flags
flags: member.user?.flags,
premiumType: member.user?.premium_type,
publicFlags: member.user?.public_flags
}
});
}
Expand All @@ -150,12 +156,26 @@ export class GuildCreateListener extends Listener {
await this.store.drizzle.insert(members).values({
id: member.user.id,
avatar: member.avatar,
flags: member.flags
flags: member.flags,
communicationDisabledUntil: member.communication_disabled_until,
deaf: member.deaf,
joinedAt: member.joined_at,
mute: member.mute,
nick: member.nick,
pending: member.pending,
premiumSince: member.premium_since
}).onConflictDoUpdate({
target: members.id,
set: {
avatar: member.avatar,
flags: member.flags
flags: member.flags,
communicationDisabledUntil: member.communication_disabled_until,
deaf: member.deaf,
joinedAt: member.joined_at,
mute: member.mute,
nick: member.nick,
pending: member.pending,
premiumSince: member.premium_since
}
});

Expand All @@ -172,7 +192,9 @@ export class GuildCreateListener extends Listener {
for (const channel of payload.data.d.channels) {
await this.store.drizzle.insert(channels).values({
id: channel.id,
name: channel.name
name: channel.name,
type: channel.type,
flags: channel.flags
}).onConflictDoNothing({ target: channels.id });

await this.store.drizzle.insert(guildsChannels).values({
Expand All @@ -189,7 +211,15 @@ export class GuildCreateListener extends Listener {
channelId: voice.channel_id,
guildId: payload.data.d.id,
sessionId: voice.session_id,
memberId: voice.user_id
memberId: voice.user_id,
deaf: voice.deaf,
mute: voice.mute,
requestToSpeakTimestamp: voice.request_to_speak_timestamp,
selfDeaf: voice.self_deaf,
selfMute: voice.self_mute,
selfStream: voice.self_stream,
selfVideo: voice.self_video,
suppress: voice.suppress
}).onConflictDoUpdate({ target: voiceStates.channelId, set: { sessionId: voice.session_id } });
}
}
Expand Down
33 changes: 32 additions & 1 deletion src/Listeners/Caches/Guilds/GuildUpdateListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,38 @@ export class GuildCreateListener extends Listener {
name: payload.data.d.name,
banner: payload.data.d.banner,
owner: payload.data.d.owner,
ownerId: payload.data.d.owner_id
ownerId: payload.data.d.owner_id,
afkChannelId: payload.data.d.afk_channel_id,
afkTimeout: payload.data.d.afk_timeout,
defaultMessageNotifications: payload.data.d.default_message_notifications,
explicitContentFilter: payload.data.d.explicit_content_filter,
icon: payload.data.d.icon,
mfaLevel: payload.data.d.mfa_level,
region: payload.data.d.region,
systemChannelId: payload.data.d.system_channel_id,
verificationLevel: payload.data.d.verification_level,
widgetChannelId: payload.data.d.widget_channel_id,
widgetEnabled: payload.data.d.widget_enabled,
approximateMemberCount: payload.data.d.approximate_member_count,
approximatePresenceCount: payload.data.d.approximate_presence_count,
description: payload.data.d.description,
discoverySplash: payload.data.d.discovery_splash,
iconHash: payload.data.d.icon_hash,
maxMembers: payload.data.d.max_members,
maxPresences: payload.data.d.max_presences,
premiumSubscriptionCount: payload.data.d.premium_subscription_count,
premiumTier: payload.data.d.premium_tier,
vanityUrlCode: payload.data.d.vanity_url_code,
nsfwLevel: payload.data.d.nsfw_level,
rulesChannelId: payload.data.d.rules_channel_id,
publicUpdatesChannelId: payload.data.d.public_updates_channel_id,
preferredLocale: payload.data.d.preferred_locale,
maxVideoChannelUsers: payload.data.d.max_video_channel_users,
permissions: payload.data.d.permissions,
premiumProgressBarEnabled: payload.data.d.premium_progress_bar_enabled,
safetyAlertChannelId: payload.data.d.safety_alerts_channel_id,
splash: payload.data.d.splash,
systemChannelFlags: payload.data.d.system_channel_flags
}).where(eq(guilds.id, payload.data.d.id));

await this.store.amqp.publish(RabbitMQ.GATEWAY_QUEUE_SEND, RoutingKey(clientId, payload.shardId), Buffer.from(JSON.stringify({
Expand Down
32 changes: 29 additions & 3 deletions src/Listeners/Caches/Messages/MessageCreateListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,19 @@ export class MessageCreateListener extends Listener {
await this.store.drizzle.insert(messages).values({
id: payload.data.d.id,
channelId: payload.data.d.channel_id,
content: payload.data.d.content
content: payload.data.d.content,
applicationId: payload.data.d.application_id,
authorId: payload.data.d.author.id,
editedTimestamp: payload.data.d.edited_timestamp,
flags: payload.data.d.flags,
type: payload.data.d.type,
mentionEveryone: payload.data.d.mention_everyone,
pinned: payload.data.d.pinned,
position: payload.data.d.position,
timestamp: payload.data.d.timestamp,
tts: payload.data.d.tts,
webhookId: payload.data.d.webhook_id,
nonce: payload.data.d.nonce?.toString()
});
}

Expand All @@ -32,15 +44,29 @@ export class MessageCreateListener extends Listener {
globalName: payload.data.d.author.global_name ?? null,
avatar: payload.data.d.author.avatar ?? null,
bot: payload.data.d.author.bot ?? false,
flags: payload.data.d.flags
flags: payload.data.d.flags,
accentColor: payload.data.d.author.accent_color,
avatarDecoration: payload.data.d.author.avatar_decoration,
banner: payload.data.d.author.banner,
locale: payload.data.d.author.locale,
mfaEnabled: payload.data.d.author.mfa_enabled,
premiumType: payload.data.d.author.premium_type,
publicFlags: payload.data.d.author.public_flags
}).onConflictDoNothing({ target: users.id });
}

if (stateMembers && payload.data.d.member !== undefined) {
await this.store.drizzle.insert(members).values({
id: payload.data.d.id,
avatar: payload.data.d.member.avatar,
flags: payload.data.d.member.flags
flags: payload.data.d.member.flags,
joinedAt: payload.data.d.member.joined_at,
nick: payload.data.d.member.nick,
communicationDisabledUntil: payload.data.d.member.communication_disabled_until,
deaf: payload.data.d.member.deaf,
mute: payload.data.d.member.mute,
pending: payload.data.d.member.pending,
premiumSince: payload.data.d.member.premium_since
}).onConflictDoNothing({ target: members.id });

for (const role of payload.data.d.member.roles) {
Expand Down
29 changes: 27 additions & 2 deletions src/Listeners/Caches/Messages/MessageUpdateListener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,20 @@ export class MessageUpdateListener extends Listener {
if (message === null) {
await this.store.drizzle.insert(messages).values({
id: payload.data.d.id,
channelId: payload.data.d.channel_id
channelId: payload.data.d.channel_id,
applicationId: payload.data.d.application_id,
authorId: payload.data.d.author?.id,
content: payload.data.d.content,
editedTimestamp: payload.data.d.edited_timestamp,
flags: payload.data.d.flags,
mentionEveryone: payload.data.d.mention_everyone,
nonce: payload.data.d.nonce?.toString(),
pinned: payload.data.d.pinned,
timestamp: payload.data.d.timestamp,
tts: payload.data.d.tts,
position: payload.data.d.position,
type: payload.data.d.type,
webhookId: payload.data.d.webhook_id
});
} else {
// if (message.attachments.length > 0) message.attachments = payload.data.d.attachments ?? [];
Expand All @@ -43,7 +56,19 @@ export class MessageUpdateListener extends Listener {

await this.store.drizzle.update(messages).set({
channelId: payload.data.d.channel_id,
content: payload.data.d.content
applicationId: payload.data.d.application_id,
authorId: payload.data.d.author?.id,
content: payload.data.d.content,
editedTimestamp: payload.data.d.edited_timestamp,
flags: payload.data.d.flags,
mentionEveryone: payload.data.d.mention_everyone,
nonce: payload.data.d.nonce?.toString(),
pinned: payload.data.d.pinned,
timestamp: payload.data.d.timestamp,
tts: payload.data.d.tts,
position: payload.data.d.position,
type: payload.data.d.type,
webhookId: payload.data.d.webhook_id
}).where(eq(messages.id, payload.data.d.id));
}
}
Expand Down
Loading

0 comments on commit e865f7b

Please sign in to comment.