mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
fix(ws/shard): update status update payload (#559)
* fix(ws/shard): update status update payload * :( * Update src/types/discord.ts Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com> * it\'s activitypayload * Update src/types/discord.ts * idk * idk Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
} from "./guild.ts";
|
||||
import { MemberCreatePayload } from "./member.ts";
|
||||
import { Activity, Application } from "./message.ts";
|
||||
import { ActivityPayload } from "./mod.ts";
|
||||
import { ClientStatusPayload } from "./presence.ts";
|
||||
|
||||
export interface DiscordPayload {
|
||||
@@ -363,3 +364,15 @@ export interface InviteDeleteEvent {
|
||||
/** the unique invite code */
|
||||
code: string;
|
||||
}
|
||||
|
||||
/** https://discord.com/developers/docs/topics/gateway#update-status-gateway-status-update-structure */
|
||||
export interface GatewayStatusUpdatePayload {
|
||||
/** unix time (in milliseconds) of when the client went idle, or null if the client is not idle */
|
||||
since: number | null;
|
||||
/** null, or the user's activities */
|
||||
activities: Pick<ActivityPayload, "name" | "type" | "url">[] | null;
|
||||
/** the user's new status */
|
||||
status: StatusType;
|
||||
/** whether or not the client is afk */
|
||||
afk: boolean;
|
||||
}
|
||||
|
||||
+16
-14
@@ -1,30 +1,32 @@
|
||||
import { encode } from "../../deps.ts";
|
||||
import {
|
||||
Activity,
|
||||
ActivityType,
|
||||
GatewayOpcode,
|
||||
GatewayStatusUpdatePayload,
|
||||
ImageFormats,
|
||||
ImageSize,
|
||||
StatusType,
|
||||
} from "../types/mod.ts";
|
||||
import { sendGatewayCommand } from "../ws/shard_manager.ts";
|
||||
import { basicShards, sendWS } from "../ws/shard.ts";
|
||||
|
||||
export const sleep = (timeout: number) => {
|
||||
return new Promise((resolve) => setTimeout(resolve, timeout));
|
||||
};
|
||||
|
||||
export interface BotStatusRequest {
|
||||
status: StatusType;
|
||||
game: {
|
||||
name?: string;
|
||||
type: ActivityType;
|
||||
};
|
||||
}
|
||||
|
||||
export function editBotsStatus(
|
||||
status: StatusType,
|
||||
name?: string,
|
||||
type = ActivityType.Game,
|
||||
export function editBotStatus(
|
||||
data: Pick<GatewayStatusUpdatePayload, "activities" | "status">,
|
||||
) {
|
||||
sendGatewayCommand("EDIT_BOTS_STATUS", { status, game: { name, type } });
|
||||
basicShards.forEach((shard) => {
|
||||
sendWS({
|
||||
op: GatewayOpcode.StatusUpdate,
|
||||
d: {
|
||||
since: null,
|
||||
afk: false,
|
||||
...data,
|
||||
},
|
||||
}, shard.id);
|
||||
});
|
||||
}
|
||||
|
||||
export function chooseRandom<T>(array: T[]) {
|
||||
|
||||
+3
-21
@@ -6,14 +6,15 @@ import {
|
||||
DiscordPayload,
|
||||
FetchMembersOptions,
|
||||
GatewayOpcode,
|
||||
GatewayStatusUpdatePayload,
|
||||
ReadyPayload,
|
||||
} from "../types/mod.ts";
|
||||
import { BotStatusRequest, delay } from "../util/utils.ts";
|
||||
import { delay } from "../util/utils.ts";
|
||||
import { decompressWith } from "./deps.ts";
|
||||
import { handleDiscordPayload } from "./shard_manager.ts";
|
||||
import { Collection } from "../util/collection.ts";
|
||||
|
||||
const basicShards = new Collection<number, BasicShard>();
|
||||
export const basicShards = new Collection<number, BasicShard>();
|
||||
const heartbeating = new Map<number, boolean>();
|
||||
const utf8decoder = new TextDecoder();
|
||||
const RequestMembersQueue: RequestMemberQueuedRequest[] = [];
|
||||
@@ -383,25 +384,6 @@ async function processGatewayQueue() {
|
||||
await processGatewayQueue();
|
||||
}
|
||||
|
||||
export function botGatewayStatusRequest(payload: BotStatusRequest) {
|
||||
basicShards.forEach((shard) => {
|
||||
sendWS({
|
||||
op: GatewayOpcode.StatusUpdate,
|
||||
d: {
|
||||
since: null,
|
||||
game: payload.game.name
|
||||
? {
|
||||
name: payload.game.name,
|
||||
type: payload.game.type,
|
||||
}
|
||||
: null,
|
||||
status: payload.status,
|
||||
afk: false,
|
||||
},
|
||||
}, shard.id);
|
||||
});
|
||||
}
|
||||
|
||||
/** Enqueues the specified data to be transmitted to the server over the WebSocket connection, */
|
||||
export function sendWS(payload: DiscordPayload, shardID = 0) {
|
||||
const shard = basicShards.get(shardID);
|
||||
|
||||
+3
-18
@@ -8,15 +8,12 @@ import {
|
||||
DiscordPayload,
|
||||
FetchMembersOptions,
|
||||
GatewayOpcode,
|
||||
GatewayStatusUpdatePayload,
|
||||
} from "../types/mod.ts";
|
||||
import { cache } from "../util/cache.ts";
|
||||
import { Collection } from "../util/collection.ts";
|
||||
import { BotStatusRequest, delay } from "../util/utils.ts";
|
||||
import {
|
||||
botGatewayStatusRequest,
|
||||
createShard,
|
||||
requestGuildMembers,
|
||||
} from "./mod.ts";
|
||||
import { delay } from "../util/utils.ts";
|
||||
import { createShard, requestGuildMembers } from "./mod.ts";
|
||||
|
||||
let createNextShard = true;
|
||||
|
||||
@@ -108,15 +105,3 @@ export async function requestAllMembers(
|
||||
options,
|
||||
);
|
||||
}
|
||||
|
||||
export function sendGatewayCommand(
|
||||
type: "EDIT_BOTS_STATUS",
|
||||
// deno-lint-ignore no-explicit-any
|
||||
payload: Record<string, any>,
|
||||
) {
|
||||
if (type === "EDIT_BOTS_STATUS") {
|
||||
botGatewayStatusRequest(payload as BotStatusRequest);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user