Move schemas to /src/util/schemas
This commit is contained in:
@@ -36,7 +36,7 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
|
||||
data = bigIntJson.parse(buffer as string);
|
||||
}
|
||||
else if (typeof buffer == "string") {
|
||||
data = bigIntJson.parse(buffer as string)
|
||||
data = bigIntJson.parse(buffer as string);
|
||||
}
|
||||
else return;
|
||||
|
||||
@@ -51,14 +51,14 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
|
||||
return;
|
||||
}
|
||||
|
||||
// const transaction = Sentry.startTransaction({
|
||||
// op: OPCODES[data.op],
|
||||
// name: `GATEWAY ${OPCODES[data.op]}`,
|
||||
// data: {
|
||||
// ...data.d,
|
||||
// token: data?.d?.token ? "[Redacted]" : undefined,
|
||||
// },
|
||||
// });
|
||||
const transaction = Sentry.startTransaction({
|
||||
op: OPCODES[data.op],
|
||||
name: `GATEWAY ${OPCODES[data.op]}`,
|
||||
data: {
|
||||
...data.d,
|
||||
token: data?.d?.token ? "[Redacted]" : undefined,
|
||||
},
|
||||
});
|
||||
|
||||
try {
|
||||
var ret = await OPCodeHandler.call(this, data);
|
||||
@@ -66,7 +66,7 @@ export async function Message(this: WebSocket, buffer: WS.Data) {
|
||||
return ret;
|
||||
} catch (error) {
|
||||
Sentry.captureException(error);
|
||||
// transaction.finish();
|
||||
transaction.finish();
|
||||
console.error(`Error: Op ${data.op}`, error);
|
||||
// if (!this.CLOSED && this.CLOSING)
|
||||
return this.close(CLOSECODES.Unknown_error);
|
||||
|
||||
@@ -20,12 +20,12 @@ import {
|
||||
PresenceUpdateEvent,
|
||||
DefaultUserGuildSettings,
|
||||
UserGuildSettings,
|
||||
IdentifySchema,
|
||||
} from "@fosscord/util";
|
||||
import { Send } from "../util/Send";
|
||||
import { CLOSECODES, OPCODES } from "../util/Constants";
|
||||
import { genSessionId } from "../util/SessionUtils";
|
||||
import { setupListener } from "../listener/listener";
|
||||
import { IdentifySchema } from "../schema/Identify";
|
||||
// import experiments from "./experiments.json";
|
||||
const experiments: any = [];
|
||||
import { check } from "./instanceOf";
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { getDatabase, getPermission, listenEvent, Member, Role, Session } from "@fosscord/util";
|
||||
import { getDatabase, getPermission, listenEvent, Member, Role, Session, LazyRequestSchema } from "@fosscord/util";
|
||||
import { WebSocket, Payload, handlePresenceUpdate, OPCODES, Send } from "@fosscord/gateway";
|
||||
import { LazyRequest } from "../schema/LazyRequest";
|
||||
import { check } from "./instanceOf";
|
||||
|
||||
// TODO: only show roles/members that have access to this channel
|
||||
@@ -137,8 +136,8 @@ async function getMembers(guild_id: string, range: [number, number]) {
|
||||
|
||||
export async function onLazyRequest(this: WebSocket, { d }: Payload) {
|
||||
// TODO: check data
|
||||
check.call(this, LazyRequest, d);
|
||||
const { guild_id, typing, channels, activities } = d as LazyRequest;
|
||||
check.call(this, LazyRequestSchema, d);
|
||||
const { guild_id, typing, channels, activities } = d as LazyRequestSchema;
|
||||
|
||||
const channel_id = Object.keys(channels || {}).first();
|
||||
if (!channel_id) return;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { WebSocket, Payload } from "@fosscord/gateway";
|
||||
import { emitEvent, PresenceUpdateEvent, Session, User } from "@fosscord/util";
|
||||
import { ActivitySchema } from "../schema/Activity";
|
||||
import { emitEvent, PresenceUpdateEvent, Session, User, ActivitySchema } from "@fosscord/util";
|
||||
import { check } from "./instanceOf";
|
||||
|
||||
export async function onPresenceUpdate(this: WebSocket, { d }: Payload) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { VoiceStateUpdateSchema } from "../schema/VoiceStateUpdateSchema";
|
||||
import { Payload, WebSocket } from "@fosscord/gateway";
|
||||
import { genVoiceToken } from "../util/SessionUtils";
|
||||
import { check } from "./instanceOf";
|
||||
@@ -11,6 +10,7 @@ import {
|
||||
VoiceServerUpdateEvent,
|
||||
VoiceState,
|
||||
VoiceStateUpdateEvent,
|
||||
VoiceStateUpdateSchema,
|
||||
} from "@fosscord/util";
|
||||
// TODO: check if a voice server is setup
|
||||
// Notice: Bot users respect the voice channel's user limit, if set. When the voice channel is full, you will not receive the Voice State Update or Voice Server Update events in response to your own Voice State Update. Having MANAGE_CHANNELS permission bypasses this limit and allows you to join regardless of the channel being full or not.
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
import { Activity, Status } from "@fosscord/util";
|
||||
|
||||
export const ActivitySchema = {
|
||||
afk: Boolean,
|
||||
status: String,
|
||||
$activities: [
|
||||
{
|
||||
name: String,
|
||||
type: Number,
|
||||
$url: String,
|
||||
$created_at: Date,
|
||||
$timestamps: {
|
||||
$start: Number,
|
||||
$end: Number,
|
||||
},
|
||||
$application_id: String,
|
||||
$details: String,
|
||||
$state: String,
|
||||
$emoji: {
|
||||
$name: String,
|
||||
$id: String,
|
||||
$animated: Boolean,
|
||||
},
|
||||
$party: {
|
||||
$id: String,
|
||||
$size: [Number, Number],
|
||||
},
|
||||
$assets: {
|
||||
$large_image: String,
|
||||
$large_text: String,
|
||||
$small_image: String,
|
||||
$small_text: String,
|
||||
},
|
||||
$secrets: {
|
||||
$join: String,
|
||||
$spectate: String,
|
||||
$match: String,
|
||||
},
|
||||
$instance: Boolean,
|
||||
$flags: String,
|
||||
|
||||
$id: String,
|
||||
$sync_id: String,
|
||||
$metadata: { // spotify
|
||||
$context_uri: String,
|
||||
album_id: String,
|
||||
artist_ids: [String],
|
||||
},
|
||||
$session_id: String,
|
||||
},
|
||||
],
|
||||
$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: Status;
|
||||
activities?: Activity[];
|
||||
since?: number; // unix time (in milliseconds) of when the client went idle, or null if the client is not idle
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
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: Object,
|
||||
// {
|
||||
// // discord uses $ in the property key for bots, so we need to double prefix it, because instanceOf treats $ (prefix) as a optional key
|
||||
// $os: String,
|
||||
// $os_arch: String,
|
||||
// $browser: String,
|
||||
// $device: String,
|
||||
// $$os: String,
|
||||
// $$browser: String,
|
||||
// $$device: String,
|
||||
// $browser_user_agent: String,
|
||||
// $browser_version: String,
|
||||
// $os_version: String,
|
||||
// $referrer: String,
|
||||
// $$referrer: String,
|
||||
// $referring_domain: String,
|
||||
// $$referring_domain: String,
|
||||
// $referrer_current: String,
|
||||
// $referring_domain_current: String,
|
||||
// $release_channel: String,
|
||||
// $client_build_number: Number,
|
||||
// $client_event_source: String,
|
||||
// $client_version: String,
|
||||
// $system_locale: String,
|
||||
// $window_manager: String,
|
||||
// $distro: String,
|
||||
// },
|
||||
$presence: ActivitySchema,
|
||||
$compress: Boolean,
|
||||
$large_threshold: Number,
|
||||
$shard: [BigInt, BigInt],
|
||||
$guild_subscriptions: Boolean,
|
||||
$capabilities: Number,
|
||||
$client_state: {
|
||||
$guild_hashes: Object,
|
||||
$highest_last_message_id: String || Number,
|
||||
$read_state_version: Number,
|
||||
$user_guild_settings_version: Number,
|
||||
$user_settings_version: undefined,
|
||||
$useruser_guild_settings_version: undefined,
|
||||
},
|
||||
$clientState: {
|
||||
$guildHashes: Object,
|
||||
$highestLastMessageId: String || Number,
|
||||
$readStateVersion: Number,
|
||||
$useruserGuildSettingsVersion: undefined,
|
||||
$userGuildSettingsVersion: undefined,
|
||||
},
|
||||
$v: Number,
|
||||
$version: Number,
|
||||
};
|
||||
|
||||
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;
|
||||
os_atch?: string;
|
||||
browser?: string;
|
||||
device?: string;
|
||||
$os?: string;
|
||||
$browser?: string;
|
||||
$device?: string;
|
||||
browser_user_agent?: string;
|
||||
browser_version?: string;
|
||||
os_version?: string;
|
||||
referrer?: string;
|
||||
referring_domain?: string;
|
||||
referrer_current?: string;
|
||||
referring_domain_current?: string;
|
||||
release_channel?: "stable" | "dev" | "ptb" | "canary";
|
||||
client_build_number?: number;
|
||||
client_event_source?: any;
|
||||
client_version?: string;
|
||||
system_locale?: 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;
|
||||
largeThreshold?: number;
|
||||
shard?: [bigint, bigint];
|
||||
guild_subscriptions?: boolean;
|
||||
capabilities?: number;
|
||||
client_state?: {
|
||||
guild_hashes?: any;
|
||||
highest_last_message_id?: string | number;
|
||||
read_state_version?: number;
|
||||
user_guild_settings_version?: number;
|
||||
user_settings_version?: number;
|
||||
useruser_guild_settings_version?: number;
|
||||
};
|
||||
clientState?: {
|
||||
guildHashes?: any;
|
||||
highestLastMessageId?: string | number;
|
||||
readStateVersion?: number;
|
||||
userGuildSettingsVersion?: number;
|
||||
useruserGuildSettingsVersion?: number;
|
||||
};
|
||||
v?: number;
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
export interface LazyRequest {
|
||||
guild_id: string;
|
||||
channels?: Record<string, [number, number][]>;
|
||||
activities?: boolean;
|
||||
threads?: boolean;
|
||||
typing?: true;
|
||||
members?: any[];
|
||||
thread_member_lists?: any[];
|
||||
}
|
||||
|
||||
export const LazyRequest = {
|
||||
guild_id: String,
|
||||
$activities: Boolean,
|
||||
$channels: Object,
|
||||
$typing: Boolean,
|
||||
$threads: Boolean,
|
||||
$members: [] as any[],
|
||||
$thread_member_lists: [] as any[],
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
export const VoiceStateUpdateSchema = {
|
||||
$guild_id: String,
|
||||
$channel_id: String,
|
||||
self_mute: Boolean,
|
||||
self_deaf: Boolean,
|
||||
$self_video: Boolean, //required in docs but bots don't always send it
|
||||
$preferred_region: String,
|
||||
};
|
||||
|
||||
export interface VoiceStateUpdateSchema {
|
||||
guild_id?: string;
|
||||
channel_id?: string;
|
||||
self_mute: boolean;
|
||||
self_deaf: boolean;
|
||||
self_video?: boolean;
|
||||
preferred_region?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user