Merge remote-tracking branch 'origin/fp-attempt-9001' into fp-attempt-9001

This commit is contained in:
TriForMine
2021-10-21 22:10:37 +02:00
10 changed files with 57 additions and 42 deletions
@@ -8,5 +8,7 @@ export async function deleteThread(bot: Bot, threadId: bigint, reason?: string)
if (channel?.guildId) await bot.utils.requireBotGuildPermissions(bot, channel.guildId, ["MANAGE_THREADS"]);
}
return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.CHANNEL_BASE(threadId), { reason });
return await bot.rest.runMethod<undefined>(bot.rest, "delete", bot.constants.endpoints.CHANNEL_BASE(threadId), {
reason,
});
}
+12 -17
View File
@@ -1,26 +1,21 @@
import type { ModifyThread } from "../../../types/channels/threads/modify_thread.ts";
import type { Bot } from "../../../bot.ts";
import {channelToThread} from "../../../util/transformers/channel_to_thread.ts";
import { channelToThread } from "../../../util/transformers/channel_to_thread.ts";
/** Update a thread's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
export async function editThread(bot: Bot, threadId: bigint, options: ModifyThread, reason?: string) {
// const thread = await cacheHandlers.get("threads", threadId);
// const thread = await cacheHandlers.get("threads", threadId);
// TODO: permission checking
// TODO: permission checking
const result = await bot.rest.runMethod(
bot.rest,
"patch",
bot.constants.endpoints.CHANNEL_BASE(threadId),
{
name: options.name,
archived: options.archived,
auto_archive_duration: options.autoArchiveDuration,
locked: options.locked,
rate_limit_per_user: options.rateLimitPerUser,
reason,
}
);
const result = await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.CHANNEL_BASE(threadId), {
name: options.name,
archived: options.archived,
auto_archive_duration: options.autoArchiveDuration,
locked: options.locked,
rate_limit_per_user: options.rateLimitPerUser,
reason,
});
return channelToThread(result);
return channelToThread(result);
}
@@ -1,14 +1,18 @@
import type { Bot } from "../../../bot.ts";
import type { ListActiveThreads } from "../../../types/channels/threads/list_active_threads.ts";
import { Collection } from "../../../util/collection.ts";
import {channelToThread} from "../../../util/transformers/channel_to_thread.ts";
import { channelToThread } from "../../../util/transformers/channel_to_thread.ts";
/** Returns all active threads in the channel, including public and private threads. Threads are ordered by their id, in descending order. Requires the VIEW_CHANNEL permission. */
export async function getActiveThreads(bot: Bot, channelId: bigint) {
await bot.utils.requireBotChannelPermissions(bot, channelId, ["VIEW_CHANNEL"]);
// TODO: pagination
const result = (await bot.rest.runMethod(bot.rest,"get", bot.constants.endpoints.THREAD_ACTIVE(channelId))) as ListActiveThreads;
const result = (await bot.rest.runMethod(
bot.rest,
"get",
bot.constants.endpoints.THREAD_ACTIVE(channelId)
)) as ListActiveThreads;
const threads = new Collection(
result.threads.map((t) => {
@@ -3,11 +3,11 @@ import { ListPublicArchivedThreads } from "../../../types/channels/threads/list_
import { PermissionStrings } from "../../../types/permissions/permission_strings.ts";
import { Collection } from "../../../util/collection.ts";
import type { Bot } from "../../../bot.ts";
import {channelToThread} from "../../../util/transformers/channel_to_thread.ts";
import { channelToThread } from "../../../util/transformers/channel_to_thread.ts";
/** Get the archived threads for this channel, defaults to public */
export async function getArchivedThreads(
bot: Bot,
bot: Bot,
channelId: bigint,
options?: ListPublicArchivedThreads & {
type?: "public" | "private" | "privateJoinedThreads";
@@ -21,18 +21,20 @@ export async function getArchivedThreads(
// TODO: pagination
const result = (await bot.rest.runMethod(
bot.rest,
bot.rest,
"get",
options?.type === "privateJoinedThreads"
? bot.constants.endpoints.THREAD_ARCHIVED_PRIVATE_JOINED(channelId)
: options?.type === "private"
? bot.constants.endpoints.THREAD_ARCHIVED_PRIVATE(channelId)
: bot.constants.endpoints.THREAD_ARCHIVED_PUBLIC(channelId),
options ? {
before: options.before,
limit: options.limit,
type: options.type
} : {}
options
? {
before: options.before,
limit: options.limit,
type: options.type,
}
: {}
)) as ListActiveThreads;
const threads = new Collection(
@@ -2,11 +2,14 @@ import type { Bot } from "../../../bot.ts";
import { ThreadMember } from "../../../types/channels/threads/thread_member.ts";
import { DiscordGatewayIntents } from "../../../types/gateway/gateway_intents.ts";
import { Collection } from "../../../util/collection.ts";
import {threadMemberModified} from "../../../util/transformers/thread_member_modified.ts";
import { threadMemberModified } from "../../../util/transformers/thread_member_modified.ts";
/** Returns thread members objects that are members of the thread. */
export async function getThreadMembers(bot: Bot, threadId: bigint) {
// Check if intents is not 0 as proxy ws won't set intents in other instances
if (bot.gateway.identifyPayload.intents && !(bot.gateway.identifyPayload.intents & DiscordGatewayIntents.GuildMembers)) {
if (
bot.gateway.identifyPayload.intents &&
!(bot.gateway.identifyPayload.intents & DiscordGatewayIntents.GuildMembers)
) {
throw new Error(bot.constants.Errors.MISSING_INTENT_GUILD_MEMBERS);
}
@@ -17,7 +20,11 @@ export async function getThreadMembers(bot: Bot, threadId: bigint) {
throw new Error(bot.constants.Errors.CANNOT_GET_MEMBERS_OF_AN_UNJOINED_PRIVATE_THREAD);
}
const result = await bot.rest.runMethod<ThreadMember[]>(bot.rest,"get", bot.constants.endpoints.THREAD_MEMBERS(threadId));
const result = await bot.rest.runMethod<ThreadMember[]>(
bot.rest,
"get",
bot.constants.endpoints.THREAD_MEMBERS(threadId)
);
const members = result.map((member) => threadMemberModified(member));
+1 -1
View File
@@ -7,5 +7,5 @@ export async function joinThread(bot: Bot, threadId: bigint) {
throw new Error(bot.contants.Errors.CANNOT_ADD_USER_TO_ARCHIVED_THREADS);
}
return await bot.rest.runMethod<undefined>(bot.rest,"put", bot.constants.endpoints.THREAD_ME(threadId));
return await bot.rest.runMethod<undefined>(bot.rest, "put", bot.constants.endpoints.THREAD_ME(threadId));
}
+1 -1
View File
@@ -5,5 +5,5 @@ export async function leaveThread(bot: Bot, threadId: bigint) {
const thread = await bot.cache.threads.get(threadId);
if (thread?.archived) throw new Error(bot.constants.Errors.CANNOT_LEAVE_ARCHIVED_THREAD);
return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.THREAD_ME(threadId));
return await bot.rest.runMethod<undefined>(bot.rest, "delete", bot.constants.endpoints.THREAD_ME(threadId));
}
@@ -12,5 +12,5 @@ export async function removeThreadMember(bot: Bot, threadId: bigint, userId: big
}
}
return await bot.rest.runMethod<undefined>(bot.rest,"delete", bot.constants.endpoints.THREAD_USER(threadId, userId));
return await bot.rest.runMethod<undefined>(bot.rest, "delete", bot.constants.endpoints.THREAD_USER(threadId, userId));
}
@@ -1,7 +1,7 @@
import type { Channel } from "../../../types/channels/channel.ts";
import type { StartThread } from "../../../types/channels/threads/start_thread.ts";
import type { Bot } from "../../../bot.ts";
import {channelToThread} from "../../../util/transformers/channel_to_thread.ts";
import { channelToThread } from "../../../util/transformers/channel_to_thread.ts";
/** Creates a new private thread. Returns a thread channel. */
export async function startPrivateThread(bot: Bot, channelId: bigint, options: StartThread) {
@@ -15,9 +15,9 @@ export async function startPrivateThread(bot: Bot, channelId: bigint, options: S
}
return channelToThread(
await bot.rest.runMethod<Channel>(bot.rest,"post", bot.constants.endpoints.THREAD_START_PRIVATE(channelId), {
await bot.rest.runMethod<Channel>(bot.rest, "post", bot.constants.endpoints.THREAD_START_PRIVATE(channelId), {
name: options.name,
auto_archive_duration: options.autoArchiveDuration
auto_archive_duration: options.autoArchiveDuration,
})
);
}
+10 -5
View File
@@ -1,7 +1,7 @@
import type { Channel } from "../../../types/channels/channel.ts";
import type { StartThread } from "../../../types/channels/threads/start_thread.ts";
import type { Bot } from "../../../bot.ts";
import {channelToThread} from "../../../util/transformers/channel_to_thread.ts";
import { channelToThread } from "../../../util/transformers/channel_to_thread.ts";
/** Creates a new public thread from an existing message. Returns a thread channel. */
export async function startThread(bot: Bot, channelId: bigint, messageId: bigint, options: StartThread) {
@@ -15,9 +15,14 @@ export async function startThread(bot: Bot, channelId: bigint, messageId: bigint
}
return channelToThread(
await bot.rest.runMethod<Channel>(bot.rest,"post", bot.constants.endpoints.THREAD_START_PUBLIC(channelId, messageId), {
name: options.name,
auto_archive_duration: options.autoArchiveDuration
})
await bot.rest.runMethod<Channel>(
bot.rest,
"post",
bot.constants.endpoints.THREAD_START_PUBLIC(channelId, messageId),
{
name: options.name,
auto_archive_duration: options.autoArchiveDuration,
}
)
);
}