fix(handlers): add missing imports (#724)

* Update GUILD_EMOJIS_UPDATE.ts

* fix imports

Co-authored-by: ayntee <ayyantee@gmail.com>
This commit is contained in:
ITOH
2021-04-02 15:33:14 +02:00
committed by GitHub
parent 455cc6fb24
commit 99c252d2d5
12 changed files with 48 additions and 17 deletions
@@ -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) {
@@ -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;
});
+10 -4
View File
@@ -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<Permission> = new Set(["MANAGE_CHANNELS"]);
const requiredPerms: Set<PermissionStrings> = 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);
+1
View File
@@ -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";
@@ -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,
+2 -1
View File
@@ -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;
}
+2 -1
View File
@@ -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,
+2 -1
View File
@@ -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[];
}
+2 -1
View File
@@ -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);
+2 -1
View File
@@ -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)),
+4 -3
View File
@@ -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);
+2 -1
View File
@@ -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.";