A fast, light-weight framework for consuming incoming messages from Discord 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 includes a DiscordRestClient
, which can be used for sending
information to the Discord API directly or through a rate-limiting proxy.
Ratelimits are managed by default, but this can be disabled.
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.
- Fast
- Low-level
- Customizable
- Connects to any message broker (adapters are included for AMQP and STOMP)
- Allows for caching (included adapter available for Redis)
- Allows for collecting statistics via an event emitter
npm install discord-worker-framework --no-optional
# Install EventEmitter3 for extra performance
npm install eventemitter3
# If you would like to use the included Redis, AMQP or STOMP adapters, make sure
# that `redis`, `amqp.node` and/or `stompit` are installed:
npm install redis amqp.node stompit
Examples can be found in the examples/ directory. The pingpong demonstrates a simple ping pong bot. None of the examples set a valid MessageBrokerConsumer, so you may need to edit files to make them work for you.
All received events from the MessageBrokerConsumer must follow a standard JSON structure or they will cause the Worker to fail to process incoming events:
{
"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
}
discord-gateway-client is a project written in Golang that sends websocket events in this structure to a STOMP broker, and is intended for use with this framework.
The Worker currently emits the following events:
discord:*
: Discord events, see examples for more information- i.e.
discord:MESSAGE_CREATE
is aMESSAGE_CREATE
event from Discord
- i.e.
event:recv
: emitted when any event is received, with the dataevent: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 raw received object from the MessageBrokerConsumer
- Discuss major changes you wish to propose by creating an issue first
- Fork, clone, make changes (semistandard codestyle), push
- PR to the
master
branch (this will change in the future)
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.
A copy of the MIT license can be found in LICENSE.