# @commandhandler/core

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

Latest version **1.0.0** (published 2022-07-01) · 0 weekly downloads

## Install

```sh
npm install @commandhandler/core
pnpm add @commandhandler/core
yarn add @commandhandler/core
bun add @commandhandler/core
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2022-07-01 |
| First published | 2022-06-30 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 5 |
| Unpacked size | 198.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | radioactive-publish-bot |
| Keywords | command, handler, core, discord, discord.js, command handler |

## Links

- npm: https://www.npmjs.com/package/@commandhandler/core
- Repository: https://gitlab.hobbylos.org/hobbylose-senior-full-stack-developer/commandhandler/core
- Issues: https://gitlab.hobbylos.org/hobbylose-senior-full-stack-developer/commandhandler/core/-/issues
- npm.io page: https://npm.io/package/@commandhandler/core

## Dependencies (5)

- [tslib](https://npm.io/package/tslib.md) ^2.4.0
- [@types/node](https://npm.io/package/@types/node.md) ^18.0.0
- [@logmanager/core](https://npm.io/package/@logmanager/core.md) ^1.0.0
- [@commandhandler/utils](https://npm.io/package/@commandhandler/utils.md) ^1.0.0-alpha.3
- [@logmanager/package-console](https://npm.io/package/@logmanager/package-console.md) ^1.0.0

## Alternatives

- [@salesforce/cli](https://npm.io/package/@salesforce/cli.md) — 389.7K weekly downloads
- [@mintlify/cli](https://npm.io/package/@mintlify/cli.md) — 208.9K weekly downloads
- [@grafana/e2e-selectors](https://npm.io/package/@grafana/e2e-selectors.md) — 128.7K weekly downloads
- [mintlify](https://npm.io/package/mintlify.md) — 112.0K weekly downloads
- [@intlayer/cli](https://npm.io/package/@intlayer/cli.md) — 22.8K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2022-07-01
- 1.0.0-alpha.2 (alpha) — 2022-07-01
- 1.0.0-alpha.1 — 2022-06-30

## README

# @commandhandler/core

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

## Installation

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

## Quick Start

```typescript
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

```typescript
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())
```

---
_Source: https://npm.io/package/@commandhandler/core · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
