mirror of
https://github.com/discordeno/discordeno.git
synced 2026-09-17 16:57:22 +00:00
feat: application command transformer
This commit is contained in:
@@ -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<Transformers>) {
|
||||
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,
|
||||
|
||||
@@ -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<ApplicationCommand>(
|
||||
const result = await bot.rest.runMethod<ApplicationCommand>(
|
||||
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
|
||||
|
||||
@@ -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<ApplicationCommand>
|
||||
): 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;
|
||||
}
|
||||
@@ -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<ApplicationCommandOption>
|
||||
): 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;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user