From f26b677c4ff8b381b26db474e7f5b1c906ec3fa4 Mon Sep 17 00:00:00 2001 From: Cat++ <69035887+NotGhex@users.noreply.github.com> Date: Sat, 13 Jul 2024 23:01:43 +0800 Subject: [PATCH] Add more jsdoc --- .../decorators/src/decorators/commands.ts | 10 +-- packages/decorators/src/decorators/events.ts | 78 +++++++++++++++++++ 2 files changed, 83 insertions(+), 5 deletions(-) diff --git a/packages/decorators/src/decorators/commands.ts b/packages/decorators/src/decorators/commands.ts index e2cf35e2..51db02c9 100644 --- a/packages/decorators/src/decorators/commands.ts +++ b/packages/decorators/src/decorators/commands.ts @@ -5,7 +5,7 @@ import type { RecipleModuleDecoratorMetadata } from '../types/structures.js'; /** * Sets a context menu command decorator. * - * ``` + * ```ts * @setRecipleModule() * class MyModule implements RecipleModuleData { * @setRecipleModuleStart() @@ -15,7 +15,7 @@ import type { RecipleModuleDecoratorMetadata } from '../types/structures.js'; * * @setContextMenuCommand({ name: 'Test', type: 'Message' }) * async handleContextMenuExecute(data: ContextMenuCommandExecuteData) { - * await data.interaction('Test'); + * await data.interaction.reply('Test'); * } * } * ``` @@ -55,7 +55,7 @@ export function setContextMenuCommand(data: /** * Sets a slash command decorator. * - * ``` + * ```ts * @setRecipleModule() * class MyModule implements RecipleModuleData { * @setRecipleModuleStart() @@ -94,7 +94,7 @@ export function setMessageCommand(data: * * @setSlashCommand({ name: 'Test', description: 'Test command' }) * async handleSlashCommandExecute(data: SlashCommandExecuteData) { - * await data.interaction('Test'); + * await data.interaction.reply('Test'); * } * } * ``` diff --git a/packages/decorators/src/decorators/events.ts b/packages/decorators/src/decorators/events.ts index 49b99e47..15c4ab3a 100644 --- a/packages/decorators/src/decorators/events.ts +++ b/packages/decorators/src/decorators/events.ts @@ -8,6 +8,32 @@ export interface RecipleModuleEventDecoratorMap { rest: RestEvents; } +/** + * Sets a client event + * + * ```ts + * @setRecipleModule() + * class MyModule implements RecipleModuleData { + * @setRecipleModuleStart() + * async onStart() { + * return true; + * } + * + * @setRecipleModuleLoad() + * async onLoad() {} + * + * @setRecipleModuleUnload() + * async onUnload() {} + * + * @setClientEvent('messageCreate') + * async handleMessageEvent(message: Message) { + * await message.reply('Test'); + * } + * } + * ``` + * @param event The event name + * @param once True if the event should only be triggered once + */ export function setClientEvent(event: E, once?: boolean): TypedMethodDecorator<(...args: A) => any>; export function setClientEvent(event: E, once?: boolean): TypedMethodDecorator<(...args: A) => any>; export function setClientEvent(event: E, once?: boolean): TypedMethodDecorator<(...args: A) => any> { @@ -21,6 +47,32 @@ export function setClientEvent(event: } } +/** + * Sets a websocket event + * + * ```ts + * @setRecipleModule() + * class MyModule implements RecipleModuleData { + * @setRecipleModuleStart() + * async onStart() { + * return true; + * } + * + * @setRecipleModuleLoad() + * async onLoad() {} + * + * @setRecipleModuleUnload() + * async onUnload() {} + * + * @setWebsocketEvent(GatewayDispatchEvents.MessageCreate) + * async handleWebsocketEvent(data: any) { + * console.log(data); + * } + * } + * ``` + * @param event The event name + * @param once True if the event should only be triggered once + */ export function setWebsocketEvent(event: E, once?: boolean): TypedMethodDecorator<(...args: A) => any>; export function setWebsocketEvent(event: E, once?: boolean): TypedMethodDecorator<(...args: A) => any>; export function setWebsocketEvent(event: E, once?: boolean): TypedMethodDecorator<(...args: A) => any> { @@ -34,6 +86,32 @@ export function setWebsocketEvent(even } } +/** + * Sets a REST event + * + * ```ts + * @setRecipleModule() + * class MyModule implements RecipleModuleData { + * @setRecipleModuleStart() + * async onStart() { + * return true; + * } + * + * @setRecipleModuleLoad() + * async onLoad() {} + * + * @setRecipleModuleUnload() + * async onUnload() {} + * + * @setRESTEvent('restDebug') + * async handleRESTEvent(info: string) { + * console.log(info); + * } + * } + * ``` + * @param event The event name + * @param once True if the event should only be triggered once + */ export function setRESTEvent(event: E, once?: boolean): TypedMethodDecorator<(...args: A) => any>; export function setRESTEvent(event: E, once?: boolean): TypedMethodDecorator<(...args: A) => any>; export function setRESTEvent(event: E, once?: boolean): TypedMethodDecorator<(...args: A) => any> {