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

1.0.0 • Public • Published

@commandhandler/core

Core Library of commandhandler, a command library that supports the same commands on many platforms with the same code.

Installation

npm i @commandhanlder/core @logmanager/service-{your-choice}

Quick Start

import { CommandHandler, StandardArgument, Command } from "@commandhandler/core"
import { YourServiceImplementation } from "@commandhandler/service-{your-service}"

const commandHander = new CommandHandler();

await commandHandler.addService(new YourServiceImplementation())

class PingCommand extends Command<StandardArgument> {
    readonly name = "ping"
    readonly description = "Ping command"

    async onExec(context: CommandExecutionContext, event: CommandExecEvent<Dispatcher, PingCommand>): Promise<void> {
        await event.actions.reply("pong!")
    }
}

await commandHandler.addCommand(new PingCommand())

WIP: Example for discord using discord.js and german internationalization of errors and custom logManager

import { CommandHandler, StandardArgument, Command, RequireArgumentCommandError } from "@commandhandler/core"
import { DiscordImplementation } from "@commandhandler/service-discord.js"
import { ErrorCollection } from "@commandhandler/i18n-de"
import { LogManager, LogLevel } from "@logmanager/core"
import { ConsoleLogger } from "@logmanager/package-console"

const logManager = new LogManager(new ConsoleLogger(), LogLevel.VERBOSE)

const germanErrorCollection = new ErrorCollection()

germanErrorCollection.register(
        RequireArgumentCommandError.id,
        (error: RequireArgumentCommandError) =>
            `Argument '${error.argument.name}' ist erforderlich für das Kommando '${error.command.name}'.`,
        "DE",
    )

const commandHander = new CommandHandler(logManager, germanErrorCollection);

await commandHandler.addService(new DiscordImplementation.createClient(process.env.DISCORD_TOKEN))

class PingCommand extends Command<StandardArgument> {
    readonly name = "ping"
    readonly description = "Ping command"

    async onExec(context: CommandExecutionContext, event: CommandExecEvent<Dispatcher, PingCommand>): Promise<void> {
        await event.actions.reply("pong!")
    }
}

await commandHandler.addCommand(new PingCommand())

Package Sidebar

Install

npm i @commandhandler/core

Weekly Downloads

3

Version

1.0.0

License

none

Unpacked Size

204 kB

Total Files

47

Last publish

Collaborators

  • radioactive-publish-bot