refactor: move edit_bot_status to another file in helpers (#838)

This commit is contained in:
Skillz4Killz
2021-04-12 11:17:55 -04:00
committed by GitHub
parent ef9aa237bb
commit af3dbf1564
2 changed files with 23 additions and 25 deletions

View File

@@ -0,0 +1,23 @@
import { eventHandlers } from "../../bot.ts";
import { DiscordGatewayOpcodes } from "../../types/codes/gateway_opcodes.ts";
import { StatusUpdate } from "../../types/gateway/status_update.ts";
import { ws } from "../../ws/ws.ts";
export function editBotStatus(data: Omit<StatusUpdate, "afk" | "since">) {
ws.shards.forEach((shard) => {
eventHandlers.debug?.(
"loop",
`Running forEach loop in editBotStatus function.`
);
shard.ws.send(
JSON.stringify({
op: DiscordGatewayOpcodes.StatusUpdate,
d: {
since: null,
afk: false,
...data,
},
})
);
});
}

View File

@@ -1,36 +1,11 @@
import { encode } from "../../deps.ts";
import { eventHandlers } from "../bot.ts";
import { DiscordGatewayOpcodes } from "../types/codes/gateway_opcodes.ts";
import { StatusUpdate } from "../types/gateway/status_update.ts";
import { DiscordApplicationCommandOptionTypes } from "../types/interactions/application_command_option_types.ts";
import { Errors } from "../types/misc/errors.ts";
import { DiscordImageFormat } from "../types/misc/image_format.ts";
import { DiscordImageSize } from "../types/misc/image_size.ts";
import { ws } from "../ws/ws.ts";
import { SLASH_COMMANDS_NAME_REGEX } from "./constants.ts";
// TODO: move this function to helpers
export function editBotStatus(
data: Omit<StatusUpdate, "afk" | "since">,
) {
ws.shards.forEach((shard) => {
eventHandlers.debug?.(
"loop",
`Running forEach loop in editBotStatus function.`,
);
shard.ws.send(
JSON.stringify({
op: DiscordGatewayOpcodes.StatusUpdate,
d: {
since: null,
afk: false,
...data,
},
}),
);
});
}
export async function urlToBase64(url: string) {
const buffer = await fetch(url).then((res) => res.arrayBuffer());
const imageStr = encode(buffer);