Skip to content

project-holo/discord-worker-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discord Worker Framework

js-semistandard-style

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.

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 AMQP and STOMP)
  • Allows for caching (included adapter available for Redis)
  • Allows for collecting statistics via an event emitter

Installing

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

Usage and Examples

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.

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:

{
  "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.

Events

The Worker currently emits the following events:

  • discord:*: Discord events, see examples for more information
    • i.e. discord:MESSAGE_CREATE is a MESSAGE_CREATE event from Discord
  • 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 raw received object from the MessageBrokerConsumer

Contributing

  1. Discuss major changes you wish to propose by creating an issue first
  2. Fork, clone, make changes (semistandard codestyle), push
  3. PR to the master branch (this will change in the future)

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.

About

⚙️ Discord multiservice worker framework consuming from MQTT/AMQP/STOMP.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published