Merge branch 'main' into threads

This commit is contained in:
ITOH
2021-05-03 20:50:53 +02:00
192 changed files with 1364 additions and 623 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
import { cacheHandlers } from "../../cache.ts";
/** Gets an array of all the channels ids that are the children of this category. */
export function categoryChildren(id: string) {
export function categoryChildren(id: bigint) {
return cacheHandlers.filter(
"channels",
(channel) => channel.parentId === id,
@@ -4,9 +4,13 @@ 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: DiscordOverwrite[],
guildId: bigint,
id: bigint,
overwrites: (Omit<DiscordOverwrite, "id" | "allow" | "deny"> & {
id: bigint;
allow: bigint;
deny: bigint;
})[],
permissions: PermissionStrings[],
) {
const overwrite = overwrites.find((perm) => perm.id === id) ||
+9 -6
View File
@@ -2,11 +2,12 @@ import { cacheHandlers } from "../../cache.ts";
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
import { CreateGuildChannel } from "../../types/guilds/create_guild_channel.ts";
import { Errors } from "../../types/misc/errors.ts";
import { bigintToSnowflake } from "../../util/bigint.ts";
import { calculatePermissions } from "../../util/permissions.ts";
import { createChannel } from "./create_channel.ts";
/** Create a copy of a channel */
export async function cloneChannel(channelId: string, reason?: string) {
export async function cloneChannel(channelId: bigint, reason?: string) {
const channelToClone = await cacheHandlers.get("channels", channelId);
//Return undefined if channel is not cached
if (!channelToClone) throw new Error(Errors.CHANNEL_NOT_FOUND);
@@ -23,14 +24,16 @@ export async function cloneChannel(channelId: string, reason?: string) {
...channelToClone,
name: channelToClone.name!,
topic: channelToClone.topic || undefined,
parentId: channelToClone.parentId || undefined,
permissionOverwrites: channelToClone.permissionOverwrites?.map((
parentId: channelToClone.parentId
? bigintToSnowflake(channelToClone.parentId)
: undefined,
permissionOverwrites: channelToClone.permissionOverwrites.map((
overwrite,
) => ({
id: overwrite.id,
id: overwrite.id.toString(),
type: overwrite.type,
allow: calculatePermissions(overwrite.allow),
deny: calculatePermissions(overwrite.deny),
allow: calculatePermissions(overwrite.allow.toString()),
deny: calculatePermissions(overwrite.deny.toString()),
})),
};
+1 -1
View File
@@ -16,7 +16,7 @@ import { camelKeysToSnakeCase } from "../../util/utils.ts";
/** Create a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
export async function createChannel(
guildId: string,
guildId: bigint,
options?: CreateGuildChannel,
reason?: string,
) {
+1 -1
View File
@@ -7,7 +7,7 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Delete a channel in your server. Bot needs MANAGE_CHANNEL permissions in the server. */
export async function deleteChannel(
channelId: string,
channelId: bigint,
reason?: string,
) {
const channel = await cacheHandlers.get("channels", channelId);
@@ -4,9 +4,9 @@ import { requireBotGuildPermissions } from "../../util/permissions.ts";
/** Delete the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
export async function deleteChannelOverwrite(
guildId: string,
channelId: string,
overwriteId: string,
guildId: bigint,
channelId: bigint,
overwriteId: bigint,
): Promise<undefined> {
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
+5 -6
View File
@@ -20,7 +20,7 @@ import { camelKeysToSnakeCase, hasOwnProperty } from "../../util/utils.ts";
//TODO(threads): check thread perms
/** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
export async function editChannel(
channelId: string,
channelId: bigint,
options: ModifyChannel | ModifyThread,
reason?: string,
) {
@@ -46,7 +46,7 @@ export async function editChannel(
permissions.add("MANAGE_THREADS");
}
await requireBotChannelPermissions(channel.parentId ?? "", [
await requireBotChannelPermissions(channel.parentId ?? 0n, [
...permissions,
]);
}
@@ -117,15 +117,14 @@ export async function editChannel(
interface EditChannelRequest {
amount: number;
timestamp: number;
channelId: string;
channelId: bigint;
items: {
channelId: string;
channelId: bigint;
options: ModifyChannel;
}[];
}
const editChannelNameTopicQueue = new Map<string, EditChannelRequest>();
const editChannelNameTopicQueue = new Map<bigint, EditChannelRequest>();
let editChannelProcessing = false;
function processEditChannelQueue() {
@@ -8,9 +8,9 @@ import {
/** Edit the channel permission overwrites for a user or role in this channel. Requires `MANAGE_ROLES` permission. */
export async function editChannelOverwrite(
guildId: string,
channelId: string,
overwriteId: string,
guildId: bigint,
channelId: bigint,
overwriteId: bigint,
options: Omit<Overwrite, "id">,
): Promise<undefined> {
await requireBotGuildPermissions(guildId, ["MANAGE_ROLES"]);
+2 -2
View File
@@ -5,8 +5,8 @@ import { requireBotChannelPermissions } from "../../util/permissions.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(
sourceChannelId: string,
targetChannelId: string,
sourceChannelId: bigint,
targetChannelId: bigint,
) {
await requireBotChannelPermissions(targetChannelId, ["MANAGE_WEBHOOKS"]);
+3 -2
View File
@@ -2,13 +2,14 @@ import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { structures } from "../../structures/mod.ts";
import { Channel } from "../../types/channels/channel.ts";
import { snowflakeToBigint } from "../../util/bigint.ts";
import { endpoints } from "../../util/constants.ts";
/** Fetches a single channel object from the api.
*
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
*/
export async function getChannel(channelId: string, addToCache = true) {
export async function getChannel(channelId: bigint, addToCache = true) {
const result = await rest.runMethod<Channel>(
"get",
endpoints.CHANNEL_BASE(channelId),
@@ -16,7 +17,7 @@ export async function getChannel(channelId: string, addToCache = true) {
const discordenoChannel = await structures.createDiscordenoChannel(
result,
result.guildId,
result.guildId ? snowflakeToBigint(result.guildId) : undefined,
);
if (addToCache) {
await cacheHandlers.set(
+1 -1
View File
@@ -5,7 +5,7 @@ import { endpoints } from "../../util/constants.ts";
import { requireBotChannelPermissions } from "../../util/permissions.ts";
/** Gets the webhooks for this channel. Requires MANAGE_WEBHOOKS */
export async function getChannelWebhooks(channelId: string) {
export async function getChannelWebhooks(channelId: bigint) {
await requireBotChannelPermissions(channelId, ["MANAGE_WEBHOOKS"]);
const result = await rest.runMethod<Webhook[]>(
+1 -1
View File
@@ -9,7 +9,7 @@ import { endpoints } from "../../util/constants.ts";
*
* ⚠️ **If you need this, you are probably doing something wrong. This is not intended for use. Your channels will be cached in your guild.**
*/
export async function getChannels(guildId: string, addToCache = true) {
export async function getChannels(guildId: bigint, addToCache = true) {
const result = await rest.runMethod<Channel[]>(
"get",
endpoints.GUILD_CHANNELS(guildId),
+1 -1
View File
@@ -4,7 +4,7 @@ import { Message } from "../../types/messages/message.ts";
import { endpoints } from "../../util/constants.ts";
/** Get pinned messages in this channel. */
export async function getPins(channelId: string) {
export async function getPins(channelId: bigint) {
const result = await rest.runMethod<Message[]>(
"get",
endpoints.CHANNEL_PINS(channelId),
+1 -1
View File
@@ -1,7 +1,7 @@
import { cacheHandlers } from "../../cache.ts";
/** Checks whether a channel is synchronized with its parent/category channel or not. */
export async function isChannelSynced(channelId: string) {
export async function isChannelSynced(channelId: bigint) {
const channel = await cacheHandlers.get("channels", channelId);
if (!channel?.parentId) return false;
+1 -1
View File
@@ -10,7 +10,7 @@ import { botHasChannelPermissions } from "../../util/permissions.ts";
* However, if a bot is responding to a command and expects the computation to take a few seconds,
* this endpoint may be called to let the user know that the bot is processing their message.
*/
export async function startTyping(channelId: string) {
export async function startTyping(channelId: bigint) {
const channel = await cacheHandlers.get("channels", channelId);
// If the channel is cached, we can do extra checks/safety
if (channel) {
+1 -1
View File
@@ -4,7 +4,7 @@ import { endpoints } from "../../util/constants.ts";
/** Modify the positions of channels on the guild. Requires MANAGE_CHANNELS permisison. */
export async function swapChannels(
guildId: string,
guildId: bigint,
channelPositions: ModifyGuildChannelPositions[],
) {
if (channelPositions.length < 2) {