thenorthsolution / Reciple

⚡Discord.js framework that just works
https://reciple.js.org
GNU General Public License v3.0
12 stars 1 forks source link

Typescript Decorators #61

Closed catplvsplus closed 3 months ago

catplvsplus commented 3 months ago

Added Decorators

Class Decorators

Method Decorators

Usage

import { setClientEvent, setContextMenuCommand, setMessageCommand, setRecipleModule, setRecipleModuleLoad, setRecipleModuleStart, setRecipleModuleUnload, setSlashCommand } from '@reciple/decorators';
import { AnyCommandExecuteData, CommandType, RecipleModuleData } from "reciple";
import { ApplicationCommandType, type Message } from 'discord.js';

@setRecipleModule()
export class ExampleModule implements RecipleModuleData {
    /**
     * Executed when module is started (Bot is not logged in).
     */
    @setRecipleModuleStart()
    async onStart(): Promise<boolean> {
        return true;
    }

    /**
     * Executes when the module is loaded (Bot is logged in).
     */
    @setRecipleModuleLoad()
    async onLoad(): Promise<void> {}

    /**
     * Executes when the module is unloaded (Bot is pre log out).
     */
    @setRecipleModuleUnload()
    async onUnload(): Promise<void> {}

    /**
     * Sets the commands
     */
    @setContextMenuCommand({ name: 'ping', type: ApplicationCommandType.Message })
    @setMessageCommand({ name: 'ping', description: 'Replies with pong!' })
    @setSlashCommand({ name: 'ping', description: 'Replies with pong!' })
    async handleCommandExecute(data: AnyCommandExecuteData): Promise<void> {
        switch (data.type) {
            case CommandType.ContextMenuCommand:
            case CommandType.SlashCommand:
                await data.interaction.reply('Pong!');
                return;
            case CommandType.MessageCommand:
                await data.message.reply('Pong!');
                return;
        }
    }

    @setClientEvent('messageCreate')
    async handleMessageEvent(message: Message): Promise<void> {
        if (!reciple.isReady() || (!message.content.includes(reciple.user.id) && !message.content.includes(reciple.user.displayName))) return;

        await message.react('👀');
    }
}

export default new ExampleModule();