From 99c252d2d59a549ec1ce050216d4cbe8e55bd023 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Fri, 2 Apr 2021 15:33:14 +0200 Subject: [PATCH] fix(handlers): add missing imports (#724) * Update GUILD_EMOJIS_UPDATE.ts * fix imports Co-authored-by: ayntee --- src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts | 4 ++++ .../channel_overwrite_has_permission.ts | 20 +++++++++++++++---- src/helpers/channels/create_channel.ts | 14 +++++++++---- src/helpers/channels/delete_channel.ts | 1 + .../channels/edit_channel_overwrite.ts | 1 + src/helpers/channels/follow_channel.ts | 3 ++- src/helpers/channels/get_channel.ts | 3 ++- src/helpers/channels/get_channel_webhooks.ts | 3 ++- src/helpers/channels/get_channels.ts | 3 ++- src/helpers/channels/get_pins.ts | 3 ++- src/helpers/channels/start_typing.ts | 7 ++++--- src/helpers/channels/swap_channels.ts | 3 ++- 12 files changed, 48 insertions(+), 17 deletions(-) diff --git a/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts b/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts index e84b592cb..83fce84bc 100644 --- a/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts +++ b/src/handlers/emojis/GUILD_EMOJIS_UPDATE.ts @@ -1,5 +1,9 @@ import { eventHandlers } from "../../bot.ts"; import { cacheHandlers } from "../../cache.ts"; +import { + DiscordGatewayPayload, + DiscordGuildEmojisUpdate, +} from "../../types/mod.ts"; import { Collection } from "../../util/collection.ts"; export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) { diff --git a/src/helpers/channels/channel_overwrite_has_permission.ts b/src/helpers/channels/channel_overwrite_has_permission.ts index 500afd6c0..cbf4cb650 100644 --- a/src/helpers/channels/channel_overwrite_has_permission.ts +++ b/src/helpers/channels/channel_overwrite_has_permission.ts @@ -1,9 +1,13 @@ +import { DiscordOverwrite } from "../../types/channels/overwrite.ts"; +import { DiscordBitwisePermissionFlags } from "../../types/permissions/bitwise_permission_flags.ts"; +import { PermissionStrings } from "../../types/permissions/permission_strings.ts"; + /** Checks if a channel overwrite for a user id or a role id has permission in this channel */ export function channelOverwriteHasPermission( guildId: string, id: string, - overwrites: RawOverwrite[], - permissions: Permission[], + overwrites: DiscordOverwrite[], + permissions: PermissionStrings[], ) { const overwrite = overwrites.find((perm) => perm.id === id) || overwrites.find((perm) => perm.id === guildId); @@ -12,8 +16,16 @@ export function channelOverwriteHasPermission( if (overwrite) { const allowBits = overwrite.allow; const denyBits = overwrite.deny; - if (BigInt(denyBits) & BigInt(Permissions[perm])) return false; - if (BigInt(allowBits) & BigInt(Permissions[perm])) return true; + if ( + BigInt(denyBits) & BigInt(DiscordBitwisePermissionFlags[perm]) + ) { + return false; + } + if ( + BigInt(allowBits) & BigInt(DiscordBitwisePermissionFlags[perm]) + ) { + return true; + } } return false; }); diff --git a/src/helpers/channels/create_channel.ts b/src/helpers/channels/create_channel.ts index 2fcf03dac..985a848db 100644 --- a/src/helpers/channels/create_channel.ts +++ b/src/helpers/channels/create_channel.ts @@ -1,6 +1,12 @@ import { cacheHandlers } from "../../cache.ts"; import { RequestManager } from "../../rest/request_manager.ts"; import { structures } from "../../structures/mod.ts"; +import { + CreateGuildChannel, + DiscordChannel, + DiscordChannelTypes, + PermissionStrings, +} from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, @@ -11,9 +17,9 @@ import { export async function createChannel( guildId: string, name: string, - options?: ChannelCreateOptions, + options?: CreateGuildChannel, ) { - const requiredPerms: Set = new Set(["MANAGE_CHANNELS"]); + const requiredPerms: Set = new Set(["MANAGE_CHANNELS"]); options?.permissionOverwrites?.forEach((overwrite) => { overwrite.allow.forEach(requiredPerms.add, requiredPerms); @@ -33,9 +39,9 @@ export async function createChannel( allow: calculateBits(perm.allow), deny: calculateBits(perm.deny), })), - type: options?.type || ChannelTypes.GUILD_TEXT, + type: options?.type || DiscordChannelTypes.GUILD_TEXT, }, - )) as ChannelCreatePayload; + )) as DiscordChannel; const channelStruct = await structures.createChannelStruct(result); await cacheHandlers.set("channels", channelStruct.id, channelStruct); diff --git a/src/helpers/channels/delete_channel.ts b/src/helpers/channels/delete_channel.ts index 387206f33..934e65331 100644 --- a/src/helpers/channels/delete_channel.ts +++ b/src/helpers/channels/delete_channel.ts @@ -1,5 +1,6 @@ import { cacheHandlers } from "../../cache.ts"; import { RequestManager } from "../../rest/request_manager.ts"; +import { Errors } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotGuildPermissions } from "../../util/permissions.ts"; diff --git a/src/helpers/channels/edit_channel_overwrite.ts b/src/helpers/channels/edit_channel_overwrite.ts index 0b5918896..3df0ee6b6 100644 --- a/src/helpers/channels/edit_channel_overwrite.ts +++ b/src/helpers/channels/edit_channel_overwrite.ts @@ -1,4 +1,5 @@ import { RequestManager } from "../../rest/request_manager.ts"; +import { Overwrite } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { calculateBits, diff --git a/src/helpers/channels/follow_channel.ts b/src/helpers/channels/follow_channel.ts index 65c0c010e..03483f9f3 100644 --- a/src/helpers/channels/follow_channel.ts +++ b/src/helpers/channels/follow_channel.ts @@ -1,4 +1,5 @@ import { RequestManager } from "../../rest/request_manager.ts"; +import { DiscordFollowedChannel } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -14,7 +15,7 @@ export async function followChannel( { webhook_channel_id: targetChannelId, }, - )) as FollowedChannelPayload; + )) as DiscordFollowedChannel; return data.webhook_id; } diff --git a/src/helpers/channels/get_channel.ts b/src/helpers/channels/get_channel.ts index 6d471e263..9b48f0b7f 100644 --- a/src/helpers/channels/get_channel.ts +++ b/src/helpers/channels/get_channel.ts @@ -1,6 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { RequestManager } from "../../rest/request_manager.ts"; import { structures } from "../../structures/mod.ts"; +import { DiscordChannel } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; /** Fetches a single channel object from the api. @@ -10,7 +11,7 @@ import { endpoints } from "../../util/constants.ts"; export async function getChannel(channelId: string, addToCache = true) { const result = (await RequestManager.get( endpoints.CHANNEL_BASE(channelId), - )) as ChannelCreatePayload; + )) as DiscordChannel; const channelStruct = await structures.createChannelStruct( result, diff --git a/src/helpers/channels/get_channel_webhooks.ts b/src/helpers/channels/get_channel_webhooks.ts index 972a54f61..8767b9468 100644 --- a/src/helpers/channels/get_channel_webhooks.ts +++ b/src/helpers/channels/get_channel_webhooks.ts @@ -1,4 +1,5 @@ import { RequestManager } from "../../rest/request_manager.ts"; +import { DiscordWebhook } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { requireBotChannelPermissions } from "../../util/permissions.ts"; @@ -10,5 +11,5 @@ export async function getChannelWebhooks(channelId: string) { endpoints.CHANNEL_WEBHOOKS(channelId), ); - return result as WebhookPayload[]; + return result as DiscordWebhook[]; } diff --git a/src/helpers/channels/get_channels.ts b/src/helpers/channels/get_channels.ts index f00aa37be..8508e0b7a 100644 --- a/src/helpers/channels/get_channels.ts +++ b/src/helpers/channels/get_channels.ts @@ -1,6 +1,7 @@ import { cacheHandlers } from "../../cache.ts"; import { RequestManager } from "../../rest/request_manager.ts"; import { structures } from "../../structures/mod.ts"; +import { DiscordChannel } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; /** Returns a list of guild channel objects. @@ -10,7 +11,7 @@ import { endpoints } from "../../util/constants.ts"; export async function getChannels(guildId: string, addToCache = true) { const result = (await RequestManager.get( endpoints.GUILD_CHANNELS(guildId), - ) as ChannelCreatePayload[]); + ) as DiscordChannel[]); return Promise.all(result.map(async (res) => { const channelStruct = await structures.createChannelStruct(res, guildId); diff --git a/src/helpers/channels/get_pins.ts b/src/helpers/channels/get_pins.ts index 9dbde3195..296b12a65 100644 --- a/src/helpers/channels/get_pins.ts +++ b/src/helpers/channels/get_pins.ts @@ -1,12 +1,13 @@ import { RequestManager } from "../../rest/request_manager.ts"; import { structures } from "../../structures/mod.ts"; +import { DiscordMessage } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; /** Get pinned messages in this channel. */ export async function getPins(channelId: string) { const result = (await RequestManager.get( endpoints.CHANNEL_PINS(channelId), - )) as MessageCreateOptions[]; + )) as DiscordMessage[]; return Promise.all( result.map((res) => structures.createMessageStruct(res)), diff --git a/src/helpers/channels/start_typing.ts b/src/helpers/channels/start_typing.ts index e0e612bdd..0463b294b 100644 --- a/src/helpers/channels/start_typing.ts +++ b/src/helpers/channels/start_typing.ts @@ -1,5 +1,6 @@ import { cacheHandlers } from "../../cache.ts"; import { RequestManager } from "../../rest/request_manager.ts"; +import { DiscordChannelTypes, Errors } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; import { botHasChannelPermissions } from "../../util/permissions.ts"; @@ -14,9 +15,9 @@ export async function startTyping(channelId: string) { if (channel) { if ( ![ - ChannelTypes.DM, - ChannelTypes.GUILD_NEWS, - ChannelTypes.GUILD_TEXT, + DiscordChannelTypes.DM, + DiscordChannelTypes.GUILD_NEWS, + DiscordChannelTypes.GUILD_TEXT, ].includes(channel.type) ) { throw new Error(Errors.CHANNEL_NOT_TEXT_BASED); diff --git a/src/helpers/channels/swap_channels.ts b/src/helpers/channels/swap_channels.ts index 0239c2ac6..1ee9b2340 100644 --- a/src/helpers/channels/swap_channels.ts +++ b/src/helpers/channels/swap_channels.ts @@ -1,10 +1,11 @@ import { RequestManager } from "../../rest/request_manager.ts"; +import { ModifyGuildChannelPositions } from "../../types/mod.ts"; import { endpoints } from "../../util/constants.ts"; /** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */ export async function swapChannels( guildId: string, - channelPositions: PositionSwap[], + channelPositions: ModifyGuildChannelPositions[], ) { if (channelPositions.length < 2) { throw "You must provide at least two channels to be swapped.";