mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
add sendShardMessage
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { DiscordGatewayOpcodes } from "../../types/codes/gateway_opcodes.ts";
|
import { DiscordGatewayOpcodes } from "../../types/codes/gateway_opcodes.ts";
|
||||||
import type { StatusUpdate } from "../../types/gateway/status_update.ts";
|
import type { StatusUpdate } from "../../types/gateway/status_update.ts";
|
||||||
|
import { sendShardMessage } from "../../ws/send_shard_message.ts";
|
||||||
import { ws } from "../../ws/ws.ts";
|
import { ws } from "../../ws/ws.ts";
|
||||||
|
|
||||||
export function editBotStatus(data: Omit<StatusUpdate, "afk" | "since">) {
|
export function editBotStatus(data: Omit<StatusUpdate, "afk" | "since">) {
|
||||||
@@ -10,7 +11,7 @@ export function editBotStatus(data: Omit<StatusUpdate, "afk" | "since">) {
|
|||||||
`Running forEach loop in editBotStatus function.`,
|
`Running forEach loop in editBotStatus function.`,
|
||||||
);
|
);
|
||||||
|
|
||||||
shard.queue.push({
|
sendShardMessage(shard, {
|
||||||
op: DiscordGatewayOpcodes.StatusUpdate,
|
op: DiscordGatewayOpcodes.StatusUpdate,
|
||||||
d: {
|
d: {
|
||||||
since: null,
|
since: null,
|
||||||
@@ -18,6 +19,5 @@ export function editBotStatus(data: Omit<StatusUpdate, "afk" | "since">) {
|
|||||||
...data,
|
...data,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
ws.processQueue(shard.id);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -1,5 +1,6 @@
|
|||||||
import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts";
|
import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts";
|
||||||
import { closeWS } from "./close_ws.ts";
|
import { closeWS } from "./close_ws.ts";
|
||||||
|
import { sendShardMessage } from "./send_shard_message.ts";
|
||||||
import { ws } from "./ws.ts";
|
import { ws } from "./ws.ts";
|
||||||
|
|
||||||
export async function identify(shardId: number, maxShards: number) {
|
export async function identify(shardId: number, maxShards: number) {
|
||||||
@@ -40,11 +41,10 @@ export async function identify(shardId: number, maxShards: number) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
socket.onopen = () => {
|
socket.onopen = () => {
|
||||||
ws.shards.get(shardId)?.queue.unshift({
|
sendShardMessage(shardId, {
|
||||||
op: DiscordGatewayOpcodes.Identify,
|
op: DiscordGatewayOpcodes.Identify,
|
||||||
d: { ...ws.identifyPayload, shard: [shardId, maxShards] },
|
d: { ...ws.identifyPayload, shard: [shardId, maxShards] },
|
||||||
});
|
}, true);
|
||||||
ws.processQueue(shardId);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import { DiscordenoShard, WebSocketRequest, ws } from "./ws.ts";
|
||||||
|
|
||||||
|
export function sendShardMessage(
|
||||||
|
shard: number | DiscordenoShard,
|
||||||
|
message: WebSocketRequest,
|
||||||
|
highPriority = false,
|
||||||
|
) {
|
||||||
|
if (typeof shard === "number") shard = ws.shards.get(shard)!;
|
||||||
|
if (!shard) return;
|
||||||
|
|
||||||
|
if (!highPriority) {
|
||||||
|
shard.queue.push(message);
|
||||||
|
} else {
|
||||||
|
shard.queue.unshift(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
ws.processQueue(shard.id);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user