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"]); 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,
});
} }
+3 -8
View File
@@ -1,6 +1,6 @@
import type { ModifyThread } from "../../../types/channels/threads/modify_thread.ts"; import type { ModifyThread } from "../../../types/channels/threads/modify_thread.ts";
import type { Bot } from "../../../bot.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. */ /** 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) { export async function editThread(bot: Bot, threadId: bigint, options: ModifyThread, reason?: string) {
@@ -8,19 +8,14 @@ export async function editThread(bot: Bot, threadId: bigint, options: ModifyThre
// TODO: permission checking // TODO: permission checking
const result = await bot.rest.runMethod( const result = await bot.rest.runMethod(bot.rest, "patch", bot.constants.endpoints.CHANNEL_BASE(threadId), {
bot.rest,
"patch",
bot.constants.endpoints.CHANNEL_BASE(threadId),
{
name: options.name, name: options.name,
archived: options.archived, archived: options.archived,
auto_archive_duration: options.autoArchiveDuration, auto_archive_duration: options.autoArchiveDuration,
locked: options.locked, locked: options.locked,
rate_limit_per_user: options.rateLimitPerUser, rate_limit_per_user: options.rateLimitPerUser,
reason, reason,
} });
);
return channelToThread(result); return channelToThread(result);
} }
@@ -1,14 +1,18 @@
import type { Bot } from "../../../bot.ts"; import type { Bot } from "../../../bot.ts";
import type { ListActiveThreads } from "../../../types/channels/threads/list_active_threads.ts"; import type { ListActiveThreads } from "../../../types/channels/threads/list_active_threads.ts";
import { Collection } from "../../../util/collection.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. */ /** 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) { export async function getActiveThreads(bot: Bot, channelId: bigint) {
await bot.utils.requireBotChannelPermissions(bot, channelId, ["VIEW_CHANNEL"]); await bot.utils.requireBotChannelPermissions(bot, channelId, ["VIEW_CHANNEL"]);
// TODO: pagination // 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( const threads = new Collection(
result.threads.map((t) => { result.threads.map((t) => {
@@ -3,7 +3,7 @@ import { ListPublicArchivedThreads } from "../../../types/channels/threads/list_
import { PermissionStrings } from "../../../types/permissions/permission_strings.ts"; import { PermissionStrings } from "../../../types/permissions/permission_strings.ts";
import { Collection } from "../../../util/collection.ts"; import { Collection } from "../../../util/collection.ts";
import type { Bot } from "../../../bot.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 */ /** Get the archived threads for this channel, defaults to public */
export async function getArchivedThreads( export async function getArchivedThreads(
@@ -28,11 +28,13 @@ export async function getArchivedThreads(
: options?.type === "private" : options?.type === "private"
? bot.constants.endpoints.THREAD_ARCHIVED_PRIVATE(channelId) ? bot.constants.endpoints.THREAD_ARCHIVED_PRIVATE(channelId)
: bot.constants.endpoints.THREAD_ARCHIVED_PUBLIC(channelId), : bot.constants.endpoints.THREAD_ARCHIVED_PUBLIC(channelId),
options ? { options
? {
before: options.before, before: options.before,
limit: options.limit, limit: options.limit,
type: options.type type: options.type,
} : {} }
: {}
)) as ListActiveThreads; )) as ListActiveThreads;
const threads = new Collection( const threads = new Collection(
@@ -2,11 +2,14 @@ import type { Bot } from "../../../bot.ts";
import { ThreadMember } from "../../../types/channels/threads/thread_member.ts"; import { ThreadMember } from "../../../types/channels/threads/thread_member.ts";
import { DiscordGatewayIntents } from "../../../types/gateway/gateway_intents.ts"; import { DiscordGatewayIntents } from "../../../types/gateway/gateway_intents.ts";
import { Collection } from "../../../util/collection.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. */ /** Returns thread members objects that are members of the thread. */
export async function getThreadMembers(bot: Bot, threadId: bigint) { export async function getThreadMembers(bot: Bot, threadId: bigint) {
// Check if intents is not 0 as proxy ws won't set intents in other instances // 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); 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); 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)); 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); 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); const thread = await bot.cache.threads.get(threadId);
if (thread?.archived) throw new Error(bot.constants.Errors.CANNOT_LEAVE_ARCHIVED_THREAD); 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 { Channel } from "../../../types/channels/channel.ts";
import type { StartThread } from "../../../types/channels/threads/start_thread.ts"; import type { StartThread } from "../../../types/channels/threads/start_thread.ts";
import type { Bot } from "../../../bot.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. */ /** Creates a new private thread. Returns a thread channel. */
export async function startPrivateThread(bot: Bot, channelId: bigint, options: StartThread) { 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( 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, name: options.name,
auto_archive_duration: options.autoArchiveDuration auto_archive_duration: options.autoArchiveDuration,
}) })
); );
} }
+9 -4
View File
@@ -1,7 +1,7 @@
import type { Channel } from "../../../types/channels/channel.ts"; import type { Channel } from "../../../types/channels/channel.ts";
import type { StartThread } from "../../../types/channels/threads/start_thread.ts"; import type { StartThread } from "../../../types/channels/threads/start_thread.ts";
import type { Bot } from "../../../bot.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. */ /** 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) { 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( return channelToThread(
await bot.rest.runMethod<Channel>(bot.rest,"post", bot.constants.endpoints.THREAD_START_PUBLIC(channelId, messageId), { await bot.rest.runMethod<Channel>(
bot.rest,
"post",
bot.constants.endpoints.THREAD_START_PUBLIC(channelId, messageId),
{
name: options.name, name: options.name,
auto_archive_duration: options.autoArchiveDuration auto_archive_duration: options.autoArchiveDuration,
}) }
)
); );
} }