From caafbc606ce722f3afaa72ead4a2c28f8fbbe5e2 Mon Sep 17 00:00:00 2001 From: Flam3rboy <34555296+Flam3rboy@users.noreply.github.com> Date: Wed, 10 Feb 2021 22:04:55 +0100 Subject: [PATCH] move Schema from util to gateway --- src/opcodes/Identify.ts | 3 +- src/schema/Activity.ts | 81 +++++++++++++++++++++++++++++++++++++++++ src/schema/Emoji.ts | 11 ++++++ src/schema/Identify.ts | 33 +++++++++++++++++ 4 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/schema/Activity.ts create mode 100644 src/schema/Emoji.ts create mode 100644 src/schema/Identify.ts diff --git a/src/opcodes/Identify.ts b/src/opcodes/Identify.ts index f0546a41..da993ec8 100644 --- a/src/opcodes/Identify.ts +++ b/src/opcodes/Identify.ts @@ -1,8 +1,9 @@ import { CLOSECODES, Payload } from "../util/Constants"; import WebSocket from "../util/WebSocket"; -import { checkToken, IdentifySchema } from "fosscord-server-util"; +import { checkToken } from "fosscord-server-util"; import { setupListener } from "../listener/listener"; import { instanceOf } from "lambert-server"; +import { IdentifySchema } from "../schema/Identify"; export async function onIdentify(this: WebSocket, data: Payload) { try { diff --git a/src/schema/Activity.ts b/src/schema/Activity.ts new file mode 100644 index 00000000..00772743 --- /dev/null +++ b/src/schema/Activity.ts @@ -0,0 +1,81 @@ +import { EmojiSchema } from "./Emoji"; + +export const ActivitySchema = { + afk: Boolean, + status: String, + $activities: [ + { + name: String, // the activity's name + type: Number, // activity type // TODO: check if its between range 0-5 + $url: String, // stream url, is validated when type is 1 + $created_at: Number, // unix timestamp of when the activity was added to the user's session + $timestamps: { + // unix timestamps for start and/or end of the game + start: Number, + end: Number, + }, + $application_id: BigInt, // application id for the game + $details: String, + $State: String, + $emoji: EmojiSchema, + $party: { + $id: String, + $size: [Number], // used to show the party's current and maximum size // TODO: array length 2 + }, + $assets: { + $large_image: String, // the id for a large asset of the activity, usually a snowflake + $large_text: String, // text displayed when hovering over the large image of the activity + $small_image: String, // the id for a small asset of the activity, usually a snowflake + $small_text: String, // text displayed when hovering over the small image of the activity + }, + $secrets: { + $join: String, // the secret for joining a party + $spectate: String, // the secret for spectating a game + $match: String, // the secret for a specific instanced match + }, + $instance: Boolean, + flags: BigInt, // activity flags OR d together, describes what the payload includes + }, + ], + $since: Number, // unix time (in milliseconds) of when the client went idle, or null if the client is not idle +}; + +export interface ActivitySchema { + afk: boolean; + status: string; + activities?: [ + { + name: string; // the activity's name + type: number; // activity type // TODO: check if its between range 0-5 + url?: string; // stream url, is validated when type is 1 + created_at?: number; // unix timestamp of when the activity was added to the user's session + timestamps?: { + // unix timestamps for start and/or end of the game + start: number; + end: number; + }; + application_id?: bigint; // application id for the game + details?: string; + State?: string; + emoji?: EmojiSchema; + party?: { + id?: string; + size?: [number]; // used to show the party's current and maximum size // TODO: array length 2 + }; + assets?: { + large_image?: string; // the id for a large asset of the activity, usually a snowflake + large_text?: string; // text displayed when hovering over the large image of the activity + small_image?: string; // the id for a small asset of the activity, usually a snowflake + small_text?: string; // text displayed when hovering over the small image of the activity + }; + secrets?: { + join?: string; // the secret for joining a party + spectate?: string; // the secret for spectating a game + match?: string; // the secret for a specific instanced match + }; + instance?: boolean; + flags: bigint; // activity flags OR d together, describes what the payload includes + } + ]; + since?: number; // unix time (in milliseconds) of when the client went idle, or null if the client is not idle +} diff --git a/src/schema/Emoji.ts b/src/schema/Emoji.ts new file mode 100644 index 00000000..09f3ebb1 --- /dev/null +++ b/src/schema/Emoji.ts @@ -0,0 +1,11 @@ +export const EmojiSchema = { + name: String, // the name of the emoji + $id: BigInt, // the id of the emoji + animated: Boolean, // whether this emoji is animated +}; + +export interface EmojiSchema { + name: string; + id?: bigint; + animated: Boolean; +} diff --git a/src/schema/Identify.ts b/src/schema/Identify.ts new file mode 100644 index 00000000..cfc3702a --- /dev/null +++ b/src/schema/Identify.ts @@ -0,0 +1,33 @@ +import { ActivitySchema } from "./Activity"; + +export const IdentifySchema = { + token: String, + intents: BigInt, // discord uses a Integer for bitfields we use bigints tho. | instanceOf will automatically convert the Number to a BigInt + $properties: { + // bruh discord really uses $ in the property key, so we need to double prefix it, because instanceOf treats $ (prefix) as a optional key + $$os: String, + $$browser: String, + $$device: String, + }, + $presence: ActivitySchema, + $compress: Boolean, + $large_threshold: Number, + $shard: [Number], + $guild_subscriptions: Boolean, +}; + +export interface IdentifySchema { + token: string; + properties: { + // bruh discord really uses $ in the property key, so we need to double prefix it, because instanceOf treats $ (prefix) as a optional key + $$os: string; + $$browser: string; + $$device: string; + }; + intents: bigint; // discord uses a Integer for bitfields we use bigints tho. | instanceOf will automatically convert the Number to a BigInt + presence?: ActivitySchema; + compress?: boolean; + large_threshold?: number; + shard?: [number]; + guild_subscriptions?: boolean; +}