mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
Guilds helpers
This commit is contained in:
@@ -1,22 +1,28 @@
|
||||
import { botId } from "../../bot.ts";
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import type { CreateGuild } from "../../types/guilds/create_guild.ts";
|
||||
import type { Guild } from "../../types/guilds/guild.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { snakelize } from "../../util/utils.ts";
|
||||
import { getMember } from "../members/get_member.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Create a new guild. Returns a guild object on success. Fires a Guild Create Gateway event. This endpoint can be used only by bots in less than 10 guilds. */
|
||||
export async function createGuild(options: CreateGuild) {
|
||||
const result = await rest.runMethod<Guild>("post", endpoints.GUILDS, snakelize(options));
|
||||
export async function createGuild(bot: Bot, options: CreateGuild) {
|
||||
const result = await bot.rest.runMethod<Guild>(bot.rest,"post", bot.constants.endpoints.GUILDS, {
|
||||
name: options.name,
|
||||
afk_channel_id: options.afkChannelId,
|
||||
afk_timeout: options.afkTimeout,
|
||||
channels: options.channels,
|
||||
default_message_notifications: options.defaultMessageNotifications,
|
||||
explicit_content_filter: options.explicitContentFilter,
|
||||
icon: options.icon,
|
||||
roles: options.roles,
|
||||
system_channel_flags: options.systemChannelFlags,
|
||||
system_channel_id: options.systemChannelId,
|
||||
verification_level: options.verificationLevel
|
||||
});
|
||||
|
||||
const guild = await structures.createDiscordenoGuild(result, 0);
|
||||
const guild = bot.transformers.guild(bot, {guild: result, shardId: 0});
|
||||
// MANUALLY CACHE THE GUILD
|
||||
await cacheHandlers.set("guilds", guild.id, guild);
|
||||
await bot.cache.guilds.set(guild.id, guild);
|
||||
// MANUALLY CACHE THE BOT
|
||||
await getMember(guild.id, botId);
|
||||
await bot.helpers.getMember(bot, guild.id, bot.id);
|
||||
|
||||
return guild;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Delete a guild permanently. User must be owner. Returns 204 No Content on success. Fires a Guild Delete Gateway event. */
|
||||
export async function deleteGuild(guildId: bigint) {
|
||||
return await rest.runMethod<undefined>("delete", endpoints.GUILDS_BASE(guildId));
|
||||
export async function deleteGuild(bot: Bot, guildId: bigint) {
|
||||
return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.GUILDS_BASE(guildId));
|
||||
}
|
||||
|
||||
@@ -1,34 +1,33 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { structures } from "../../structures/mod.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { Guild } from "../../types/guilds/guild.ts";
|
||||
import type { ModifyGuild } from "../../types/guilds/modify_guild.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import { snakelize, 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"]);
|
||||
export async function editGuild(bot: Bot, guildId: bigint, options: ModifyGuild) {
|
||||
await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
if (options.icon && !options.icon.startsWith("data:image/")) {
|
||||
options.icon = await urlToBase64(options.icon);
|
||||
options.icon = await bot.utils.urlToBase64(options.icon);
|
||||
}
|
||||
|
||||
if (options.banner && !options.banner.startsWith("data:image/")) {
|
||||
options.banner = await urlToBase64(options.banner);
|
||||
options.banner = await bot.utils.urlToBase64(options.banner);
|
||||
}
|
||||
|
||||
if (options.splash && !options.splash.startsWith("data:image/")) {
|
||||
options.splash = await urlToBase64(options.splash);
|
||||
options.splash = await bot.utils.urlToBase64(options.splash);
|
||||
}
|
||||
|
||||
const result = await rest.runMethod<Guild>("patch", endpoints.GUILDS_BASE(guildId), snakelize(options));
|
||||
const result = await bot.rest.runMethod<Guild>(bot.rest,"patch", bot.constants.endpoints.GUILDS_BASE(guildId), {
|
||||
|
||||
const cached = await cacheHandlers.get("guilds", guildId);
|
||||
return structures.createDiscordenoGuild(
|
||||
result,
|
||||
cached?.shardId || Number((BigInt(result.id) >> 22n % BigInt(ws.botGatewayData.shards)).toString())
|
||||
});
|
||||
|
||||
const cached = await bot.cache.guilds.get(guildId);
|
||||
return bot.transformers.guild(
|
||||
bot,
|
||||
{
|
||||
guild: result,
|
||||
shardId: cached?.shardId || Number((BigInt(result.id) >> 22n % BigInt(bot.gateway.botGatewayData.shards)).toString())
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,18 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { ModifyGuildWelcomeScreen } from "../../types/guilds/modify_guild_welcome_screen.ts";
|
||||
import type { WelcomeScreen } from "../../types/guilds/welcome_screen.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { snakelize } from "../../util/utils.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
export async function editWelcomeScreen(guildId: bigint, options: ModifyGuildWelcomeScreen) {
|
||||
return await rest.runMethod<WelcomeScreen>("patch", endpoints.GUILD_WELCOME_SCREEN(guildId), snakelize(options));
|
||||
export async function editWelcomeScreen(bot: Bot, guildId: bigint, options: ModifyGuildWelcomeScreen) {
|
||||
return await bot.rest.runMethod<WelcomeScreen>("patch", bot.constants.endpoints.GUILD_WELCOME_SCREEN(guildId), {
|
||||
enabled: options.enabled,
|
||||
welcomeScreen: options.welcomeScreen?.map((welcomeScreen) => {
|
||||
return {
|
||||
channel_id: welcomeScreen.channelId,
|
||||
description: welcomeScreen.description,
|
||||
emoji_id: welcomeScreen.emojiId,
|
||||
emoji_name: welcomeScreen.emojiName
|
||||
}
|
||||
}),
|
||||
description: options.description
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,13 +1,11 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { GuildWidget } from "../../types/guilds/guild_widget.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */
|
||||
export async function editWidget(guildId: bigint, enabled: boolean, channelId?: string | null) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
export async function editWidget(bot: Bot, guildId: bigint, enabled: boolean, channelId?: string | null) {
|
||||
await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return await rest.runMethod<GuildWidget>("patch", endpoints.GUILD_WIDGET(guildId), {
|
||||
return await bot.rest.runMethod<GuildWidget>(bot.rest,"patch", bot.constants.endpoints.GUILD_WIDGET(guildId), {
|
||||
enabled,
|
||||
channel_id: channelId,
|
||||
});
|
||||
|
||||
@@ -1,20 +1,20 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { AuditLog } from "../../types/audit_log/audit_log.ts";
|
||||
import type { GetGuildAuditLog } from "../../types/audit_log/get_guild_audit_log.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import { snakelize } from "../../util/utils.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */
|
||||
export async function getAuditLogs(guildId: bigint, options?: GetGuildAuditLog) {
|
||||
await requireBotGuildPermissions(guildId, ["VIEW_AUDIT_LOG"]);
|
||||
export async function getAuditLogs(bot: Bot, guildId: bigint, options?: GetGuildAuditLog) {
|
||||
await bot.utils.requireBotGuildPermissions(bot, guildId, ["VIEW_AUDIT_LOG"]);
|
||||
|
||||
return await rest.runMethod<AuditLog>(
|
||||
return await bot.rest.runMethod<AuditLog>(
|
||||
bot.rest,
|
||||
"get",
|
||||
endpoints.GUILD_AUDIT_LOGS(guildId),
|
||||
snakelize({
|
||||
...options,
|
||||
bot.constants.endpoints.GUILD_AUDIT_LOGS(guildId),
|
||||
{
|
||||
user_id: options.userId,
|
||||
action_type: options.actionType,
|
||||
before: options.before,
|
||||
limit: options?.limit && options.limit >= 1 && options.limit <= 100 ? options.limit : 50,
|
||||
})
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { VoiceRegion } from "../../types/voice/voice_region.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Returns an array of voice regions that can be used when creating servers. */
|
||||
export async function getAvailableVoiceRegions() {
|
||||
return await rest.runMethod<VoiceRegion>("get", endpoints.VOICE_REGIONS);
|
||||
export async function getAvailableVoiceRegions(bot: Bot) {
|
||||
return await bot.rest.runMethod<VoiceRegion>(bot.rest,"get", bot.constants.endpoints.VOICE_REGIONS);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { Ban } from "../../types/guilds/ban.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Returns a ban object for the given user or a 404 not found if the ban cannot be found. Requires the BAN_MEMBERS permission. */
|
||||
export async function getBan(guildId: bigint, memberId: bigint) {
|
||||
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
||||
export async function getBan(bot: Bot, guildId: bigint, memberId: bigint) {
|
||||
await bot.utils.requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]);
|
||||
|
||||
return await rest.runMethod<Ban>("get", endpoints.GUILD_BAN(guildId, memberId));
|
||||
return await bot.rest.runMethod<Ban>(bot.rest,"get", bot.constants.endpoints.GUILD_BAN(guildId, memberId));
|
||||
}
|
||||
|
||||
@@ -1,15 +1,12 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { Ban } from "../../types/guilds/ban.ts";
|
||||
import { snowflakeToBigint } from "../../util/bigint.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
|
||||
/** Returns a list of ban objects for the users banned from this guild. Requires the BAN_MEMBERS permission. */
|
||||
export async function getBans(guildId: bigint) {
|
||||
await requireBotGuildPermissions(guildId, ["BAN_MEMBERS"]);
|
||||
export async function getBans(bot: Bot, guildId: bigint) {
|
||||
await bot.utils.requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]);
|
||||
|
||||
const results = await rest.runMethod<Ban[]>("get", endpoints.GUILD_BANS(guildId));
|
||||
const results = await bot.rest.runMethod<Ban[]>(bot.rest,"get", bot.constants.endpoints.GUILD_BANS(guildId));
|
||||
|
||||
return new Collection<bigint, Ban>(results.map((res) => [snowflakeToBigint(res.user.id), res]));
|
||||
return new Collection<bigint, Ban>(results.map((res) => [bot.transformers.snowflake(res.user.id), res]));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
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 { endpoints } from "../../util/constants.ts";
|
||||
import { ws } from "../../ws/ws.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/**
|
||||
* ⚠️ **If you need this, you are probably doing something wrong. Always use cache.guilds.get()
|
||||
@@ -13,23 +9,27 @@ import { ws } from "../../ws/ws.ts";
|
||||
* So it does not cache the guild, you must do it manually.
|
||||
* */
|
||||
export async function getGuild(
|
||||
guildId: bigint,
|
||||
options: { counts?: boolean; addToCache?: boolean } = {
|
||||
counts: true,
|
||||
addToCache: true,
|
||||
}
|
||||
bot: Bot,
|
||||
guildId: bigint,
|
||||
options: { counts?: boolean; addToCache?: boolean } = {
|
||||
counts: true,
|
||||
addToCache: true,
|
||||
}
|
||||
) {
|
||||
const result = await rest.runMethod<Guild>("get", endpoints.GUILDS_BASE(guildId), {
|
||||
const result = await bot.rest.runMethod<Guild>(bot.rest,"get", bot.constants.endpoints.GUILDS_BASE(guildId), {
|
||||
with_counts: options.counts,
|
||||
});
|
||||
|
||||
const guild = await structures.createDiscordenoGuild(
|
||||
result,
|
||||
Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards))
|
||||
const guild = await bot.transformers.guild(
|
||||
bot,
|
||||
{
|
||||
guild: result,
|
||||
shardId: Number((BigInt(guildId) >> 22n) % BigInt(ws.botGatewayData.shards))
|
||||
}
|
||||
);
|
||||
|
||||
if (options.addToCache) {
|
||||
await cacheHandlers.set("guilds", guild.id, guild);
|
||||
await bot.cache.guilds.set(guild.id, guild);
|
||||
}
|
||||
|
||||
return guild;
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { GuildPreview } from "../../types/guilds/guild_preview.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Returns the guild preview object for the given id. If the bot is not in the guild, then the guild must be Discoverable. */
|
||||
export async function getGuildPreview(guildId: bigint) {
|
||||
return await rest.runMethod<GuildPreview>("get", endpoints.GUILD_PREVIEW(guildId));
|
||||
export async function getGuildPreview(bot: Bot, guildId: bigint) {
|
||||
return await bot.rest.runMethod<GuildPreview>(bot.rest,"get", bot.constants.endpoints.GUILD_PREVIEW(guildId));
|
||||
}
|
||||
|
||||
@@ -1,20 +1,19 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { Errors } from "../../types/discordeno/errors.ts";
|
||||
import type { GetGuildPruneCountQuery } from "../../types/guilds/get_guild_prune_count.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import { snakelize } from "../../util/utils.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */
|
||||
export async function getPruneCount(guildId: bigint, options?: GetGuildPruneCountQuery) {
|
||||
if (options?.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
|
||||
export async function getPruneCount(bot: Bot, guildId: bigint, options?: GetGuildPruneCountQuery) {
|
||||
if (options?.days && options.days < 1) throw new Error(bot.constants.Errors.PRUNE_MIN_DAYS);
|
||||
if (options?.days && options.days > 30) {
|
||||
throw new Error(Errors.PRUNE_MAX_DAYS);
|
||||
throw new Error(bot.constants.Errors.PRUNE_MAX_DAYS);
|
||||
}
|
||||
|
||||
await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
|
||||
await bot.utils.requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
|
||||
|
||||
const result = await rest.runMethod("get", endpoints.GUILD_PRUNE(guildId), snakelize(options ?? {}));
|
||||
const result = await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.GUILD_PRUNE(guildId), options ? {
|
||||
days: options.days,
|
||||
include_roles: options.includeRoles
|
||||
} : {});
|
||||
|
||||
return result.pruned as number;
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { InviteMetadata } from "../../types/invites/invite_metadata.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Returns the code and uses of the vanity url for this server if it is enabled else `code` will be null. Requires the `MANAGE_GUILD` permission. */
|
||||
export async function getVanityURL(guildId: bigint) {
|
||||
return await rest.runMethod<
|
||||
export async function getVanityURL(bot: Bot, guildId: bigint) {
|
||||
return await bot.rest.runMethod<
|
||||
| (Partial<InviteMetadata> & Pick<InviteMetadata, "uses" | "code">)
|
||||
| {
|
||||
code: null;
|
||||
}
|
||||
>("get", endpoints.GUILD_VANITY_URL(guildId));
|
||||
>(bot.rest,"get", bot.constants.endpoints.GUILD_VANITY_URL(guildId));
|
||||
}
|
||||
@@ -1,11 +1,10 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { VoiceRegion } from "../../types/voice/voice_region.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */
|
||||
export async function getVoiceRegions(guildId: bigint) {
|
||||
const result = await rest.runMethod<VoiceRegion[]>("get", endpoints.GUILD_REGIONS(guildId));
|
||||
export async function getVoiceRegions(boot: Bot, guildId: bigint) {
|
||||
const result = await bot.rest.runMethod<VoiceRegion[]>(bot.rest,"get", bot.constants.endpoints.GUILD_REGIONS(guildId));
|
||||
|
||||
return new Collection<string, VoiceRegion>(result.map((region) => [region.id, region]));
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { WelcomeScreen } from "../../types/guilds/welcome_screen.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
export async function getWelcomeScreen(guildId: bigint) {
|
||||
return await rest.runMethod<WelcomeScreen>("get", endpoints.GUILD_WELCOME_SCREEN(guildId));
|
||||
export async function getWelcomeScreen(bot: Bot, guildId: bigint) {
|
||||
return await bot.rest.runMethod<WelcomeScreen>(bot.rset,"get", bot.constants.endpoints.GUILD_WELCOME_SCREEN(guildId));
|
||||
}
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { GuildWidgetDetails } from "../../types/guilds/guild_widget_details.ts";
|
||||
import { Errors } from "../../types/discordeno/errors.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Returns the widget for the guild. */
|
||||
export async function getWidget(guildId: bigint, options?: { force: boolean }) {
|
||||
export async function getWidget(bot: Bot, guildId: bigint, options?: { force: boolean }) {
|
||||
if (!options?.force) {
|
||||
const guild = await cacheHandlers.get("guilds", guildId);
|
||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||
if (!guild?.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
|
||||
const guild = await bot.cacahe.guilds.get(guildId);
|
||||
if (!guild) throw new Error(bot.constants.Errors.GUILD_NOT_FOUND);
|
||||
if (!guild?.widgetEnabled) throw new Error(bot.constants.Errors.GUILD_WIDGET_NOT_ENABLED);
|
||||
}
|
||||
|
||||
return await rest.runMethod<GuildWidgetDetails>("get", `${endpoints.GUILD_WIDGET(guildId)}.json`);
|
||||
return await bot.rest.runMethod<GuildWidgetDetails>(bot.rest,"get", `${bot.constants.endpoints.GUILD_WIDGET(guildId)}.json`);
|
||||
}
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
import { cacheHandlers } from "../../cache.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
import type { GetGuildWidgetImageQuery } from "../../types/guilds/get_guild_widget_image.ts";
|
||||
import { Errors } from "../../types/discordeno/errors.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
|
||||
/** Returns the widget image URL for the guild. */
|
||||
export async function getWidgetImageURL(guildId: bigint, options?: GetGuildWidgetImageQuery & { force?: boolean }) {
|
||||
export async function getWidgetImageURL(bot: Bot, guildId: bigint, options?: GetGuildWidgetImageQuery & { force?: boolean }) {
|
||||
if (!options?.force) {
|
||||
const guild = await cacheHandlers.get("guilds", guildId);
|
||||
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
|
||||
if (!guild.widgetEnabled) throw new Error(Errors.GUILD_WIDGET_NOT_ENABLED);
|
||||
const guild = await bot.cache.guilds.get(guildId);
|
||||
if (!guild) throw new Error(bot.constants.Errors.GUILD_NOT_FOUND);
|
||||
if (!guild.widgetEnabled) throw new Error(bot.constants.Errors.GUILD_WIDGET_NOT_ENABLED);
|
||||
}
|
||||
|
||||
return `${endpoints.GUILD_WIDGET(guildId)}.png?style=${options?.style ?? "shield"}`;
|
||||
return `${bot.constants.endpoints.GUILD_WIDGET(guildId)}.png?style=${options?.style ?? "shield"}`;
|
||||
}
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import type { GuildWidget } from "../../types/guilds/guild_widget.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Returns the guild widget object. Requires the MANAGE_GUILD permission. */
|
||||
export async function getWidgetSettings(guildId: bigint) {
|
||||
await requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
export async function getWidgetSettings(bot: Bot, guildId: bigint) {
|
||||
await bot.utils.requireBotGuildPermissions(guildId, ["MANAGE_GUILD"]);
|
||||
|
||||
return await rest.runMethod<GuildWidget>("get", endpoints.GUILD_WIDGET(guildId));
|
||||
return await bot.rest.runMethod<GuildWidget>(bot.rest,"get", bot.constants.endpoints.GUILD_WIDGET(guildId));
|
||||
}
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import type { DiscordImageFormat } from "../../types/misc/image_format.ts";
|
||||
import type { DiscordImageSize } from "../../types/misc/image_size.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { iconBigintToHash } from "../../util/hash.ts";
|
||||
import { formatImageURL } from "../../util/utils.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** The full URL of the banner from Discords CDN. Undefined if no banner is set. */
|
||||
export function guildBannerURL(
|
||||
bot: Bot,
|
||||
id: bigint,
|
||||
options: {
|
||||
banner?: string | bigint;
|
||||
@@ -15,12 +14,12 @@ export function guildBannerURL(
|
||||
}
|
||||
) {
|
||||
return options.banner
|
||||
? formatImageURL(
|
||||
endpoints.GUILD_BANNER(
|
||||
? bot.utils.formatImageURL(
|
||||
bot.constants.endpoints.GUILD_BANNER(
|
||||
id,
|
||||
typeof options.banner === "string"
|
||||
? options.banner
|
||||
: iconBigintToHash(options.banner, options.animated ?? true)
|
||||
: bot.utils.iconBigintToHash(options.banner, options.animated ?? true)
|
||||
),
|
||||
options.size || 128,
|
||||
options.format
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import type { DiscordImageFormat } from "../../types/misc/image_format.ts";
|
||||
import type { DiscordImageSize } from "../../types/misc/image_size.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { iconBigintToHash } from "../../util/hash.ts";
|
||||
import { formatImageURL } from "../../util/utils.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** The full URL of the icon from Discords CDN. Undefined when no icon is set. */
|
||||
export function guildIconURL(
|
||||
bot: Bot,
|
||||
id: bigint,
|
||||
options: {
|
||||
icon?: string | bigint;
|
||||
@@ -15,10 +14,10 @@ export function guildIconURL(
|
||||
}
|
||||
) {
|
||||
return options.icon
|
||||
? formatImageURL(
|
||||
endpoints.GUILD_ICON(
|
||||
? bot.utils.formatImageURL(
|
||||
bot.constants.endpoints.GUILD_ICON(
|
||||
id,
|
||||
typeof options.icon === "string" ? options.icon : iconBigintToHash(options.icon, options.animated ?? true)
|
||||
typeof options.icon === "string" ? options.icon : bot.utils.iconBigintToHash(options.icon, options.animated ?? true)
|
||||
),
|
||||
options.size || 128,
|
||||
options.format
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import type { DiscordImageFormat } from "../../types/misc/image_format.ts";
|
||||
import type { DiscordImageSize } from "../../types/misc/image_size.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import { iconBigintToHash } from "../../util/hash.ts";
|
||||
import { formatImageURL } from "../../util/utils.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** The full URL of the splash from Discords CDN. Undefined if no splash is set. */
|
||||
export function guildSplashURL(
|
||||
bot: Bot,
|
||||
id: bigint,
|
||||
options: {
|
||||
splash?: string | bigint;
|
||||
@@ -15,12 +14,12 @@ export function guildSplashURL(
|
||||
}
|
||||
) {
|
||||
return options.splash
|
||||
? formatImageURL(
|
||||
endpoints.GUILD_SPLASH(
|
||||
? bot.utils.formatImageURL(
|
||||
bot.constants.endpoints.GUILD_SPLASH(
|
||||
id,
|
||||
typeof options.splash === "string"
|
||||
? options.splash
|
||||
: iconBigintToHash(options.splash, options.animated ?? true)
|
||||
: bot.utils.iconBigintToHash(options.splash, options.animated ?? true)
|
||||
),
|
||||
options.size || 128,
|
||||
options.format
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import { rest } from "../../rest/rest.ts";
|
||||
import { endpoints } from "../../util/constants.ts";
|
||||
import type { Bot } from "../../bot.ts";
|
||||
|
||||
/** Leave a guild */
|
||||
export async function leaveGuild(guildId: bigint) {
|
||||
return await rest.runMethod<undefined>("delete", endpoints.GUILD_LEAVE(guildId));
|
||||
export async function leaveGuild(bot: Bot, guildId: bigint) {
|
||||
return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.GUILD_LEAVE(guildId));
|
||||
}
|
||||
|
||||
@@ -66,5 +66,5 @@ export async function editSlashResponse(bot: Bot, token: string, options: Discor
|
||||
// If the original message was edited, this will not return a message
|
||||
if (!options.messageId) return result as undefined;
|
||||
|
||||
return bot.transformers.message(result);
|
||||
return bot.transformers.message(bot, result);
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ export async function getOriginalInteractionResponse(bot: Bot, token: string) {
|
||||
bot.constants.endpoints.INTERACTION_ORIGINAL_ID_TOKEN(bot.applicationId, token)
|
||||
);
|
||||
|
||||
return bot.transformers.message(result);
|
||||
return bot.transformers.message(bot, result);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ export async function sendDirectMessage(bot: Bot, memberId: bigint, content: str
|
||||
recipient_id: memberId,
|
||||
}
|
||||
);
|
||||
const discordenoChannel = await bot.transformers.channel(bot, dmChannelData);
|
||||
const discordenoChannel = await bot.transformers.channel(bot, {channel: dmChannelData});
|
||||
// Recreate the channel and add it under the users id
|
||||
await bot.cache.channels.set(memberId, discordenoChannel);
|
||||
dmChannel = discordenoChannel;
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ import { getBans } from "./guilds/get_bans.ts";
|
||||
import { getGuild } from "./guilds/get_guild.ts";
|
||||
import { getGuildPreview } from "./guilds/get_guild_preview.ts";
|
||||
import { getPruneCount } from "./guilds/get_prune_count.ts";
|
||||
import { getVanityURL } from "./guilds/get_vainty_url.ts";
|
||||
import { getVanityURL } from "./guilds/get_vanity_url.ts";
|
||||
import { getVoiceRegions } from "./guilds/get_voice_regions.ts";
|
||||
import { getWelcomeScreen } from "./guilds/get_welcome_screen.ts";
|
||||
import { getWidget } from "./guilds/get_widget.ts";
|
||||
|
||||
@@ -67,5 +67,5 @@ export async function editWebhookMessage(
|
||||
}
|
||||
);
|
||||
|
||||
return bot.transformers.message(result);
|
||||
return bot.transformers.message(bot, result);
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ export async function getWebhookMessage(bot: Bot, webhookId: bigint, webhookToke
|
||||
bot.constants.endpoints.WEBHOOK_MESSAGE(webhookId, webhookToken, messageId)
|
||||
);
|
||||
|
||||
return bot.transformers.message(result);
|
||||
return bot.transformers.message(bot, result);
|
||||
}
|
||||
|
||||
@@ -58,5 +58,5 @@ export async function sendWebhook(bot: Bot, webhookId: bigint, webhookToken: str
|
||||
);
|
||||
if (!options.wait) return;
|
||||
|
||||
return bot.transformers.message(result);
|
||||
return bot.transformers.message(bot, result);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user