mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
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:
@@ -1,5 +1,9 @@
|
|||||||
import { eventHandlers } from "../../bot.ts";
|
import { eventHandlers } from "../../bot.ts";
|
||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
|
import {
|
||||||
|
DiscordGatewayPayload,
|
||||||
|
DiscordGuildEmojisUpdate,
|
||||||
|
} from "../../types/mod.ts";
|
||||||
import { Collection } from "../../util/collection.ts";
|
import { Collection } from "../../util/collection.ts";
|
||||||
|
|
||||||
export async function handleGuildEmojisUpdate(data: DiscordGatewayPayload) {
|
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 */
|
/** Checks if a channel overwrite for a user id or a role id has permission in this channel */
|
||||||
export function channelOverwriteHasPermission(
|
export function channelOverwriteHasPermission(
|
||||||
guildId: string,
|
guildId: string,
|
||||||
id: string,
|
id: string,
|
||||||
overwrites: RawOverwrite[],
|
overwrites: DiscordOverwrite[],
|
||||||
permissions: Permission[],
|
permissions: PermissionStrings[],
|
||||||
) {
|
) {
|
||||||
const overwrite = overwrites.find((perm) => perm.id === id) ||
|
const overwrite = overwrites.find((perm) => perm.id === id) ||
|
||||||
overwrites.find((perm) => perm.id === guildId);
|
overwrites.find((perm) => perm.id === guildId);
|
||||||
@@ -12,8 +16,16 @@ export function channelOverwriteHasPermission(
|
|||||||
if (overwrite) {
|
if (overwrite) {
|
||||||
const allowBits = overwrite.allow;
|
const allowBits = overwrite.allow;
|
||||||
const denyBits = overwrite.deny;
|
const denyBits = overwrite.deny;
|
||||||
if (BigInt(denyBits) & BigInt(Permissions[perm])) return false;
|
if (
|
||||||
if (BigInt(allowBits) & BigInt(Permissions[perm])) return true;
|
BigInt(denyBits) & BigInt(DiscordBitwisePermissionFlags[perm])
|
||||||
|
) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
BigInt(allowBits) & BigInt(DiscordBitwisePermissionFlags[perm])
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import {
|
||||||
|
CreateGuildChannel,
|
||||||
|
DiscordChannel,
|
||||||
|
DiscordChannelTypes,
|
||||||
|
PermissionStrings,
|
||||||
|
} from "../../types/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import {
|
import {
|
||||||
calculateBits,
|
calculateBits,
|
||||||
@@ -11,9 +17,9 @@ import {
|
|||||||
export async function createChannel(
|
export async function createChannel(
|
||||||
guildId: string,
|
guildId: string,
|
||||||
name: 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) => {
|
options?.permissionOverwrites?.forEach((overwrite) => {
|
||||||
overwrite.allow.forEach(requiredPerms.add, requiredPerms);
|
overwrite.allow.forEach(requiredPerms.add, requiredPerms);
|
||||||
@@ -33,9 +39,9 @@ export async function createChannel(
|
|||||||
allow: calculateBits(perm.allow),
|
allow: calculateBits(perm.allow),
|
||||||
deny: calculateBits(perm.deny),
|
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);
|
const channelStruct = await structures.createChannelStruct(result);
|
||||||
await cacheHandlers.set("channels", channelStruct.id, channelStruct);
|
await cacheHandlers.set("channels", channelStruct.id, channelStruct);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
|
import { Errors } from "../../types/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
import { requireBotGuildPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
|
import { Overwrite } from "../../types/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import {
|
import {
|
||||||
calculateBits,
|
calculateBits,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
|
import { DiscordFollowedChannel } from "../../types/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
@@ -14,7 +15,7 @@ export async function followChannel(
|
|||||||
{
|
{
|
||||||
webhook_channel_id: targetChannelId,
|
webhook_channel_id: targetChannelId,
|
||||||
},
|
},
|
||||||
)) as FollowedChannelPayload;
|
)) as DiscordFollowedChannel;
|
||||||
|
|
||||||
return data.webhook_id;
|
return data.webhook_id;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { DiscordChannel } from "../../types/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Fetches a single channel object from the api.
|
/** 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) {
|
export async function getChannel(channelId: string, addToCache = true) {
|
||||||
const result = (await RequestManager.get(
|
const result = (await RequestManager.get(
|
||||||
endpoints.CHANNEL_BASE(channelId),
|
endpoints.CHANNEL_BASE(channelId),
|
||||||
)) as ChannelCreatePayload;
|
)) as DiscordChannel;
|
||||||
|
|
||||||
const channelStruct = await structures.createChannelStruct(
|
const channelStruct = await structures.createChannelStruct(
|
||||||
result,
|
result,
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
|
import { DiscordWebhook } from "../../types/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
import { requireBotChannelPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
@@ -10,5 +11,5 @@ export async function getChannelWebhooks(channelId: string) {
|
|||||||
endpoints.CHANNEL_WEBHOOKS(channelId),
|
endpoints.CHANNEL_WEBHOOKS(channelId),
|
||||||
);
|
);
|
||||||
|
|
||||||
return result as WebhookPayload[];
|
return result as DiscordWebhook[];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { DiscordChannel } from "../../types/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Returns a list of guild channel objects.
|
/** 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) {
|
export async function getChannels(guildId: string, addToCache = true) {
|
||||||
const result = (await RequestManager.get(
|
const result = (await RequestManager.get(
|
||||||
endpoints.GUILD_CHANNELS(guildId),
|
endpoints.GUILD_CHANNELS(guildId),
|
||||||
) as ChannelCreatePayload[]);
|
) as DiscordChannel[]);
|
||||||
|
|
||||||
return Promise.all(result.map(async (res) => {
|
return Promise.all(result.map(async (res) => {
|
||||||
const channelStruct = await structures.createChannelStruct(res, guildId);
|
const channelStruct = await structures.createChannelStruct(res, guildId);
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
import { structures } from "../../structures/mod.ts";
|
import { structures } from "../../structures/mod.ts";
|
||||||
|
import { DiscordMessage } from "../../types/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Get pinned messages in this channel. */
|
/** Get pinned messages in this channel. */
|
||||||
export async function getPins(channelId: string) {
|
export async function getPins(channelId: string) {
|
||||||
const result = (await RequestManager.get(
|
const result = (await RequestManager.get(
|
||||||
endpoints.CHANNEL_PINS(channelId),
|
endpoints.CHANNEL_PINS(channelId),
|
||||||
)) as MessageCreateOptions[];
|
)) as DiscordMessage[];
|
||||||
|
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
result.map((res) => structures.createMessageStruct(res)),
|
result.map((res) => structures.createMessageStruct(res)),
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { cacheHandlers } from "../../cache.ts";
|
import { cacheHandlers } from "../../cache.ts";
|
||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
|
import { DiscordChannelTypes, Errors } from "../../types/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
import { botHasChannelPermissions } from "../../util/permissions.ts";
|
import { botHasChannelPermissions } from "../../util/permissions.ts";
|
||||||
|
|
||||||
@@ -14,9 +15,9 @@ export async function startTyping(channelId: string) {
|
|||||||
if (channel) {
|
if (channel) {
|
||||||
if (
|
if (
|
||||||
![
|
![
|
||||||
ChannelTypes.DM,
|
DiscordChannelTypes.DM,
|
||||||
ChannelTypes.GUILD_NEWS,
|
DiscordChannelTypes.GUILD_NEWS,
|
||||||
ChannelTypes.GUILD_TEXT,
|
DiscordChannelTypes.GUILD_TEXT,
|
||||||
].includes(channel.type)
|
].includes(channel.type)
|
||||||
) {
|
) {
|
||||||
throw new Error(Errors.CHANNEL_NOT_TEXT_BASED);
|
throw new Error(Errors.CHANNEL_NOT_TEXT_BASED);
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { RequestManager } from "../../rest/request_manager.ts";
|
import { RequestManager } from "../../rest/request_manager.ts";
|
||||||
|
import { ModifyGuildChannelPositions } from "../../types/mod.ts";
|
||||||
import { endpoints } from "../../util/constants.ts";
|
import { endpoints } from "../../util/constants.ts";
|
||||||
|
|
||||||
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
|
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
|
||||||
export async function swapChannels(
|
export async function swapChannels(
|
||||||
guildId: string,
|
guildId: string,
|
||||||
channelPositions: PositionSwap[],
|
channelPositions: ModifyGuildChannelPositions[],
|
||||||
) {
|
) {
|
||||||
if (channelPositions.length < 2) {
|
if (channelPositions.length < 2) {
|
||||||
throw "You must provide at least two channels to be swapped.";
|
throw "You must provide at least two channels to be swapped.";
|
||||||
|
|||||||
Reference in New Issue
Block a user