diff --git a/packages/kanao-schema/drizzle/0006_even_genesis.sql b/packages/kanao-schema/drizzle/0006_even_genesis.sql new file mode 100644 index 00000000..2dfc0883 --- /dev/null +++ b/packages/kanao-schema/drizzle/0006_even_genesis.sql @@ -0,0 +1 @@ +ALTER TABLE "messages" ADD COLUMN "guild_id" text; \ No newline at end of file diff --git a/packages/kanao-schema/drizzle/meta/0006_snapshot.json b/packages/kanao-schema/drizzle/meta/0006_snapshot.json new file mode 100644 index 00000000..bc41a745 --- /dev/null +++ b/packages/kanao-schema/drizzle/meta/0006_snapshot.json @@ -0,0 +1,879 @@ +{ + "id": "5ac99a53-bd5f-4e1a-a8b0-dcc98bedc66b", + "prevId": "3fdaad60-5932-45ca-a6c7-b7b5729bada6", + "version": "5", + "dialect": "pg", + "tables": { + "members": { + "name": "members", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "guild_id": { + "name": "guild_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nick": { + "name": "nick", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "avatar": { + "name": "avatar", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "flags": { + "name": "flags", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "joined_at": { + "name": "joined_at", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "premium_since": { + "name": "premium_since", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deaf": { + "name": "deaf", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "mute": { + "name": "mute", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "pending": { + "name": "pending", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "communication_disabled_until": { + "name": "communication_disabled_until", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "users": { + "name": "users", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "discriminator": { + "name": "discriminator", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "global_name": { + "name": "global_name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "avatar": { + "name": "avatar", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "bot": { + "name": "bot", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "flags": { + "name": "flags", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "premium_type": { + "name": "premium_type", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "public_flags": { + "name": "public_flags", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "avatar_decoration": { + "name": "avatar_decoration", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "locale": { + "name": "locale", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "accent_color": { + "name": "accent_color", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "banner": { + "name": "banner", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "mfa_enabled": { + "name": "mfa_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "member_roles": { + "name": "member_roles", + "schema": "", + "columns": { + "member_id": { + "name": "member_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role_id": { + "name": "role_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "guild_id": { + "name": "guild_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "voice_states_member_id_role_id_guild_id": { + "name": "voice_states_member_id_role_id_guild_id", + "columns": [ + "member_id", + "role_id" + ] + } + }, + "uniqueConstraints": {} + }, + "roles": { + "name": "roles", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "color": { + "name": "color", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "hoist": { + "name": "hoist", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "permissions": { + "name": "permissions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "guild_id": { + "name": "guild_id", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "guilds": { + "name": "guilds", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "unavailable": { + "name": "unavailable", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "icon_hash": { + "name": "icon_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "splash": { + "name": "splash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "discovery_splash": { + "name": "discovery_splash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "owner": { + "name": "owner", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "owner_id": { + "name": "owner_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "permissions": { + "name": "permissions", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "region": { + "name": "region", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "afk_channel_id": { + "name": "afk_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "afk_timeout": { + "name": "afk_timeout", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "widget_enabled": { + "name": "widget_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "widget_channel_id": { + "name": "widget_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "verification_level": { + "name": "verification_level", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "default_message_notifications": { + "name": "default_message_notifications", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "explicit_content_filter": { + "name": "explicit_content_filter", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "mfa_level": { + "name": "mfa_level", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "system_channel_id": { + "name": "system_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "system_channel_flags": { + "name": "system_channel_flags", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rules_channel_id": { + "name": "rules_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "max_presences": { + "name": "max_presences", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "max_members": { + "name": "max_members", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "vanity_url_code": { + "name": "vanity_url_code", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "banner": { + "name": "banner", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "premium_tier": { + "name": "premium_tier", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "premium_subscription_count": { + "name": "premium_subscription_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "preferred_locale": { + "name": "preferred_locale", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "public_updates_channel_id": { + "name": "public_updates_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "max_video_channel_users": { + "name": "max_video_channel_users", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "approximate_member_count": { + "name": "approximate_member_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "approximate_presence_count": { + "name": "approximate_presence_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "nsfw_level": { + "name": "nsfw_level", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "premium_progress_bar_enabled": { + "name": "premium_progress_bar_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "safety_alert_channel_id": { + "name": "safety_alert_channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "channels": { + "name": "channels", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "type": { + "name": "type", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "topic": { + "name": "topic", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "nsfw": { + "name": "nsfw", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "last_message_id": { + "name": "last_message_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "bitrate": { + "name": "bitrate", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_limit": { + "name": "user_limit", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rate_limit_per_user": { + "name": "rate_limit_per_user", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "icon": { + "name": "icon", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "owner_id": { + "name": "owner_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "parent_id": { + "name": "parent_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "last_pin_timestamp": { + "name": "last_pin_timestamp", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rtc_region": { + "name": "rtc_region", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "video_quality_mode": { + "name": "video_quality_mode", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "message_count": { + "name": "message_count", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "default_auto_archive_duration": { + "name": "default_auto_archive_duration", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "flags": { + "name": "flags", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "guild_id": { + "name": "guild_id", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "channels_overwrite": { + "name": "channels_overwrite", + "schema": "", + "columns": { + "user_or_role": { + "name": "user_or_role", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "channel_id": { + "name": "channel_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "allow": { + "name": "allow", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deny": { + "name": "deny", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "channels_overwrite_user_or_role_channel_id": { + "name": "channels_overwrite_user_or_role_channel_id", + "columns": [ + "user_or_role", + "channel_id" + ] + } + }, + "uniqueConstraints": {} + }, + "voice_states": { + "name": "voice_states", + "schema": "", + "columns": { + "member_id": { + "name": "member_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "guild_id": { + "name": "guild_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "session_id": { + "name": "session_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "deaf": { + "name": "deaf", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "mute": { + "name": "mute", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "self_deaf": { + "name": "self_deaf", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "self_mute": { + "name": "self_mute", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "self_stream": { + "name": "self_stream", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "self_video": { + "name": "self_video", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "suppress": { + "name": "suppress", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "request_to_speak_timestamp": { + "name": "request_to_speak_timestamp", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "voice_states_member_id_guild_id": { + "name": "voice_states_member_id_guild_id", + "columns": [ + "member_id", + "guild_id" + ] + } + }, + "uniqueConstraints": {} + }, + "messages": { + "name": "messages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "channel_id": { + "name": "channel_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "author_id": { + "name": "author_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "guild_id": { + "name": "guild_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "timestamp": { + "name": "timestamp", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "edited_timestamp": { + "name": "edited_timestamp", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "tts": { + "name": "tts", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "mention_everyone": { + "name": "mention_everyone", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "nonce": { + "name": "nonce", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pinned": { + "name": "pinned", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "webhook_id": { + "name": "webhook_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "type": { + "name": "type", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "application_id": { + "name": "application_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "flags": { + "name": "flags", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + } + }, + "enums": {}, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/kanao-schema/drizzle/meta/_journal.json b/packages/kanao-schema/drizzle/meta/_journal.json index 58acbaa8..a989cffb 100644 --- a/packages/kanao-schema/drizzle/meta/_journal.json +++ b/packages/kanao-schema/drizzle/meta/_journal.json @@ -43,6 +43,13 @@ "when": 1709348529932, "tag": "0005_living_silvermane", "breakpoints": true + }, + { + "idx": 6, + "version": "5", + "when": 1709349065405, + "tag": "0006_even_genesis", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/kanao-schema/src/Schema/message.ts b/packages/kanao-schema/src/Schema/message.ts index e96e5e7c..fda66531 100644 --- a/packages/kanao-schema/src/Schema/message.ts +++ b/packages/kanao-schema/src/Schema/message.ts @@ -5,6 +5,7 @@ export const messages = pgTable("messages", { channelId: text("channel_id").notNull(), authorId: text("author_id").notNull(), + guildId: text("guild_id"), content: text("content"), timestamp: text("timestamp"), diff --git a/services/kanao-cache/src/Listeners/Caches/GuildMembers/GuildMembersChunkListener.ts b/services/kanao-cache/src/Listeners/Caches/GuildMembers/GuildMembersChunkListener.ts index 8af175bd..8ffa0574 100644 --- a/services/kanao-cache/src/Listeners/Caches/GuildMembers/GuildMembersChunkListener.ts +++ b/services/kanao-cache/src/Listeners/Caches/GuildMembers/GuildMembersChunkListener.ts @@ -62,7 +62,8 @@ export class GuildMembersChunkListener extends Listener { mute: member.mute, nick: member.nick, pending: member.pending, - premiumSince: member.premium_since + premiumSince: member.premium_since, + guildId: payload.data.d.guild_id })) ).onConflictDoUpdate({ target: members.id, diff --git a/services/kanao-cache/src/Listeners/Caches/Messages/MessageCreateListener.ts b/services/kanao-cache/src/Listeners/Caches/Messages/MessageCreateListener.ts index dd0b27c8..0a17e0f5 100644 --- a/services/kanao-cache/src/Listeners/Caches/Messages/MessageCreateListener.ts +++ b/services/kanao-cache/src/Listeners/Caches/Messages/MessageCreateListener.ts @@ -51,7 +51,7 @@ export class MessageCreateListener extends Listener { }); } - if (stateMembers && payload.data.d.member !== undefined) { + if (stateMembers && payload.data.d.member !== undefined && payload.data.d.guild_id) { await this.container.client.drizzle.insert(members).values({ id: payload.data.d.author.id, guildId: payload.data.d.guild_id, @@ -83,7 +83,7 @@ export class MessageCreateListener extends Listener { await this.container.client.drizzle.insert(memberRoles).values(payload.data.d.member.roles.map(role => ({ memberId: payload.data.d.author.id, roleId: role, - guildId: payload.data.d.guild_id + guildId: payload.data.d.guild_id! }))).onConflictDoNothing({ target: [memberRoles.memberId, memberRoles.roleId] }); } } @@ -104,7 +104,8 @@ export class MessageCreateListener extends Listener { timestamp: payload.data.d.timestamp, tts: payload.data.d.tts, webhookId: payload.data.d.webhook_id, - nonce: payload.data.d.nonce?.toString() + nonce: payload.data.d.nonce?.toString(), + guildId: payload.data.d.guild_id }).onConflictDoNothing({ target: messages.id }); } diff --git a/services/kanao-cache/src/Listeners/Caches/Messages/MessageUpdateListener.ts b/services/kanao-cache/src/Listeners/Caches/Messages/MessageUpdateListener.ts index f107b646..6b13e9ed 100644 --- a/services/kanao-cache/src/Listeners/Caches/Messages/MessageUpdateListener.ts +++ b/services/kanao-cache/src/Listeners/Caches/Messages/MessageUpdateListener.ts @@ -52,7 +52,7 @@ export class MessageUpdateListener extends Listener { }); } - if (stateMembers && payload.data.d.member !== undefined && payload.data.d.author !== undefined) { + if (stateMembers && payload.data.d.member !== undefined && payload.data.d.author !== undefined && payload.data.d.guild_id) { await this.container.client.drizzle.insert(members).values({ id: payload.data.d.author.id, guildId: payload.data.d.guild_id, @@ -84,7 +84,7 @@ export class MessageUpdateListener extends Listener { await this.container.client.drizzle.insert(memberRoles).values(payload.data.d.member.roles.map(role => ({ memberId: payload.data.d.author!.id, roleId: role, - guildId: payload.data.d.guild_id + guildId: payload.data.d.guild_id! }))).onConflictDoNothing({ target: [memberRoles.memberId, memberRoles.roleId] }); } } @@ -95,7 +95,7 @@ export class MessageUpdateListener extends Listener { channelId: payload.data.d.channel_id, content: payload.data.d.content, applicationId: payload.data.d.application_id, - authorId: payload.data.d.author?.id, + authorId: payload.data.d.author!.id, editedTimestamp: payload.data.d.edited_timestamp, flags: payload.data.d.flags, type: payload.data.d.type, diff --git a/services/kanao-cache/src/Listeners/Caches/Voices/VoiceStateUpdateListener.ts b/services/kanao-cache/src/Listeners/Caches/Voices/VoiceStateUpdateListener.ts index 4b24298f..fc9c94ce 100644 --- a/services/kanao-cache/src/Listeners/Caches/Voices/VoiceStateUpdateListener.ts +++ b/services/kanao-cache/src/Listeners/Caches/Voices/VoiceStateUpdateListener.ts @@ -37,7 +37,7 @@ export class VoiceStateUpdateListener extends Listener { if (stateMembers && payload.data.d.member !== undefined) { await this.container.client.drizzle.insert(members).values({ id: payload.data.d.user_id, - guildId: payload.data.d.guild_id, + guildId: payload.data.d.guild_id!, avatar: payload.data.d.member.avatar, flags: payload.data.d.member.flags, communicationDisabledUntil: payload.data.d.member.premium_since, @@ -53,7 +53,7 @@ export class VoiceStateUpdateListener extends Listener { await this.container.client.drizzle.insert(memberRoles).values(payload.data.d.member.roles.map(role => ({ memberId: payload.data.d.user_id, roleId: role, - guildId: payload.data.d.guild_id + guildId: payload.data.d.guild_id! }))).onConflictDoNothing({ target: [memberRoles.memberId, memberRoles.roleId] }); } }