add: return type

This commit is contained in:
ITOH
2021-06-19 17:13:08 +02:00
parent 5202e3f6ae
commit f3353f512c
7 changed files with 18 additions and 12 deletions
@@ -4,8 +4,7 @@ import { Errors } from "../../../types/discordeno/errors.ts";
import { endpoints } from "../../../util/constants.ts"; import { endpoints } from "../../../util/constants.ts";
import { requireBotChannelPermissions } from "../../../util/permissions.ts"; import { requireBotChannelPermissions } from "../../../util/permissions.ts";
/** Adds a user to a thread. Requires the ability to send messages in the thread. Requires the thread is not archived. /** Adds a user to a thread. Requires the ability to send messages in the thread. Requires the thread is not archived. */
*/
export async function addToThread(threadId: bigint, userId: bigint) { export async function addToThread(threadId: bigint, userId: bigint) {
const thread = await cacheHandlers.get("threads", threadId); const thread = await cacheHandlers.get("threads", threadId);
if (thread) { if (thread) {
@@ -19,5 +18,5 @@ export async function addToThread(threadId: bigint, userId: bigint) {
if (channel) await requireBotChannelPermissions(channel, ["SEND_MESSAGES"]); if (channel) await requireBotChannelPermissions(channel, ["SEND_MESSAGES"]);
} }
return await rest.runMethod("put", endpoints.THREAD_USER(threadId, userId)); return await rest.runMethod<undefined>("put", endpoints.THREAD_USER(threadId, userId));
} }
@@ -11,5 +11,5 @@ export async function deleteThread(threadId: bigint, reason?: string) {
if (channel?.guildId) await requireBotGuildPermissions(channel.guildId, ["MANAGE_THREADS"]); if (channel?.guildId) await requireBotGuildPermissions(channel.guildId, ["MANAGE_THREADS"]);
} }
return await rest.runMethod("delete", endpoints.CHANNEL_BASE(threadId), { reason }); return await rest.runMethod<undefined>("delete", endpoints.CHANNEL_BASE(threadId), { reason });
} }
+1 -1
View File
@@ -10,5 +10,5 @@ export async function joinThread(threadId: bigint) {
throw new Error(Errors.CANNOT_ADD_USER_TO_ARCHIVED_THREADS); throw new Error(Errors.CANNOT_ADD_USER_TO_ARCHIVED_THREADS);
} }
return await rest.runMethod("put", endpoints.THREAD_ME(threadId)); return await rest.runMethod<undefined>("put", endpoints.THREAD_ME(threadId));
} }
+1 -1
View File
@@ -8,5 +8,5 @@ export async function leaveThread(threadId: bigint) {
const thread = await cacheHandlers.get("threads", threadId); const thread = await cacheHandlers.get("threads", threadId);
if (thread?.archived) throw new Error(Errors.CANNOT_LEAVE_ARCHIVED_THREAD); if (thread?.archived) throw new Error(Errors.CANNOT_LEAVE_ARCHIVED_THREAD);
return await rest.runMethod("delete", endpoints.THREAD_ME(threadId)); return await rest.runMethod<undefined>("delete", endpoints.THREAD_ME(threadId));
} }
@@ -17,5 +17,5 @@ export async function removeThreadMember(threadId: bigint, userId: bigint) {
} }
} }
return await rest.runMethod("delete", endpoints.THREAD_USER(threadId, userId)); return await rest.runMethod<undefined>("delete", endpoints.THREAD_USER(threadId, userId));
} }
@@ -1,5 +1,6 @@
import { cacheHandlers } from "../../../cache.ts"; import { cacheHandlers } from "../../../cache.ts";
import { rest } from "../../../rest/rest.ts"; import { rest } from "../../../rest/rest.ts";
import { Channel } from "../../../types/channels/channel.ts";
import { StartThread } from "../../../types/channels/threads/start_thread.ts"; import { StartThread } from "../../../types/channels/threads/start_thread.ts";
import { Errors } from "../../../types/discordeno/errors.ts"; import { Errors } from "../../../types/discordeno/errors.ts";
import { endpoints } from "../../../util/constants.ts"; import { endpoints } from "../../../util/constants.ts";
@@ -18,5 +19,7 @@ export async function startPrivateThread(channelId: bigint, options: StartThread
await requireBotChannelPermissions(channel, ["SEND_MESSAGES", "USE_PRIVATE_THREADS"]); await requireBotChannelPermissions(channel, ["SEND_MESSAGES", "USE_PRIVATE_THREADS"]);
} }
return channelToThread(await rest.runMethod("post", endpoints.THREAD_START_PRIVATE(channelId), snakelize(options))); return channelToThread(
await rest.runMethod<Channel>("post", endpoints.THREAD_START_PRIVATE(channelId), snakelize(options))
);
} }
+8 -4
View File
@@ -1,9 +1,11 @@
import { cacheHandlers } from "../../../cache.ts"; import { cacheHandlers } from "../../../cache.ts";
import { rest } from "../../../rest/rest.ts"; import { rest } from "../../../rest/rest.ts";
import { Channel } from "../../../types/channels/channel.ts";
import { StartThread } from "../../../types/channels/threads/start_thread.ts"; import { StartThread } from "../../../types/channels/threads/start_thread.ts";
import { Errors } from "../../../types/discordeno/errors.ts"; import { Errors } from "../../../types/discordeno/errors.ts";
import { endpoints } from "../../../util/constants.ts"; import { endpoints } from "../../../util/constants.ts";
import { requireBotChannelPermissions } from "../../../util/permissions.ts"; import { requireBotChannelPermissions } from "../../../util/permissions.ts";
import { channelToThread } from "../../../util/transformers/channel_to_thread.ts";
import { snakelize } from "../../../util/utils.ts"; import { snakelize } from "../../../util/utils.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. */
@@ -17,9 +19,11 @@ export async function startThread(channelId: bigint, options: StartThread & { me
await requireBotChannelPermissions(channel, ["SEND_MESSAGES", "USE_PUBLIC_THREADS"]); await requireBotChannelPermissions(channel, ["SEND_MESSAGES", "USE_PUBLIC_THREADS"]);
} }
return await rest.runMethod( return channelToThread(
"post", await rest.runMethod<Channel>(
endpoints.THREAD_START_PUBLIC(channelId, options.messageId), "post",
snakelize(options) endpoints.THREAD_START_PUBLIC(channelId, options.messageId),
snakelize(options)
)
); );
} }