From 75ff4ec2aa8ce4f5dde8ce760f5558503e59528b Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Fri, 5 Nov 2021 15:17:08 +0000 Subject: [PATCH 01/14] change: prettier code --- src/bot.ts | 2 +- src/rest/simplify_url.ts | 2 +- tests/mod.ts | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 07d00846a..a1dc30d46 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -214,7 +214,7 @@ export function createRestManager(options: CreateRestManagerOptions) { const version = options.version || "9"; if (options.customUrl) { - baseEndpoints.BASE_URL = `${options.customUrl}/v${version}` + baseEndpoints.BASE_URL = `${options.customUrl}/v${version}`; } return { diff --git a/src/rest/simplify_url.ts b/src/rest/simplify_url.ts index 4e3078f40..aee44d102 100644 --- a/src/rest/simplify_url.ts +++ b/src/rest/simplify_url.ts @@ -9,7 +9,7 @@ export function simplifyUrl(url: string, method: string) { .replace(/\/([a-z-]+)\/(?:[0-9]{17,19})/g, function (match, p) { return ["channels", "guilds"].includes(p) ? match : `/${p}/skillzPrefersID`; }) - .replace(/\/reactions\/[^/]+/g, "/reactions/skillzPrefersID") + .replace(/\/reactions\/[^/]+/g, "/reactions/skillzPrefersID"); // GENERAL /reactions and /reactions/emoji/@me share the buckets if (route.includes("/reactions")) { diff --git a/tests/mod.ts b/tests/mod.ts index ad6f99956..49d5f9288 100644 --- a/tests/mod.ts +++ b/tests/mod.ts @@ -575,18 +575,18 @@ Deno.test({ name: "[channel] delete a channel overwrite", async fn() { await deleteChannelOverwriteTests(bot, guild.id, t); - } + }, }), t.step({ name: "[channel] edit a channel w/o a reason", async fn() { await editChannelTests(bot, guild.id, {}, t); - } + }, }), t.step({ name: "[channel] edit a channel w/ a reason", async fn() { - await editChannelTests(bot, guild.id, { reason: "Blame wolf"}, t); + await editChannelTests(bot, guild.id, { reason: "Blame wolf" }, t); }, }), ]); From 42e2f825b9f400ffefa3a420d18f51185bf618c5 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Fri, 5 Nov 2021 17:23:35 +0000 Subject: [PATCH 02/14] change: prettier code --- src/bot.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/bot.ts b/src/bot.ts index 65478819b..76db807a6 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -395,7 +395,10 @@ export function createGatewayManager( $os: options.$os ?? "linux", $browser: options.$browser ?? "Discordeno", $device: options.$device ?? "Discordeno", - intents: (Array.isArray(options.intents) ? options.intents.reduce((bits, next) => (bits |= DiscordGatewayIntents[next]), 0) : options.intents) ?? 0, + intents: + (Array.isArray(options.intents) + ? options.intents.reduce((bits, next) => (bits |= DiscordGatewayIntents[next]), 0) + : options.intents) ?? 0, shard: options.shard ?? [0, options.shardsRecommended ?? 1], urlWSS: options.urlWSS ?? "wss://gateway.discord.gg/?v=9&encoding=json", shardsRecommended: options.shardsRecommended ?? 1, From 66be78d0e92958a8a11f7b63c35629911d92e459 Mon Sep 17 00:00:00 2001 From: Nicholas Sylke Date: Fri, 5 Nov 2021 20:17:05 -0500 Subject: [PATCH 03/14] return customUrl on rest --- src/bot.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bot.ts b/src/bot.ts index e67f4a879..51283a5e9 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -222,6 +222,7 @@ export function createRestManager(options: CreateRestManagerOptions) { token: `${options.token.startsWith("Bot ") ? "" : "Bot "}${options.token}`, maxRetryCount: options.maxRetryCount || 10, secretKey: options.secretKey || "discordeno_best_lib_ever", + customUrl: options.customUrl || "", pathQueues: new Map< string, { From f5ba30098ac80ad0aa7d6f6186a169a324d9eb33 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Sun, 7 Nov 2021 00:02:35 +0000 Subject: [PATCH 04/14] change: prettier code --- src/helpers/channels/clone_channel.ts | 2 -- src/transformers/auditlogEntry.ts | 4 ++-- src/transformers/channel.ts | 6 +++--- tests/helpers/channels/categoryChannels.ts | 8 ++++++-- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/helpers/channels/clone_channel.ts b/src/helpers/channels/clone_channel.ts index 27f770a76..2e2da197e 100644 --- a/src/helpers/channels/clone_channel.ts +++ b/src/helpers/channels/clone_channel.ts @@ -29,8 +29,6 @@ export async function cloneChannel(bot: Bot, channelId: bigint, reason?: string) }), }; - - //Create the channel (also handles permissions) return await bot.helpers.createChannel(channelToClone.guildId!, createChannelOptions, reason); } diff --git a/src/transformers/auditlogEntry.ts b/src/transformers/auditlogEntry.ts index f2dab6df5..8530b3419 100644 --- a/src/transformers/auditlogEntry.ts +++ b/src/transformers/auditlogEntry.ts @@ -21,11 +21,11 @@ export function transformAuditlogEntry( key: change.key, new: { id: bot.transformers.snowflake(change.new_value.id!), - name: change.new_value.name + name: change.new_value.name, }, old: { id: bot.transformers.snowflake(change.old_value.id!), - name: change.old_value.name + name: change.old_value.name, }, }; case "discovery_splash_hash": diff --git a/src/transformers/channel.ts b/src/transformers/channel.ts index 812731a77..1696487b5 100644 --- a/src/transformers/channel.ts +++ b/src/transformers/channel.ts @@ -26,9 +26,9 @@ function unpack64(v: bigint, shift: number) { return (v >> BigInt(shift * 64)) & Mask; } function pack64(v: string | number, shift: number) { - const b = BigInt(v); - if(b < 0 || b > Mask) throw new Error("should have been a 64 bit unsigned integer: " + v); - return b << BigInt(shift * 64) + const b = BigInt(v); + if (b < 0 || b > Mask) throw new Error("should have been a 64 bit unsigned integer: " + v); + return b << BigInt(shift * 64); } export function separate(v: bigint) { return [Number(unpack64(v, 3)), unpack64(v, 2), unpack64(v, 0), unpack64(v, 1)] as [number, bigint, bigint, bigint]; diff --git a/tests/helpers/channels/categoryChannels.ts b/tests/helpers/channels/categoryChannels.ts index 9e80cd3d7..28db31648 100644 --- a/tests/helpers/channels/categoryChannels.ts +++ b/tests/helpers/channels/categoryChannels.ts @@ -35,8 +35,12 @@ export async function categoryChildrenTest(bot: Bot, guildId: bigint, t: Deno.Te const ids = await bot.helpers.categoryChildren(category.id); if (ids.size !== channels.length || !channels.every((c) => ids.has(c.id))) { - console.log('cccc 1', ids.size, channels.length); - console.log('cccc 2', channels.every((c) => ids.has(c.id)), ids); + console.log("cccc 1", ids.size, channels.length); + console.log( + "cccc 2", + channels.every((c) => ids.has(c.id)), + ids + ); throw new Error("The category channel ids did not match with the category channels."); } } From 135293993a8e4c1ed43183136f04f413a9b363d8 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Mon, 8 Nov 2021 20:34:04 +0000 Subject: [PATCH 05/14] change: prettier code --- src/bot.ts | 4 ++-- src/types/codes/json_error_codes.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 1f23efdde..1b9820fae 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -849,7 +849,7 @@ export interface Transformers { thread: typeof transformThread; webhook: typeof transformWebhook; auditlogEntry: typeof transformAuditlogEntry; - applicationCommandPermission: typeof transformApplicationCommandPermission + applicationCommandPermission: typeof transformApplicationCommandPermission; } export function createTransformers(options: Partial) { @@ -876,7 +876,7 @@ export function createTransformers(options: Partial) { snowflake: options.snowflake || snowflakeToBigint, webhook: options.webhook || transformWebhook, auditlogEntry: options.auditlogEntry || transformAuditlogEntry, - applicationCommandPermission: transformApplicationCommandPermission + applicationCommandPermission: transformApplicationCommandPermission, }; } diff --git a/src/types/codes/json_error_codes.ts b/src/types/codes/json_error_codes.ts index e031f4293..c39ffbf89 100644 --- a/src/types/codes/json_error_codes.ts +++ b/src/types/codes/json_error_codes.ts @@ -33,7 +33,7 @@ export enum DiscordJsonErrorCodes { UnknownInteraction = 10062, UnknownApplicationCommand = 10063, UnknownApplicationCommandPermissions = 10066, - UnknownStageInstance, + UnknownStageInstance, UnknownGuildMemberVerificationForm, BotsCannotUseThisEndpoint = 20001, OnlyBotsCanUseThisEndpoint, From d97c924201127a1f228fe64fa61b964495e5feb6 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Tue, 9 Nov 2021 02:28:35 +0000 Subject: [PATCH 06/14] change: prettier code --- src/helpers/channels/threads/get_active_threads.ts | 2 +- .../channels/threads/startThreadWithMessage.ts | 7 ++++++- src/types/audit_log/audit_log_change.ts | 12 +++++++++++- src/types/channels/threads/start_thread.ts | 7 +++++-- src/types/channels/threads/thread_members_update.ts | 1 - 5 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/helpers/channels/threads/get_active_threads.ts b/src/helpers/channels/threads/get_active_threads.ts index a484a6b1e..ca6335099 100644 --- a/src/helpers/channels/threads/get_active_threads.ts +++ b/src/helpers/channels/threads/get_active_threads.ts @@ -4,7 +4,7 @@ import { Collection } from "../../../util/collection.ts"; // import { channelToThread } from "../../../util/transformers/channel_to_thread.ts"; /** Returns all active threads in the guild, including public and private threads. Threads are ordered by their `id`, in descending order. */ -export async function getActiveThreads(bot: Bot, guildId: bigint) { +export async function getActiveThreads(bot: Bot, guildId: bigint) { // const result = (await bot.rest.runMethod( // bot.rest, // "get", diff --git a/src/helpers/channels/threads/startThreadWithMessage.ts b/src/helpers/channels/threads/startThreadWithMessage.ts index 73bc0a1c7..7acba11e5 100644 --- a/src/helpers/channels/threads/startThreadWithMessage.ts +++ b/src/helpers/channels/threads/startThreadWithMessage.ts @@ -3,7 +3,12 @@ import type { StartThreadWithMessage } from "../../../types/channels/threads/sta import type { Bot } from "../../../bot.ts"; /** Creates a new public thread from an existing message. Returns a thread channel. */ -export async function startThreadWithMessage(bot: Bot, channelId: bigint, messageId: bigint, options: StartThreadWithMessage) { +export async function startThreadWithMessage( + bot: Bot, + channelId: bigint, + messageId: bigint, + options: StartThreadWithMessage +) { // const channel = await bot.cache.channels.get(channelId); // if (channel) { // if (!channel.isGuildTextBasedChannel) { diff --git a/src/types/audit_log/audit_log_change.ts b/src/types/audit_log/audit_log_change.ts index 176a986a3..c5f321410 100644 --- a/src/types/audit_log/audit_log_change.ts +++ b/src/types/audit_log/audit_log_change.ts @@ -66,7 +66,17 @@ export type AuditLogChange = | { newValue: boolean; oldValue: boolean; - key: "widget_enabled" | "nsfw" | "hoist" | "mentionable" | "temporary" | "deaf" | "mute" | "enable_emoticons" | "archived" | "locked"; + key: + | "widget_enabled" + | "nsfw" + | "hoist" + | "mentionable" + | "temporary" + | "deaf" + | "mute" + | "enable_emoticons" + | "archived" + | "locked"; } | { newValue: Overwrite[]; diff --git a/src/types/channels/threads/start_thread.ts b/src/types/channels/threads/start_thread.ts index e68e66280..807ea7b51 100644 --- a/src/types/channels/threads/start_thread.ts +++ b/src/types/channels/threads/start_thread.ts @@ -17,7 +17,10 @@ export interface StartThreadWithMessage extends StartThreadBase { export interface StartThreadWithoutMessage extends StartThreadBase { /** the type of thread to create */ - type: DiscordChannelTypes.GuildNewsThread | DiscordChannelTypes.GuildPublicThread | DiscordChannelTypes.GuildPrivateThread; + type: + | DiscordChannelTypes.GuildNewsThread + | DiscordChannelTypes.GuildPublicThread + | DiscordChannelTypes.GuildPrivateThread; /** whether non-moderators can add other non-moderators to a thread; only available when creating a private thread */ invitable?: boolean; -} \ No newline at end of file +} diff --git a/src/types/channels/threads/thread_members_update.ts b/src/types/channels/threads/thread_members_update.ts index 1a01fd2cc..eafe9c275 100644 --- a/src/types/channels/threads/thread_members_update.ts +++ b/src/types/channels/threads/thread_members_update.ts @@ -29,4 +29,3 @@ export interface ThreadMembersUpdateModified extends ThreadMembersUpdateBase { // TODO: verify this // \* In this gateway event, the thread member objects will also include the [guild member](#DOCS_RESOURCES_GUILD/guild-member-object) and [presence](#DOCS_TOPICS_GATEWAY/presence) objects for each added thread member. } - From 6efb2e8df377e30764c0e2c3b26aff636db02657 Mon Sep 17 00:00:00 2001 From: TriForMine Date: Tue, 9 Nov 2021 16:03:32 +0100 Subject: [PATCH 07/14] Update mod.ts --- src/helpers/mod.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index 0b70e3f2d..d5372314e 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -149,8 +149,8 @@ import { joinThread } from "./channels/threads/join_thread.ts"; import { leaveThread } from "./channels/threads/leave_thread.ts"; import { lockThread } from "./channels/threads/lock_thread.ts"; import { removeThreadMember } from "./channels/threads/remove_thread_member.ts"; -import { startPrivateThread } from "./channels/threads/start_private_thread.ts"; -import { startThread } from "./channels/threads/start_thread.ts"; +import { startThreadWithMessage } from "./channels/threads/startThreadWithMessage.ts"; +import { startThreadWithoutMessage } from "./channels/threads/startThreadWithoutMessage.ts"; import { unarchiveThread } from "./channels/threads/unarchive_thread.ts"; import { unlockThread } from "./channels/threads/unlock_thread.ts"; import { cloneChannel } from "./channels/clone_channel.ts"; From a0e51d575e4d534510951323d19001d3e6fd516e Mon Sep 17 00:00:00 2001 From: TriForMine Date: Tue, 9 Nov 2021 16:05:09 +0100 Subject: [PATCH 08/14] Update mod.ts --- src/helpers/mod.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/mod.ts b/src/helpers/mod.ts index d5372314e..dec183c71 100644 --- a/src/helpers/mod.ts +++ b/src/helpers/mod.ts @@ -309,8 +309,8 @@ export { leaveThread, lockThread, removeThreadMember, - startPrivateThread, - startThread, + startThreadWithMessage, + startThreadWithoutMessage, unarchiveThread, unlockThread, suppressEmbeds, From 1c64bf50acd2457b1e57baaf5c62a640af8e2daa Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Tue, 9 Nov 2021 17:57:49 +0000 Subject: [PATCH 09/14] test fix cache for tri --- src/bot.ts | 21 ++++++++++----- src/cache.ts | 76 +++++++++++++++++++++++++++------------------------- 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index f538e0da1..44037bd4a 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -127,7 +127,7 @@ type CacheOptions = export function createBot( options: CreateBotOptions ): Bot { - return { + const bot = { id: options.botId, applicationId: options.applicationId || options.botId, token: `Bot ${options.token}`, @@ -138,9 +138,12 @@ export function createBot( activeGuildIds: new Set(), constants: createBotConstants(), handlers: createBotGatewayHandlers({}), - // @ts-ignore b quiet - cache: createCache(options?.cache?.isAsync ?? false, options?.cache?.customTableCreator), - } as unknown as Bot; + } + + // @ts-ignore itoh cache types plz + bot.cache = createCache(bot as Bot, options.cache); + + return bot as unknown as Bot; } export function createEventHandlers(events: Partial): EventHandlers { @@ -260,12 +263,18 @@ export function createRestManager(options: CreateRestManagerOptions) { }; } -export async function startBot(bot: Bot) { - // SETUP +export function setupBot(bot: Bot) { bot.utils = createUtils({}); bot.transformers = createTransformers(bot.transformers || {}); bot.helpers = createHelpers(bot); + return bot; +} + +export async function startBot(bot: Bot) { + // SETUP BOT + bot = setupBot(bot); + // START REST bot.rest = createRestManager({ token: bot.token, debug: bot.events.debug }); if (!bot.botGatewayData) bot.botGatewayData = await bot.helpers.getGatewayBot(); diff --git a/src/cache.ts b/src/cache.ts index 887292fc7..e10b234b1 100644 --- a/src/cache.ts +++ b/src/cache.ts @@ -48,36 +48,40 @@ function channelSweeper(bot: Bot, channel: DiscordenoChannel, key: bigint } export function createCache( - isAsync: true, - // deno-lint-ignore no-explicit-any - tableCreator: (tableName: TableNames) => AsyncCacheHandler + bot: Bot, + options: { + isAsync: true; + tableCreator: (bot: Bot, tableName: TableNames) => AsyncCacheHandler; + } ): AsyncCache; export function createCache( - isAsync: false, - // deno-lint-ignore no-explicit-any - tableCreator?: (tableName: TableNames) => CacheHandler + bot: Bot, + options: { + isAsync: false; + tableCreator?: (bot: Bot, tableName: TableNames) => CacheHandler; + } ): Cache; export function createCache( - isAsync: boolean, - tableCreator?: ( - tableName: TableNames - // deno-lint-ignore no-explicit-any - ) => CacheHandler | AsyncCacheHandler + bot: Bot, + options: { + isAsync: boolean; + tableCreator?: (bot: Bot, tableName: TableNames) => CacheHandler | AsyncCacheHandler; + } ): Omit | Omit { - if (isAsync) { - if (!tableCreator) { + if (options.isAsync) { + if (!options.tableCreator) { throw new Error("Async cache requires a tableCreator to be passed."); } const cache = { - guilds: tableCreator("guilds"), - users: tableCreator("users"), - members: tableCreator("members"), - channels: tableCreator("channels"), - messages: tableCreator("messages"), - presences: tableCreator("presences"), - // threads: tableCreator("threads"), - unavailableGuilds: tableCreator("unavailableGuilds"), + guilds: options.tableCreator(bot, "guilds"), + users: options.tableCreator(bot, "users"), + members: options.tableCreator(bot, "members"), + channels: options.tableCreator(bot, "channels"), + messages: options.tableCreator(bot, "messages"), + presences: options.tableCreator(bot, "presences"), + // threads: options.tableCreator(bot, "threads"), + unavailableGuilds: options.tableCreator(bot, "unavailableGuilds"), executedSlashCommands: new Set(), fetchAllMembersProcessingRequests: new Map(), } as AsyncCache; @@ -88,17 +92,17 @@ export function createCache( return cache; } - if (!tableCreator) tableCreator = createTable; + if (!options.tableCreator) options.tableCreator = createTable; const cache = { - guilds: tableCreator("guilds"), - users: tableCreator("users"), - members: tableCreator("members"), - channels: tableCreator("channels"), - messages: tableCreator("messages"), - presences: tableCreator("presences"), - // threads: tableCreator("threads"), - unavailableGuilds: tableCreator("unavailableGuilds"), + guilds: options.tableCreator(bot, "guilds"), + users: options.tableCreator(bot, "users"), + members: options.tableCreator(bot, "members"), + channels: options.tableCreator(bot, "channels"), + messages: options.tableCreator(bot, "messages"), + presences: options.tableCreator(bot, "presences"), + // threads: options.tableCreator(bot, "threads"), + unavailableGuilds: options.tableCreator(bot, "unavailableGuilds"), executedSlashCommands: new Set(), fetchAllMembersProcessingRequests: new Map(), } as Cache; @@ -149,18 +153,18 @@ export interface AsyncCache { execute: CacheExecutor; } -function createTable(_table: TableNames): CacheHandler { +function createTable(bot: Bot, _table: TableNames): CacheHandler { const table = new Collection(); // @ts-ignore TODO: fix type error itoh pwease - if (_table === "guilds") table.startSweeper({ filter: guildSweeper, interval: 3660000 }); + if (_table === "guilds") table.startSweeper({ filter: guildSweeper, interval: 3660000, bot }); // @ts-ignore TODO: fix type error itoh pwease - if (_table === "channels") table.startSweeper({ filter: channelSweeper, interval: 3660000 }); + if (_table === "channels") table.startSweeper({ filter: channelSweeper, interval: 3660000, bot }); // @ts-ignore TODO: fix type error itoh pwease - if (_table === "messages") table.startSweeper({ filter: messageSweeper, interval: 300000 }); + if (_table === "messages") table.startSweeper({ filter: messageSweeper, interval: 300000, bot }); // @ts-ignore TODO: fix type error itoh pwease - if (_table === "members") table.startSweeper({ filter: memberSweeper, interval: 300000 }); - if (_table === "presences") table.startSweeper({ filter: () => true, interval: 300000 }); + if (_table === "members") table.startSweeper({ filter: memberSweeper, interval: 300000, bot }); + if (_table === "presences") table.startSweeper({ filter: () => true, interval: 300000, bot }); return { clear: () => table.clear(), From cfd0406ee2a33e4027eb141358c7127632704820 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Tue, 9 Nov 2021 17:59:49 +0000 Subject: [PATCH 10/14] change: prettier code --- src/bot.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index 4545ab000..e1303a44e 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -138,7 +138,7 @@ export function createBot( activeGuildIds: new Set(), constants: createBotConstants(), handlers: createBotGatewayHandlers({}), - } + }; // @ts-ignore itoh cache types plz bot.cache = createCache(bot as Bot, options.cache); @@ -275,7 +275,7 @@ export function setupBot(bot: Bot) { export async function startBot(bot: Bot) { // SETUP BOT bot = setupBot(bot); - + // START REST bot.rest = createRestManager({ token: bot.token, debug: bot.events.debug }); if (!bot.botGatewayData) bot.botGatewayData = await bot.helpers.getGatewayBot(); From 0055882729052c46f9dad289ab08e3ebccbac80d Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Tue, 9 Nov 2021 18:09:23 +0000 Subject: [PATCH 11/14] fix send message issue --- src/helpers/messages/send_message.ts | 10 +++++----- src/types/messages/create_message.ts | 21 +++++++++++++++++++-- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index 66d799a75..39b25f0ec 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -132,8 +132,8 @@ export async function sendMessage(bot: Bot, channelId: bigint, content: string | allowed_mentions: content.allowedMentions ? { parse: content.allowedMentions?.parse, - roles: content.allowedMentions?.roles, - users: content.allowedMentions?.users, + roles: content.allowedMentions?.roles?.map(id => id.toString()), + users: content.allowedMentions?.users?.map(id => id.toString()), replied_user: content.allowedMentions?.repliedUser, } : undefined, @@ -183,9 +183,9 @@ export async function sendMessage(bot: Bot, channelId: bigint, content: string | ...(content.messageReference?.messageId ? { message_reference: { - message_id: content.messageReference.messageId, - channel_id: content.messageReference.channelId, - guild_id: content.messageReference.guildId, + message_id: content.messageReference.messageId.toString(), + channel_id: content.messageReference.channelId?.toString(), + guild_id: content.messageReference.guildId?.toString(), fail_if_not_exists: content.messageReference.failIfNotExists === true, }, } diff --git a/src/types/messages/create_message.ts b/src/types/messages/create_message.ts index 73eaded32..b33a325b7 100644 --- a/src/types/messages/create_message.ts +++ b/src/types/messages/create_message.ts @@ -13,9 +13,26 @@ export interface CreateMessage { /** Embedded `rich` content (up to 6000 characters) */ embeds?: Embed[]; /** Allowed mentions for the message */ - allowedMentions?: AllowedMentions; + allowedMentions?: Omit & { + /** Array of role_ids to mention (Max size of 100) */ + roles?: bigint[]; + /** Array of user_ids to mention (Max size of 100) */ + users?: bigint[]; + }; /** Include to make your message a reply */ - messageReference?: MessageReference; + messageReference?: { + /** id of the originating message */ + messageId?: bigint; + /** + * id of the originating message's channel + * Note: `channel_id` is optional when creating a reply, but will always be present when receiving an event/response that includes this data model. + */ + channelId?: bigint; + /** id of the originating message's guild */ + guildId?: bigint; + /** When sending, whether to error if the referenced message doesn't exist instead of sending as a normal (non-reply) message, default true */ + failIfNotExists: boolean; + }; /** The contents of the file being sent */ file?: FileContent | FileContent[]; /** The components you would like to have sent in this message */ From 9cbd196bc95f0dff2b9eb0fc06f6543483e77ca6 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Tue, 9 Nov 2021 18:18:04 +0000 Subject: [PATCH 12/14] Merge branch 'fp-attempt-9001' of https://github.com/discordeno/discordeno into fp-attempt-9001 --- src/bot.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bot.ts b/src/bot.ts index e1303a44e..1e1aaccd1 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -652,8 +652,8 @@ export interface Helpers { leaveThread: typeof helpers.leaveThread; lockThread: typeof helpers.lockThread; removeThreadMember: typeof helpers.removeThreadMember; - startPrivateThread: typeof helpers.startPrivateThread; - startThread: typeof helpers.startThread; + startThreadWithoutMessage: typeof helpers.startThreadWithoutMessage; + startThreadWithMessage: typeof helpers.startThreadWithMessage; unarchiveThread: typeof helpers.unarchiveThread; unlockThread: typeof helpers.unlockThread; suppressEmbeds: typeof helpers.suppressEmbeds; @@ -827,8 +827,8 @@ export function createBaseHelpers(options: Partial) { leaveThread: options.leaveThread || helpers.leaveThread, lockThread: options.lockThread || helpers.lockThread, removeThreadMember: options.removeThreadMember || helpers.removeThreadMember, - startPrivateThread: options.startPrivateThread || helpers.startPrivateThread, - startThread: options.startThread || helpers.startThread, + startThreadWithoutMessage: options.startThreadWithoutMessage || helpers.startThreadWithoutMessage, + startThreadWithMessage: options.startThreadWithMessage || helpers.startThreadWithMessage, unarchiveThread: options.unarchiveThread || helpers.unarchiveThread, unlockThread: options.unlockThread || helpers.unlockThread, suppressEmbeds: options.suppressEmbeds || helpers.suppressEmbeds, From 16b0fa292acab91460caf853e97a7ad46276761d Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Tue, 9 Nov 2021 18:42:37 +0000 Subject: [PATCH 13/14] test edit message fix --- src/helpers/messages/edit_message.ts | 14 ++++++++++++-- src/types/messages/edit_message.ts | 9 +++++++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/helpers/messages/edit_message.ts b/src/helpers/messages/edit_message.ts index fbe11a469..b15c93708 100644 --- a/src/helpers/messages/edit_message.ts +++ b/src/helpers/messages/edit_message.ts @@ -88,10 +88,20 @@ export async function editMessage(bot: Bot, channelId: bigint, messageId: bigint })), allowed_mentions: { parse: content.allowedMentions?.parse, - roles: content.allowedMentions?.roles, - users: content.allowedMentions?.users, + roles: content.allowedMentions?.roles?.map((id) => id.toString()), + users: content.allowedMentions?.users?.map((id) => id.toString()), replied_user: content.allowedMentions?.repliedUser, }, + attachments: content.attachments?.map((attachment) => ({ + id: attachment.id.toString(), + filename: attachment.filename, + content_type: attachment.contentType, + size: attachment.size, + url: attachment.url, + proxy_url: attachment.proxyUrl, + height: attachment.height, + width: attachment.width, + })), file: content.file, components: content.components?.map((component) => ({ type: component.type, diff --git a/src/types/messages/edit_message.ts b/src/types/messages/edit_message.ts index ac76bf263..4c682013e 100644 --- a/src/types/messages/edit_message.ts +++ b/src/types/messages/edit_message.ts @@ -15,9 +15,14 @@ export interface EditMessage { /** The contents of the file being sent/edited */ file?: FileContent | FileContent[] | null; /** Allowed mentions for the message */ - allowedMentions?: AllowedMentions | null; + allowedMentions?: Omit & { + /** Array of role_ids to mention (Max size of 100) */ + roles?: bigint[]; + /** Array of user_ids to mention (Max size of 100) */ + users?: bigint[]; + } | null; /** Attached files to keep */ - attachments?: Attachment | null; + attachments?: Attachment[]; /** The components you would like to have sent in this message */ components?: MessageComponents; } From 29f215eafea8e054ce89aeb6be589a1f80a98d20 Mon Sep 17 00:00:00 2001 From: Skillz4Killz Date: Tue, 9 Nov 2021 18:43:44 +0000 Subject: [PATCH 14/14] change: prettier code --- src/helpers/messages/send_message.ts | 4 ++-- src/types/messages/create_message.ts | 22 +++++++++++----------- src/types/messages/edit_message.ts | 14 ++++++++------ 3 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/helpers/messages/send_message.ts b/src/helpers/messages/send_message.ts index 39b25f0ec..d17f1efe4 100644 --- a/src/helpers/messages/send_message.ts +++ b/src/helpers/messages/send_message.ts @@ -132,8 +132,8 @@ export async function sendMessage(bot: Bot, channelId: bigint, content: string | allowed_mentions: content.allowedMentions ? { parse: content.allowedMentions?.parse, - roles: content.allowedMentions?.roles?.map(id => id.toString()), - users: content.allowedMentions?.users?.map(id => id.toString()), + roles: content.allowedMentions?.roles?.map((id) => id.toString()), + users: content.allowedMentions?.users?.map((id) => id.toString()), replied_user: content.allowedMentions?.repliedUser, } : undefined, diff --git a/src/types/messages/create_message.ts b/src/types/messages/create_message.ts index b33a325b7..ae8f1a2a2 100644 --- a/src/types/messages/create_message.ts +++ b/src/types/messages/create_message.ts @@ -21,17 +21,17 @@ export interface CreateMessage { }; /** Include to make your message a reply */ messageReference?: { - /** id of the originating message */ - messageId?: bigint; - /** - * id of the originating message's channel - * Note: `channel_id` is optional when creating a reply, but will always be present when receiving an event/response that includes this data model. - */ - channelId?: bigint; - /** id of the originating message's guild */ - guildId?: bigint; - /** When sending, whether to error if the referenced message doesn't exist instead of sending as a normal (non-reply) message, default true */ - failIfNotExists: boolean; + /** id of the originating message */ + messageId?: bigint; + /** + * id of the originating message's channel + * Note: `channel_id` is optional when creating a reply, but will always be present when receiving an event/response that includes this data model. + */ + channelId?: bigint; + /** id of the originating message's guild */ + guildId?: bigint; + /** When sending, whether to error if the referenced message doesn't exist instead of sending as a normal (non-reply) message, default true */ + failIfNotExists: boolean; }; /** The contents of the file being sent */ file?: FileContent | FileContent[]; diff --git a/src/types/messages/edit_message.ts b/src/types/messages/edit_message.ts index 4c682013e..34e7f4b28 100644 --- a/src/types/messages/edit_message.ts +++ b/src/types/messages/edit_message.ts @@ -15,12 +15,14 @@ export interface EditMessage { /** The contents of the file being sent/edited */ file?: FileContent | FileContent[] | null; /** Allowed mentions for the message */ - allowedMentions?: Omit & { - /** Array of role_ids to mention (Max size of 100) */ - roles?: bigint[]; - /** Array of user_ids to mention (Max size of 100) */ - users?: bigint[]; - } | null; + allowedMentions?: + | (Omit & { + /** Array of role_ids to mention (Max size of 100) */ + roles?: bigint[]; + /** Array of user_ids to mention (Max size of 100) */ + users?: bigint[]; + }) + | null; /** Attached files to keep */ attachments?: Attachment[]; /** The components you would like to have sent in this message */