diff --git a/helpers/channels/createChannel.ts b/helpers/channels/createChannel.ts index 3ba1cb098..1e0741e1b 100644 --- a/helpers/channels/createChannel.ts +++ b/helpers/channels/createChannel.ts @@ -1,8 +1,9 @@ import type { Bot } from "../../bot.ts"; +import { WithReason } from "../../mod.ts"; import { Channel } from "../../transformers/channel.ts"; import { DiscordChannel } from "../../types/discord.ts"; +import { OverwriteReadable } from "../../types/discordeno.ts"; import { ChannelTypes } from "../../types/shared.ts"; -import { OverwriteReadable } from "./editChannelPermissionOverrides.ts"; /** * Creates a channel within a guild. @@ -23,12 +24,7 @@ import { OverwriteReadable } from "./editChannelPermissionOverrides.ts"; * * @see {@link https://discord.com/developers/docs/resources/guild#create-guild-channel} */ -export async function createChannel( - bot: Bot, - guildId: bigint, - options?: CreateGuildChannel, - reason?: string, -): Promise { +export async function createChannel(bot: Bot, guildId: bigint, options?: CreateGuildChannel): Promise { // BITRATE IS IN THOUSANDS SO IF USER PROVIDES 32 WE CONVERT TO 32000 if (options?.bitrate && options.bitrate < 1000) options.bitrate *= 1000; @@ -53,7 +49,7 @@ export async function createChannel( deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : null, })), type: options?.type || ChannelTypes.GuildText, - reason, + reason: options.reason, default_auto_archive_duration: options?.defaultAutoArchiveDuration, } : {}, @@ -62,7 +58,7 @@ export async function createChannel( return bot.transformers.channel(bot, { channel: result, guildId }); } -export interface CreateGuildChannel { +export interface CreateGuildChannel extends WithReason { /** Channel name (1-100 characters) */ name: string; /** The type of channel */ diff --git a/helpers/channels/deleteChannelPermissionOverride.ts b/helpers/channels/deleteChannelPermissionOverride.ts index e21efbd2f..b79ea700c 100644 --- a/helpers/channels/deleteChannelPermissionOverride.ts +++ b/helpers/channels/deleteChannelPermissionOverride.ts @@ -14,10 +14,16 @@ import type { Bot } from "../../bot.ts"; * * @see {@link https://discord.com/developers/docs/resources/channel#delete-channel-permission} */ -export async function deleteChannelPermissionOverride(bot: Bot, channelId: bigint, overwriteId: bigint): Promise { +export async function deleteChannelPermissionOverride( + bot: Bot, + channelId: bigint, + overwriteId: bigint, + reason?: string, +): Promise { return await bot.rest.runMethod( bot.rest, "DELETE", bot.constants.routes.CHANNEL_OVERWRITE(channelId, overwriteId), + reason ? { reason } : undefined, ); } diff --git a/helpers/channels/editChannel.ts b/helpers/channels/editChannel.ts index a45f48815..2f6be26d1 100644 --- a/helpers/channels/editChannel.ts +++ b/helpers/channels/editChannel.ts @@ -1,8 +1,9 @@ import type { Bot } from "../../bot.ts"; +import { WithReason } from "../../mod.ts"; import { Channel } from "../../transformers/channel.ts"; import { DiscordChannel } from "../../types/discord.ts"; +import { OverwriteReadable } from "../../types/discordeno.ts"; import { ChannelTypes, VideoQualityModes } from "../../types/shared.ts"; -import { OverwriteReadable } from "./editChannelPermissionOverrides.ts"; /** * Edits a channel's settings. @@ -34,12 +35,7 @@ import { OverwriteReadable } from "./editChannelPermissionOverrides.ts"; * - Otherwise: * - Fires a _Channel Update_ gateway event. */ -export async function editChannel( - bot: Bot, - channelId: bigint, - options: ModifyChannel, - reason?: string, -): Promise { +export async function editChannel(bot: Bot, channelId: bigint, options: ModifyChannel): Promise { if (options.name || options.topic) { const request = editChannelNameTopicQueue.get(channelId); if (!request) { @@ -107,7 +103,7 @@ export async function editChannel( emoji_name: options.defaultReactionEmoji.emojiName, } : undefined, - reason, + reason: options.reason, }, ); @@ -171,7 +167,7 @@ function processEditChannelQueue(bot: Bot): void { } } -export interface ModifyChannel { +export interface ModifyChannel extends WithReason { /** 1-100 character channel name */ name?: string; /** The type of channel; only conversion between text and news is supported and only in guilds with the "NEWS" feature */ diff --git a/helpers/channels/editChannelPermissionOverrides.ts b/helpers/channels/editChannelPermissionOverrides.ts index fd9e22e84..a08ea1657 100644 --- a/helpers/channels/editChannelPermissionOverrides.ts +++ b/helpers/channels/editChannelPermissionOverrides.ts @@ -1,12 +1,13 @@ import type { Bot } from "../../bot.ts"; -import { OverwriteTypes, PermissionStrings } from "../../types/shared.ts"; +import { WithReason } from "../../mod.ts"; +import { OverwriteReadable } from "../../types/discordeno.ts"; /** * Edits the permission overrides for a user or role in a channel. * * @param bot - The bot instance to use to make the request. * @param channelId - The ID of the channel to edit the permission overrides of. - * @param overwrite - The permission override. + * @param options - The permission override. * * @remarks * Requires the `MANAGE_ROLES` permission. @@ -20,38 +21,19 @@ import { OverwriteTypes, PermissionStrings } from "../../types/shared.ts"; export async function editChannelPermissionOverrides( bot: Bot, channelId: bigint, - overwrite: OverwriteReadable, + options: EditChannelPermissionOverridesOptions, ): Promise { return await bot.rest.runMethod( bot.rest, "PUT", - bot.constants.routes.CHANNEL_OVERWRITE(channelId, overwrite.id), + bot.constants.routes.CHANNEL_OVERWRITE(channelId, options.id), { - allow: overwrite.allow ? bot.utils.calculateBits(overwrite.allow) : "0", - deny: overwrite.deny ? bot.utils.calculateBits(overwrite.deny) : "0", - type: overwrite.type, + allow: options.allow ? bot.utils.calculateBits(options.allow) : "0", + deny: options.deny ? bot.utils.calculateBits(options.deny) : "0", + type: options.type, + reason: options.reason, }, ); } -export interface OverwriteReadable { - /** Role or user id */ - id: bigint; - /** Either 0 (role) or 1 (member) */ - type: OverwriteTypes; - /** Permission bit set */ - allow?: PermissionStrings[]; - /** Permission bit set */ - deny?: PermissionStrings[]; -} - -export interface Overwrite { - /** Role or user id */ - id: bigint; - /** Either 0 (role) or 1 (member) */ - type: OverwriteTypes; - /** Permission bit set */ - allow?: bigint; - /** Permission bit set */ - deny?: bigint; -} +export interface EditChannelPermissionOverridesOptions extends OverwriteReadable, WithReason {} diff --git a/helpers/channels/forums/createForumThread.ts b/helpers/channels/forums/createForumThread.ts index 14dd6cca3..219ab7d27 100644 --- a/helpers/channels/forums/createForumThread.ts +++ b/helpers/channels/forums/createForumThread.ts @@ -2,7 +2,7 @@ import type { Bot } from "../../../bot.ts"; import { Channel } from "../../../transformers/channel.ts"; import { Embed } from "../../../transformers/embed.ts"; import { DiscordChannel } from "../../../types/discord.ts"; -import { AllowedMentions, FileContent, MessageComponents } from "../../../types/mod.ts"; +import { AllowedMentions, FileContent, MessageComponents, WithReason } from "../../../types/mod.ts"; /** * Creates a new thread in a forum channel, and sends a message within the created thread. @@ -55,18 +55,13 @@ export async function createForumThread( return bot.transformers.channel(bot, { channel: result, guildId: bot.transformers.snowflake(result.guild_id!) }); } -export interface CreateForumPostWithMessage extends CreateForumMessage { +export interface CreateForumPostWithMessage extends WithReason { /** 1-100 character thread name */ name: string; /** Duration in minutes to automatically archive the thread after recent activity */ autoArchiveDuration: 60 | 1440 | 4320 | 10080; /** Amount of seconds a user has to wait before sending another message (0-21600) */ rateLimitPerUser?: number | null; - /** The reason you are creating the thread */ - reason?: string; -} - -export interface CreateForumMessage { /** The message contents (up to 2000 characters) */ content?: string; /** Embedded `rich` content (up to 6000 characters) */ diff --git a/helpers/channels/stages/createStageInstance.ts b/helpers/channels/stages/createStageInstance.ts index d422777bc..45b20705d 100644 --- a/helpers/channels/stages/createStageInstance.ts +++ b/helpers/channels/stages/createStageInstance.ts @@ -1,4 +1,5 @@ import type { Bot } from "../../../bot.ts"; +import { WithReason } from "../../../mod.ts"; import { StageInstance } from "../../../transformers/stageInstance.ts"; import { DiscordStageInstance } from "../../../types/discord.ts"; @@ -25,13 +26,14 @@ export async function createStageInstance(bot: Bot, options: CreateStageInstance channel_id: options.channelId.toString(), topic: options.topic, send_start_notification: options.sendStartNotification, + reason: options.reason, }, ); return bot.transformers.stageInstance(bot, result); } -export interface CreateStageInstance { +export interface CreateStageInstance extends WithReason { channelId: bigint; topic: string; /** Notify @everyone that the stage instance has started. Requires the MENTION_EVERYONE permission. */ diff --git a/helpers/channels/stages/deleteStageInstance.ts b/helpers/channels/stages/deleteStageInstance.ts index 480ec087d..46f1e5c9c 100644 --- a/helpers/channels/stages/deleteStageInstance.ts +++ b/helpers/channels/stages/deleteStageInstance.ts @@ -13,6 +13,11 @@ import type { Bot } from "../../../bot.ts"; * * @see {@link https://discord.com/developers/docs/resources/stage-instance#delete-stage-instance} */ -export async function deleteStageInstance(bot: Bot, channelId: bigint): Promise { - return await bot.rest.runMethod(bot.rest, "DELETE", bot.constants.routes.STAGE_INSTANCE(channelId)); +export async function deleteStageInstance(bot: Bot, channelId: bigint, reason?: string): Promise { + return await bot.rest.runMethod( + bot.rest, + "DELETE", + bot.constants.routes.STAGE_INSTANCE(channelId), + reason ? { reason } : undefined, + ); } diff --git a/helpers/channels/stages/editStageInstance.ts b/helpers/channels/stages/editStageInstance.ts index a2c855589..55174ca68 100644 --- a/helpers/channels/stages/editStageInstance.ts +++ b/helpers/channels/stages/editStageInstance.ts @@ -1,7 +1,7 @@ import type { Bot } from "../../../bot.ts"; +import { WithReason } from "../../../mod.ts"; import { StageInstance } from "../../../transformers/stageInstance.ts"; import { DiscordStageInstance } from "../../../types/discord.ts"; -import { AtLeastOne } from "../../../types/shared.ts"; /** * Edits a stage instance. @@ -20,7 +20,7 @@ import { AtLeastOne } from "../../../types/shared.ts"; export async function editStageInstance( bot: Bot, channelId: bigint, - data: AtLeastOne>, + data: EditStageInstanceOptions, ): Promise { const result = await bot.rest.runMethod( bot.rest, @@ -33,3 +33,8 @@ export async function editStageInstance( return bot.transformers.stageInstance(bot, result); } + +export interface EditStageInstanceOptions extends WithReason { + /** The topic of the Stage instance (1-120 characters) */ + topic: string; +} diff --git a/helpers/channels/threads/startThreadWithMessage.ts b/helpers/channels/threads/startThreadWithMessage.ts index 93cae4472..b19a41760 100644 --- a/helpers/channels/threads/startThreadWithMessage.ts +++ b/helpers/channels/threads/startThreadWithMessage.ts @@ -1,4 +1,5 @@ import type { Bot } from "../../../bot.ts"; +import { WithReason } from "../../../mod.ts"; import { Channel } from "../../../transformers/channel.ts"; import { DiscordChannel } from "../../../types/discord.ts"; @@ -35,19 +36,19 @@ export async function startThreadWithMessage( { name: options.name, auto_archive_duration: options.autoArchiveDuration, + rate_limit_per_user: options.rateLimitPerUser, + reason: options.reason, }, ); return bot.transformers.channel(bot, { channel: result, guildId: bot.transformers.snowflake(result.guild_id!) }); } -export interface StartThreadWithMessage { +export interface StartThreadWithMessage extends WithReason { /** 1-100 character thread name */ name: string; /** Duration in minutes to automatically archive the thread after recent activity */ autoArchiveDuration: 60 | 1440 | 4320 | 10080; /** Amount of seconds a user has to wait before sending another message (0-21600) */ rateLimitPerUser?: number | null; - /** The reason you are creating the thread */ - reason?: string; } diff --git a/helpers/channels/threads/startThreadWithoutMessage.ts b/helpers/channels/threads/startThreadWithoutMessage.ts index 2e611c018..e6e310596 100644 --- a/helpers/channels/threads/startThreadWithoutMessage.ts +++ b/helpers/channels/threads/startThreadWithoutMessage.ts @@ -1,4 +1,5 @@ import type { Bot } from "../../../bot.ts"; +import { WithReason } from "../../../mod.ts"; import { Channel } from "../../../transformers/channel.ts"; import { DiscordChannel } from "../../../types/discord.ts"; import { ChannelTypes } from "../../../types/shared.ts"; @@ -30,6 +31,10 @@ export async function startThreadWithoutMessage( { name: options.name, auto_archive_duration: options.autoArchiveDuration, + rate_limit_per_user: options.rateLimitPerUser, + type: options.type, + invitable: options.invitable, + reason: options.reason, }, ); @@ -39,15 +44,13 @@ export async function startThreadWithoutMessage( }); } -export interface StartThreadWithoutMessage { +export interface StartThreadWithoutMessage extends WithReason { /** 1-100 character thread name */ name: string; /** Duration in minutes to automatically archive the thread after recent activity */ autoArchiveDuration: 60 | 1440 | 4320 | 10080; /** Amount of seconds a user has to wait before sending another message (0-21600) */ rateLimitPerUser?: number | null; - /** The reason you are creating the thread */ - reason?: string; /** the type of thread to create */ type: ChannelTypes.AnnouncementThread | ChannelTypes.PublicThread | ChannelTypes.PrivateThread; /** whether non-moderators can add other non-moderators to a thread; only available when creating a private thread */ diff --git a/helpers/emojis/createEmoji.ts b/helpers/emojis/createEmoji.ts index 751330a66..45f5fb52d 100644 --- a/helpers/emojis/createEmoji.ts +++ b/helpers/emojis/createEmoji.ts @@ -1,4 +1,5 @@ import type { Bot } from "../../bot.ts"; +import { WithReason } from "../../mod.ts"; import { Emoji } from "../../transformers/emoji.ts"; import { DiscordEmoji } from "../../types/discord.ts"; @@ -40,13 +41,11 @@ export async function createEmoji(bot: Bot, guildId: bigint, options: CreateGuil } /** https://discord.com/developers/docs/resources/emoji#create-guild-emoji */ -export interface CreateGuildEmoji { +export interface CreateGuildEmoji extends WithReason { /** Name of the emoji */ name: string; /** The 128x128 emoji image. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */ image: string; /** Roles allowed to use this emoji */ roles?: bigint[]; - /** The reason you are creating this emoji */ - reason?: string; } diff --git a/helpers/emojis/editEmoji.ts b/helpers/emojis/editEmoji.ts index 05697ba93..bd644ae60 100644 --- a/helpers/emojis/editEmoji.ts +++ b/helpers/emojis/editEmoji.ts @@ -1,4 +1,5 @@ import type { Bot } from "../../bot.ts"; +import { WithReason } from "../../mod.ts"; import { Emoji } from "../../transformers/emoji.ts"; import { DiscordEmoji } from "../../types/discord.ts"; @@ -27,6 +28,7 @@ export async function editEmoji(bot: Bot, guildId: bigint, id: bigint, options: name: options.name, // NEED TERNARY TO SUPPORT NULL AS VALID roles: options.roles ? options.roles.map((role) => role.toString()) : options.roles, + reason: options.reason, }, ); @@ -34,7 +36,7 @@ export async function editEmoji(bot: Bot, guildId: bigint, id: bigint, options: } /** https://discord.com/developers/docs/resources/emoji#modify-guild-emoji */ -export interface ModifyGuildEmoji { +export interface ModifyGuildEmoji extends WithReason { /** Name of the emoji */ name?: string; /** Roles allowed to use this emoji */ diff --git a/helpers/guilds/automod/createAutomodRule.ts b/helpers/guilds/automod/createAutomodRule.ts index 387abf860..378d6f814 100644 --- a/helpers/guilds/automod/createAutomodRule.ts +++ b/helpers/guilds/automod/createAutomodRule.ts @@ -1,4 +1,5 @@ import { Bot } from "../../../bot.ts"; +import { WithReason } from "../../../mod.ts"; import { AutoModerationRule } from "../../../transformers/automodRule.ts"; import { AutoModerationActionType, @@ -61,7 +62,7 @@ export async function createAutomodRule( return bot.transformers.automodRule(bot, result); } -export interface CreateAutoModerationRuleOptions { +export interface CreateAutoModerationRuleOptions extends WithReason { /** The name of the rule. */ name: string; /** The type of event to trigger the rule on. */ @@ -97,6 +98,4 @@ export interface CreateAutoModerationRuleOptions { exemptRoles?: bigint[]; /** The channel ids that should not be effected by the rule. */ exemptChannels?: bigint[]; - /** The reason to add to the audit logs. */ - reason?: string; } diff --git a/helpers/guilds/automod/editAutomodRule.ts b/helpers/guilds/automod/editAutomodRule.ts index 35bcdc87b..fde2b109d 100644 --- a/helpers/guilds/automod/editAutomodRule.ts +++ b/helpers/guilds/automod/editAutomodRule.ts @@ -1,4 +1,5 @@ import { Bot } from "../../../bot.ts"; +import { WithReason } from "../../../mod.ts"; import { AutoModerationRule } from "../../../transformers/automodRule.ts"; import { AutoModerationActionType, @@ -61,7 +62,7 @@ export async function editAutomodRule( return bot.transformers.automodRule(bot, result); } -export interface EditAutoModerationRuleOptions { +export interface EditAutoModerationRuleOptions extends WithReason { /** The name of the rule. */ name: string; /** The type of event to trigger the rule on. */ @@ -96,6 +97,4 @@ export interface EditAutoModerationRuleOptions { exemptRoles?: bigint[]; /** The channel ids that should not be effected by the rule. */ exemptChannels?: bigint[]; - /** The reason to add to the audit logs. */ - reason?: string; } diff --git a/helpers/guilds/events/createScheduledEvent.ts b/helpers/guilds/events/createScheduledEvent.ts index 10b444ff8..9ba247e71 100644 --- a/helpers/guilds/events/createScheduledEvent.ts +++ b/helpers/guilds/events/createScheduledEvent.ts @@ -1,4 +1,5 @@ import { Bot } from "../../../bot.ts"; +import { WithReason } from "../../../mod.ts"; import { ScheduledEvent } from "../../../transformers/scheduledEvent.ts"; import { DiscordScheduledEvent } from "../../../types/discord.ts"; import { ScheduledEventEntityType, ScheduledEventPrivacyLevel } from "../../../types/shared.ts"; @@ -67,7 +68,7 @@ export async function createScheduledEvent( return bot.transformers.scheduledEvent(bot, result); } -export interface CreateScheduledEvent { +export interface CreateScheduledEvent extends WithReason { /** the channel id of the scheduled event. */ channelId?: bigint; /** location of the event. Required for events with `entityType: ScheduledEventEntityType.External` */ @@ -84,5 +85,4 @@ export interface CreateScheduledEvent { privacyLevel?: ScheduledEventPrivacyLevel; /** the type of hosting entity associated with a scheduled event */ entityType: ScheduledEventEntityType; - reason?: string; } diff --git a/helpers/guilds/events/editScheduledEvent.ts b/helpers/guilds/events/editScheduledEvent.ts index fedd92aa2..7433a49ec 100644 --- a/helpers/guilds/events/editScheduledEvent.ts +++ b/helpers/guilds/events/editScheduledEvent.ts @@ -1,4 +1,5 @@ import { Bot } from "../../../bot.ts"; +import { WithReason } from "../../../mod.ts"; import { ScheduledEvent } from "../../../transformers/scheduledEvent.ts"; import { DiscordScheduledEvent } from "../../../types/discord.ts"; import { ScheduledEventEntityType, ScheduledEventPrivacyLevel, ScheduledEventStatus } from "../../../types/shared.ts"; @@ -62,7 +63,7 @@ export async function editScheduledEvent( return bot.transformers.scheduledEvent(bot, result); } -export interface EditScheduledEvent { +export interface EditScheduledEvent extends WithReason { /** the channel id of the scheduled event. null if switching to external event. */ channelId: bigint | null; /** location of the event */ @@ -81,5 +82,4 @@ export interface EditScheduledEvent { entityType: ScheduledEventEntityType; /** the status of the scheduled event */ status: ScheduledEventStatus; - reason?: string; } diff --git a/helpers/guilds/invites/createInvite.ts b/helpers/guilds/invites/createInvite.ts index f02148e63..e9649ffba 100644 --- a/helpers/guilds/invites/createInvite.ts +++ b/helpers/guilds/invites/createInvite.ts @@ -1,4 +1,5 @@ import type { Bot } from "../../../bot.ts"; +import { WithReason } from "../../../mod.ts"; import { DiscordInvite } from "../../../types/discord.ts"; import { TargetTypes } from "../../../types/shared.ts"; import { BaseInvite } from "./getInvite.ts"; @@ -57,7 +58,7 @@ export async function createInvite( }; } -export interface CreateChannelInvite { +export interface CreateChannelInvite extends WithReason { /** Duration of invite in seconds before expiry, or 0 for never. Between 0 and 604800 (7 days). Default: 86400 (24 hours) */ maxAge?: number; /** Max number of users or 0 for unlimited. Between 0 and 100. Default: 0 */ diff --git a/helpers/guilds/invites/deleteInvite.ts b/helpers/guilds/invites/deleteInvite.ts index b99194256..1e80acfae 100644 --- a/helpers/guilds/invites/deleteInvite.ts +++ b/helpers/guilds/invites/deleteInvite.ts @@ -13,6 +13,11 @@ import type { Bot } from "../../../bot.ts"; * * @see {@link https://discord.com/developers/docs/resources/channel#delete-channel-invite} */ -export async function deleteInvite(bot: Bot, inviteCode: string): Promise { - return await bot.rest.runMethod(bot.rest, "DELETE", bot.constants.routes.INVITE(inviteCode)); +export async function deleteInvite(bot: Bot, inviteCode: string, reason?: string): Promise { + return await bot.rest.runMethod( + bot.rest, + "DELETE", + bot.constants.routes.INVITE(inviteCode), + reason ? { reason } : undefined, + ); } diff --git a/helpers/members/banMember.ts b/helpers/members/banMember.ts index 5e9cf6de6..8c3d3ff70 100644 --- a/helpers/members/banMember.ts +++ b/helpers/members/banMember.ts @@ -1,4 +1,5 @@ import type { Bot } from "../../bot.ts"; +import { WithReason } from "../../mod.ts"; /** * Bans a user from a guild. @@ -15,7 +16,12 @@ import type { Bot } from "../../bot.ts"; * * @see {@link https://discord.com/developers/docs/resources/guild#create-guild-ban} */ -export async function banMember(bot: Bot, guildId: bigint, userId: bigint, options?: CreateGuildBan): Promise { +export async function banMember( + bot: Bot, + guildId: bigint, + userId: bigint, + options?: CreateGuildBan, +): Promise { return await bot.rest.runMethod( bot.rest, "PUT", @@ -28,9 +34,7 @@ export async function banMember(bot: Bot, guildId: bigint, userId: bigint, optio } /** https://discord.com/developers/docs/resources/guild#create-guild-ban */ -export interface CreateGuildBan { +export interface CreateGuildBan extends WithReason { /** Number of seconds to delete messages for, between 0 and 604800 (7 days) */ deleteMessageSeconds?: number; - /** Reason for the ban */ - reason?: string; } diff --git a/helpers/members/editBotMember.ts b/helpers/members/editBotMember.ts index 8604e2789..c268bbc47 100644 --- a/helpers/members/editBotMember.ts +++ b/helpers/members/editBotMember.ts @@ -1,5 +1,5 @@ import type { Bot } from "../../bot.ts"; -import { DiscordMember, Member } from "../../mod.ts"; +import { DiscordMember, Member, WithReason } from "../../mod.ts"; /** * Edits the nickname of the bot user. @@ -17,14 +17,21 @@ import { DiscordMember, Member } from "../../mod.ts"; export async function editBotMember( bot: Bot, guildId: bigint, - options: { nick: string | null; reason?: string }, + options: EditBotMemberOptions, ): Promise { const result = await bot.rest.runMethod( bot.rest, "PATCH", bot.constants.routes.USER_NICK(guildId), - options, + { + nick: options.nick, + reason: options.reason, + }, ); return bot.transformers.member(bot, result, guildId, bot.id); } + +export interface EditBotMemberOptions extends WithReason { + nick?: string | null; +} diff --git a/helpers/messages/pinMessage.ts b/helpers/messages/pinMessage.ts index 63b92086b..df10893f1 100644 --- a/helpers/messages/pinMessage.ts +++ b/helpers/messages/pinMessage.ts @@ -18,6 +18,11 @@ import type { Bot } from "../../bot.ts"; * * @see {@link https://discord.com/developers/docs/resources/channel#pin-message} */ -export async function pinMessage(bot: Bot, channelId: bigint, messageId: bigint): Promise { - return await bot.rest.runMethod(bot.rest, "PUT", bot.constants.routes.CHANNEL_PIN(channelId, messageId)); +export async function pinMessage(bot: Bot, channelId: bigint, messageId: bigint, reason?: string): Promise { + return await bot.rest.runMethod( + bot.rest, + "PUT", + bot.constants.routes.CHANNEL_PIN(channelId, messageId), + reason ? { reason } : undefined, + ); } diff --git a/helpers/messages/unpinMessage.ts b/helpers/messages/unpinMessage.ts index bdf92f09a..3ea4789fe 100644 --- a/helpers/messages/unpinMessage.ts +++ b/helpers/messages/unpinMessage.ts @@ -16,10 +16,11 @@ import type { Bot } from "../../bot.ts"; * * @see {@link https://discord.com/developers/docs/resources/channel#unpin-message} */ -export async function unpinMessage(bot: Bot, channelId: bigint, messageId: bigint): Promise { +export async function unpinMessage(bot: Bot, channelId: bigint, messageId: bigint, reason?: string): Promise { return await bot.rest.runMethod( bot.rest, "DELETE", bot.constants.routes.CHANNEL_PIN(channelId, messageId), + reason ? { reason } : undefined, ); } diff --git a/helpers/webhooks/createWebhook.ts b/helpers/webhooks/createWebhook.ts index 8d48acb9f..ad3b3be96 100644 --- a/helpers/webhooks/createWebhook.ts +++ b/helpers/webhooks/createWebhook.ts @@ -1,4 +1,5 @@ import type { Bot } from "../../bot.ts"; +import { WithReason } from "../../mod.ts"; import { Webhook } from "../../transformers/webhook.ts"; import { DiscordWebhook } from "../../types/discord.ts"; @@ -34,11 +35,9 @@ export async function createWebhook(bot: Bot, channelId: bigint, options: Create return bot.transformers.webhook(bot, result); } -export interface CreateWebhook { +export interface CreateWebhook extends WithReason { /** Name of the webhook (1-80 characters) */ name: string; /** Image url for the default webhook avatar */ avatar?: string | null; - /** The reason you are creating this webhook */ - reason?: string; } diff --git a/helpers/webhooks/editWebhook.ts b/helpers/webhooks/editWebhook.ts index 979dcaacc..b4964a3ab 100644 --- a/helpers/webhooks/editWebhook.ts +++ b/helpers/webhooks/editWebhook.ts @@ -1,4 +1,5 @@ import type { Bot } from "../../bot.ts"; +import { WithReason } from "../../mod.ts"; import { Webhook } from "../../transformers/webhook.ts"; import { DiscordWebhook } from "../../types/discord.ts"; @@ -32,13 +33,11 @@ export async function editWebhook(bot: Bot, webhookId: bigint, options: ModifyWe return bot.transformers.webhook(bot, result); } -export interface ModifyWebhook { +export interface ModifyWebhook extends WithReason { /** The default name of the webhook */ name?: string; /** Image for the default webhook avatar */ avatar?: bigint | null; /** The new channel id this webhook should be moved to */ channelId?: bigint; - /** The reason you are modifying this webhook */ - reason?: string; } diff --git a/types/discordeno.ts b/types/discordeno.ts index c903380c2..0b54490b6 100644 --- a/types/discordeno.ts +++ b/types/discordeno.ts @@ -8,6 +8,7 @@ import { InteractionResponseTypes, Localization, MessageComponentTypes, + OverwriteTypes, PermissionStrings, TextStyles, } from "./shared.ts"; @@ -212,3 +213,19 @@ export interface InteractionCallbackData { /** Autocomplete choices (max of 25 choices) */ choices?: ApplicationCommandOptionChoice[]; } + +export interface WithReason { + /** The reason which should be added in the audit logs for doing this action. */ + reason?: string; +} + +export interface OverwriteReadable { + /** Role or user id */ + id: bigint; + /** Either 0 (role) or 1 (member) */ + type: OverwriteTypes; + /** Permission bit set */ + allow?: PermissionStrings[]; + /** Permission bit set */ + deny?: PermissionStrings[]; +}