From 2266e9dd0034b8851adaab18af3195cc14ab104f Mon Sep 17 00:00:00 2001 From: TriForMine Date: Thu, 21 Oct 2021 19:42:37 +0000 Subject: [PATCH] change: prettier code --- src/helpers/channels/threads/delete_thread.ts | 4 ++- src/helpers/channels/threads/edit_thread.ts | 29 ++++++++----------- .../channels/threads/get_active_threads.ts | 8 +++-- .../channels/threads/get_archived_threads.ts | 18 +++++++----- .../channels/threads/get_thread_members.ts | 13 +++++++-- src/helpers/channels/threads/join_thread.ts | 2 +- src/helpers/channels/threads/leave_thread.ts | 2 +- .../channels/threads/remove_thread_member.ts | 2 +- .../channels/threads/start_private_thread.ts | 6 ++-- src/helpers/channels/threads/start_thread.ts | 15 ++++++---- 10 files changed, 57 insertions(+), 42 deletions(-) diff --git a/src/helpers/channels/threads/delete_thread.ts b/src/helpers/channels/threads/delete_thread.ts index c6df49288..2ed94ec8b 100644 --- a/src/helpers/channels/threads/delete_thread.ts +++ b/src/helpers/channels/threads/delete_thread.ts @@ -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(bot.rest,"delete", bot.constants.endpoints.CHANNEL_BASE(threadId), { reason }); + return await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.CHANNEL_BASE(threadId), { + reason, + }); } diff --git a/src/helpers/channels/threads/edit_thread.ts b/src/helpers/channels/threads/edit_thread.ts index 51ebfe281..ef32fc3a9 100644 --- a/src/helpers/channels/threads/edit_thread.ts +++ b/src/helpers/channels/threads/edit_thread.ts @@ -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); } diff --git a/src/helpers/channels/threads/get_active_threads.ts b/src/helpers/channels/threads/get_active_threads.ts index fef963417..391edc336 100644 --- a/src/helpers/channels/threads/get_active_threads.ts +++ b/src/helpers/channels/threads/get_active_threads.ts @@ -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) => { diff --git a/src/helpers/channels/threads/get_archived_threads.ts b/src/helpers/channels/threads/get_archived_threads.ts index baf42e4a9..329b2b6ac 100644 --- a/src/helpers/channels/threads/get_archived_threads.ts +++ b/src/helpers/channels/threads/get_archived_threads.ts @@ -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( diff --git a/src/helpers/channels/threads/get_thread_members.ts b/src/helpers/channels/threads/get_thread_members.ts index ed84f81d7..adba7691b 100644 --- a/src/helpers/channels/threads/get_thread_members.ts +++ b/src/helpers/channels/threads/get_thread_members.ts @@ -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(bot.rest,"get", bot.constants.endpoints.THREAD_MEMBERS(threadId)); + const result = await bot.rest.runMethod( + bot.rest, + "get", + bot.constants.endpoints.THREAD_MEMBERS(threadId) + ); const members = result.map((member) => threadMemberModified(member)); diff --git a/src/helpers/channels/threads/join_thread.ts b/src/helpers/channels/threads/join_thread.ts index 091feff0b..4bd636368 100644 --- a/src/helpers/channels/threads/join_thread.ts +++ b/src/helpers/channels/threads/join_thread.ts @@ -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(bot.rest,"put", bot.constants.endpoints.THREAD_ME(threadId)); + return await bot.rest.runMethod(bot.rest, "put", bot.constants.endpoints.THREAD_ME(threadId)); } diff --git a/src/helpers/channels/threads/leave_thread.ts b/src/helpers/channels/threads/leave_thread.ts index a4e4961c1..157868221 100644 --- a/src/helpers/channels/threads/leave_thread.ts +++ b/src/helpers/channels/threads/leave_thread.ts @@ -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(bot.rest,"delete", bot.constants.endpoints.THREAD_ME(threadId)); + return await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.THREAD_ME(threadId)); } diff --git a/src/helpers/channels/threads/remove_thread_member.ts b/src/helpers/channels/threads/remove_thread_member.ts index 5b4b633be..38c7ae646 100644 --- a/src/helpers/channels/threads/remove_thread_member.ts +++ b/src/helpers/channels/threads/remove_thread_member.ts @@ -12,5 +12,5 @@ export async function removeThreadMember(bot: Bot, threadId: bigint, userId: big } } - return await bot.rest.runMethod(bot.rest,"delete", bot.constants.endpoints.THREAD_USER(threadId, userId)); + return await bot.rest.runMethod(bot.rest, "delete", bot.constants.endpoints.THREAD_USER(threadId, userId)); } diff --git a/src/helpers/channels/threads/start_private_thread.ts b/src/helpers/channels/threads/start_private_thread.ts index f62b416fe..ca1b65ef1 100644 --- a/src/helpers/channels/threads/start_private_thread.ts +++ b/src/helpers/channels/threads/start_private_thread.ts @@ -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(bot.rest,"post", bot.constants.endpoints.THREAD_START_PRIVATE(channelId), { + await bot.rest.runMethod(bot.rest, "post", bot.constants.endpoints.THREAD_START_PRIVATE(channelId), { name: options.name, - auto_archive_duration: options.autoArchiveDuration + auto_archive_duration: options.autoArchiveDuration, }) ); } diff --git a/src/helpers/channels/threads/start_thread.ts b/src/helpers/channels/threads/start_thread.ts index e53d25a62..4f820d8c0 100644 --- a/src/helpers/channels/threads/start_thread.ts +++ b/src/helpers/channels/threads/start_thread.ts @@ -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(bot.rest,"post", bot.constants.endpoints.THREAD_START_PUBLIC(channelId, messageId), { - name: options.name, - auto_archive_duration: options.autoArchiveDuration - }) + await bot.rest.runMethod( + bot.rest, + "post", + bot.constants.endpoints.THREAD_START_PUBLIC(channelId, messageId), + { + name: options.name, + auto_archive_duration: options.autoArchiveDuration, + } + ) ); }