diff options
author | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-12-21 16:10:26 +1100 |
---|---|---|
committer | Madeline <46743919+MaddyUnderStars@users.noreply.github.com> | 2022-12-21 16:10:26 +1100 |
commit | fe4db63ab8ac42c669048b705a78c68434e64856 (patch) | |
tree | c90651f93305dc9382467b6933b3d3c70727d60f /src | |
parent | Set default cdn endpoints so that local testing works (diff) | |
parent | Merge pull request #917 from Puyodead1/refactor/client/165341 (diff) | |
download | server-fe4db63ab8ac42c669048b705a78c68434e64856.tar.xz |
Merge branch 'maddy/refactor' of github.com:fosscord/fosscord-server into maddy/refactor
Diffstat (limited to 'src')
-rw-r--r-- | src/gateway/opcodes/Identify.ts | 16 | ||||
-rw-r--r-- | src/util/dtos/ReadyGuildDTO.ts | 153 | ||||
-rw-r--r-- | src/util/dtos/index.ts | 1 | ||||
-rw-r--r-- | src/util/entities/Member.ts | 4 | ||||
-rw-r--r-- | src/util/interfaces/Event.ts | 5 | ||||
-rw-r--r-- | src/util/schemas/IdentifySchema.ts | 8 |
6 files changed, 176 insertions, 11 deletions
diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts index 5f569fee..69a60880 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts @@ -22,6 +22,8 @@ import { IdentifySchema, DefaultUserGuildSettings, UserGuildSettings, + ReadyGuildDTO, + Guild, } from "@fosscord/util"; import { Send } from "../util/Send"; import { CLOSECODES, OPCODES } from "../util/Constants"; @@ -255,17 +257,17 @@ export async function onIdentify(this: WebSocket, data: Payload) { }; const d: ReadyEventData = { - v: 8, + v: 9, application: { id: application?.id ?? '', flags: application?.flags ?? 0 }, //TODO: check this code! user: privateUser, user_settings: user.settings, // @ts-ignore guilds: guilds.map((x) => { - // @ts-ignore - x.guild_hashes = {}; // @ts-ignore - x.guild_scheduled_events = []; // @ts-ignore - x.threads = []; - return x; + return { + ...new ReadyGuildDTO(x as Guild & { joined_at: Date }).toJSON(), + guild_hashes: {}, + joined_at: x.joined_at + }; }), guild_experiments: [], // TODO geo_ordered_rtc_regions: [], // TODO @@ -298,8 +300,6 @@ export async function onIdentify(this: WebSocket, data: Payload) { merged_members: merged_members, // shard // TODO: only for user sharding sessions: [], // TODO: - presences: [], // TODO: - tutorial: null, }; // TODO: send real proper data structure diff --git a/src/util/dtos/ReadyGuildDTO.ts b/src/util/dtos/ReadyGuildDTO.ts new file mode 100644 index 00000000..0cf30331 --- /dev/null +++ b/src/util/dtos/ReadyGuildDTO.ts @@ -0,0 +1,153 @@ +import { Channel, Emoji, Guild, Member, Role, Sticker } from "../entities"; + +export interface IReadyGuildDTO { + application_command_counts?: { 1: number; 2: number; 3: number }; // ???????????? + channels: Channel[]; + data_mode: string; // what is this + emojis: Emoji[]; + guild_scheduled_events: any[]; + id: string; + large: boolean | undefined; + lazy: boolean; + member_count: number | undefined; + members: Member[]; + premium_subscription_count: number | undefined; + properties: { + name: string; + description?: string | null; + icon?: string | null; + splash?: string | null; + banner?: string | null; + features: string[]; + preferred_locale?: string | null; + owner_id?: string | null; + application_id?: string | null; + afk_channel_id?: string | null; + afk_timeout: number | undefined; + system_channel_id?: string | null; + verification_level: number | undefined; + explicit_content_filter: number | undefined; + default_message_notifications: number | undefined; + mfa_level: number | undefined; + vanity_url_code?: string | null; + premium_tier: number | undefined; + premium_progress_bar_enabled: boolean; + system_channel_flags: number | undefined; + discovery_splash?: string | null; + rules_channel_id?: string | null; + public_updates_channel_id?: string | null; + max_video_channel_users: number | undefined; + max_members: number | undefined; + nsfw_level: number | undefined; + hub_type?: any | null; // ???? + }; + roles: Role[]; + stage_instances: any[]; + stickers: Sticker[]; + threads: any[]; + version: string; +} + +export class ReadyGuildDTO implements IReadyGuildDTO { + application_command_counts?: { 1: number; 2: number; 3: number }; // ???????????? + channels: Channel[]; + data_mode: string; // what is this + emojis: Emoji[]; + guild_scheduled_events: any[]; + id: string; + large: boolean | undefined; + lazy: boolean; + member_count: number | undefined; + members: Member[]; + premium_subscription_count: number | undefined; + properties: { + name: string; + description?: string | null; + icon?: string | null; + splash?: string | null; + banner?: string | null; + features: string[]; + preferred_locale?: string | null; + owner_id?: string | null; + application_id?: string | null; + afk_channel_id?: string | null; + afk_timeout: number | undefined; + system_channel_id?: string | null; + verification_level: number | undefined; + explicit_content_filter: number | undefined; + default_message_notifications: number | undefined; + mfa_level: number | undefined; + vanity_url_code?: string | null; + premium_tier: number | undefined; + premium_progress_bar_enabled: boolean; + system_channel_flags: number | undefined; + discovery_splash?: string | null; + rules_channel_id?: string | null; + public_updates_channel_id?: string | null; + max_video_channel_users: number | undefined; + max_members: number | undefined; + nsfw_level: number | undefined; + hub_type?: any | null; // ???? + }; + roles: Role[]; + stage_instances: any[]; + stickers: Sticker[]; + threads: any[]; + version: string; + + constructor(guild: Guild) { + this.application_command_counts = { + 1: 5, + 2: 2, + 3: 2, + }; // ????? + this.channels = guild.channels; + this.data_mode = "full"; + this.emojis = guild.emojis; + this.guild_scheduled_events = []; + this.id = guild.id; + this.large = guild.large; + this.lazy = true; // ?????????? + this.member_count = guild.member_count; + this.members = guild.members; + this.premium_subscription_count = guild.premium_subscription_count; + this.properties = { + name: guild.name, + description: guild.description, + icon: guild.icon, + splash: guild.splash, + banner: guild.banner, + features: guild.features, + preferred_locale: guild.preferred_locale, + owner_id: guild.owner_id, + application_id: null, // ????? + afk_channel_id: guild.afk_channel_id, + afk_timeout: guild.afk_timeout, + system_channel_id: guild.system_channel_id, + verification_level: guild.verification_level, + explicit_content_filter: guild.explicit_content_filter, + default_message_notifications: guild.default_message_notifications, + mfa_level: guild.mfa_level, + vanity_url_code: null, // ????? + premium_tier: guild.premium_tier, + premium_progress_bar_enabled: guild.premium_progress_bar_enabled, + system_channel_flags: guild.system_channel_flags, + discovery_splash: guild.discovery_splash, + rules_channel_id: guild.rules_channel_id, + public_updates_channel_id: guild.public_updates_channel_id, + max_video_channel_users: guild.max_video_channel_users, + max_members: guild.max_members, + nsfw_level: guild.nsfw_level, + hub_type: null, + }; + this.roles = guild.roles; + this.stage_instances = []; + this.stickers = guild.stickers; + this.threads = []; + this.version = "1"; // ?????? + } + + toJSON() { + return this as IReadyGuildDTO; + } +} diff --git a/src/util/dtos/index.ts b/src/util/dtos/index.ts index 0e8f8459..b25cac9c 100644 --- a/src/util/dtos/index.ts +++ b/src/util/dtos/index.ts @@ -1,2 +1,3 @@ export * from "./DmChannelDTO"; +export * from "./ReadyGuildDTO"; export * from "./UserDTO"; diff --git a/src/util/entities/Member.ts b/src/util/entities/Member.ts index 1c8bfbef..bffec326 100644 --- a/src/util/entities/Member.ts +++ b/src/util/entities/Member.ts @@ -29,6 +29,7 @@ import { Role } from "./Role"; import { BaseClassWithoutId } from "./BaseClass"; import { Ban, PublicGuildRelations } from "."; import { DiscordApiErrors } from "../util/Constants"; +import { ReadyGuildDTO } from "../dtos"; export const MemberPrivateProjection: (keyof Member)[] = [ "id", @@ -363,7 +364,7 @@ export class Member extends BaseClassWithoutId { emitEvent({ event: "GUILD_CREATE", data: { - ...guild, + ...new ReadyGuildDTO(guild).toJSON(), members: [...memberPreview, { ...member, user }], member_count: memberCount + 1, guild_hashes: {}, @@ -373,6 +374,7 @@ export class Member extends BaseClassWithoutId { stage_instances: [], threads: [], embedded_activities: [], + voice_states: guild.voice_states }, user_id, } as GuildCreateEvent), diff --git a/src/util/interfaces/Event.ts b/src/util/interfaces/Event.ts index 36eedbfc..f5bccb2f 100644 --- a/src/util/interfaces/Event.ts +++ b/src/util/interfaces/Event.ts @@ -20,6 +20,7 @@ import { Status, Presence, UserSettings, + IReadyGuildDTO, } from "@fosscord/util"; export interface Event { @@ -62,7 +63,7 @@ export interface ReadyEventData { }; private_channels: Channel[]; // this will be empty for bots session_id: string; // resuming - guilds: Guild[]; + guilds: IReadyGuildDTO[]; analytics_token?: string; connected_accounts?: ConnectedAccount[]; consents?: { @@ -155,7 +156,7 @@ export interface ChannelRecipientRemoveEvent extends Event { export interface GuildCreateEvent extends Event { event: "GUILD_CREATE"; - data: Guild & { + data: IReadyGuildDTO & { joined_at: Date; // TODO: add them to guild guild_scheduled_events: never[]; diff --git a/src/util/schemas/IdentifySchema.ts b/src/util/schemas/IdentifySchema.ts index 848ea0a6..0e44af38 100644 --- a/src/util/schemas/IdentifySchema.ts +++ b/src/util/schemas/IdentifySchema.ts @@ -44,6 +44,8 @@ export const IdentifySchema = { $user_settings_version: undefined, $useruser_guild_settings_version: undefined, $private_channels_version: Number, + $guild_versions: Object, + $api_code_version: Number, }, $clientState: { $guildHashes: Object, @@ -51,6 +53,8 @@ export const IdentifySchema = { $readStateVersion: Number, $useruserGuildSettingsVersion: undefined, $userGuildSettingsVersion: undefined, + $guildVersions: Object, + $apiCodeVersion: Number, }, $v: Number, $version: Number, @@ -96,6 +100,8 @@ export interface IdentifySchema { user_settings_version?: number; useruser_guild_settings_version?: number; private_channels_version?: number; + guild_versions?: any; + api_code_version?: number; }; clientState?: { guildHashes?: any; @@ -103,6 +109,8 @@ export interface IdentifySchema { readStateVersion?: number; userGuildSettingsVersion?: number; useruserGuildSettingsVersion?: number; + guildVersions?: any; + apiCodeVersion?: number; }; v?: number; } |