Files
discordeno/src/utils/utils.ts
T
ITOH 7bdbcb76d6 refactor: centralize types (#235)
* Centralize types and structures

* Resolve Conflict

* Update cache.ts
2020-12-08 22:23:36 +04:00

35 lines
951 B
TypeScript

import { encode } from "../../deps.ts";
import { sendGatewayCommand } from "../module/shardingManager.ts";
import { ActivityType, StatusType } from "../types/types.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,
) {
sendGatewayCommand("EDIT_BOTS_STATUS", { status, game: { name, type } });
}
export function chooseRandom<T>(array: T[]) {
return array[Math.floor(Math.random() * array.length)];
}
export async function urlToBase64(url: string) {
const buffer = await fetch(url).then((res) => res.arrayBuffer());
const imageStr = encode(buffer);
const type = url.substring(url.lastIndexOf(".") + 1);
return `data:image/${type};base64,${imageStr}`;
}