diff --git a/src/bot.ts b/src/bot.ts index ea1d4697f..e89262411 100644 --- a/src/bot.ts +++ b/src/bot.ts @@ -86,6 +86,8 @@ import { calculateBits, calculatePermissions } from "./util/permissions.ts"; import { transformScheduledEvent } from "./transformers/scheduledEvent.ts"; import { DiscordenoScheduledEvent } from "./transformers/scheduledEvent.ts"; import { transformThreadMember } from "./transformers/threadMember.ts"; +import { transformApplicationCommandOption } from "./transformers/applicationCommandOption.ts"; +import { transformApplicationCommand } from "./transformers/applicationCommand.ts"; type CacheOptions = | { @@ -492,6 +494,8 @@ export interface Transformers { component: typeof transformComponent; webhook: typeof transformWebhook; auditlogEntry: typeof transformAuditlogEntry; + applicationCommand: typeof transformApplicationCommand; + applicationCommandOption: typeof transformApplicationCommandOption; applicationCommandPermission: typeof transformApplicationCommandPermission; scheduledEvent: typeof transformScheduledEvent; threadMember: typeof transformThreadMember; @@ -520,6 +524,8 @@ export function createTransformers(options: Partial) { snowflake: options.snowflake || snowflakeToBigint, webhook: options.webhook || transformWebhook, auditlogEntry: options.auditlogEntry || transformAuditlogEntry, + applicationCommand: options.applicationCommand || transformApplicationCommand, + applicationCommandOption: options.applicationCommandOption || transformApplicationCommandOption, applicationCommandPermission: options.applicationCommandPermission || transformApplicationCommandPermission, scheduledEvent: options.scheduledEvent || transformScheduledEvent, threadMember: options.threadMember || transformThreadMember, diff --git a/src/helpers/interactions/commands/createApplicationCommand.ts b/src/helpers/interactions/commands/createApplicationCommand.ts index 7697739ca..cdc163fe7 100644 --- a/src/helpers/interactions/commands/createApplicationCommand.ts +++ b/src/helpers/interactions/commands/createApplicationCommand.ts @@ -15,7 +15,7 @@ import { ApplicationCommandOption } from "../../../types/interactions/commands/a * Guild commands update **instantly**. We recommend you use guild commands for quick testing, and global commands when they're ready for public use. */ export async function createApplicationCommand(bot: Bot, options: CreateGlobalApplicationCommand, guildId?: bigint) { - return await bot.rest.runMethod( + const result = await bot.rest.runMethod( bot.rest, "post", guildId @@ -28,6 +28,8 @@ export async function createApplicationCommand(bot: Bot, options: CreateGlobalAp options: options.options ? makeOptionsForCommand(options.options) : undefined, } ); + + return bot.transformers.applicationCommand(bot, result); } // @ts-ignore TODO: see if we can make this not circular diff --git a/src/transformers/applicationCommand.ts b/src/transformers/applicationCommand.ts new file mode 100644 index 000000000..96c59b67a --- /dev/null +++ b/src/transformers/applicationCommand.ts @@ -0,0 +1,44 @@ +import { Bot } from "../bot.ts"; +import { ApplicationCommand } from "../types/interactions/commands/applicationCommand.ts"; +import { ApplicationCommandTypes } from "../types/interactions/commands/applicationCommandTypes.ts"; +import { SnakeCasedPropertiesDeep } from "../types/util.ts"; +import { DiscordenoApplicationCommandOption } from "./applicationCommandOption.ts"; + +export function transformApplicationCommand( + bot: Bot, + payload: SnakeCasedPropertiesDeep +): DiscordenoApplicationCommand { + return { + id: bot.transformers.snowflake(payload.id), + applicationId: bot.transformers.snowflake(payload.application_id), + guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined, + name: payload.name, + description: payload.description, + defaultPermission: payload.default_permission ?? false, + type: payload.type, + version: payload.version, + + options: payload.options?.map(option => bot.transformers.applicationCommandOption(bot, option)) + }; +} + +export interface DiscordenoApplicationCommand { + /** Unique id of the command */ + id: bigint; + /** Unique id of the parent application */ + applicationId: bigint; + /** Guild id of the command, if not global */ + guildId?: bigint; + /** 1-32 character name matching */ + name: string; + /** 1-100 character description */ + description?: string; + /** The parameters for the command */ + options?: DiscordenoApplicationCommandOption[]; + /** Whether the command is enbaled by default when the app is added to a guild */ + defaultPermission?: boolean; + /** The type of command. By default this is a slash command(ChatInput). */ + type?: ApplicationCommandTypes; + /** Autoincrementing version identifier updated during substantial record changes */ + version: string; +} diff --git a/src/transformers/applicationCommandOption.ts b/src/transformers/applicationCommandOption.ts new file mode 100644 index 000000000..f32072afd --- /dev/null +++ b/src/transformers/applicationCommandOption.ts @@ -0,0 +1,48 @@ +import { Bot } from "../bot.ts"; +import { ChannelTypes } from "../types/channels/channelTypes.ts"; +import { ApplicationCommandOption } from "../types/interactions/commands/applicationCommandOption.ts"; +import { ApplicationCommandOptionChoice } from "../types/interactions/commands/applicationCommandOptionChoice.ts"; +import { ApplicationCommandOptionTypes } from "../types/interactions/commands/applicationCommandOptionTypes.ts"; +import { SnakeCasedPropertiesDeep } from "../types/util.ts"; + +export function transformApplicationCommandOption( + bot: Bot, + payload: SnakeCasedPropertiesDeep +): DiscordenoApplicationCommandOption { + return { + type: payload.type, + name: payload.name, + description: payload.description, + required: payload.required ?? false, + choices: payload.choices, + autocomplete: payload.autocomplete, + channelTypes: payload.channel_types, + minValue: payload.min_value, + maxValue: payload.max_value, + + options: payload.options?.map((option) => bot.transformers.applicationCommandOption(bot, option)), + }; +} + +export interface DiscordenoApplicationCommandOption { + /** Value of Application Command Option Type */ + type: ApplicationCommandOptionTypes; + /** 1-32 character name matching lowercase `^[\w-]{1,32}$` */ + name: string; + /** 1-100 character description */ + description: string; + /** If the parameter is required or optional--default `false` */ + required?: boolean; + /** Choices for `string` and `int` types for the user to pick from */ + choices?: ApplicationCommandOptionChoice[]; + /** If the option is a subcommand or subcommand group type, this nested options will be the parameters */ + options?: ApplicationCommandOption[]; + /** Whether this option should make autocomplete interactions. */ + autocomplete?: boolean; + /** If the option is a channel type, the channels shown will be restricted to these types */ + channelTypes?: ChannelTypes[]; + /** Minimum number desired. */ + minValue?: number; + /** Maximum number desired. */ + maxValue?: number; +} diff --git a/src/transformers/channel.ts b/src/transformers/channel.ts index a74edcb88..3c566c43d 100644 --- a/src/transformers/channel.ts +++ b/src/transformers/channel.ts @@ -135,7 +135,7 @@ export interface DiscordenoChannel { guildId: bigint; /** The id of the last message sent in this channel (may not point to an existing or valid message) */ lastMessageId?: bigint; - /** id of the DM creator */ + /** id of the DM creator or thread */ ownerId?: bigint; /** Application id of the group DM creator if it is bot-created */ applicationId?: bigint; diff --git a/src/transformers/mod.ts b/src/transformers/mod.ts index fb2e55756..9ea7fecb0 100644 --- a/src/transformers/mod.ts +++ b/src/transformers/mod.ts @@ -1,5 +1,7 @@ export * from "./activity.ts"; export * from "./application.ts"; +export * from "./applicationCommand.ts"; +export * from "./applicationCommandOption.ts"; export * from "./applicationCommandPermission.ts"; export * from "./attachment.ts"; export * from "./auditlogEntry.ts"; @@ -15,6 +17,8 @@ export * from "./member.ts"; export * from "./message.ts"; export * from "./presence.ts"; export * from "./role.ts"; +export * from "./scheduledEvent.ts"; export * from "./team.ts"; +export * from "./threadMember.ts"; export * from "./voiceState.ts"; export * from "./webhook.ts";