mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 01:10:07 +00:00
* refactor(helpers): Organise functions. (#2425) * refactor: Move stage instance helper functions into `/stages` subdirectory. * refactor: Move `followChannel.ts` to `/announcements` subdirectory. * refactor: Move `updateVoiceState.ts` to `/guilds` directory. * refactor: Move `getPins.ts` to `/messages` directory. * refactor: Move voice-related helper functions into `/voice` subdirectory. * refactor: Rename `/scheduledEvents` to `/events`. * refactor: Move widget-related helper functions into `/widgets` subdirectory. * refactor: Make `/integrations` a subdirectory of `/guilds`. * refactor: Move helper functions related to interaction responses into the `/responses` subdirectory. * refactor: Move `verifySignature.ts` to `/util` directory. * refactor: Move `getChannelInvites.ts` to `/channels` directory. * refactor: Make `/invites` a subdirectory of `/guilds`. * refactor: Move reaction-related helper functions into the /reactions subdirectory. * refactor: Move `getApplicationInfo.ts` into the `/misc` directory. * refactor: Move voice-related helper functions from `/voice` to `/guilds/voice`. * fix: Update and simplify type imports. * refactor!(helpers): Rename helpers to match Discord API. Create a 1:1 helper-to-endpoint correspondence. (#2427) * refactor: Move stage instance helper functions into `/stages` subdirectory. * refactor: Move `followChannel.ts` to `/announcements` subdirectory. * refactor: Move `updateVoiceState.ts` to `/guilds` directory. * refactor: Move `getPins.ts` to `/messages` directory. * refactor: Move voice-related helper functions into `/voice` subdirectory. * refactor: Rename `/scheduledEvents` to `/events`. * refactor: Move widget-related helper functions into `/widgets` subdirectory. * refactor: Make `/integrations` a subdirectory of `/guilds`. * refactor: Move helper functions related to interaction responses into the `/responses` subdirectory. * refactor: Move `verifySignature.ts` to `/util` directory. * refactor: Move `getChannelInvites.ts` to `/channels` directory. * refactor: Make `/invites` a subdirectory of `/guilds`. * refactor: Move reaction-related helper functions into the /reactions subdirectory. * refactor: Move `getApplicationInfo.ts` into the `/misc` directory. * refactor: Move voice-related helper functions from `/voice` to `/guilds/voice`. * fix: Update and simplify type imports. * refactor: Rename `followChannel` -> `followAnnouncementChannel`. * refactor: Rename `createForumPost` -> `startForumThread`. * refactor: Normalise keyword `update` -> `edit`. * refactor: Rename `addToThread` -> `addThreadMember`. * refactor: Rename `ChannelOverwrite` -> `ChannelPermissions`. * refactor: Rename `startTyping` -> `triggerTypingIndicator`. * refactor: Rename `swapChannels` -> `editChannelPositions`. * refactor: Rename `getPins` -> `getPinnedMessages`. * refactor: Rename `publish` -> `crosspost`. * refactor: Normalise keyword `modify` -> `edit`. * refactor: Normalise naming. * fix: Imports. * style: Remove empty object. * refactor: Split `getArchivedThreads` into three files for public, private and private joined threads. * refactor: Split `getApplicationCommands` into two files, for guild and global commands respectively. * refactor: Split `getApplicationCommand` into two files, for guild and global commands respectively. * fmt: Organise imports. * misc: Include application command reverse transformer. * misc: Make ordering of fields match up with the Discord API. * fix: Add missing payload properties. * refactor: Split `createApplicationCommand` into two files, for guild and global commands respectively. * refactor: Split `upsertApplicationCommand` into two files, for guild and global commands respectively. * refactor: Split `upsertApplicationCommands` into two files, for guild and global commands respectively. * fix: Update exports. * refactor: Split `deleteApplicationCommand` into two files, for guild and global commands respectively. * fix: Add missing exports. * refactor: Separate file into two to make 1 file correspond to 1 endpoint. * refactor: Separate file into two to make 1 file correspond to 1 endpoint. * feat: Create `getInteractionResponse.ts`. * refactor: Matching API: `InteractionResponse` -> `FollowupMessage`. * refactor: Separate file into two to make 1 file correspond to 1 endpoint. * refactor: Remove `/followups` directory in favour of newly created files in `/responses`. * refactor: Rename `bot`/`self` -> `own`, `others` -> `user`. * refactor: Split function into `deleteOwnReaction` and `deleteUserReaction`. * refactor: Reduce code duplication in processing reaction string. * refactor: Separate file into two to make 1 file correspond to 1 endpoint. * refactor: Rename function name. * misc: Add aliases to functions to reduce breakage. * refactor: Rename `startForumThread` -> `createForumThread`. * misc: Move types from helper file to `/types` and create transformer. * fix: Imports. * style: Rename parameter `command` -> `payload`. * feat: Create interaction response transformer. * misc: Adapt code to use the interaction response transformer. * misc: Adapt code to use interaction response transformer. * refactor: Re-include the keyword `Override` in the file + function names. * refactor: Rename `updateVoiceState` -> `editVoiceState` for consistency reasons. Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> * BREAKING: docs(helpers): Document helper functions. (#2437) * refactor: Move stage instance helper functions into `/stages` subdirectory. * refactor: Move `followChannel.ts` to `/announcements` subdirectory. * refactor: Move `updateVoiceState.ts` to `/guilds` directory. * refactor: Move `getPins.ts` to `/messages` directory. * refactor: Move voice-related helper functions into `/voice` subdirectory. * refactor: Rename `/scheduledEvents` to `/events`. * refactor: Move widget-related helper functions into `/widgets` subdirectory. * refactor: Make `/integrations` a subdirectory of `/guilds`. * refactor: Move helper functions related to interaction responses into the `/responses` subdirectory. * refactor: Move `verifySignature.ts` to `/util` directory. * refactor: Move `getChannelInvites.ts` to `/channels` directory. * refactor: Make `/invites` a subdirectory of `/guilds`. * refactor: Move reaction-related helper functions into the /reactions subdirectory. * refactor: Move `getApplicationInfo.ts` into the `/misc` directory. * refactor: Move voice-related helper functions from `/voice` to `/guilds/voice`. * fix: Update and simplify type imports. * refactor: Rename `followChannel` -> `followAnnouncementChannel`. * refactor: Rename `createForumPost` -> `startForumThread`. * refactor: Normalise keyword `update` -> `edit`. * refactor: Rename `addToThread` -> `addThreadMember`. * refactor: Rename `ChannelOverwrite` -> `ChannelPermissions`. * refactor: Rename `startTyping` -> `triggerTypingIndicator`. * refactor: Rename `swapChannels` -> `editChannelPositions`. * refactor: Rename `getPins` -> `getPinnedMessages`. * refactor: Rename `publish` -> `crosspost`. * refactor: Normalise keyword `modify` -> `edit`. * refactor: Normalise naming. * fix: Imports. * style: Remove empty object. * refactor: Split `getArchivedThreads` into three files for public, private and private joined threads. * refactor: Split `getApplicationCommands` into two files, for guild and global commands respectively. * refactor: Split `getApplicationCommand` into two files, for guild and global commands respectively. * fmt: Organise imports. * misc: Include application command reverse transformer. * misc: Make ordering of fields match up with the Discord API. * fix: Add missing payload properties. * refactor: Split `createApplicationCommand` into two files, for guild and global commands respectively. * refactor: Split `upsertApplicationCommand` into two files, for guild and global commands respectively. * refactor: Split `upsertApplicationCommands` into two files, for guild and global commands respectively. * fix: Update exports. * refactor: Split `deleteApplicationCommand` into two files, for guild and global commands respectively. * fix: Add missing exports. * refactor: Separate file into two to make 1 file correspond to 1 endpoint. * refactor: Separate file into two to make 1 file correspond to 1 endpoint. * feat: Create `getInteractionResponse.ts`. * refactor: Matching API: `InteractionResponse` -> `FollowupMessage`. * refactor: Separate file into two to make 1 file correspond to 1 endpoint. * refactor: Remove `/followups` directory in favour of newly created files in `/responses`. * refactor: Rename `bot`/`self` -> `own`, `others` -> `user`. * refactor: Split function into `deleteOwnReaction` and `deleteUserReaction`. * refactor: Reduce code duplication in processing reaction string. * refactor: Separate file into two to make 1 file correspond to 1 endpoint. * refactor: Rename function name. * misc: Add aliases to functions to reduce breakage. * refactor: Rename `startForumThread` -> `createForumThread`. * misc: Move types from helper file to `/types` and create transformer. * fix: Imports. * style: Rename parameter `command` -> `payload`. * feat: Create interaction response transformer. * misc: Adapt code to use the interaction response transformer. * misc: Adapt code to use interaction response transformer. * docs: Document announcement channel helpers. * docs: Document forum channel helpers. * docs: Document stage instance helpers. * misc: Update wording. * docs: Document thread channel helpers. * refactor: Re-include the keyword `Override` in the file + function names. * refactor: Rename `updateVoiceState` -> `editVoiceState` for consistency reasons. * docs: Document channel helpers. * docs: Use `parameters` instead of `options` for descriptions. * docs: Document guild discovery helpers. * docs: Document emoji helpers. * docs: Add missing information about which gateway events are fired. * docs: Document auto moderation helpers. * docs: Document scheduled event helpers. * docs: Document integration helpers. * docs: Document invite helpers. * refactor: Rename `editWidget` -> `editWidgetSettings`. * docs: Document guild widget helpers. * docs: 'event' -> 'gateway event'. * refactor: Rename `getAuditLogs` -> `getAuditLog`. * docs: Document guild helpers. * refactor: Rename `upsert*ApplicationCommand` -> `edit*ApplicationCommand`. * docs: Document application command helpers. * docs: Improve consistency in indentation. * docs: Document interaction response + follow-up message helpers. * docs: Document gateway event firings for endpoints. * refactor: Delete `editBotNickname` due to being a subset of `editMember`. * docs: Fix inconsistency. * docs: Document member helpers. * docs: Document reaction helpers. * docs: Improve consistency. * docs: Document message helpers. * docs: Document role helpers. * docs: Document guild template helpers. * docs: Fix incorrect gateway event. * refactor: Rename `sendWebhookMessage` -> `executeWebhook`. * docs: Document webhook helpers. * docs: Document voice helpers. * fmt: Run Deno formatter. * docs: Improve consistency. * refactor: Rename the `/widgets` directory to `/widget`. * fmt: Run Deno formatter. * misc: Re-add the deleted `editBotNickname()` helper. (#2443) * refactor: Move stage instance helper functions into `/stages` subdirectory. * refactor: Move `followChannel.ts` to `/announcements` subdirectory. * refactor: Move `updateVoiceState.ts` to `/guilds` directory. * refactor: Move `getPins.ts` to `/messages` directory. * refactor: Move voice-related helper functions into `/voice` subdirectory. * refactor: Rename `/scheduledEvents` to `/events`. * refactor: Move widget-related helper functions into `/widgets` subdirectory. * refactor: Make `/integrations` a subdirectory of `/guilds`. * refactor: Move helper functions related to interaction responses into the `/responses` subdirectory. * refactor: Move `verifySignature.ts` to `/util` directory. * refactor: Move `getChannelInvites.ts` to `/channels` directory. * refactor: Make `/invites` a subdirectory of `/guilds`. * refactor: Move reaction-related helper functions into the /reactions subdirectory. * refactor: Move `getApplicationInfo.ts` into the `/misc` directory. * refactor: Move voice-related helper functions from `/voice` to `/guilds/voice`. * fix: Update and simplify type imports. * refactor: Rename `followChannel` -> `followAnnouncementChannel`. * refactor: Rename `createForumPost` -> `startForumThread`. * refactor: Normalise keyword `update` -> `edit`. * refactor: Rename `addToThread` -> `addThreadMember`. * refactor: Rename `ChannelOverwrite` -> `ChannelPermissions`. * refactor: Rename `startTyping` -> `triggerTypingIndicator`. * refactor: Rename `swapChannels` -> `editChannelPositions`. * refactor: Rename `getPins` -> `getPinnedMessages`. * refactor: Rename `publish` -> `crosspost`. * refactor: Normalise keyword `modify` -> `edit`. * refactor: Normalise naming. * fix: Imports. * style: Remove empty object. * refactor: Split `getArchivedThreads` into three files for public, private and private joined threads. * refactor: Split `getApplicationCommands` into two files, for guild and global commands respectively. * refactor: Split `getApplicationCommand` into two files, for guild and global commands respectively. * fmt: Organise imports. * misc: Include application command reverse transformer. * misc: Make ordering of fields match up with the Discord API. * fix: Add missing payload properties. * refactor: Split `createApplicationCommand` into two files, for guild and global commands respectively. * refactor: Split `upsertApplicationCommand` into two files, for guild and global commands respectively. * refactor: Split `upsertApplicationCommands` into two files, for guild and global commands respectively. * fix: Update exports. * refactor: Split `deleteApplicationCommand` into two files, for guild and global commands respectively. * fix: Add missing exports. * refactor: Separate file into two to make 1 file correspond to 1 endpoint. * refactor: Separate file into two to make 1 file correspond to 1 endpoint. * feat: Create `getInteractionResponse.ts`. * refactor: Matching API: `InteractionResponse` -> `FollowupMessage`. * refactor: Separate file into two to make 1 file correspond to 1 endpoint. * refactor: Remove `/followups` directory in favour of newly created files in `/responses`. * refactor: Rename `bot`/`self` -> `own`, `others` -> `user`. * refactor: Split function into `deleteOwnReaction` and `deleteUserReaction`. * refactor: Reduce code duplication in processing reaction string. * refactor: Separate file into two to make 1 file correspond to 1 endpoint. * refactor: Rename function name. * misc: Add aliases to functions to reduce breakage. * refactor: Rename `startForumThread` -> `createForumThread`. * misc: Move types from helper file to `/types` and create transformer. * fix: Imports. * style: Rename parameter `command` -> `payload`. * feat: Create interaction response transformer. * misc: Adapt code to use the interaction response transformer. * misc: Adapt code to use interaction response transformer. * docs: Document announcement channel helpers. * docs: Document forum channel helpers. * docs: Document stage instance helpers. * misc: Update wording. * docs: Document thread channel helpers. * refactor: Re-include the keyword `Override` in the file + function names. * refactor: Rename `updateVoiceState` -> `editVoiceState` for consistency reasons. * docs: Document channel helpers. * docs: Use `parameters` instead of `options` for descriptions. * docs: Document guild discovery helpers. * docs: Document emoji helpers. * docs: Add missing information about which gateway events are fired. * docs: Document auto moderation helpers. * docs: Document scheduled event helpers. * docs: Document integration helpers. * docs: Document invite helpers. * refactor: Rename `editWidget` -> `editWidgetSettings`. * docs: Document guild widget helpers. * docs: 'event' -> 'gateway event'. * refactor: Rename `getAuditLogs` -> `getAuditLog`. * docs: Document guild helpers. * refactor: Rename `upsert*ApplicationCommand` -> `edit*ApplicationCommand`. * docs: Document application command helpers. * docs: Improve consistency in indentation. * docs: Document interaction response + follow-up message helpers. * docs: Document gateway event firings for endpoints. * refactor: Delete `editBotNickname` due to being a subset of `editMember`. * docs: Fix inconsistency. * docs: Document member helpers. * docs: Document reaction helpers. * docs: Improve consistency. * docs: Document message helpers. * docs: Document role helpers. * docs: Document guild template helpers. * docs: Fix incorrect gateway event. * refactor: Rename `sendWebhookMessage` -> `executeWebhook`. * docs: Document webhook helpers. * docs: Document voice helpers. * fmt: Run Deno formatter. * docs: Improve consistency. * refactor: Rename the `/widgets` directory to `/widget`. * fmt: Run Deno formatter. * feat: Re-add `editBotNickname.ts`. * Update helpers/members/editBotNickname.ts Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> * fix: tests * fix: bot member tests * fix: remove submode * fix: edit bot member returns full member Co-authored-by: Dorian Oszczęda <vxern@wordcollector.co.uk>
116 lines
4.8 KiB
TypeScript
116 lines
4.8 KiB
TypeScript
import type { Bot } from "../../bot.ts";
|
|
import { Guild } from "../../transformers/guild.ts";
|
|
import { DiscordGuild } from "../../types/discord.ts";
|
|
import {
|
|
DefaultMessageNotificationLevels,
|
|
ExplicitContentFilterLevels,
|
|
GuildFeatures,
|
|
SystemChannelFlags,
|
|
VerificationLevels,
|
|
} from "../../types/shared.ts";
|
|
|
|
// TODO: Put the `shardId` parameter before `options`.
|
|
|
|
/**
|
|
* Edits a guild's settings.
|
|
*
|
|
* @param bot - The bot instance to use to make the request.
|
|
* @param guildId - The ID of the guild to edit.
|
|
* @param shardId - The ID of the shard the guild is in.
|
|
* @param options - The parameters for the edit of the guild.
|
|
* @returns An instance of the edited {@link Guild}.
|
|
*
|
|
* @remarks
|
|
* Requires the `MANAGE_GUILD` permission.
|
|
*
|
|
* If attempting to add or remove the {@link GuildFeatures.Community} feature:
|
|
* - Requires the `ADMINISTRATOR` permission.
|
|
*
|
|
* Fires a _Guild Update_ gateway event.
|
|
*
|
|
* @see {@link https://discord.com/developers/docs/resources/guild#modify-guild}
|
|
*/
|
|
export async function editGuild(bot: Bot, guildId: bigint, options: ModifyGuild, shardId: number): Promise<Guild> {
|
|
if (options.icon && !options.icon.startsWith("data:image/")) {
|
|
options.icon = await bot.utils.urlToBase64(options.icon);
|
|
}
|
|
|
|
if (options.banner && !options.banner.startsWith("data:image/")) {
|
|
options.banner = await bot.utils.urlToBase64(options.banner);
|
|
}
|
|
|
|
if (options.splash && !options.splash.startsWith("data:image/")) {
|
|
options.splash = await bot.utils.urlToBase64(options.splash);
|
|
}
|
|
|
|
const result = await bot.rest.runMethod<DiscordGuild>(
|
|
bot.rest,
|
|
"PATCH",
|
|
bot.constants.routes.GUILD(guildId),
|
|
{
|
|
name: options.name,
|
|
verification_levels: options.verificationLevel,
|
|
default_message_notifications: options.defaultMessageNotifications,
|
|
explicit_content_filter: options.explicitContentFilter,
|
|
afk_channel_id: options.afkChannelId ? options.afkChannelId.toString() : options.afkChannelId,
|
|
afk_timeout: options.afkTimeout,
|
|
icon: options.icon,
|
|
owner_id: options.ownerId ? options.ownerId.toString() : options.ownerId,
|
|
splash: options.splash,
|
|
discovery_splash: options.discoverySplash,
|
|
banner: options.banner,
|
|
system_channel_id: options.systemChannelId ? options.systemChannelId.toString() : options.systemChannelId,
|
|
system_channel_flags: options.systemChannelFlags,
|
|
rules_channel_id: options.rulesChannelId ? options.rulesChannelId.toString() : options.rulesChannelId,
|
|
public_updates_channel_id: options.publicUpdatesChannelId
|
|
? options.publicUpdatesChannelId.toString()
|
|
: options.publicUpdatesChannelId,
|
|
preferred_locale: options.preferredLocale,
|
|
features: options.features,
|
|
premium_progress_bar_enabled: options.premiumProgressBarEnabled,
|
|
},
|
|
);
|
|
|
|
return bot.transformers.guild(bot, { guild: result, shardId });
|
|
}
|
|
|
|
/** https://discord.com/developers/docs/resources/guild#modify-guild */
|
|
export interface ModifyGuild {
|
|
/** Guild name */
|
|
name?: string;
|
|
/** Verification level */
|
|
verificationLevel?: VerificationLevels | null;
|
|
/** Default message notification filter level */
|
|
defaultMessageNotifications?: DefaultMessageNotificationLevels | null;
|
|
/** Explicit content filter level */
|
|
explicitContentFilter?: ExplicitContentFilterLevels | null;
|
|
/** Id for afk channel */
|
|
afkChannelId?: bigint | null;
|
|
/** Afk timeout in seconds */
|
|
afkTimeout?: number;
|
|
/** Base64 1024x1024 png/jpeg/gif image for the guild icon (can be animated gif when the server has the `ANIMATED_ICON` feature) */
|
|
icon?: string | null;
|
|
/** User id to transfer guild ownership to (must be owner) */
|
|
ownerId?: bigint;
|
|
/** Base64 16:9 png/jpeg image for the guild splash (when the server has `INVITE_SPLASH` feature) */
|
|
splash?: string | null;
|
|
/** Base64 16:9 png/jpeg image for the guild discovery spash (when the server has the `DISCOVERABLE` feature) */
|
|
discoverySplash?: string | null;
|
|
/** Base64 16:9 png/jpeg image for the guild banner (when the server has BANNER feature) */
|
|
banner?: string | null;
|
|
/** The id of the channel where guild notices such as welcome messages and boost events are posted */
|
|
systemChannelId?: bigint | null;
|
|
/** System channel flags */
|
|
systemChannelFlags?: SystemChannelFlags;
|
|
/** The id of the channel where Community guilds display rules and/or guidelines */
|
|
rulesChannelId?: bigint | null;
|
|
/** The id of the channel where admins and moderators of Community guilds receive notices from Discord */
|
|
publicUpdatesChannelId?: bigint | null;
|
|
/** The preferred locale of a Community guild used in server discovery and notices from Discord; defaults to "en-US" */
|
|
preferredLocale?: string | null;
|
|
/** Enabled guild features */
|
|
features?: GuildFeatures[];
|
|
/** Whether the guild's boost progress bar should be enabled */
|
|
premiumProgressBarEnabled?: boolean;
|
|
}
|