summary refs log tree commit diff
path: root/src/gateway/opcodes
diff options
context:
space:
mode:
Diffstat (limited to 'src/gateway/opcodes')
-rw-r--r--src/gateway/opcodes/GuildSync.ts8
-rw-r--r--src/gateway/opcodes/RequestChannelInfo.ts8
-rw-r--r--src/gateway/opcodes/RequestChannelStatuses.ts7
-rw-r--r--src/gateway/opcodes/RequestGuildMembers.ts8
4 files changed, 25 insertions, 6 deletions
diff --git a/src/gateway/opcodes/GuildSync.ts b/src/gateway/opcodes/GuildSync.ts

index 34bfdb90..6a427ad7 100644 --- a/src/gateway/opcodes/GuildSync.ts +++ b/src/gateway/opcodes/GuildSync.ts
@@ -31,8 +31,9 @@ import { timePromise, Stopwatch, Guild, + Config, } from "@spacebar/util"; -import { WebSocket, Payload, handlePresenceUpdate, OPCODES, Send, getMostRelevantSession } from "@spacebar/gateway"; +import { WebSocket, Payload, handlePresenceUpdate, OPCODES, Send, getMostRelevantSession, handleOffloadedGatewayRequest } from "@spacebar/gateway"; import murmur from "murmurhash-js/murmurhash3_gc"; import { check } from "./instanceOf"; import { LazyRequestSchema, PublicMember } from "@spacebar/schemas"; @@ -45,6 +46,11 @@ import { In } from "typeorm"; export async function onGuildSync(this: WebSocket, { d }: Payload) { const sw = Stopwatch.startNew(); if (!Array.isArray(d)) throw new Error("Invalid payload for GUILD_SYNC"); + + if (Config.get().offload.gateway.guildSyncUrl !== null) { + return await handleOffloadedGatewayRequest(this, Config.get().offload.gateway.guildSyncUrl!, d); + } + const guild_ids = d as string[]; const joinedGuildIds = await Member.find({ where: { id: this.user_id, guild_id: In(guild_ids) }, select: { guild_id: true } }).then((members) => diff --git a/src/gateway/opcodes/RequestChannelInfo.ts b/src/gateway/opcodes/RequestChannelInfo.ts
index f0c7e9ce..efa3e728 100644 --- a/src/gateway/opcodes/RequestChannelInfo.ts +++ b/src/gateway/opcodes/RequestChannelInfo.ts
@@ -16,15 +16,19 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { WebSocket, Payload, OPCODES, Send } from "@spacebar/gateway"; +import { WebSocket, Payload, OPCODES, Send, handleOffloadedGatewayRequest } from "@spacebar/gateway"; import { ChannelType } from "@spacebar/schemas"; -import { Channel } from "@spacebar/util"; +import { Channel, Config } from "@spacebar/util"; export async function onRequestChannelInfo(this: WebSocket, { d }: Payload) { // Schema validation can only accept either string or array, so transforming it here to support both if (!d.guild_id) throw new Error('"guild_id" is required'); if (!d.fields) throw new Error('"fields" is required'); + if (Config.get().offload.gateway.channelInfoUrl !== null) { + return await handleOffloadedGatewayRequest(this, Config.get().offload.gateway.channelInfoUrl!, d); + } + const channels = ( await Channel.find({ where: { guild_id: d.guild_id, type: ChannelType.GUILD_VOICE }, diff --git a/src/gateway/opcodes/RequestChannelStatuses.ts b/src/gateway/opcodes/RequestChannelStatuses.ts
index 533ece22..1747faae 100644 --- a/src/gateway/opcodes/RequestChannelStatuses.ts +++ b/src/gateway/opcodes/RequestChannelStatuses.ts
@@ -16,12 +16,17 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { WebSocket, Payload, OPCODES, Send } from "@spacebar/gateway"; +import { WebSocket, Payload, OPCODES, Send, handleOffloadedGatewayRequest } from "@spacebar/gateway"; +import { Config } from "@spacebar/util"; export async function onRequestChannelStatuses(this: WebSocket, { d }: Payload) { // Schema validation can only accept either string or array, so transforming it here to support both if (!d.guild_id) throw new Error('"guild_id" is required'); + if (Config.get().offload.gateway.channelStatusesUrl !== null) { + return await handleOffloadedGatewayRequest(this, Config.get().offload.gateway.channelStatusesUrl!, d); + } + // TODO: implement await Send(this, { op: OPCODES.Dispatch, diff --git a/src/gateway/opcodes/RequestGuildMembers.ts b/src/gateway/opcodes/RequestGuildMembers.ts
index 0e65b6cc..cba2c89c 100644 --- a/src/gateway/opcodes/RequestGuildMembers.ts +++ b/src/gateway/opcodes/RequestGuildMembers.ts
@@ -16,8 +16,8 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -import { DateBuilder, getDatabase, getPermission, GuildMembersChunkEvent, Member, Presence, Session } from "@spacebar/util"; -import { WebSocket, Payload, OPCODES, Send } from "@spacebar/gateway"; +import { Config, DateBuilder, getDatabase, getPermission, GuildMembersChunkEvent, Member, Presence, Session } from "@spacebar/util"; +import { WebSocket, Payload, OPCODES, Send, handleOffloadedGatewayRequest } from "@spacebar/gateway"; import { check } from "./instanceOf"; import { FindManyOptions, ILike, In, MoreThan } from "typeorm"; import { RequestGuildMembersSchema } from "@spacebar/schemas"; @@ -30,6 +30,10 @@ export async function onRequestGuildMembers(this: WebSocket, { d }: Payload) { if (d.user_ids && !Array.isArray(d.user_ids)) d.user_ids = [d.user_ids]; + if (Config.get().offload.gateway.guildMembersUrl !== null) { + return await handleOffloadedGatewayRequest(this, Config.get().offload.gateway.guildMembersUrl!, d); + } + check.call(this, RequestGuildMembersSchema, d); const { presences, nonce, query: requestQuery } = d as RequestGuildMembersSchema;