Nocturnal Programmer's Machine

    @scorpion-kitty/core
    TypeScript icon, indicating that this package has built-in type declarations

    1.3.2 • Public • Published

    Scorpion Kitty Core

    npm version build status

    This package contains the brain of the Scorpion Kitty Discord bot as it has the complexity of handling and registering the commands abstracted away in this internal framework.

    The way this framework is supposed to be used and feel like is greatly inspired by Angular and Nest.js.

    This way to see a more detailed documentation.

    Usage

    Services

    A simple service with one method looks like this:

    // main.service.ts
    import { Injectable } from '@scorpion-kitty/core';
     
    @Injectable()
    export class MainService {
        async pingAsync(param: string): Promise<string> {
            return param;
        }
    }

    Controllers

    A controller with one command looks like this:

    // main.controller.ts
    import {
        BotController,
        BotCommand,
        HasServerPermission,
        IsBotOwner,
        Message
    } from '@scorpion-kitty/core';
     
    import { MainService } from './main.service';
     
    @BotController()
    export class MainController {
        // The constructor will be called from the framework and filled with provided services,
        // so they are ready to use inside the controller
        constructor(private mainService: MainService) {}
     
        // This method will be called, when a messages with the first word '?test' or '?t' will be received
        // and only, if the author has the MANAGE_MESSAGES permission
        @BotCommand('test :param :text', { aliases: ['t'] })
        @HasServerPermission(
            ['MANAGE_MESSAGES'],
            `You can't just go around and test stuff`
        )
        async command(
            @Msg() msg: Message,
            @Param('param') param: string,
            @Param('text') someText: string
        ) {
            await msg.reply('I got your test-command');
            const result = await this.mainService.pingAsync('Hi');
            await msg.channel.send(
                `${param}, ${text} and the async service says ${result}`
            );
        }
     
        // This command will only be allowed to be used by the discord user who owns the bot
        @BotCommand('owner')
        @IsBotOwner('Do not touch me')
        async ownerCommand(@Msg() msg: Message) {
            await msg.reply('yes?');
        }
    }

    This will create a controller that contains a command registered as ?test and ?t.

    Modules

    To register controllers, so the bot can start handling them, you need to create modules.

    // main.module.ts
    import { BotModule } from '@scorpion-kitty/core';
    import { MainService } from './main.service';
    import { MainController } from './main.controller';
     
    @BotModule({
        imports: [],
        providers: [MainService],
        controllers: [MainController]
    })
    export class MainModule {}

    Register the root module

    One module is needed as root for the bot to be created. Furthermore, the bots Discord Bot Client Token from a registered Discord Application is needed to start the bot.

    // main.ts
    import { ScorpionKittyFactory } from '@scorpion-kitty/core';
     
    const token = process.env.TOKEN;
     
    const bot = ScorpionKittyFactory.create(MainModule);
    bot.login(token, { customPrefix: '!', logLevel: 'trace' });

    Keywords

    none

    Install

    npm i @scorpion-kitty/core

    DownloadsWeekly Downloads

    58

    Version

    1.3.2

    License

    MIT

    Unpacked Size

    97 kB

    Total Files

    77

    Last publish

    Collaborators

    • jentay