summary refs log tree commit diff
path: root/src/gateway
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/gateway/events/Message.ts20
-rw-r--r--src/gateway/opcodes/Identify.ts2
-rw-r--r--src/gateway/opcodes/LazyRequest.ts7
-rw-r--r--src/gateway/opcodes/PresenceUpdate.ts3
-rw-r--r--src/gateway/opcodes/VoiceStateUpdate.ts2
-rw-r--r--src/util/schemas/ActivitySchema.ts (renamed from src/gateway/schema/Activity.ts)2
-rw-r--r--src/util/schemas/IdentifySchema.ts (renamed from src/gateway/schema/Identify.ts)2
-rw-r--r--src/util/schemas/LazyRequestSchema.ts (renamed from src/gateway/schema/LazyRequest.ts)4
-rw-r--r--src/util/schemas/VoiceStateUpdateSchema.ts (renamed from src/gateway/schema/VoiceStateUpdateSchema.ts)25
9 files changed, 35 insertions, 32 deletions
diff --git a/src/gateway/events/Message.ts b/src/gateway/events/Message.ts

index db7dbad2..4699f1af 100644 --- a/src/gateway/events/Message.ts +++ b/src/gateway/events/Message.ts
@@ -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); diff --git a/src/gateway/opcodes/Identify.ts b/src/gateway/opcodes/Identify.ts
index 3c40962c..b4b36075 100644 --- a/src/gateway/opcodes/Identify.ts +++ b/src/gateway/opcodes/Identify.ts
@@ -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"; diff --git a/src/gateway/opcodes/LazyRequest.ts b/src/gateway/opcodes/LazyRequest.ts
index 82342224..0f21d087 100644 --- a/src/gateway/opcodes/LazyRequest.ts +++ b/src/gateway/opcodes/LazyRequest.ts
@@ -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; diff --git a/src/gateway/opcodes/PresenceUpdate.ts b/src/gateway/opcodes/PresenceUpdate.ts
index 415df6ee..d17b7dd7 100644 --- a/src/gateway/opcodes/PresenceUpdate.ts +++ b/src/gateway/opcodes/PresenceUpdate.ts
@@ -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) { diff --git a/src/gateway/opcodes/VoiceStateUpdate.ts b/src/gateway/opcodes/VoiceStateUpdate.ts
index fa63f7fc..8e1585ec 100644 --- a/src/gateway/opcodes/VoiceStateUpdate.ts +++ b/src/gateway/opcodes/VoiceStateUpdate.ts
@@ -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. diff --git a/src/gateway/schema/Activity.ts b/src/util/schemas/ActivitySchema.ts
index f58b0fa9..d316420e 100644 --- a/src/gateway/schema/Activity.ts +++ b/src/util/schemas/ActivitySchema.ts
@@ -57,4 +57,4 @@ export interface ActivitySchema { status: Status; activities?: Activity[]; since?: number; // unix time (in milliseconds) of when the client went idle, or null if the client is not idle -} +} \ No newline at end of file diff --git a/src/gateway/schema/Identify.ts b/src/util/schemas/IdentifySchema.ts
index 6f68b515..409a03da 100644 --- a/src/gateway/schema/Identify.ts +++ b/src/util/schemas/IdentifySchema.ts
@@ -1,4 +1,4 @@ -import { ActivitySchema } from "./Activity"; +import { ActivitySchema } from "@fosscord/util"; export const IdentifySchema = { token: String, diff --git a/src/gateway/schema/LazyRequest.ts b/src/util/schemas/LazyRequestSchema.ts
index 1fe658bb..e9f2df20 100644 --- a/src/gateway/schema/LazyRequest.ts +++ b/src/util/schemas/LazyRequestSchema.ts
@@ -1,4 +1,4 @@ -export interface LazyRequest { +export interface LazyRequestSchema { guild_id: string; channels?: Record<string, [number, number][]>; activities?: boolean; @@ -8,7 +8,7 @@ export interface LazyRequest { thread_member_lists?: any[]; } -export const LazyRequest = { +export const LazyRequestSchema = { guild_id: String, $activities: Boolean, $channels: Object, diff --git a/src/gateway/schema/VoiceStateUpdateSchema.ts b/src/util/schemas/VoiceStateUpdateSchema.ts
index f6480414..5f805f4d 100644 --- a/src/gateway/schema/VoiceStateUpdateSchema.ts +++ b/src/util/schemas/VoiceStateUpdateSchema.ts
@@ -1,12 +1,4 @@ -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, -}; - +//TODO need more testing when community guild and voice stage channel are working export interface VoiceStateUpdateSchema { guild_id?: string; channel_id?: string; @@ -14,4 +6,17 @@ export interface VoiceStateUpdateSchema { self_deaf: boolean; self_video?: boolean; preferred_region?: string; -} \ No newline at end of file + request_to_speak_timestamp?: Date; + suppress?: boolean; +} + +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, + $request_to_speak_timestamp: Date, + $suppress: Boolean, +}; \ No newline at end of file