tyler is bae <3

This commit is contained in:
Skillz4Killz
2021-06-17 16:38:47 +00:00
committed by GitHub
parent 482a62f0e8
commit db94a659b7
2 changed files with 20 additions and 8 deletions

View File

@@ -4,9 +4,9 @@ import { Errors } from "../../../types/discordeno/errors.ts";
import { endpoints } from "../../../util/constants.ts";
import { requireBotChannelPermissions } from "../../../util/permissions.ts";
/** Adds the bot to a thread. When a user id is provided, it adds that user to the thread. User id requires the ability to send messages in the thread. Both requires the thread is not archived.
/** Adds a user to a thread. Requires the ability to send messages in the thread. Requires the thread is not archived.
*/
export async function addToThread(threadId: bigint, userId?: bigint) {
export async function addToThread(threadId: bigint, userId: bigint) {
const thread = await cacheHandlers.get("threads", threadId);
if (thread) {
if (thread.archived) {
@@ -14,12 +14,10 @@ export async function addToThread(threadId: bigint, userId?: bigint) {
}
// If a user id is provided SEND_MESSAGES is required.
if (userId) {
const channel = await cacheHandlers.get("channels", thread.channelId);
// TODO: does MANAGE_THREADS override this????
if (channel) await requireBotChannelPermissions(channel, ["SEND_MESSAGES"]);
}
const channel = await cacheHandlers.get("channels", thread.channelId);
// TODO: does MANAGE_THREADS override this????
if (channel) await requireBotChannelPermissions(channel, ["SEND_MESSAGES"]);
}
return await rest.runMethod("put", userId ? endpoints.THREAD_USER(threadId, userId) : endpoints.THREAD_ME(threadId));
return await rest.runMethod("put", endpoints.THREAD_USER(threadId, userId));
}

View File

@@ -0,0 +1,14 @@
import { cacheHandlers } from "../../../cache.ts";
import { rest } from "../../../rest/rest.ts";
import { Errors } from "../../../types/discordeno/errors.ts";
import { endpoints } from "../../../util/constants.ts";
/** Adds the bot to the thread. Cannot join an archived thread. */
export async function joinThread(threadId: bigint) {
const thread = await cacheHandlers.get("threads", threadId);
if (thread?.archived) {
throw new Error(Errors.CANNOT_ADD_USER_TO_ARCHIVED_THREADS);
}
return await rest.runMethod("put", endpoints.THREAD_ME(threadId));
}