From e0955df780df3c35b433a6f809ca216ce946298b Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Wed, 10 Nov 2021 19:06:24 +0000 Subject: [PATCH] i love you --- src/bot.ts | 66 --- .../channels/delete_channel_overwrite.ts | 3 - .../channels/edit_channel_overwrite.ts | 3 - src/helpers/channels/follow_channel.ts | 2 - src/helpers/channels/get_channel_webhooks.ts | 2 - .../channels/threads/get_archived_threads.ts | 1 - .../discovery/add_discovery_subcategory.ts | 3 - src/helpers/discovery/edit_discovery.ts | 3 - src/helpers/discovery/get_discovery.ts | 3 - .../discovery/remove_discovery_subcategory.ts | 2 - src/helpers/emojis/create_emoji.ts | 2 - src/helpers/emojis/delete_emoji.ts | 2 - src/helpers/emojis/edit_emoji.ts | 2 - src/helpers/guilds/edit_widget.ts | 2 - src/helpers/guilds/get_audit_logs.ts | 2 - src/helpers/guilds/get_ban.ts | 2 - src/helpers/guilds/get_bans.ts | 2 - src/helpers/guilds/get_prune_count.ts | 2 - src/helpers/guilds/get_widget_settings.ts | 2 - .../integrations/delete_integration.ts | 2 - src/helpers/integrations/get_integrations.ts | 2 - src/helpers/invites/create_invite.ts | 2 - src/helpers/invites/get_channel_invites.ts | 2 - src/helpers/invites/get_invites.ts | 2 - src/helpers/members/ban_member.ts | 2 - src/helpers/members/edit_bot_nickname.ts | 2 - src/helpers/members/kick_member.ts | 14 +- src/helpers/members/prune_members.ts | 2 - src/helpers/members/unban_member.ts | 7 +- src/helpers/messages/add_reaction.ts | 2 - src/helpers/messages/delete_messages.ts | 2 - src/helpers/messages/get_messages.ts | 2 - src/helpers/messages/remove_all_reactions.ts | 2 - src/helpers/messages/remove_reaction.ts | 4 - src/helpers/messages/remove_reaction_emoji.ts | 2 - src/helpers/messages/unpin_message.ts | 7 +- src/helpers/mod.ts | 9 +- src/helpers/roles/add_role.ts | 7 - src/helpers/roles/create_role.ts | 24 +- src/helpers/roles/delete_role.ts | 2 - src/helpers/roles/edit_role.ts | 3 - src/helpers/roles/get_roles.ts | 2 - src/helpers/roles/remove_role.ts | 7 - .../templates/create_guild_template.ts | 4 - .../templates/delete_guild_template.ts | 2 - src/helpers/templates/edit_guild_template.ts | 2 - src/helpers/templates/get_guild_templates.ts | 2 - src/helpers/templates/sync_guild_template.ts | 2 - src/helpers/voice/connect_to_voice_channel.ts | 2 - src/helpers/webhooks/create_webhook.ts | 3 - src/helpers/webhooks/delete_webhook.ts | 2 - src/helpers/webhooks/edit_webhook.ts | 16 +- src/helpers/webhooks/get_webhooks.ts | 2 - src/util/mod.ts | 1 - src/util/permissions.ts | 377 ------------------ .../channels/deleteChannelOverwrite.ts | 2 +- tests/helpers/guilds/getVanityUrl.ts | 2 - tests/local.ts | 1 - tests/util/permissions.ts | 49 --- 59 files changed, 21 insertions(+), 666 deletions(-) delete mode 100644 src/util/permissions.ts delete mode 100644 tests/util/permissions.ts diff --git a/src/bot.ts b/src/bot.ts index afbfb9924..3ee562630 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -1,24 +1,3 @@ -import { - calculateChannelOverwrites, - calculateBasePermissions, - getCached, - hasChannelPermissions, - hasGuildPermissions, - validatePermissions, - getMissingChannelPermissions, - getMissingGuildPermissions, - requireGuildPermissions, - requireChannelPermissions, - highestRole, - higherRolePosition, - requireBotChannelPermissions, - requireBotGuildPermissions, - botHasChannelPermissions, - calculateBits, - isHigherPosition, - requireOverwritePermissions, - calculatePermissions, -} from "./util/permissions.ts"; import { checkRateLimits, processQueue, @@ -320,34 +299,14 @@ export function createUtils(options: Partial) { delay, iconHashToBigInt, iconBigintToHash, - // Permissions - getCached, - calculateBasePermissions, - calculateChannelOverwrites, - getMissingChannelPermissions, - getMissingGuildPermissions, - hasGuildPermissions, - hasChannelPermissions, - requireGuildPermissions, - requireChannelPermissions, - validatePermissions, - highestRole, - higherRolePosition, validateLength, validateSlashOptions, validateSlashOptionChoices, - requireBotChannelPermissions, - requireBotGuildPermissions, validateComponents, hasProperty, urlToBase64, - botHasChannelPermissions, - calculateBits, - isHigherPosition, formatImageURL, validateSlashCommands, - requireOverwritePermissions, - calculatePermissions, }; } @@ -358,33 +317,14 @@ export interface HelperUtils { delay: typeof delay; iconHashToBigInt: typeof iconHashToBigInt; iconBigintToHash: typeof iconBigintToHash; - getCached: typeof getCached; - calculateBasePermissions: typeof calculateBasePermissions; - calculateChannelOverwrites: typeof calculateChannelOverwrites; - hasGuildPermissions: typeof hasGuildPermissions; - hasChannelPermissions: typeof hasChannelPermissions; - validatePermissions: typeof validatePermissions; - getMissingChannelPermissions: typeof getMissingChannelPermissions; - getMissingGuildPermissions: typeof getMissingGuildPermissions; - requireGuildPermissions: typeof requireGuildPermissions; - requireChannelPermissions: typeof requireChannelPermissions; - highestRole: typeof highestRole; - higherRolePosition: typeof higherRolePosition; validateLength: typeof validateLength; validateSlashOptions: typeof validateSlashOptions; validateSlashOptionChoices: typeof validateSlashOptionChoices; - requireBotChannelPermissions: typeof requireBotChannelPermissions; - requireBotGuildPermissions: typeof requireBotGuildPermissions; - botHasChannelPermissions: typeof botHasChannelPermissions; validateComponents: typeof validateComponents; hasProperty: typeof hasProperty; urlToBase64: typeof urlToBase64; - calculateBits: typeof calculateBits; - isHigherPosition: typeof isHigherPosition; formatImageURL: typeof formatImageURL; validateSlashCommands: typeof validateSlashCommands; - requireOverwritePermissions: typeof requireOverwritePermissions; - calculatePermissions: typeof calculatePermissions; } export function createGatewayManager( @@ -613,7 +553,6 @@ export interface Helpers { isButton: typeof helpers.isButton; isSelectMenu: typeof helpers.isSelectMenu; isSlashCommand: typeof helpers.isSlashCommand; - kick: typeof helpers.kick; kickMember: typeof helpers.kickMember; leaveGuild: typeof helpers.leaveGuild; moveMember: typeof helpers.moveMember; @@ -632,9 +571,7 @@ export interface Helpers { startTyping: typeof helpers.startTyping; swapChannels: typeof helpers.swapChannels; syncGuildTemplate: typeof helpers.syncGuildTemplate; - unban: typeof helpers.unban; unbanMember: typeof helpers.unbanMember; - unpin: typeof helpers.unpin; unpinMessage: typeof helpers.unpinMessage; updateBotVoiceState: typeof helpers.updateBotVoiceState; updateStageInstance: typeof helpers.updateStageInstance; @@ -785,7 +722,6 @@ export function createBaseHelpers(options: Partial) { isButton: options.isButton || helpers.isButton, isSelectMenu: options.isSelectMenu || helpers.isSelectMenu, isSlashCommand: options.isSlashCommand || helpers.isSlashCommand, - kick: options.kick || helpers.kick, kickMember: options.kickMember || helpers.kickMember, leaveGuild: options.leaveGuild || helpers.leaveGuild, moveMember: options.moveMember || helpers.moveMember, @@ -804,9 +740,7 @@ export function createBaseHelpers(options: Partial) { startTyping: options.startTyping || helpers.startTyping, swapChannels: options.swapChannels || helpers.swapChannels, syncGuildTemplate: options.syncGuildTemplate || helpers.syncGuildTemplate, - unban: options.unban || helpers.unban, unbanMember: options.unbanMember || helpers.unbanMember, - unpin: options.unpin || helpers.unpin, unpinMessage: options.unpinMessage || helpers.unpinMessage, updateBotVoiceState: options.updateBotVoiceState || helpers.updateBotVoiceState, updateStageInstance: options.updateStageInstance || helpers.updateStageInstance, diff --git a/src/helpers/channels/delete_channel_overwrite.ts b/src/helpers/channels/delete_channel_overwrite.ts index 064aec2c6..1ac507244 100644 --- a/src/helpers/channels/delete_channel_overwrite.ts +++ b/src/helpers/channels/delete_channel_overwrite.ts @@ -3,12 +3,9 @@ import type { Bot } from "../../bot.ts"; /** Delete the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */ export async function deleteChannelOverwrite( bot: Bot, - guildId: bigint, channelId: bigint, overwriteId: bigint ): Promise { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]); - return await bot.rest.runMethod( bot.rest, "delete", diff --git a/src/helpers/channels/edit_channel_overwrite.ts b/src/helpers/channels/edit_channel_overwrite.ts index 686d1f170..3fac722c7 100644 --- a/src/helpers/channels/edit_channel_overwrite.ts +++ b/src/helpers/channels/edit_channel_overwrite.ts @@ -4,13 +4,10 @@ import type { Bot } from "../../bot.ts"; /** Edit the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */ export async function editChannelOverwrite( bot: Bot, - guildId: bigint, channelId: bigint, overwriteId: bigint, options: Omit ): Promise { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]); - return await bot.rest.runMethod( bot.rest, "put", diff --git a/src/helpers/channels/follow_channel.ts b/src/helpers/channels/follow_channel.ts index bdf9bdd45..22cf8a41b 100644 --- a/src/helpers/channels/follow_channel.ts +++ b/src/helpers/channels/follow_channel.ts @@ -3,8 +3,6 @@ import type { Bot } from "../../bot.ts"; /** Follow a News Channel to send messages to a target channel. Requires the `MANAGE_WEBHOOKS` permission in the target channel. Returns the webhook id. */ export async function followChannel(bot: Bot, sourceChannelId: bigint, targetChannelId: bigint) { - await bot.utils.requireBotChannelPermissions(bot, targetChannelId, ["MANAGE_WEBHOOKS"]); - const data = await bot.rest.runMethod( bot.rest, "post", diff --git a/src/helpers/channels/get_channel_webhooks.ts b/src/helpers/channels/get_channel_webhooks.ts index fe6e0cb0f..6cec421a4 100644 --- a/src/helpers/channels/get_channel_webhooks.ts +++ b/src/helpers/channels/get_channel_webhooks.ts @@ -4,8 +4,6 @@ import type { Bot } from "../../bot.ts"; /** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */ export async function getChannelWebhooks(bot: Bot, channelId: bigint) { - await bot.utils.requireBotChannelPermissions(bot, channelId, ["MANAGE_WEBHOOKS"]); - const result = await bot.rest.runMethod( bot.rest, "get", diff --git a/src/helpers/channels/threads/get_archived_threads.ts b/src/helpers/channels/threads/get_archived_threads.ts index 02bfa0ae6..fa6409ffd 100644 --- a/src/helpers/channels/threads/get_archived_threads.ts +++ b/src/helpers/channels/threads/get_archived_threads.ts @@ -15,7 +15,6 @@ export async function getArchivedThreads( ) { // const permissions = new Set(["READ_MESSAGE_HISTORY"]); // if (options?.type === "private") permissions.add("MANAGE_THREADS"); - // await bot.utils.requireBotChannelPermissions(bot, channelId, [...permissions]); // // TODO: pagination // const result = (await bot.rest.runMethod( // bot.rest, diff --git a/src/helpers/discovery/add_discovery_subcategory.ts b/src/helpers/discovery/add_discovery_subcategory.ts index bf28ce575..94ef64085 100644 --- a/src/helpers/discovery/add_discovery_subcategory.ts +++ b/src/helpers/discovery/add_discovery_subcategory.ts @@ -1,11 +1,8 @@ import type { AddGuildDiscoverySubcategory } from "../../types/discovery/add_guild_discovery_subcategory.ts"; import type { Bot } from "../../bot.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Add a discovery subcategory to the guild. Requires the `MANAGE_GUILD` permission. */ export async function addDiscoverySubcategory(bot: Bot, guildId: bigint, categoryId: number) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]); - return await bot.rest.runMethod( bot.rest, "post", diff --git a/src/helpers/discovery/edit_discovery.ts b/src/helpers/discovery/edit_discovery.ts index 81f21aab6..34f922679 100644 --- a/src/helpers/discovery/edit_discovery.ts +++ b/src/helpers/discovery/edit_discovery.ts @@ -1,12 +1,9 @@ import type { DiscoveryMetadata } from "../../types/discovery/discovery_metadata.ts"; import type { ModifyGuildDiscoveryMetadata } from "../../types/discovery/modify_guild_discovery_metadata.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import type { Bot } from "../../bot.ts"; /** Modify the discovery metadata for the guild. Requires the MANAGE_GUILD permission. Returns the updated discovery metadata object on success. */ export async function editDiscovery(bot: Bot, guildId: bigint, data: ModifyGuildDiscoveryMetadata) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]); - return await bot.rest.runMethod( bot.rest, "patch", diff --git a/src/helpers/discovery/get_discovery.ts b/src/helpers/discovery/get_discovery.ts index 49f3a588d..dca3a3e39 100644 --- a/src/helpers/discovery/get_discovery.ts +++ b/src/helpers/discovery/get_discovery.ts @@ -1,11 +1,8 @@ import type { DiscoveryMetadata } from "../../types/discovery/discovery_metadata.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; import type { Bot } from "../../bot.ts"; /** Returns the discovery metadata object for the guild. Requires the `MANAGE_GUILD` permission. */ export async function getDiscovery(bot: Bot, guildId: bigint) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]); - return await bot.rest.runMethod( bot.rest, "get", diff --git a/src/helpers/discovery/remove_discovery_subcategory.ts b/src/helpers/discovery/remove_discovery_subcategory.ts index 38fee53f0..7aec290c4 100644 --- a/src/helpers/discovery/remove_discovery_subcategory.ts +++ b/src/helpers/discovery/remove_discovery_subcategory.ts @@ -2,8 +2,6 @@ import type { Bot } from "../../bot.ts"; /** Removes a discovery subcategory from the guild. Requires the MANAGE_GUILD permission. Returns a 204 No Content on success. */ export async function removeDiscoverySubcategory(bot: Bot, guildId: bigint, categoryId: number) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]); - return await bot.rest.runMethod( bot.rest, "delete", diff --git a/src/helpers/emojis/create_emoji.ts b/src/helpers/emojis/create_emoji.ts index 2debc8bc7..2f6c2f795 100644 --- a/src/helpers/emojis/create_emoji.ts +++ b/src/helpers/emojis/create_emoji.ts @@ -4,8 +4,6 @@ import type { Bot } from "../../bot.ts"; /** Create an emoji in the server. 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. */ export async function createEmoji(bot: Bot, guildId: bigint, options: CreateGuildEmoji) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS"]); - if (options.image && !options.image.startsWith("data:image/")) { options.image = await bot.utils.urlToBase64(options.image); } diff --git a/src/helpers/emojis/delete_emoji.ts b/src/helpers/emojis/delete_emoji.ts index 075a835fa..e9c63446f 100644 --- a/src/helpers/emojis/delete_emoji.ts +++ b/src/helpers/emojis/delete_emoji.ts @@ -2,8 +2,6 @@ import type { Bot } from "../../bot.ts"; /** Delete the given emoji. Requires the MANAGE_EMOJIS permission. Returns 204 No Content on success. */ export async function deleteEmoji(bot: Bot, guildId: bigint, id: bigint, reason?: string) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS"]); - return await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.GUILD_EMOJI(guildId, id), { reason, }); diff --git a/src/helpers/emojis/edit_emoji.ts b/src/helpers/emojis/edit_emoji.ts index abd7175c0..0409afecd 100644 --- a/src/helpers/emojis/edit_emoji.ts +++ b/src/helpers/emojis/edit_emoji.ts @@ -4,7 +4,5 @@ import type { Bot } from "../../bot.ts"; /** Modify the given emoji. Requires the MANAGE_EMOJIS permission. */ export async function editEmoji(bot: Bot, guildId: bigint, id: bigint, options: ModifyGuildEmoji) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_EMOJIS"]); - return await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.GUILD_EMOJI(guildId, id), options); } diff --git a/src/helpers/guilds/edit_widget.ts b/src/helpers/guilds/edit_widget.ts index 2b17cf91e..a50c414f8 100644 --- a/src/helpers/guilds/edit_widget.ts +++ b/src/helpers/guilds/edit_widget.ts @@ -3,8 +3,6 @@ import type { Bot } from "../../bot.ts"; /** Modify a guild widget object for the guild. Requires the MANAGE_GUILD permission. */ export async function editWidget(bot: Bot, guildId: bigint, enabled: boolean, channelId?: string | null) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]); - return await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.GUILD_WIDGET(guildId), { enabled, channel_id: channelId, diff --git a/src/helpers/guilds/get_audit_logs.ts b/src/helpers/guilds/get_audit_logs.ts index e3847b2dd..c502377ea 100644 --- a/src/helpers/guilds/get_audit_logs.ts +++ b/src/helpers/guilds/get_audit_logs.ts @@ -4,8 +4,6 @@ import type { Bot } from "../../bot.ts"; /** Returns the audit logs for the guild. Requires VIEW AUDIT LOGS permission */ export async function getAuditLogs(bot: Bot, guildId: bigint, options?: GetGuildAuditLog) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["VIEW_AUDIT_LOG"]); - if (options?.userId) options.userId = options.userId.toString(); if (options?.before) options.before = options.before.toString(); if (options?.limit) options.limit = options.limit >= 1 && options.limit <= 100 ? options.limit : 50; diff --git a/src/helpers/guilds/get_ban.ts b/src/helpers/guilds/get_ban.ts index bb42517ea..3d1b8f17a 100644 --- a/src/helpers/guilds/get_ban.ts +++ b/src/helpers/guilds/get_ban.ts @@ -3,8 +3,6 @@ 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(bot: Bot, guildId: bigint, memberId: bigint) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]); - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_BAN(guildId, memberId)); return { diff --git a/src/helpers/guilds/get_bans.ts b/src/helpers/guilds/get_bans.ts index 95eb3882f..2b1b2af56 100644 --- a/src/helpers/guilds/get_bans.ts +++ b/src/helpers/guilds/get_bans.ts @@ -4,8 +4,6 @@ import { Collection } from "../../util/collection.ts"; /** Returns a list of ban objects for the users banned from this guild. Requires the BAN_MEMBERS permission. */ export async function getBans(bot: Bot, guildId: bigint) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]); - const results = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_BANS(guildId)); return new Collection(results.map((res) => [bot.transformers.snowflake(res.user.id), res])); diff --git a/src/helpers/guilds/get_prune_count.ts b/src/helpers/guilds/get_prune_count.ts index 93671bf27..a089debb7 100644 --- a/src/helpers/guilds/get_prune_count.ts +++ b/src/helpers/guilds/get_prune_count.ts @@ -8,8 +8,6 @@ export async function getPruneCount(bot: Bot, guildId: bigint, options?: GetGuil throw new Error(bot.constants.Errors.PRUNE_MAX_DAYS); } - await bot.utils.requireBotGuildPermissions(bot, guildId, ["KICK_MEMBERS"]); - const result = await bot.rest.runMethod( bot.rest, "get", diff --git a/src/helpers/guilds/get_widget_settings.ts b/src/helpers/guilds/get_widget_settings.ts index 2295e2640..69392d146 100644 --- a/src/helpers/guilds/get_widget_settings.ts +++ b/src/helpers/guilds/get_widget_settings.ts @@ -3,7 +3,5 @@ import type { Bot } from "../../bot.ts"; /** Returns the guild widget object. Requires the MANAGE_GUILD permission. */ export async function getWidgetSettings(bot: Bot, guildId: bigint) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]); - return await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_WIDGET(guildId)); } diff --git a/src/helpers/integrations/delete_integration.ts b/src/helpers/integrations/delete_integration.ts index 4cee41844..10d420230 100644 --- a/src/helpers/integrations/delete_integration.ts +++ b/src/helpers/integrations/delete_integration.ts @@ -2,8 +2,6 @@ import type { Bot } from "../../bot.ts"; /** Delete the attached integration object for the guild with this id. Requires MANAGE_GUILD permission. */ export async function deleteIntegration(bot: Bot, guildId: bigint, id: bigint) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]); - return await bot.rest.runMethod( bot.rest, "delete", diff --git a/src/helpers/integrations/get_integrations.ts b/src/helpers/integrations/get_integrations.ts index 9c1cbadac..fb0d2fec2 100644 --- a/src/helpers/integrations/get_integrations.ts +++ b/src/helpers/integrations/get_integrations.ts @@ -3,7 +3,5 @@ import type { Bot } from "../../bot.ts"; /** Returns a list of integrations for the guild. Requires the MANAGE_GUILD permission. */ export async function getIntegrations(bot: Bot, guildId: bigint) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]); - return await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_INTEGRATIONS(guildId)); } diff --git a/src/helpers/invites/create_invite.ts b/src/helpers/invites/create_invite.ts index 6936dd8b9..15e0d8d5b 100644 --- a/src/helpers/invites/create_invite.ts +++ b/src/helpers/invites/create_invite.ts @@ -6,8 +6,6 @@ import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Creates a new invite for this channel. Requires CREATE_INSTANT_INVITE */ export async function createInvite(bot: Bot, channelId: bigint, options: CreateChannelInvite = {}) { - await bot.utils.requireBotChannelPermissions(bot, channelId, ["CREATE_INSTANT_INVITE"]); - if (options.maxAge && (options.maxAge < 0 || options.maxAge > 604800)) { throw new Error(Errors.INVITE_MAX_AGE_INVALID); } diff --git a/src/helpers/invites/get_channel_invites.ts b/src/helpers/invites/get_channel_invites.ts index 65518d216..bef38db27 100644 --- a/src/helpers/invites/get_channel_invites.ts +++ b/src/helpers/invites/get_channel_invites.ts @@ -5,8 +5,6 @@ import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Gets the invites for this channel. Requires MANAGE_CHANNEL */ export async function getChannelInvites(bot: Bot, channelId: bigint) { - await bot.utils.requireBotChannelPermissions(bot, channelId, ["MANAGE_CHANNELS"]); - const result = await bot.rest.runMethod( bot.rest, "get", diff --git a/src/helpers/invites/get_invites.ts b/src/helpers/invites/get_invites.ts index 5c0b22e6d..006f9b54e 100644 --- a/src/helpers/invites/get_invites.ts +++ b/src/helpers/invites/get_invites.ts @@ -5,8 +5,6 @@ import type { Bot } from "../../bot.ts"; /** Get all the invites for this guild. Requires MANAGE_GUILD permission */ export async function getInvites(bot: Bot, guildId: bigint) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]); - const result = await bot.rest.runMethod( bot.rest, "get", diff --git a/src/helpers/members/ban_member.ts b/src/helpers/members/ban_member.ts index 06a986f0a..ff46b0147 100644 --- a/src/helpers/members/ban_member.ts +++ b/src/helpers/members/ban_member.ts @@ -3,8 +3,6 @@ import type { Bot } from "../../bot.ts"; /** Ban a user from the guild and optionally delete previous messages sent by the user. Requires the BAN_MEMBERS permission. */ export async function ban(bot: Bot, guildId: bigint, id: bigint, options?: CreateGuildBan) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]); - return await bot.rest.runMethod( bot.rest, "put", diff --git a/src/helpers/members/edit_bot_nickname.ts b/src/helpers/members/edit_bot_nickname.ts index 822cc6e42..e8bf82546 100644 --- a/src/helpers/members/edit_bot_nickname.ts +++ b/src/helpers/members/edit_bot_nickname.ts @@ -2,8 +2,6 @@ import type { Bot } from "../../bot.ts"; /** Edit the nickname of the bot in this guild */ export async function editBotNickname(bot: Bot, guildId: bigint, nickname: string | null) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["CHANGE_NICKNAME"]); - const response = await bot.rest.runMethod<{ nick: string }>( bot.rest, "patch", diff --git a/src/helpers/members/kick_member.ts b/src/helpers/members/kick_member.ts index 4a8b06bb5..c2dd61543 100644 --- a/src/helpers/members/kick_member.ts +++ b/src/helpers/members/kick_member.ts @@ -1,14 +1,7 @@ import { Bot } from "../../bot.ts"; + /** Kick a member from the server */ -export async function kick(bot: Bot, guildId: bigint, memberId: bigint, reason?: string) { - const botsHighestRole = await bot.utils.highestRole(bot, guildId, bot.id); - const membersHighestRole = await bot.utils.highestRole(bot, guildId, memberId); - if (botsHighestRole && membersHighestRole && botsHighestRole.position <= membersHighestRole.position) { - throw new Error(bot.constants.Errors.BOTS_HIGHEST_ROLE_TOO_LOW); - } - - await bot.utils.requireBotGuildPermissions(bot, guildId, ["KICK_MEMBERS"]); - +export async function kickMember(bot: Bot, guildId: bigint, memberId: bigint, reason?: string) { return await bot.rest.runMethod( bot.rest, "delete", @@ -16,6 +9,3 @@ export async function kick(bot: Bot, guildId: bigint, memberId: bigint, reason?: { reason } ); } - -// aliases -export { kick as kickMember }; diff --git a/src/helpers/members/prune_members.ts b/src/helpers/members/prune_members.ts index 22924ac9f..d2956de11 100644 --- a/src/helpers/members/prune_members.ts +++ b/src/helpers/members/prune_members.ts @@ -10,8 +10,6 @@ export async function pruneMembers(bot: Bot, guildId: bigint, options: BeginGuil if (options.days && options.days < 1) throw new Error(bot.constants.Errors.PRUNE_MIN_DAYS); if (options.days && options.days > 30) throw new Error(bot.constants.Errors.PRUNE_MAX_DAYS); - await bot.utils.requireBotGuildPermissions(bot, guildId, ["KICK_MEMBERS"]); - const result = await bot.rest.runMethod<{ pruned: number }>( bot.rest, "post", diff --git a/src/helpers/members/unban_member.ts b/src/helpers/members/unban_member.ts index d072d32d2..71bc569c5 100644 --- a/src/helpers/members/unban_member.ts +++ b/src/helpers/members/unban_member.ts @@ -1,11 +1,6 @@ import type { Bot } from "../../bot.ts"; /** Remove the ban for a user. Requires BAN_MEMBERS permission */ -export async function unban(bot: Bot, guildId: bigint, id: bigint) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["BAN_MEMBERS"]); - +export async function unbanMember(bot: Bot, guildId: bigint, id: bigint) { return await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.GUILD_BAN(guildId, id)); } - -// aliases -export { unban as unbanMember }; diff --git a/src/helpers/messages/add_reaction.ts b/src/helpers/messages/add_reaction.ts index c832b53c3..cb085f02a 100644 --- a/src/helpers/messages/add_reaction.ts +++ b/src/helpers/messages/add_reaction.ts @@ -2,8 +2,6 @@ import type { Bot } from "../../bot.ts"; /** Create a reaction for the message. Reaction takes the form of **name:id** for custom guild emoji, or Unicode characters. Requires READ_MESSAGE_HISTORY and ADD_REACTIONS */ export async function addReaction(bot: Bot, channelId: bigint, messageId: bigint, reaction: string) { - await bot.utils.requireBotChannelPermissions(bot, channelId, ["ADD_REACTIONS", "READ_MESSAGE_HISTORY"]); - if (reaction.startsWith("<:")) { reaction = reaction.substring(2, reaction.length - 1); } else if (reaction.startsWith(" 100)) { throw new Error(bot.constants.Errors.INVALID_GET_MESSAGES_LIMIT); } diff --git a/src/helpers/messages/remove_all_reactions.ts b/src/helpers/messages/remove_all_reactions.ts index 16d8d5b80..d4f18e13a 100644 --- a/src/helpers/messages/remove_all_reactions.ts +++ b/src/helpers/messages/remove_all_reactions.ts @@ -2,8 +2,6 @@ import type { Bot } from "../../bot.ts"; /** Removes all reactions for all emojis on this message. */ export async function removeAllReactions(bot: Bot, channelId: bigint, messageId: bigint) { - await bot.utils.requireBotChannelPermissions(bot, channelId, ["MANAGE_MESSAGES"]); - return await bot.rest.runMethod( bot.rest, "delete", diff --git a/src/helpers/messages/remove_reaction.ts b/src/helpers/messages/remove_reaction.ts index ada16b884..d43b84f5c 100644 --- a/src/helpers/messages/remove_reaction.ts +++ b/src/helpers/messages/remove_reaction.ts @@ -8,10 +8,6 @@ export async function removeReaction( reaction: string, options?: { userId?: bigint } ) { - if (options?.userId) { - await bot.utils.requireBotChannelPermissions(bot, channelId, ["MANAGE_MESSAGES"]); - } - if (reaction.startsWith("<:")) { reaction = reaction.substring(2, reaction.length - 1); } else if (reaction.startsWith(" { - await bot.utils.requireBotChannelPermissions(bot, channelId, ["MANAGE_MESSAGES"]); - +export async function unpinMessage(bot: Bot, channelId: bigint, messageId: bigint): Promise { return await bot.rest.runMethod( bot.rest, "delete", bot.constants.endpoints.CHANNEL_PIN(channelId, messageId) ); } - -// aliases -export { unpin as unpinMessage }; diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 6925401b2..06f4d36aa 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -74,11 +74,11 @@ import { editMember } from "./members/edit_member.ts"; import { fetchMembers } from "./members/fetch_members.ts"; import { getMember } from "./members/get_member.ts"; import { getMembers } from "./members/get_members.ts"; -import { kick, kickMember } from "./members/kick_member.ts"; +import { kickMember } from "./members/kick_member.ts"; import { moveMember } from "./members/move_member.ts"; import { pruneMembers } from "./members/prune_members.ts"; import { getDmChannel } from "./members/send_direct_message.ts"; -import { unban, unbanMember } from "./members/unban_member.ts"; +import { unbanMember } from "./members/unban_member.ts"; import { addReaction } from "./messages/add_reaction.ts"; import { addReactions } from "./messages/add_reactions.ts"; import { deleteMessage } from "./messages/delete_message.ts"; @@ -94,7 +94,7 @@ import { removeReaction } from "./messages/remove_reaction.ts"; import { removeReactionEmoji } from "./messages/remove_reaction_emoji.ts"; import { sendMessage } from "./messages/send_message.ts"; import { suppressEmbeds } from "./messages/suppress_embeds.ts"; -import { unpin, unpinMessage } from "./messages/unpin_message.ts"; +import { unpinMessage } from "./messages/unpin_message.ts"; import { editBotProfile } from "./misc/edit_bot_profile.ts"; import { editBotStatus } from "./misc/edit_bot_status.ts"; import { getGatewayBot } from "./misc/get_gateway_bot.ts"; @@ -265,7 +265,6 @@ export { isButton, isSelectMenu, isSlashCommand, - kick, kickMember, leaveGuild, moveMember, @@ -284,9 +283,7 @@ export { startTyping, swapChannels, syncGuildTemplate, - unban, unbanMember, - unpin, unpinMessage, updateBotVoiceState, updateStageInstance, diff --git a/src/helpers/roles/add_role.ts b/src/helpers/roles/add_role.ts index 230d9b43c..2e1a618f2 100644 --- a/src/helpers/roles/add_role.ts +++ b/src/helpers/roles/add_role.ts @@ -2,13 +2,6 @@ import type { Bot } from "../../bot.ts"; /** Add a role to the member */ export async function addRole(bot: Bot, guildId: bigint, memberId: bigint, roleId: bigint, reason?: string) { - const isHigherRolePosition = await bot.utils.isHigherPosition(bot, guildId, bot.id, roleId); - if (!isHigherRolePosition) { - throw new Error(bot.constants.Errors.BOTS_HIGHEST_ROLE_TOO_LOW); - } - - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]); - return await bot.rest.runMethod( bot.rest, "put", diff --git a/src/helpers/roles/create_role.ts b/src/helpers/roles/create_role.ts index 3f4966daf..15a679019 100644 --- a/src/helpers/roles/create_role.ts +++ b/src/helpers/roles/create_role.ts @@ -4,22 +4,16 @@ import type { Bot } from "../../bot.ts"; /** Create a new role for the guild. Requires the MANAGE_ROLES permission. */ export async function createRole(bot: Bot, guildId: bigint, options: CreateGuildRole, reason?: string) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]); + const result = await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.GUILD_ROLES(guildId), { + name: options.name, + color: options.color, + hoist: options.hoist, + mentionable: options.mentionable, + permissions: bot.utils.calculateBits(options?.permissions || []), + reason, + }); - const result = await bot.rest.runMethod(bot.rest, - "post", - bot.constants.endpoints.GUILD_ROLES(guildId), - { - name: options.name, - color: options.color, - hoist: options.hoist, - mentionable: options.mentionable, - permissions: bot.utils.calculateBits(options?.permissions || []), - reason, - } - ); - - const role = await bot.transformers.role(bot, { + const role = bot.transformers.role(bot, { role: result, guildId, }); diff --git a/src/helpers/roles/delete_role.ts b/src/helpers/roles/delete_role.ts index 698da0987..af217256a 100644 --- a/src/helpers/roles/delete_role.ts +++ b/src/helpers/roles/delete_role.ts @@ -2,7 +2,5 @@ import type { Bot } from "../../bot.ts"; /** Delete a guild role. Requires the MANAGE_ROLES permission. */ export async function deleteRole(bot: Bot, guildId: bigint, id: bigint) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]); - return await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.GUILD_ROLE(guildId, id)); } diff --git a/src/helpers/roles/edit_role.ts b/src/helpers/roles/edit_role.ts index 855ee060e..23735c1a5 100644 --- a/src/helpers/roles/edit_role.ts +++ b/src/helpers/roles/edit_role.ts @@ -1,12 +1,9 @@ import type { CreateGuildRole } from "../../types/guilds/create_guild_role.ts"; import type { Role } from "../../types/permissions/role.ts"; import type { Bot } from "../../bot.ts"; -import { SnakeCasedPropertiesDeep } from "../../types/util.ts"; /** Edit a guild role. Requires the MANAGE_ROLES permission. */ export async function editRole(bot: Bot, guildId: bigint, id: bigint, options: CreateGuildRole) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]); - const result = await bot.rest.runMethod( bot.rest, "patch", diff --git a/src/helpers/roles/get_roles.ts b/src/helpers/roles/get_roles.ts index 83bea7af7..fe4c012f4 100644 --- a/src/helpers/roles/get_roles.ts +++ b/src/helpers/roles/get_roles.ts @@ -8,8 +8,6 @@ import { DiscordenoRole } from "../../transformers/role.ts"; * ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your roles will be cached in your guild.** */ export async function getRoles(bot: Bot, guildId: bigint) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]); - const result = await bot.rest.runMethod(bot.rest, "get", bot.constants.endpoints.GUILD_ROLES(guildId)); const roleStructures = result.map((role) => bot.transformers.role(bot, { role, guildId })); diff --git a/src/helpers/roles/remove_role.ts b/src/helpers/roles/remove_role.ts index 6cdc3602f..b45a7a788 100644 --- a/src/helpers/roles/remove_role.ts +++ b/src/helpers/roles/remove_role.ts @@ -2,13 +2,6 @@ import type { Bot } from "../../bot.ts"; /** Remove a role from the member */ export async function removeRole(bot: Bot, guildId: bigint, memberId: bigint, roleId: bigint, reason?: string) { - const isHigherRolePosition = await bot.utils.isHigherPosition(bot, guildId, bot.id, roleId); - if (!isHigherRolePosition) { - throw new Error(bot.constants.Errors.BOTS_HIGHEST_ROLE_TOO_LOW); - } - - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_ROLES"]); - return await bot.rest.runMethod( bot.rest, "delete", diff --git a/src/helpers/templates/create_guild_template.ts b/src/helpers/templates/create_guild_template.ts index 1c971601c..b3b5a1fc2 100644 --- a/src/helpers/templates/create_guild_template.ts +++ b/src/helpers/templates/create_guild_template.ts @@ -1,7 +1,5 @@ import type { Template } from "../../types/templates/template.ts"; import type { Bot } from "../../bot.ts"; -import { User } from "../../types/users/user.ts"; -import { Guild } from "../../types/guilds/guild.ts"; /** * Creates a template for the guild. @@ -11,8 +9,6 @@ import { Guild } from "../../types/guilds/guild.ts"; * @param data */ export async function createGuildTemplate(bot: Bot, guildId: bigint, data: Template) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]); - if (data.name.length < 1 || data.name.length > 100) { throw new Error("The name can only be in between 1-100 characters."); } diff --git a/src/helpers/templates/delete_guild_template.ts b/src/helpers/templates/delete_guild_template.ts index ec12f2a58..720b34c27 100644 --- a/src/helpers/templates/delete_guild_template.ts +++ b/src/helpers/templates/delete_guild_template.ts @@ -6,8 +6,6 @@ import type { Bot } from "../../bot.ts"; * Requires the `MANAGE_GUILD` permission. */ export async function deleteGuildTemplate(bot: Bot, guildId: bigint, templateCode: string) { - await bot.utils.requireBotGuildPermissions(bot, guildId, ["MANAGE_GUILD"]); - return await bot.rest.runMethod