fix: more bugs bugs bugs

This commit is contained in:
Skillz4Killz
2021-06-17 20:08:30 +00:00
committed by GitHub
parent d1b4ee8047
commit 88e52c6170
6 changed files with 43 additions and 30 deletions
@@ -1,36 +1,24 @@
import { cacheHandlers } from "../../../cache.ts";
import { rest } from "../../../rest/rest.ts";
import { ChannelTypes } from "../../../types/channels/channel_types.ts";
import { Errors } from "../../../types/discordeno/errors.ts";
import { DiscordGatewayIntents } from "../../../types/gateway/gateway_intents.ts";
import { endpoints } from "../../../util/constants.ts";
import { botHasChannelPermissions } from "../../../util/permissions.ts";
import { ws } from "../../../ws/ws.ts";
/** Returns array of thread members objects that are members of the thread. */
export async function getThreadMembers(channelId: bigint) {
if (!(ws.identifyPayload.intents & DiscordGatewayIntents.GuildMembers)) {
/** Returns thread members objects that are members of the thread. */
export async function getThreadMembers(threadId: bigint) {
// Check if intents is not 0 as proxy ws won't set intents in other instances
if (ws.identifyPayload.intents && !(ws.identifyPayload.intents & DiscordGatewayIntents.GuildMembers)) {
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
}
const channel = await cacheHandlers.get("channels", channelId);
if (channel) {
if (
![ChannelTypes.GuildNewsThread, ChannelTypes.GuildPivateThread, ChannelTypes.GuildPublicThread].includes(
channel.type
)
) {
throw new Error(Errors.NOT_A_THREAD_CHANNEL);
}
if (
channel.type === ChannelTypes.GuildPivateThread &&
!(await botHasChannelPermissions(channel, ["MANAGE_THREADS"])) &&
!channel.member
)
const thread = await cacheHandlers.get("threads", threadId);
if (thread?.isPrivate) {
const channel = await cacheHandlers.get("channels", thread.channelId);
if (channel && !(await botHasChannelPermissions(channel, ["MANAGE_THREADS"])) && !thread.botIsMember)
throw new Error(Errors.CANNOT_GET_MEMBERS_OF_AN_UNJOINED_PRIVATE_THREAD);
}
// TODO: v12 map the result to a nice collection
return await rest.runMethod("get", endpoints.THREAD_MEMBERS(channelId));
return await rest.runMethod("get", endpoints.THREAD_MEMBERS(threadId));
}
@@ -15,7 +15,7 @@ export async function startPrivateThread(channelId: bigint, options: StartThread
if (channel.isNewsChannel) throw new Error(Errors.GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS);
await requireBotChannelPermissions(channel, ["USE_PRIVATE_THREADS"]);
await requireBotChannelPermissions(channel, ["SEND_MESSAGES", "USE_PRIVATE_THREADS"]);
}
return channelToThread(await rest.runMethod("post", endpoints.THREAD_START_PRIVATE(channelId), snakelize(options)));
+1 -1
View File
@@ -14,7 +14,7 @@ export async function startThread(channelId: bigint, options: StartThread & { me
throw new Error(Errors.INVALID_THREAD_PARENT_CHANNEL_TYPE);
}
await requireBotChannelPermissions(channel, ["USE_PUBLIC_THREADS"]);
await requireBotChannelPermissions(channel, ["SEND_MESSAGES", "USE_PUBLIC_THREADS"]);
}
return await rest.runMethod(