feat: fix typo in name and add isThreadChannel

This commit is contained in:
Skillz4Killz
2021-06-17 18:13:54 +00:00
committed by GitHub
parent 2d004ba156
commit d1b4ee8047
5 changed files with 13 additions and 19 deletions

View File

@@ -1,7 +1,6 @@
import { cacheHandlers } from "../../cache.ts";
import { rest } from "../../rest/rest.ts";
import { Errors } from "../../types/discordeno/errors.ts";
import { ChannelTypes } from "../../types/channels/channel_types.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
@@ -14,14 +13,7 @@ export async function deleteChannel(channelId: bigint, reason?: string) {
if (!guild) throw new Error(Errors.GUILD_NOT_FOUND);
// TODO(threads): check if this requires guild perms or channel is enough
await requireBotGuildPermissions(
guild,
[ChannelTypes.GuildNewsThread, ChannelTypes.GuildPivateThread, ChannelTypes.GuildPublicThread].includes(
channel.type
)
? ["MANAGE_THREADS"]
: ["MANAGE_CHANNELS"]
);
await requireBotGuildPermissions(guild, channel.isThreadChannel ? ["MANAGE_THREADS"] : ["MANAGE_CHANNELS"]);
if (guild.rulesChannelId === channelId) {
throw new Error(Errors.RULES_CHANNEL_CANNOT_BE_DELETED);
}

View File

@@ -4,7 +4,6 @@ import { rest } from "../../rest/rest.ts";
import type { DiscordenoChannel } from "../../structures/channel.ts";
import { structures } from "../../structures/mod.ts";
import type { Channel } from "../../types/channels/channel.ts";
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
import type { ModifyChannel } from "../../types/channels/modify_channel.ts";
import type { ModifyThread } from "../../types/channels/threads/modify_thread.ts";
import type { PermissionStrings } from "../../types/permissions/permission_strings.ts";
@@ -19,13 +18,7 @@ export async function editChannel(channelId: bigint, options: ModifyChannel | Mo
const channel = await cacheHandlers.get("channels", channelId);
if (channel) {
if (
[
DiscordChannelTypes.GuildNewsThread,
DiscordChannelTypes.GuildPivateThread,
DiscordChannelTypes.GuildPublicThread,
].includes(channel.type)
) {
if (channel.isThreadChannel) {
const permissions = new Set<PermissionStrings>();
if (hasOwnProperty(options, "archive") && options.archive === false) {

View File

@@ -20,7 +20,7 @@ export async function startTyping(channelId: bigint) {
DiscordChannelTypes.GuildNews,
DiscordChannelTypes.GuildText,
DiscordChannelTypes.GuildNewsThread,
DiscordChannelTypes.GuildPivateThread,
DiscordChannelTypes.GuildPrivateThread,
DiscordChannelTypes.GuildPublicThread,
].includes(channel.type)
) {

View File

@@ -24,7 +24,7 @@ export async function sendMessage(channelId: bigint, content: string | CreateMes
DiscordChannelTypes.GuildNews,
DiscordChannelTypes.GuildText,
DiscordChannelTypes.GuildPublicThread,
DiscordChannelTypes.GuildPivateThread,
DiscordChannelTypes.GuildPrivateThread,
DiscordChannelTypes.GuildNewsThread,
].includes(channel.type)
) {

View File

@@ -82,6 +82,13 @@ const baseChannel: Partial<DiscordenoChannel> = {
get isGuildTextBasedChannel() {
return [DiscordChannelTypes.GuildNews, DiscordChannelTypes.GuildText].includes(this.type!);
},
get isThreadChannel() {
return [
DiscordChannelTypes.GuildNewsThread,
DiscordChannelTypes.GuildPrivateThread,
DiscordChannelTypes.GuildPublicThread,
].includes(this.type!);
},
send(content) {
return sendMessage(this.id!, content);
},
@@ -195,6 +202,8 @@ export interface DiscordenoChannel
isNewsChannel: boolean;
/** Whether the channel is a news or text channel in a guild. */
isGuildTextBasedChannel: boolean;
/** Whether the channel is a thread type channel. */
isThreadChannel: boolean;
// METHODS