Disgord is a Go module for interacting with the Discord API (REST + socket)
Clone or download
Permalink
Failed to load latest commit information.
.circleci enforces go fmt Oct 9, 2018
cache πŸ“adds comment to most structs and funcs (affects #57) Oct 12, 2018
constant πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
docs adds sharding (fixes #45) Oct 7, 2018
endpoint πŸ“adds comment to most structs and funcs (affects #57) Oct 12, 2018
event πŸ“adds comment to most structs and funcs (affects #57) Oct 12, 2018
generate/events πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
httd πŸ“adds comment to most structs and funcs (affects #57) Oct 12, 2018
testdata βœ…β¬†οΈπŸ”₯snowflake => 2.0.3 + events unmarshal testing + patched guild and… Oct 10, 2018
websocket πŸ“adds comment to most structs and funcs (affects #57) Oct 12, 2018
.codeclimate.yml Added .codeclimate.yml Oct 3, 2018
.gitignore Feature/http requests WIP (#16) Mar 17, 2018
CONTRIBUTING.md πŸ“updates README and CONTRIBUTING Oct 6, 2018
LICENSE Develop (#31) Aug 21, 2018
README.md πŸ“updates README and CONTRIBUTING Oct 6, 2018
cache.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
cache_channels.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
cache_channels_test.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
cache_guilds.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
cache_users.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
cache_voiceState.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
client.go removed println that was flooding the console Oct 13, 2018
client.go.old 🎨client + session cleanup & seperation Sep 22, 2018
commands.go πŸ”₯🎨🐎improves socket (readability, performance) + renames addListener t… Sep 20, 2018
disgord.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
event_dispatcher.go βœ…β¬†οΈπŸ”₯snowflake => 2.0.3 + events unmarshal testing + patched guild and… Oct 10, 2018
event_dispatcher_gen.go Removed line at request of repo owner Oct 3, 2018
events.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
events_gen.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
events_test.go βœ…β¬†οΈπŸ”₯snowflake => 2.0.3 + events unmarshal testing + patched guild and… Oct 10, 2018
go.mod βœ…β¬†οΈπŸ”₯snowflake => 2.0.3 + events unmarshal testing + patched guild and… Oct 10, 2018
go.sum βœ…β¬†οΈπŸ”₯snowflake => 2.0.3 + events unmarshal testing + patched guild and… Oct 10, 2018
rest.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
rest_auditlog.go πŸ“πŸŽ¨adds func name for REST funcs to their comment Oct 10, 2018
rest_auditlog_test.go πŸ”₯βœ…fixes channel saver + some channel tests + improved channel caching Oct 9, 2018
rest_channel.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
rest_channel_test.go πŸ”₯βœ…fixes channel saver + some channel tests + improved channel caching Oct 9, 2018
rest_emoji.go πŸ“πŸŽ¨adds func name for REST funcs to their comment Oct 10, 2018
rest_emoji_test.go πŸ”₯βœ…fixes channel saver + some channel tests + improved channel caching Oct 9, 2018
rest_guild.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
rest_invite.go πŸ“πŸŽ¨adds func name for REST funcs to their comment Oct 10, 2018
rest_invite_test.go πŸ”₯βœ…fixes channel saver + some channel tests + improved channel caching Oct 9, 2018
rest_test.go πŸ”₯βœ…fixes channel saver + some channel tests + improved channel caching Oct 9, 2018
rest_user.go πŸ“πŸŽ¨adds func name for REST funcs to their comment Oct 10, 2018
rest_user_test.go βœ…fixes issue with default values overwriting correct ones Oct 9, 2018
rest_voice.go πŸ“πŸŽ¨adds func name for REST funcs to their comment Oct 10, 2018
rest_voice_test.go πŸ”₯βœ…fixes channel saver + some channel tests + improved channel caching Oct 9, 2018
rest_webhook.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
session.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
struct.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
struct_auditlog.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
struct_auditlog_test.go βœ…tests DeepCopier & Copier for Audit log structs Sep 15, 2018
struct_channel.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
struct_channel_test.go πŸ”₯βœ…fixes channel saver + some channel tests + improved channel caching Oct 9, 2018
struct_emoji.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
struct_emoji_test.go adds DeepCopier and Copier to Emoji Sep 13, 2018
struct_guild.go πŸ“adds comment to most structs and funcs (affects #57) Oct 12, 2018
struct_guild_test.go πŸ”₯🎨 clean up Sep 26, 2018
struct_invite.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
struct_invite_test.go βœ…adds DeepCopier & Copier to invite objects Sep 15, 2018
struct_role.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
struct_role_test.go adds Copier, DeepCopier, SaveTo and DeleteFrom-Discord to Role Sep 13, 2018
struct_test.go πŸ”₯βœ…fixes channel saver + some channel tests + improved channel caching Oct 9, 2018
struct_user.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
struct_user_test.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
struct_voice.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018
struct_voice_test.go βœ…πŸ”₯adds DeepCopier & Copier to Voice objects + removes Clear method Sep 15, 2018
struct_webhook.go πŸ“πŸ”₯removes old interfaces + adds diff discord levels + update comments (… Oct 12, 2018

README.md

Disgord Documentation

forthebadgeforthebadgeforthebadge

Health

Branch Build status Code climate Go Report Card Codacy
develop CircleCI Maintainability Go Report Card Codacy Badge

About

GoLang module for interacting with the Discord API. Supports socketing and REST functionality. Discord object will also have implemented helper functions such as Message.RespondString(session, "hello"), or Session.SaveToDiscord(&Emoji) for simplicity/readability.

Disgord has complete implementation for Discord's documented REST API. It lacks comprehensive testing, although unit-tests have been created for several of the Disgord REST implementations. The socketing is not complete, but does support all event types that are documented (using both channels and callbacks).

Note that caching is yet to be implemented. Versions from v0.5.1 and below, had caching to some degree, but was scrapped once a complete rework of the project structure was done.

Disgord does not utilize reflection, except in unit tests and unmarshalling/marshalling of JSON. But does return custom error messages for some functions which can be type checked in a switch for a more readable error handling as well potentially giving access to more information.

To get started see the examples in docs

Alternative GoLang package for Discord: DiscordGo

Discord channel/server: Discord Gophers#Disgord

Package structure

None of the sub-packages should be used outside the library. If there exists a requirement for that, please create an issue or pull request.

github.com/andersfylling/disgord
└──.circleci    :CircleCI configuration
└──cache        :Different cache replacement algorithms
└──constant     :Constants such as version, GitHub URL, etc.
└──docs         :Examples, templates, (documentation)
└──endpoint     :All the REST endpoints of Discord
└──event        :All the Discord event identifiers
└──generate     :All go generate scripts for "generic" code
└──httd         :Deals with rate limits and http calls
└──testdata     :Holds all test data for unit tests (typically JSON files)
└──websocket    :Discord Websocket logic (reconnect, resume, etc.)

Dependencies

github.com/andersfylling/disgord
└──github.com/andersfylling/snowflake  :The snowflake ID designed for Discord
└──github.com/json-iterator/go         :For faster JSON decoding/encoding
└──github.com/sergi/go-diff            :Unit testing for checking JSON encoding/decoding of structs
└──github.com/sirupsen/logrus          :Logging (will be replaced with a simplified interface for DI)

If you do not wish to use json-iterator, you can pass -tags=json-std to switch to "encoding/json". However, json-iterator is the recommended default for this library.

Contributing

Please see the CONTRIBUTING.md file (Note that it can be useful to read this regardless if you have the time)

Git branching model

The branch:develop holds the most recent changes, as it name implies. There is no master branch as there will never be a "stable latest branch" except the git tags (or releases).

Mental model

Caching

The cache can be either immutable (recommended) or mutable. When the cache is mutable you will share the memory space with the cache, such that if you change your data structure you might also change the cache directly. However, by using the immutable option all incoming data is deep copied to the cache and you will not be able to directly access the memory space, this should keep your code less error-prone and allow for concurrent cache access in case you want to use channels or other long-running tasks/processes.

Requests

For every REST API request the request is rate limited and cached auto-magically by Disgord. This means that when you utilize the Session interface you won't have to worry about rate limits and data is cached to improve performance. See the GoDoc for how to bypass the caching.

Events

The reactor pattern is used. This will always be the default behavior, however channels will ofcourse work more as a pro-actor system as you deal with the data parallel to other functions. Incoming events from the discord servers are parsed into respective structs and dispatched to either a) handlers, or b) through channels. Both are dispatched from the same place, and the arguments share the same memory space. Pick handlers (register them using Session.On method) simplicity as they run in sequence, while channels are executed in a parallel setting (it's expected you understand how channels work so I won't go in-depth here).

Quick example

NOTE: To see more examples go visit the docs/examples folder. See the GoDoc for a in-depth introduction on the various topics (or disgord.go package comment). Below is an example of the traditional ping-pong bot.

// create a Disgord session
session, err := disgord.NewSession(&disgord.Config{
    Token: os.Getenv("DISGORD_TOKEN"),
})
if err != nil {
    panic(err)
}

// create a handler and bind it to new message events
session.On(disgord.EventMessageCreate, func(session disgord.Session, data *disgord.MessageCreate) {
    msg := data.Message

    if msg.Content == "ping" {
        msg.RespondString(session, "pong")
    }
})

// connect to the discord gateway to receive events
err = session.Connect()
if err != nil {
    panic(err)
}

// Keep the socket connection alive, until you terminate the application
session.DisconnectOnInterrupt()

Q&A

1. Reason for making another Discord lib in GoLang?

I'm trying to take over the world and then become a intergalactic war lord. Have to start somewhere.