Files
discordeno/src/helpers/guilds/edit_guild.ts
T
Skillz4Killz 3d39b3878a change: ids to use bigint instead of string (#892)
* p1 of bigints change

* shtuff fixes and bits

* Commit from GitHub Actions (Lint)

* finish bigint structs

* typings fixes

* Commit from GitHub Actions (Lint)

* more fixes

* Commit from GitHub Actions (Lint)

* more fixes

* Commit from GitHub Actions (Lint)

* blame wolf

* Commit from GitHub Actions (Lint)

* foxed

* Commit from GitHub Actions (Lint)

* fix unit tests

* Commit from GitHub Actions (Lint)

* change: guildUpdate guild ID can't change

* delete server has been renamed to delete guild

* fixes

Co-authored-by: Skillz4Killz <Skillz4Killz@users.noreply.github.com>
Co-authored-by: ITOH <72305210+itohatweb@users.noreply.github.com>
2021-05-03 18:05:18 +01:00

43 lines
1.4 KiB
TypeScript

import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { Guild } from "../../types/guilds/guild.ts";
import { ModifyGuild } from "../../types/guilds/modify_guild.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { urlToBase64 } from "../../util/utils.ts";
import { ws } from "../../ws/ws.ts";
/** Modify a guilds settings. Requires the MANAGE_GUILD permission. */
export async function editGuild(guildId: bigint, options: ModifyGuild) {
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
if (options.icon && !options.icon.startsWith("data:image/")) {
options.icon = await urlToBase64(options.icon);
}
if (options.banner && !options.banner.startsWith("data:image/")) {
options.banner = await urlToBase64(options.banner);
}
if (options.splash && !options.splash.startsWith("data:image/")) {
options.splash = await urlToBase64(options.splash);
}
const result = await rest.runMethod<Guild>(
"patch",
endpoints.GUILDS_BASE(guildId),
options,
);
const cached = await cacheHandlers.get("guilds", guildId);
return structures.createDiscordenoGuild(
result,
cached?.shardId ||
Number(
(BigInt(result.id) >> 22n % BigInt(ws.botGatewayData.shards))
.toString(),
),
);
}