mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 17:30:07 +00:00
@@ -20,7 +20,6 @@ export async function deleteChannel(channelId: bigint, reason?: string) {
|
||||
throw new Error(Errors.UPDATES_CHANNEL_CANNOT_BE_DELETED);
|
||||
}
|
||||
|
||||
// TODO(threads): check if this requires guild perms or channel is enough
|
||||
await requireBotGuildPermissions(guild, ["MANAGE_CHANNELS"]);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@ import { endpoints } from "../../util/constants.ts";
|
||||
import { calculateBits, requireOverwritePermissions } from "../../util/permissions.ts";
|
||||
import { snakelize } from "../../util/utils.ts";
|
||||
|
||||
//TODO: implement DM group channel edit
|
||||
/** Update a channel's settings. Requires the `MANAGE_CHANNELS` permission for the guild. */
|
||||
export async function editChannel(channelId: bigint, options: ModifyChannel, reason?: string) {
|
||||
const channel = await cacheHandlers.get("channels", channelId);
|
||||
|
||||
@@ -4,8 +4,7 @@ import { Errors } from "../../../types/discordeno/errors.ts";
|
||||
import { endpoints } from "../../../util/constants.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) {
|
||||
const thread = await cacheHandlers.get("threads", threadId);
|
||||
if (thread) {
|
||||
@@ -19,5 +18,5 @@ export async function addToThread(threadId: bigint, userId: bigint) {
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { editThread } from "./edit_thread.ts";
|
||||
|
||||
/** Sets a thread channel to be archived. */
|
||||
export function archiveThread(threadId: bigint) {
|
||||
return editThread(threadId, { archived: true });
|
||||
export async function archiveThread(threadId: bigint) {
|
||||
return await editThread(threadId, { archived: true });
|
||||
}
|
||||
|
||||
@@ -11,5 +11,5 @@ export async function deleteThread(threadId: bigint, reason?: string) {
|
||||
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,9 +1,12 @@
|
||||
import { cacheHandlers } from "../../../cache.ts";
|
||||
import { rest } from "../../../rest/rest.ts";
|
||||
import { ThreadMember } from "../../../types/channels/threads/thread_member.ts";
|
||||
import { Errors } from "../../../types/discordeno/errors.ts";
|
||||
import { DiscordGatewayIntents } from "../../../types/gateway/gateway_intents.ts";
|
||||
import { Collection } from "../../../util/collection.ts";
|
||||
import { endpoints } from "../../../util/constants.ts";
|
||||
import { botHasChannelPermissions } from "../../../util/permissions.ts";
|
||||
import { threadMemberModified } from "../../../util/transformers/thread_member_modified.ts";
|
||||
import { ws } from "../../../ws/ws.ts";
|
||||
|
||||
/** Returns thread members objects that are members of the thread. */
|
||||
@@ -20,5 +23,9 @@ export async function getThreadMembers(threadId: bigint) {
|
||||
throw new Error(Errors.CANNOT_GET_MEMBERS_OF_AN_UNJOINED_PRIVATE_THREAD);
|
||||
}
|
||||
|
||||
return await rest.runMethod("get", endpoints.THREAD_MEMBERS(threadId));
|
||||
const result = await rest.runMethod<ThreadMember[]>("get", endpoints.THREAD_MEMBERS(threadId));
|
||||
|
||||
const members = result.map((member) => threadMemberModified(member));
|
||||
|
||||
return new Collection(members.map((member) => [member.id, member]));
|
||||
}
|
||||
|
||||
@@ -10,5 +10,5 @@ export async function joinThread(threadId: bigint) {
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -8,5 +8,5 @@ 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));
|
||||
return await rest.runMethod<undefined>("delete", endpoints.THREAD_ME(threadId));
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { editThread } from "./edit_thread.ts";
|
||||
|
||||
/** Sets a thread channel to be locked. */
|
||||
export function lockThread(threadId: bigint) {
|
||||
return editThread(threadId, { locked: true });
|
||||
export async function lockThread(threadId: bigint) {
|
||||
return await editThread(threadId, { locked: true });
|
||||
}
|
||||
|
||||
@@ -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 { rest } from "../../../rest/rest.ts";
|
||||
import { Channel } from "../../../types/channels/channel.ts";
|
||||
import { StartThread } from "../../../types/channels/threads/start_thread.ts";
|
||||
import { Errors } from "../../../types/discordeno/errors.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"]);
|
||||
}
|
||||
|
||||
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))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import { cacheHandlers } from "../../../cache.ts";
|
||||
import { rest } from "../../../rest/rest.ts";
|
||||
import { Channel } from "../../../types/channels/channel.ts";
|
||||
import { StartThread } from "../../../types/channels/threads/start_thread.ts";
|
||||
import { Errors } from "../../../types/discordeno/errors.ts";
|
||||
import { endpoints } from "../../../util/constants.ts";
|
||||
import { requireBotChannelPermissions } from "../../../util/permissions.ts";
|
||||
import { channelToThread } from "../../../util/transformers/channel_to_thread.ts";
|
||||
import { snakelize } from "../../../util/utils.ts";
|
||||
|
||||
/** 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"]);
|
||||
}
|
||||
|
||||
return await rest.runMethod(
|
||||
"post",
|
||||
endpoints.THREAD_START_PUBLIC(channelId, options.messageId),
|
||||
snakelize(options)
|
||||
return channelToThread(
|
||||
await rest.runMethod<Channel>(
|
||||
"post",
|
||||
endpoints.THREAD_START_PUBLIC(channelId, options.messageId),
|
||||
snakelize(options)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { editThread } from "./edit_thread.ts";
|
||||
|
||||
/** Sets a thread channel to be unarchived. */
|
||||
export function unarchiveThread(threadId: bigint) {
|
||||
return editThread(threadId, { archived: false });
|
||||
export async function unarchiveThread(threadId: bigint) {
|
||||
return await editThread(threadId, { archived: false });
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { editThread } from "./edit_thread.ts";
|
||||
|
||||
/** Sets a thread channel to be unlocked. */
|
||||
export function unlockThread(threadId: bigint) {
|
||||
return editThread(threadId, { locked: false });
|
||||
export async function unlockThread(threadId: bigint) {
|
||||
return await editThread(threadId, { locked: false });
|
||||
}
|
||||
|
||||
@@ -29,11 +29,6 @@ export async function editMessage(channelId: bigint, messageId: bigint, content:
|
||||
validateComponents(content.components);
|
||||
}
|
||||
|
||||
// TODO: v12 remove
|
||||
if (content.embed) {
|
||||
content.embeds = [content.embed, ...(content.embeds || [])];
|
||||
content.embed = undefined;
|
||||
}
|
||||
content.embeds?.splice(10);
|
||||
|
||||
if (content.content && content.content.length > 2000) {
|
||||
|
||||
@@ -34,11 +34,6 @@ export async function sendMessage(channelId: bigint, content: string | CreateMes
|
||||
const requiredPerms: Set<PermissionStrings> = new Set(["SEND_MESSAGES", "VIEW_CHANNEL"]);
|
||||
|
||||
if (content.tts) requiredPerms.add("SEND_TTS_MESSAGES");
|
||||
// TODO: v12 remove
|
||||
if (content.embed) {
|
||||
content.embeds = [content.embed, ...(content.embeds || [])];
|
||||
content.embed = undefined;
|
||||
}
|
||||
if (content.embeds?.length) {
|
||||
requiredPerms.add("EMBED_LINKS");
|
||||
content.embeds?.splice(10);
|
||||
|
||||
@@ -10,11 +10,6 @@ export interface CreateMessage {
|
||||
content?: string;
|
||||
/** true if this is a TTS message */
|
||||
tts?: boolean;
|
||||
// TODO: v12 remove
|
||||
/** Embedded `rich` content
|
||||
* @deprecated will be removed in Discordeno v12 use embeds
|
||||
*/
|
||||
embed?: Embed;
|
||||
/** Embedded `rich` content (up to 6000 characters) */
|
||||
embeds?: Embed[];
|
||||
/** Allowed mentions for the message */
|
||||
|
||||
@@ -8,11 +8,6 @@ import { MessageComponents } from "./components/message_components.ts";
|
||||
export interface EditMessage {
|
||||
/** The new message contents (up to 2000 characters) */
|
||||
content?: string | null;
|
||||
// TODO: v12 remove
|
||||
/** Embedded `rich` content
|
||||
* @deprecated will be removed in Discordeno v12 use embeds
|
||||
*/
|
||||
embed?: Embed | null;
|
||||
/** Embedded `rich` content (up to 6000 characters) */
|
||||
embeds?: Embed[] | null;
|
||||
/** Edit the flags of the message (only `SUPRESS_EMBEDS` can currently be set/unset) */
|
||||
|
||||
@@ -59,6 +59,7 @@ export function channelToThread(channel: Channel) {
|
||||
bitfield: createNewProp(bitfield),
|
||||
ownerId: createNewProp(snowflakeToBigint(channel.ownerId!)),
|
||||
botIsMember: createNewProp(Boolean(channel.member)),
|
||||
guildId: createNewProp(snowflakeToBigint(channel.guildId!)),
|
||||
members: createNewProp(new Collection<bigint, Omit<ThreadMemberModified, "id">>()),
|
||||
}) as DiscordenoThread;
|
||||
}
|
||||
@@ -78,6 +79,7 @@ export interface Thread {
|
||||
locked: boolean;
|
||||
ownerId: string;
|
||||
botIsMember: boolean;
|
||||
guildId: string;
|
||||
}
|
||||
|
||||
export interface DiscordenoThread {
|
||||
@@ -98,6 +100,7 @@ export interface DiscordenoThread {
|
||||
isPrivate: boolean;
|
||||
isPublic: boolean;
|
||||
botIsMember: boolean;
|
||||
guildId: bigint;
|
||||
members: Collection<bigint, Omit<ThreadMemberModified, "id">>;
|
||||
toJSON(): Thread;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user