From 304e3a26ac53f3a9a3d4e41e4904fae42faa0891 Mon Sep 17 00:00:00 2001 From: ITOH <72305210+itohatweb@users.noreply.github.com> Date: Mon, 3 May 2021 21:47:03 +0200 Subject: [PATCH] NOT TESTED BECAUSE DISCORD NOT WORKING --- src/helpers/channels/threads/add_to_thread.ts | 35 +++++++++++++++++++ .../channels/threads/get_active_threads.ts | 12 +++++++ 2 files changed, 47 insertions(+) create mode 100644 src/helpers/channels/threads/add_to_thread.ts create mode 100644 src/helpers/channels/threads/get_active_threads.ts diff --git a/src/helpers/channels/threads/add_to_thread.ts b/src/helpers/channels/threads/add_to_thread.ts new file mode 100644 index 000000000..1fd913b5f --- /dev/null +++ b/src/helpers/channels/threads/add_to_thread.ts @@ -0,0 +1,35 @@ +import { cacheHandlers } from "../../../cache.ts"; +import { rest } from "../../../rest/rest.ts"; +import { ChannelTypes, Errors } from "../../../types/mod.ts"; +import { endpoints } from "../../../util/constants.ts"; +//TODO(threads): this does not work rn +/** Adds the current user to a thread. Returns a 204 empty response on success. Also requires the thread is not archived. Fires a Thread Members Update Gateway event.Adds another user to a thread. Requires the ability to send messages in the thread. Also requires the thread is not archived. Returns a 204 empty response on success. Fires a Thread Members Update Gateway event. + * @param userId the user to add to the thread defaults to bot + */ +export async function addToThread(channelId: bigint, userId?: bigint) { + // TODO(threads): perm check + 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); + } + } + console.log( + "put", + userId + ? endpoints.THREAD_USER(channelId, userId) + : endpoints.THREAD_ME(channelId), + ); + return await rest.runMethod( + "put", + userId + ? endpoints.THREAD_USER(channelId, userId) + : endpoints.THREAD_ME(channelId), + ); +} diff --git a/src/helpers/channels/threads/get_active_threads.ts b/src/helpers/channels/threads/get_active_threads.ts new file mode 100644 index 000000000..6fd529bd2 --- /dev/null +++ b/src/helpers/channels/threads/get_active_threads.ts @@ -0,0 +1,12 @@ +import { rest } from "../../../rest/rest.ts"; +import { endpoints } from "../../../util/constants.ts"; + +/** Returns all active threads in the channel, including public and private threads. Threads are ordered by their id, in descending order. Requires the READ_MESSAGE_HISTORY permission. */ +export async function getActiveThreads(channelId: bigint) { + // TODO(threads): perm check + // TODO(threads): test if it works + return rest.runMethod( + "get", + endpoints.THREAD_ACTIVE(channelId), + ); +}