mirror of
https://github.com/swc-project/swc.git
synced 2024-12-21 12:41:54 +03:00
d60c3242af
swc_bundler: - Fix cycle detection for complex circular imports. (denoland/deno#10752) swc_ecma_transforms_typescript: - Allow using large values for an enum variant.
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
// Loaded from https://deno.land/x/discordeno@11.0.0-rc.2/src/helpers/templates/create_guild_from_template.ts
|
|
|
|
|
|
import { cacheHandlers } from "../../cache.ts";
|
|
import { rest } from "../../rest/rest.ts";
|
|
import { structures } from "../../structures/mod.ts";
|
|
import type { Guild } from "../../types/guilds/guild.ts";
|
|
import type { CreateGuildFromTemplate } from "../../types/templates/create_guild_from_template.ts";
|
|
import { endpoints } from "../../util/constants.ts";
|
|
import { urlToBase64 } from "../../util/utils.ts";
|
|
import { ws } from "../../ws/ws.ts";
|
|
|
|
/**
|
|
* Create a new guild based on a template
|
|
* NOTE: This endpoint can be used only by bots in less than 10 guilds.
|
|
*/
|
|
export async function createGuildFromTemplate(templateCode: string, data: CreateGuildFromTemplate) {
|
|
if ((await cacheHandlers.size("guilds")) >= 10) {
|
|
throw new Error("This function can only be used by bots in less than 10 guilds.");
|
|
}
|
|
|
|
if (data.icon) {
|
|
data.icon = await urlToBase64(data.icon);
|
|
}
|
|
|
|
const createdGuild = await rest.runMethod<Guild>("post", endpoints.GUILD_TEMPLATE(templateCode), data);
|
|
|
|
return await structures.createDiscordenoGuild(
|
|
createdGuild,
|
|
Number((BigInt(createdGuild.id) >> 22n % BigInt(ws.botGatewayData.shards)).toString())
|
|
);
|
|
}
|