# discord-worker-framework

> Discord multiservice worker framework consuming from various message brokers.

Latest version **0.1.0** (published 2017-05-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install discord-worker-framework
pnpm add discord-worker-framework
yarn add discord-worker-framework
bun add discord-worker-framework
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2017-05-01 |
| First published | 2017-05-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Dean Sheather |
| Maintainers | deansheather |
| Keywords | discord, bot, framework, microservice |

## Links

- npm: https://www.npmjs.com/package/discord-worker-framework
- Repository: https://github.com/project-holo/discord-worker-framework
- Homepage: https://github.com/project-holo/discord-worker-framework#readme
- Issues: https://github.com/project-holo/discord-worker-framework/issues
- npm.io page: https://npm.io/package/discord-worker-framework

## Dependencies (3)

- [raven](https://npm.io/package/raven.md) ^1.2.1
- [form-data](https://npm.io/package/form-data.md) ^2.1.4
- [eventemitter3](https://npm.io/package/eventemitter3.md) ^2.0.2

## Alternatives

- [@sveltejs/kit](https://npm.io/package/@sveltejs/kit.md) — 2.2M weekly downloads
- [@atlaskit/theme](https://npm.io/package/@atlaskit/theme.md) — 402.0K weekly downloads
- [@tangle-network/brand](https://npm.io/package/@tangle-network/brand.md) — 10.0K weekly downloads
- [seneca](https://npm.io/package/seneca.md) — 7.4K weekly downloads
- [@bsb/base](https://npm.io/package/@bsb/base.md) — 7.2K weekly downloads

## Recent versions

- 0.1.0 (latest) — 2017-05-01

## README

# Discord Worker Framework
[![js-semistandard-style](https://img.shields.io/badge/code%20style-semistandard-brightgreen.svg?style=flat-square)](https://github.com/Flet/semistandard)

A fast, light-weight framework for consuming incoming messages from
[Discord](https://discordapp.com "Discord Landing") in a multi-service fashion.

This package consumes from a message broker such as ActiveMQ or RabbitMQ, parses
and validates incoming data and emits it to be processed by the bot-specific
code.

This package also incorporates a `RestClient`, which can be used for sending
information to the Discord API directly or through a rate-limiting proxy. 
Ratelimits aren't currently managed by the `RestClient`.

## NOTE: THIS PACKAGE MAY BREAK AT ANY TIME
This package follows semver, and the major version is `0`. This means that
breaking changes can be introduced in any update. Do not use this in production
unless you know what you are doing.

## Features
- Fast
- Low-level
- Customizable
- Connects to any message broker (adapters are included for MQTT and AMQP)
- Allows for caching (included adapter available for Redis)
- Allows for collecting statistics via EventEmitter3

## TODO
- [ ] Move documentation to some webviewer
- [ ] Move usage to `examples/` directory and write more examples
- [ ] Remove the note above when the package major version hits `1`
- [ ] Write tests

## Installing
```
npm install discord-worker-framework --no-optional
```

If you would like to use the included Redis, MQTT or AMQP adapters, make sure
that `redis`, `mqtt` and/or `amqp.node` are installed:
```
npm install redis mqtt amqp.node
```

## Usage
```js
'use strict';

const DiscordWorkerFramework = require('discord-worker-framework');
const raven = require('raven'); // optional, for RavenWorker only

// Create a MessageBrokerConsumer, check documentation for specifics
const consumer = new DiscordWorkerFramework.MessageBrokerConsumer;

// Create a new Worker
const worker = new DiscordWorkerFramework.Worker({
  messageBrokerConsumer: consumer
});

// Create a new RestClient
const RestClient = new DiscordWorkerFramework.RestClient({
  endpoint: 'http://localhost:8000',
  // authorization: 'value of Authorization header for the endpoint'
});

// ...or a RavenWorker (RavenWorker allows for reporting errors/warnings to
// Sentry)
/*
const worker = new DiscordWorkerFramework.RavenWorker({
  messageBrokerConsumer: consumer,
  ravenClient: raven
});
*/

// Listen for new messages and respond to pings
worker.on('discord:MESSAGE_CREATE', e => {
  if (e.data.content === 'ping') {
    RestClient.createMessage(e.data.channel_id, 'pong!');
  }
});

// Listen for deleted messages and log them... for reasons
worker.on('discord:MESSAGE_DELETE', e => {
  console.log(`[MESSAGE_DELETE] ${e.data.author.username}: ${e.data.content}`);
});

// Start consuming
worker.startConsuming().then(() => {
  console.log('Ready to rumble!');
}).catch(err => {
  console.error(err.stack);
  process.exit(1);
});

```

## Incoming Event Structure
All received events from the MessageBrokerConsumer must follow a standard JSON
structure or they will cause the Worker to fail to process incoming events:

```js
{
  "type": "", // Discord event type, e.g. MESSAGE_CREATE, GUILD_CREATE
  "shard_id": 0, // shard ID which the event was received from
  "data": {} // event data, should match the structure from the Discord gateway
}
```

## Events
The Worker currently emits the following events:
- `discord:*`: Discord events, see example above
- `event:recv`: emitted when any event is received, with the data
- `event:tested`: emitted when any event has been verified to match the event
  structure schema (with result)
- `event:dispatch`: emitted when any event is broadcasted to listener 
  (`discord:*`), with the data

## Contributing
1. Discuss major changes you wish to propose by creating an issue first
2. Fork, clone, checkout `develop`, make changes (semistandard codestyle), push
3. PR to the `develop` branch

## Testing
Tests are handled with `mocha`. You can run tests by using the `npm test`
command, assuming you've cloned this repository directly and installed 
devDependencies.

### License
A copy of the MIT license can be found in `LICENSE`.

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