Skip to content

discordpkg/gateway

Repository files navigation

Gateway

Code coverage PkgGoDev

A minimal implementation for the Discord gateway logic using the state pattern. The goal is to provide the Discord gateway behavior as a library to quickly build correct shard implementation. A functional shard implementation using github.com/gobwas/ws can be found at gatewayutil sub-package.

Design

A client is holds a state that affects how the next incoming message is processed. To begin with, the client is given a HelloState, which transitions into a ReadyState, which again transitions into a ConnectedState. Each state is named in accordance with each phase of the gateway connection setup guide, and are responsible for processing different Discord messages.

Different gateway client states

The different client methods takes the websocket connection as parameters in accordance with the io package (Reader, Writer), instead of writing an abstraction compliant wrapper of whatever websocket library you want to use.

A closed client is considered dead, and can not be used for future Discord events. A new client must be created. Specify the "dead client" as a parent allows the new client to potentially resume instead of creating a fresh session.

Live bot for testing

There is a bot running the gobwas code. Found in the cmd subdir. If you want to help out the "stress testing", you can add the bot here: https://discord.com/oauth2/authorize?scope=bot&client_id=792491747711123486&permissions=0

It only reads incoming events and waits to crash. Once any alerts such as warning, error, fatal, panic triggers; I get a notification so I can quickly patch the problem!

Support

  • operation codes
  • close codes
  • Intents
  • Events
  • JSON
  • ETF (see the encoding package)
  • Rate limit
    • Identify (local implementation)
    • Commands (local implementation)
  • Shard(s) manager
  • Buffer pool

Use the existing disgord channels for discussion

Discord Gophers Discord API

About

A discord gateway module that separates Discord logic from the websocket logic

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

No packages published