mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28:17 +00:00
fix: more bugs bugs bugs
This commit is contained in:
@@ -9,6 +9,9 @@ export async function handleThreadMemberUpdate(data: DiscordGatewayPayload) {
|
|||||||
const thread = await cacheHandlers.get("threads", snowflakeToBigint(payload.id));
|
const thread = await cacheHandlers.get("threads", snowflakeToBigint(payload.id));
|
||||||
if (!thread) return;
|
if (!thread) return;
|
||||||
|
|
||||||
|
thread.botIsMember = true;
|
||||||
|
await cacheHandlers.set("threads", thread.id, thread);
|
||||||
|
|
||||||
const member = {
|
const member = {
|
||||||
...payload,
|
...payload,
|
||||||
id: snowflakeToBigint(payload.id),
|
id: snowflakeToBigint(payload.id),
|
||||||
|
|||||||
@@ -1,36 +1,24 @@
|
|||||||
import { cacheHandlers } from "../../../cache.ts";
|
import { cacheHandlers } from "../../../cache.ts";
|
||||||
import { rest } from "../../../rest/rest.ts";
|
import { rest } from "../../../rest/rest.ts";
|
||||||
import { ChannelTypes } from "../../../types/channels/channel_types.ts";
|
|
||||||
import { Errors } from "../../../types/discordeno/errors.ts";
|
import { Errors } from "../../../types/discordeno/errors.ts";
|
||||||
import { DiscordGatewayIntents } from "../../../types/gateway/gateway_intents.ts";
|
import { DiscordGatewayIntents } from "../../../types/gateway/gateway_intents.ts";
|
||||||
import { endpoints } from "../../../util/constants.ts";
|
import { endpoints } from "../../../util/constants.ts";
|
||||||
import { botHasChannelPermissions } from "../../../util/permissions.ts";
|
import { botHasChannelPermissions } from "../../../util/permissions.ts";
|
||||||
import { ws } from "../../../ws/ws.ts";
|
import { ws } from "../../../ws/ws.ts";
|
||||||
|
|
||||||
/** Returns array of thread members objects that are members of the thread. */
|
/** Returns thread members objects that are members of the thread. */
|
||||||
export async function getThreadMembers(channelId: bigint) {
|
export async function getThreadMembers(threadId: bigint) {
|
||||||
if (!(ws.identifyPayload.intents & DiscordGatewayIntents.GuildMembers)) {
|
// Check if intents is not 0 as proxy ws won't set intents in other instances
|
||||||
|
if (ws.identifyPayload.intents && !(ws.identifyPayload.intents & DiscordGatewayIntents.GuildMembers)) {
|
||||||
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
|
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
const channel = await cacheHandlers.get("channels", channelId);
|
const thread = await cacheHandlers.get("threads", threadId);
|
||||||
if (channel) {
|
if (thread?.isPrivate) {
|
||||||
if (
|
const channel = await cacheHandlers.get("channels", thread.channelId);
|
||||||
![ChannelTypes.GuildNewsThread, ChannelTypes.GuildPivateThread, ChannelTypes.GuildPublicThread].includes(
|
if (channel && !(await botHasChannelPermissions(channel, ["MANAGE_THREADS"])) && !thread.botIsMember)
|
||||||
channel.type
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
throw new Error(Errors.NOT_A_THREAD_CHANNEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
channel.type === ChannelTypes.GuildPivateThread &&
|
|
||||||
!(await botHasChannelPermissions(channel, ["MANAGE_THREADS"])) &&
|
|
||||||
!channel.member
|
|
||||||
)
|
|
||||||
throw new Error(Errors.CANNOT_GET_MEMBERS_OF_AN_UNJOINED_PRIVATE_THREAD);
|
throw new Error(Errors.CANNOT_GET_MEMBERS_OF_AN_UNJOINED_PRIVATE_THREAD);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: v12 map the result to a nice collection
|
return await rest.runMethod("get", endpoints.THREAD_MEMBERS(threadId));
|
||||||
return await rest.runMethod("get", endpoints.THREAD_MEMBERS(channelId));
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export async function startPrivateThread(channelId: bigint, options: StartThread
|
|||||||
|
|
||||||
if (channel.isNewsChannel) throw new Error(Errors.GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS);
|
if (channel.isNewsChannel) throw new Error(Errors.GUILD_NEWS_CHANNEL_ONLY_SUPPORT_PUBLIC_THREADS);
|
||||||
|
|
||||||
await requireBotChannelPermissions(channel, ["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("post", endpoints.THREAD_START_PRIVATE(channelId), snakelize(options)));
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export async function startThread(channelId: bigint, options: StartThread & { me
|
|||||||
throw new Error(Errors.INVALID_THREAD_PARENT_CHANNEL_TYPE);
|
throw new Error(Errors.INVALID_THREAD_PARENT_CHANNEL_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
await requireBotChannelPermissions(channel, ["USE_PUBLIC_THREADS"]);
|
await requireBotChannelPermissions(channel, ["SEND_MESSAGES", "USE_PUBLIC_THREADS"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return await rest.runMethod(
|
return await rest.runMethod(
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import type { DiscordenoGuild } from "../../structures/guild.ts";
|
|||||||
import type { DiscordenoMember } from "../../structures/member.ts";
|
import type { DiscordenoMember } from "../../structures/member.ts";
|
||||||
import type { DiscordenoMessage } from "../../structures/message.ts";
|
import type { DiscordenoMessage } from "../../structures/message.ts";
|
||||||
import type { DiscordenoRole } from "../../structures/role.ts";
|
import type { DiscordenoRole } from "../../structures/role.ts";
|
||||||
import { Thread } from "../../util/transformers/channel_to_thread.ts";
|
import { DiscordenoThread } from "../../util/transformers/channel_to_thread.ts";
|
||||||
import type { Collection } from "../../util/collection.ts";
|
import type { Collection } from "../../util/collection.ts";
|
||||||
import type { PresenceUpdate } from "../activity/presence_update.ts";
|
import type { PresenceUpdate } from "../activity/presence_update.ts";
|
||||||
import type { StageInstance } from "../channels/stage_instance.ts";
|
import type { StageInstance } from "../channels/stage_instance.ts";
|
||||||
@@ -129,17 +129,17 @@ export type EventHandlersDefinitions = {
|
|||||||
/** Sent when a Stage instance has been updated. */
|
/** Sent when a Stage instance has been updated. */
|
||||||
stageInstanceUpdate: [instance: StageInstance];
|
stageInstanceUpdate: [instance: StageInstance];
|
||||||
/** Sent when a thread is created */
|
/** Sent when a thread is created */
|
||||||
threadCreate: [thread: Thread];
|
threadCreate: [thread: DiscordenoThread];
|
||||||
/** Sent when a thread is updated */
|
/** Sent when a thread is updated */
|
||||||
threadUpdate: [thread: Thread, oldThread: Thread];
|
threadUpdate: [thread: DiscordenoThread, oldThread: DiscordenoThread];
|
||||||
/** Sent when the bot gains access to threads */
|
/** Sent when the bot gains access to threads */
|
||||||
threadListSync: [threads: Collection<bigint, Thread>, members: ThreadMemberModified[], guildId: bigint];
|
threadListSync: [threads: Collection<bigint, DiscordenoThread>, members: ThreadMemberModified[], guildId: bigint];
|
||||||
/** Sent when the current users thread member is updated */
|
/** Sent when the current users thread member is updated */
|
||||||
threadMemberUpdate: [threadMember: ThreadMemberModified, thread: Thread];
|
threadMemberUpdate: [threadMember: ThreadMemberModified, thread: DiscordenoThread];
|
||||||
/** Sent when anyone is added to or removed from a thread */
|
/** Sent when anyone is added to or removed from a thread */
|
||||||
threadMembersUpdate: [update: ThreadMembersUpdateModified];
|
threadMembersUpdate: [update: ThreadMembersUpdateModified];
|
||||||
/** Sent when a thread is deleted */
|
/** Sent when a thread is deleted */
|
||||||
threadDelete: [thread: Thread];
|
threadDelete: [thread: DiscordenoThread];
|
||||||
/** Sent when a user starts typing in a channel. */
|
/** Sent when a user starts typing in a channel. */
|
||||||
typingStart: [data: TypingStart];
|
typingStart: [data: TypingStart];
|
||||||
/** Sent when a user joins a voice channel */
|
/** Sent when a user joins a voice channel */
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Channel } from "../../types/channels/channel.ts";
|
import { Channel } from "../../types/channels/channel.ts";
|
||||||
|
import { DiscordChannelTypes } from "../../types/channels/channel_types.ts";
|
||||||
import { snowflakeToBigint } from "../bigint.ts";
|
import { snowflakeToBigint } from "../bigint.ts";
|
||||||
import { createNewProp } from "../utils.ts";
|
import { createNewProp } from "../utils.ts";
|
||||||
|
|
||||||
@@ -16,9 +17,16 @@ const baseThread: Partial<DiscordenoThread> = {
|
|||||||
get locked() {
|
get locked() {
|
||||||
return Boolean(this.bitfield! & threadToggles.locked);
|
return Boolean(this.bitfield! & threadToggles.locked);
|
||||||
},
|
},
|
||||||
|
get isPrivate() {
|
||||||
|
return this.type === DiscordChannelTypes.GuildPrivateThread;
|
||||||
|
},
|
||||||
|
get isPublic() {
|
||||||
|
return !this.isPrivate;
|
||||||
|
},
|
||||||
toJSON() {
|
toJSON() {
|
||||||
return {
|
return {
|
||||||
id: this.id?.toString(),
|
id: this.id?.toString(),
|
||||||
|
type: this.type,
|
||||||
channelId: this.channelId?.toString(),
|
channelId: this.channelId?.toString(),
|
||||||
memberCount: this.memberCount,
|
memberCount: this.memberCount,
|
||||||
messageCount: this.messageCount,
|
messageCount: this.messageCount,
|
||||||
@@ -39,6 +47,7 @@ export function channelToThread(channel: Channel) {
|
|||||||
|
|
||||||
return Object.create(baseThread, {
|
return Object.create(baseThread, {
|
||||||
id: createNewProp(snowflakeToBigint(channel.id)),
|
id: createNewProp(snowflakeToBigint(channel.id)),
|
||||||
|
type: createNewProp(channel.type),
|
||||||
channelId: createNewProp(snowflakeToBigint(channel.parentId!)),
|
channelId: createNewProp(snowflakeToBigint(channel.parentId!)),
|
||||||
memberCount: createNewProp(channel.memberCount),
|
memberCount: createNewProp(channel.memberCount),
|
||||||
messageCount: createNewProp(channel.messageCount),
|
messageCount: createNewProp(channel.messageCount),
|
||||||
@@ -50,12 +59,17 @@ export function channelToThread(channel: Channel) {
|
|||||||
),
|
),
|
||||||
autoArchiveDuration: createNewProp(channel.threadMetadata?.autoArchiveDuration || 0),
|
autoArchiveDuration: createNewProp(channel.threadMetadata?.autoArchiveDuration || 0),
|
||||||
bitfield: createNewProp(bitfield),
|
bitfield: createNewProp(bitfield),
|
||||||
ownerId: createNewProp(snowflakeToBigint(channel.ownerId!))
|
ownerId: createNewProp(snowflakeToBigint(channel.ownerId!)),
|
||||||
|
botIsMember: createNewProp(Boolean(channel.member))
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Thread {
|
export interface Thread {
|
||||||
id: string;
|
id: string;
|
||||||
|
type:
|
||||||
|
| DiscordChannelTypes.GuildNewsThread
|
||||||
|
| DiscordChannelTypes.GuildPublicThread
|
||||||
|
| DiscordChannelTypes.GuildPrivateThread;
|
||||||
channelId: string;
|
channelId: string;
|
||||||
memberCount: number;
|
memberCount: number;
|
||||||
messageCount: number;
|
messageCount: number;
|
||||||
@@ -65,10 +79,15 @@ export interface Thread {
|
|||||||
archived: boolean;
|
archived: boolean;
|
||||||
locked: boolean;
|
locked: boolean;
|
||||||
ownerId: string;
|
ownerId: string;
|
||||||
|
botIsMember: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DiscordenoThread {
|
export interface DiscordenoThread {
|
||||||
id: bigint;
|
id: bigint;
|
||||||
|
type:
|
||||||
|
| DiscordChannelTypes.GuildNewsThread
|
||||||
|
| DiscordChannelTypes.GuildPublicThread
|
||||||
|
| DiscordChannelTypes.GuildPrivateThread;
|
||||||
channelId: bigint;
|
channelId: bigint;
|
||||||
memberCount: number;
|
memberCount: number;
|
||||||
messageCount: number;
|
messageCount: number;
|
||||||
@@ -79,5 +98,8 @@ export interface DiscordenoThread {
|
|||||||
locked: boolean;
|
locked: boolean;
|
||||||
bitfield: bigint;
|
bitfield: bigint;
|
||||||
ownerId: bigint;
|
ownerId: bigint;
|
||||||
|
isPrivate: boolean;
|
||||||
|
isPublic: boolean;
|
||||||
|
botIsMember: boolean;
|
||||||
toJSON(): Thread;
|
toJSON(): Thread;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user