mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 16:57:22 +00:00
fix: thread transfomer is uselss
This commit is contained in:
@@ -86,7 +86,6 @@ import { transformAttachment } from "./transformers/attachment.ts";
|
||||
import { transformEmbed } from "./transformers/embed.ts";
|
||||
import { transformComponent } from "./transformers/component.ts";
|
||||
import { AsyncCache, AsyncCacheHandler, Cache, CacheHandler, createCache, TableNames } from "./cache.ts";
|
||||
import { transformThread } from "./transformers/thread.ts";
|
||||
import { transformWebhook } from "./transformers/webhook.ts";
|
||||
import { transformAuditlogEntry } from "./transformers/auditlogEntry.ts";
|
||||
import { transformApplicationCommandPermission } from "./transformers/applicationCommandPermission.ts";
|
||||
@@ -813,7 +812,6 @@ export interface Transformers {
|
||||
attachment: typeof transformAttachment;
|
||||
embed: typeof transformEmbed;
|
||||
component: typeof transformComponent;
|
||||
thread: typeof transformThread;
|
||||
webhook: typeof transformWebhook;
|
||||
auditlogEntry: typeof transformAuditlogEntry;
|
||||
applicationCommandPermission: typeof transformApplicationCommandPermission;
|
||||
@@ -839,7 +837,6 @@ export function createTransformers(options: Partial<Transformers>) {
|
||||
role: options.role || transformRole,
|
||||
user: options.user || transformUser,
|
||||
team: options.team || transformTeam,
|
||||
thread: options.thread || transformThread,
|
||||
voiceState: options.voiceState || transformVoiceState,
|
||||
snowflake: options.snowflake || snowflakeToBigint,
|
||||
webhook: options.webhook || transformWebhook,
|
||||
|
||||
@@ -9,7 +9,7 @@ export async function startThreadWithMessage(
|
||||
messageId: bigint,
|
||||
options: StartThreadWithMessage
|
||||
) {
|
||||
return await bot.rest.runMethod<Channel>(
|
||||
const result = await bot.rest.runMethod<Channel>(
|
||||
bot.rest,
|
||||
"post",
|
||||
bot.constants.endpoints.THREAD_START_PUBLIC(channelId, messageId),
|
||||
@@ -18,4 +18,6 @@ export async function startThreadWithMessage(
|
||||
auto_archive_duration: options.autoArchiveDuration,
|
||||
}
|
||||
);
|
||||
|
||||
return bot.transformers.channel(bot, { channel: result, guildId: bot.transformers.snowflake(result.guild_id!) });
|
||||
}
|
||||
|
||||
+22
-25
@@ -1,24 +1,12 @@
|
||||
import { Channel } from "../types/channels/channel.ts";
|
||||
import { Bot } from "../bot.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../types/util.ts";
|
||||
import { DiscordOverwrite } from "../types/channels/overwrite.ts";
|
||||
import { ChannelTypes } from "../types/channels/channelTypes.ts";
|
||||
import type { DiscordenoVoiceState } from "./voiceState.ts";
|
||||
import { Collection } from "../util/collection.ts";
|
||||
import { DiscordenoUser } from "./member.ts";
|
||||
import { VideoQualityModes } from "../types/channels/videoQualityModes.ts";
|
||||
|
||||
// function merge(allow: string, deny: string, id: string, type: number) {
|
||||
// return BigInt(`0x${type}g${BigInt(id)}g${BigInt(allow).toString(16)}g${BigInt(deny).toString(16)}`);
|
||||
// }
|
||||
|
||||
// export function separateOverwrites(thing: bigint) {
|
||||
// return thing
|
||||
// .toString(16)
|
||||
// .split("g")
|
||||
// .map((x, index) => index ? BigInt(`0x${x}`) : Number(x)) as [number, bigint, bigint, bigint];
|
||||
// }
|
||||
|
||||
const Mask = (1n << 64n) - 1n;
|
||||
|
||||
export function packOverwrites(allow: string, deny: string, id: string, type: number) {
|
||||
@@ -75,6 +63,16 @@ export function transformChannel(
|
||||
parentId: payload.channel.parent_id ? bot.transformers.snowflake(payload.channel.parent_id) : undefined,
|
||||
// TODO: stage channels?
|
||||
voiceStates: payload.channel.type === ChannelTypes.GuildVoice ? new Collection() : undefined,
|
||||
|
||||
memberCount: payload.channel.member_count,
|
||||
messageCount: payload.channel.message_count,
|
||||
archiveTimestamp: payload.channel.thread_metadata?.archive_timestamp
|
||||
? Date.parse(payload.channel.thread_metadata.archive_timestamp)
|
||||
: undefined,
|
||||
autoArchiveDuration: payload.channel.thread_metadata?.auto_archive_duration,
|
||||
botIsMember: Boolean(payload.channel.member),
|
||||
archived: payload.channel.thread_metadata?.archived,
|
||||
locked: payload.channel.thread_metadata?.locked,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -111,23 +109,22 @@ export interface DiscordenoChannel {
|
||||
/** An approximate count of users in a thread, stops counting at 50 */
|
||||
memberCount?: number;
|
||||
/** Thread-specifig fields not needed by other channels */
|
||||
threadMetadata?: {
|
||||
/** Whether the thread is archived */
|
||||
archived: boolean;
|
||||
/** Duration in minutes to automatically archive the thread after recent activity */
|
||||
autoArchiveDuration: 60 | 1440 | 4320 | 10080;
|
||||
// TODO(threads): channel struct should convert this to a unixx
|
||||
/** Timestamp when the thread's archive status was last changed, used for calculating recent activity */
|
||||
archiveTimestamp: string;
|
||||
/** When a thread is locked, only users with `MANAGE_THREADS` can unarchive it */
|
||||
locked?: boolean;
|
||||
/** whether non-moderators can add other non-moderators to a thread; only available on private threads */
|
||||
invitable?: boolean;
|
||||
};
|
||||
/** Whether the thread is archived */
|
||||
archived?: boolean;
|
||||
/** Duration in minutes to automatically archive the thread after recent activity */
|
||||
autoArchiveDuration?: 60 | 1440 | 4320 | 10080;
|
||||
/** Timestamp when the thread's archive status was last changed, used for calculating recent activity */
|
||||
archiveTimestamp?: number;
|
||||
/** When a thread is locked, only users with `MANAGE_THREADS` can unarchive it */
|
||||
locked?: boolean;
|
||||
/** whether non-moderators can add other non-moderators to a thread; only available on private threads */
|
||||
invitable?: boolean;
|
||||
/** The time the current user last joined the thread */
|
||||
threadJoinTimestamp?: number;
|
||||
/** Default duration for newly created threads, in minutes, to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080 */
|
||||
defaultAutoArchiveDuration?: number;
|
||||
/** Whether or not the bot is part of this channel thread. */
|
||||
botIsMember: boolean;
|
||||
/** computed permissions for the invoking user in the channel, including overwrites, only included when part of the resolved data received on a slash command interaction */
|
||||
permissions?: bigint;
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ import { MessageActivityTypes } from "../types/messages/messageActivityTypes.ts"
|
||||
import { InteractionTypes } from "../types/interactions/interactionTypes.ts";
|
||||
import { DiscordenoComponent } from "./component.ts";
|
||||
import { Application } from "../types/applications/application.ts";
|
||||
import { DiscordenoThread } from "./thread.ts";
|
||||
import { DiscordenoChannel } from "./channel.ts";
|
||||
|
||||
export function transformMessage(bot: Bot, payload: SnakeCasedPropertiesDeep<Message>): DiscordenoMessage {
|
||||
const guildId = payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined;
|
||||
@@ -53,7 +53,7 @@ export function transformMessage(bot: Bot, payload: SnakeCasedPropertiesDeep<Mes
|
||||
user: bot.transformers.user(bot, payload.interaction.user),
|
||||
}
|
||||
: undefined,
|
||||
thread: payload.thread ? bot.transformers.thread(bot, payload.thread) : undefined,
|
||||
thread: payload.thread ? bot.transformers.channel(bot, { channel: payload.thread, guildId }) : undefined,
|
||||
components: payload.components?.map((component) => bot.transformers.component(bot, component)),
|
||||
stickerItems: payload.sticker_items?.map((sticker) => ({
|
||||
id: bot.transformers.snowflake(sticker.id),
|
||||
@@ -195,7 +195,7 @@ export interface DiscordenoMessage {
|
||||
user: DiscordenoUser;
|
||||
};
|
||||
/** The thread that was started from this message, includes thread member object */
|
||||
thread?: DiscordenoThread;
|
||||
thread?: DiscordenoChannel;
|
||||
/** The components related to this message */
|
||||
components?: DiscordenoComponent[];
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
import { Bot } from "../bot.ts";
|
||||
import { Channel } from "../types/channels/channel.ts";
|
||||
import { ChannelTypes } from "../types/channels/channelTypes.ts";
|
||||
import { SnakeCasedPropertiesDeep } from "../types/util.ts";
|
||||
|
||||
export function transformThread(bot: Bot, channel: SnakeCasedPropertiesDeep<Channel>): DiscordenoThread {
|
||||
if (
|
||||
channel.type !== ChannelTypes.GuildNewsThread &&
|
||||
channel.type !== ChannelTypes.GuildPublicThread &&
|
||||
channel.type !== ChannelTypes.GuildPrivateThread
|
||||
)
|
||||
throw new Error("Cannot convert non-thread channel to a thread.");
|
||||
|
||||
return {
|
||||
name: channel.name || "",
|
||||
id: bot.transformers.snowflake(channel.id),
|
||||
type: channel.type,
|
||||
parentId: bot.transformers.snowflake(channel.parent_id!),
|
||||
memberCount: channel.member_count || 1,
|
||||
messageCount: channel.message_count || 1,
|
||||
archiveTimestamp: channel.thread_metadata?.archive_timestamp
|
||||
? Date.parse(channel.thread_metadata.archive_timestamp)
|
||||
: undefined,
|
||||
autoArchiveDuration: channel.thread_metadata?.auto_archive_duration || 0,
|
||||
ownerId: bot.transformers.snowflake(channel.owner_id!),
|
||||
botIsMember: Boolean(channel.member),
|
||||
archived: channel.thread_metadata?.archived,
|
||||
locked: channel.thread_metadata?.locked,
|
||||
};
|
||||
}
|
||||
|
||||
export interface DiscordenoThread {
|
||||
id: bigint;
|
||||
name: string;
|
||||
type: ChannelTypes.GuildNewsThread | ChannelTypes.GuildPublicThread | ChannelTypes.GuildPrivateThread;
|
||||
parentId: bigint;
|
||||
memberCount: number;
|
||||
messageCount: number;
|
||||
archiveTimestamp?: number;
|
||||
autoArchiveDuration: number;
|
||||
archived?: boolean;
|
||||
locked?: boolean;
|
||||
ownerId: bigint;
|
||||
botIsMember: boolean;
|
||||
}
|
||||
Reference in New Issue
Block a user