mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 17:30:07 +00:00
i love rigor
This commit is contained in:
12
src/helpers/channels/threads/leave_thread.ts
Normal file
12
src/helpers/channels/threads/leave_thread.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { cacheHandlers } from "../../../cache.ts";
|
||||
import { rest } from "../../../rest/rest.ts";
|
||||
import { Errors } from "../../../types/discordeno/errors.ts";
|
||||
import { endpoints } from "../../../util/constants.ts";
|
||||
|
||||
/** Removes the bot from a thread. Requires the thread is not archived. */
|
||||
export async function leaveThread(threadId: bigint) {
|
||||
const thread = await cacheHandlers.get("threads", threadId);
|
||||
if (thread?.archived) throw new Error(Errors.CANNOT_LEAVE_ARCHIVED_THREAD);
|
||||
|
||||
return await rest.runMethod("delete", endpoints.THREAD_ME(threadId));
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
import { botId } from "../../../bot.ts";
|
||||
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 { endpoints } from "../../../util/constants.ts";
|
||||
import { botHasChannelPermissions } from "../../../util/permissions.ts";
|
||||
|
||||
/** Removes another user from a thread. Requires the MANAGE_THREADS permission or that you are the creator of the thread. Also requires the thread is not archived. Returns a 204 empty response on success. Fires a Thread Members Update Gateway event. */
|
||||
export async function removeFromThread(channelId: bigint, userId?: bigint) {
|
||||
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.ownerId !== botId && !(await botHasChannelPermissions(channel, ["MANAGE_THREADS"])))
|
||||
throw new Error(Errors.HAVE_TO_BE_THE_CREATOR_OF_THE_THREAD_OR_HAVE_MANAGE_THREADS_TO_REMOVE_MEMBERS);
|
||||
}
|
||||
|
||||
return await rest.runMethod(
|
||||
"delete",
|
||||
userId ? endpoints.THREAD_USER(channelId, userId) : endpoints.THREAD_ME(channelId)
|
||||
);
|
||||
}
|
||||
21
src/helpers/channels/threads/remove_thread_member.ts
Normal file
21
src/helpers/channels/threads/remove_thread_member.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { botId } from "../../../bot.ts";
|
||||
import { cacheHandlers } from "../../../cache.ts";
|
||||
import { rest } from "../../../rest/rest.ts";
|
||||
import { Errors } from "../../../types/discordeno/errors.ts";
|
||||
import { endpoints } from "../../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../../util/permissions.ts";
|
||||
|
||||
/** Removes a user from a thread. Requires the MANAGE_THREADS permission or that you are the creator of the thread. Also requires the thread is not archived. */
|
||||
export async function removeThreadMember(threadId: bigint, userId: bigint) {
|
||||
const thread = await cacheHandlers.get("threads", threadId);
|
||||
if (thread) {
|
||||
if (thread.archived) throw new Error(Errors.CANNOT_REMOVE_FROM_ARCHIVED_THREAD);
|
||||
|
||||
if (thread.ownerId !== botId) {
|
||||
const channel = await cacheHandlers.get("channels", thread.channelId);
|
||||
if (channel) await requireBotChannelPermissions(channel, ["MANAGE_THREADS"]);
|
||||
}
|
||||
}
|
||||
|
||||
return await rest.runMethod("delete", endpoints.THREAD_USER(threadId, userId));
|
||||
}
|
||||
Reference in New Issue
Block a user