disgord

package module
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2018 License: BSD-3-Clause Imports: 15 Imported by: 0

README

Disgord

forthebadgeforthebadgeforthebadge

Health

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

About

GoLang library for interacting with the Discord API. Supports socketing and REST functions. Compared to Discordgo this library will be a little more heavy and support helper functions on objects such as Channel, Message, etc. eg. Channel.SendMsg(...), Message.Respond(...).

To get started see the examples in docs

package structure

github.com/andersfylling/disgord
└──discordws    :Deals with the discord socket connection
└──docs         :Examples, templates, (documentation)
└──event        :Data structures, callbacks, event types
└──resource     :All the Discord data structures (same setup as the Discord docs)
└──rest         :All the endpoints found in the documentation (same as resource)
└──state/cache  :Logic for caching incoming Discord information

Contributing

Please see the CONTRIBUTING.md file

The Wiki

Yes, the wiki might hold some information. But I believe everything will be placed within the "docs" package in the end.

Mental model

Caching

The cache, of discord objects, aims to reflect the same state as of the discord servers. Therefore incoming data is deep copied, as well as return values from the cache. This lib handles caching for you, so whenever you send a request to the REST API or receive a discord event. The contents are cached auto-magically to a separate memory space.

As a structure is sent into the cache module, everything is deep copied as mentioned, however if the object hold discord objects consistent of a snowflake, it does not do a deep copy. It converts given field to a nil, and stores the snowflake only in a separate struct/map. This makes sure that there will only exist one version of an object. Making updating fairly easy. When the object goes out of cache, a copy is created and every sub object containing a snowflake is deep copied from the cache as well, to create a wholesome object.

Requests

For every REST API request (which is the only way to get objects from the discord interface, without waiting for changes as events) the request is rate limited auto-magically by the library (caching coming soon for resource funcs). The functions in resource pkg are blocking, and should be used with care. For async requests, use the methods found at the Session interface, such as: Session.User(userID) which returns a channel. The channel will get content from the REST API, if not found in the cache.

Events

The reactor pattern with goroutines, or a pro-actor pattern is used. This will always be the default behavior, synchronous triggering of listeners might be implemented in the future. Incoming events from the discord servers are parsed into respective structs and dispatched to either a) callbacks, or b) through channels. Both are dispatched from the same place, and the arguments share the same memory space. So it doesn't matter which one you pick, chose your preference.

Quick example

package main

import (
    "os"
    "os/signal"
    "syscall"

    "github.com/andersfylling/disgord"
    "github.com/sirupsen/logrus"
)

func main() {
    termSignal := make(chan os.Signal, 1)
    signal.Notify(termSignal, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)

    sess, err := disgord.NewSession(&disgord.Config{
        Token: os.Getenv("DISGORD_TOKEN"),
    })
    if err != nil {
        panic(err)
    }

    // add a event listener
    sess.AddListener(event.GuildCreateKey, func(session Session, box *event.GuildCreateBox) {
        guild := box.Guild
        // do something with guild
    })

    // or use a channel to listen for events
    go func() {
        for {
            select {
            case box, alive := <- sess.Evt().GuildCreateChan():
                if !alive {
                    fmt.Println("channel is dead")
                    break
                }

                guild := box.Guild
                // do something with guild
            }
        }
    }()

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

    // eg. retrieve a specific user from the Discord servers
    userID := NewSnowflake(228846961774559232)
    userResponse := <- sess.User(userID) // sends a request to discord
    userResponse2 := <- sess.User(userID) // does a cache look up, to prevent rate limiting/banning

    // check if there was an issue (eg. rate limited or not found)
    if userResponse.Err != nil {
        panic(userResponse.Err)
    }

    // check if this is retrieved from the cache
    if userResponse.Cache {
        // ...
    }

    // get the user info
    user := userResponse.User

    // keep the app alive until terminated
    <-termSignal
    sess.Disconnect()
}

WARNING

All the REST endpoints are implemented, but may not exist on the interface yet. Create a Disgord session/client and use the REST functions found in the rest package directly (for now). See the examples in docs for using the functions in the rest package directly.

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.

Thanks to

Documentation

Overview

Disgord

Index

Constants

View Source
const (
	JSONEncoding = "JSON"

	// APIVersion desired API version to use
	APIVersion        = 6 // February 5, 2018
	DefaultAPIVersion = 6

	GitHubURL = "https://github.com/andersfylling/disgord"
	Version   = "v0.2.0"
)

Variables

This section is empty.

Functions

func Unmarshal

func Unmarshal(data []byte, box interface{})

wtf is this

Types

type ChannelCreateCallback

type ChannelCreateCallback = func(session Session, cc *ChannelCreateBox)

channel

type ChannelDeleteCallback

type ChannelDeleteCallback = func(session Session, cd *ChannelDeleteBox)

type ChannelPinsUpdateCallback

type ChannelPinsUpdateCallback = func(session Session, cpu *ChannelPinsUpdateBox)

type ChannelUpdateCallback

type ChannelUpdateCallback = func(session Session, cu *ChannelUpdateBox)

type Client

type Client struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewClient

func NewClient(conf *Config) (*Client, error)

NewClient creates a new default disgord instance

func NewClientMustCompile

func NewClientMustCompile(conf *Config) *Client

func (*Client) AddGuildMember

func (c *Client) AddGuildMember(guildID, userID Snowflake, params *rest.AddGuildMemberParams) (ret *resource.Member, err error)

func (*Client) AddGuildMemberRole

func (c *Client) AddGuildMemberRole(guildID, userID, roleID Snowflake) (err error)

func (*Client) AddListener

func (c *Client) AddListener(evtName string, listener interface{})

func (*Client) AddListenerOnce

func (c *Client) AddListenerOnce(evtName string, listener interface{})

AddListenerOnce not implemented. Do not use.

func (*Client) AddPinnedChannelMessage

func (c *Client) AddPinnedChannelMessage(channelID, msgID Snowflake) (err error)

func (*Client) BeginGuildPrune

func (c *Client) BeginGuildPrune(id Snowflake, params *rest.GuildPruneParams) (ret *resource.GuildPruneCount, err error)

func (*Client) BulkDeleteMessages

func (c *Client) BulkDeleteMessages(chanID Snowflake, params *rest.BulkDeleteMessagesParams) (err error)

func (*Client) ChannelChan

func (c *Client) ChannelChan(channelID Snowflake) <-chan *resource.Channel

func (*Client) ChannelsChan

func (c *Client) ChannelsChan(GuildID Snowflake) <-chan map[Snowflake]*resource.Channel

func (*Client) Connect

func (c *Client) Connect() (err error)

Connect establishes a websocket connection to the discord API

func (*Client) CreateChannelInvites

func (c *Client) CreateChannelInvites(id Snowflake, params *rest.CreateChannelInvitesParams) (ret *resource.Invite, err error)

func (*Client) CreateChannelMessage

func (c *Client) CreateChannelMessage(channelID Snowflake, params *rest.CreateMessageParams) (ret *resource.Message, err error)

func (*Client) CreateDM

func (c *Client) CreateDM(recipientID Snowflake) (ret *resource.Channel, err error)

func (*Client) CreateGroupDM

func (c *Client) CreateGroupDM(params *rest.CreateGroupDMParams) (ret *resource.Channel, err error)

func (*Client) CreateGuild

func (c *Client) CreateGuild(params *rest.CreateGuildParams) (ret *resource.Guild, err error)

Guild

func (*Client) CreateGuildBan

func (c *Client) CreateGuildBan(guildID, userID Snowflake, params *rest.CreateGuildBanParams) (err error)

func (*Client) CreateGuildChannel

func (c *Client) CreateGuildChannel(id Snowflake, params *rest.CreateGuildChannelParams) (ret *resource.Channel, err error)

func (*Client) CreateGuildEmoji

func (c *Client) CreateGuildEmoji(guildID Snowflake) (ret *resource.Emoji, err error)

func (*Client) CreateGuildIntegration

func (c *Client) CreateGuildIntegration(guildID Snowflake, params *rest.CreateGuildIntegrationParams) (err error)

func (*Client) CreateGuildRole

func (c *Client) CreateGuildRole(id Snowflake, params *rest.CreateGuildRoleParams) (ret *resource.Role, err error)

func (*Client) CreateReaction

func (c *Client) CreateReaction(channelID, messageID Snowflake, emoji interface{}) (ret *resource.Reaction, err error)

func (*Client) CreateWebhook

func (c *Client) CreateWebhook(channelID Snowflake, params *rest.CreateWebhookParams) (ret *resource.Webhook, err error)

Webhook

func (*Client) DeleteAllReactions

func (c *Client) DeleteAllReactions(channelID, messageID Snowflake) (err error)

func (*Client) DeleteChannel

func (c *Client) DeleteChannel(id Snowflake) (err error)

func (*Client) DeleteChannelPermission

func (c *Client) DeleteChannelPermission(channelID, overwriteID Snowflake) (err error)

func (*Client) DeleteGuild

func (c *Client) DeleteGuild(id Snowflake) (err error)

func (*Client) DeleteGuildEmoji

func (c *Client) DeleteGuildEmoji(guildID, emojiID Snowflake) (err error)

func (*Client) DeleteGuildIntegration

func (c *Client) DeleteGuildIntegration(guildID, integrationID Snowflake) (err error)

func (*Client) DeleteGuildRole

func (c *Client) DeleteGuildRole(guildID, roleID Snowflake) (err error)

func (*Client) DeleteInvite

func (c *Client) DeleteInvite(inviteCode string) (invite *resource.Invite, err error)

func (*Client) DeleteMessage

func (c *Client) DeleteMessage(channelID, msgID Snowflake) (err error)

func (*Client) DeleteOwnReaction

func (c *Client) DeleteOwnReaction(channelID, messageID Snowflake, emoji interface{}) (err error)

func (*Client) DeletePinnedChannelMessage

func (c *Client) DeletePinnedChannelMessage(channelID, msgID Snowflake) (err error)

func (*Client) DeleteUserReaction

func (c *Client) DeleteUserReaction(channelID, messageID, userID Snowflake, emoji interface{}) (err error)

func (*Client) DeleteWebhook

func (c *Client) DeleteWebhook(webhookID Snowflake) (err error)

func (*Client) DeleteWebhookWithToken

func (c *Client) DeleteWebhookWithToken(id Snowflake, token string) (err error)

func (*Client) Disconnect

func (c *Client) Disconnect() (err error)

Disconnect closes the discord websocket connection

func (*Client) EditChannelPermissions

func (c *Client) EditChannelPermissions(chanID, overwriteID Snowflake, params *rest.EditChannelPermissionsParams) (err error)

func (*Client) EditMessage

func (c *Client) EditMessage(chanID, msgID Snowflake, params *rest.EditMessageParams) (ret *resource.Message, err error)

func (*Client) Evt

func (c *Client) Evt() EvtDispatcher

func (*Client) ExecuteGitHubWebhook

func (c *Client) ExecuteGitHubWebhook(params *rest.ExecuteWebhookParams, wait bool) (err error)

func (*Client) ExecuteSlackWebhook

func (c *Client) ExecuteSlackWebhook(params *rest.ExecuteWebhookParams, wait bool) (err error)

func (*Client) ExecuteWebhook

func (c *Client) ExecuteWebhook(params *rest.ExecuteWebhookParams, wait bool, URLSuffix string) (err error)

func (*Client) GetChannel

func (c *Client) GetChannel(id Snowflake) (ret *resource.Channel, err error)

Channel

func (*Client) GetChannelInvites

func (c *Client) GetChannelInvites(id Snowflake) (ret []*resource.Invite, err error)

func (*Client) GetChannelMessage

func (c *Client) GetChannelMessage(channelID, messageID Snowflake) (ret *resource.Message, err error)

func (*Client) GetChannelMessages

func (c *Client) GetChannelMessages(channelID Snowflake, params rest.URLParameters) (ret []*resource.Message, err error)

func (*Client) GetChannelWebhooks

func (c *Client) GetChannelWebhooks(channelID Snowflake) (ret []*resource.Webhook, err error)

func (*Client) GetCurrentUser

func (c *Client) GetCurrentUser() (ret *resource.User, err error)

User

func (*Client) GetCurrentUserGuilds

func (c *Client) GetCurrentUserGuilds(params *rest.GetCurrentUserGuildsParams) (ret []*resource.Guild, err error)

func (*Client) GetGuild

func (c *Client) GetGuild(id Snowflake) (ret *resource.Guild, err error)

func (*Client) GetGuildAuditLogs

func (c *Client) GetGuildAuditLogs(guildID Snowflake, params *rest.AuditLogParams) (log *resource.AuditLog, err error)

Audit-log

func (*Client) GetGuildBan

func (c *Client) GetGuildBan(guildID, userID Snowflake) (ret *resource.Ban, err error)

func (*Client) GetGuildBans

func (c *Client) GetGuildBans(id Snowflake) (ret []*resource.Ban, err error)

func (*Client) GetGuildChannels

func (c *Client) GetGuildChannels(id Snowflake) (ret []*resource.Channel, err error)

func (*Client) GetGuildEmbed

func (c *Client) GetGuildEmbed(guildID Snowflake) (ret *resource.GuildEmbed, err error)

func (*Client) GetGuildEmoji

func (c *Client) GetGuildEmoji(guildID, emojiID Snowflake) (ret *resource.Emoji, err error)

func (*Client) GetGuildEmojis

func (c *Client) GetGuildEmojis(id Snowflake) (ret []*resource.Emoji, err error)

Emoji

func (*Client) GetGuildIntegrations

func (c *Client) GetGuildIntegrations(id Snowflake) (ret []*resource.Integration, err error)

func (*Client) GetGuildInvites

func (c *Client) GetGuildInvites(id Snowflake) (ret []*resource.Invite, err error)

func (*Client) GetGuildMember

func (c *Client) GetGuildMember(guildID, userID Snowflake) (ret *resource.Member, err error)

func (*Client) GetGuildMembers

func (c *Client) GetGuildMembers(guildID, after Snowflake, limit int) (ret []*resource.Member, err error)

func (*Client) GetGuildPruneCount

func (c *Client) GetGuildPruneCount(id Snowflake, params *rest.GuildPruneParams) (ret *resource.GuildPruneCount, err error)

func (*Client) GetGuildRoles

func (c *Client) GetGuildRoles(guildID Snowflake) (ret []*resource.Role, err error)

func (*Client) GetGuildVanityURL

func (c *Client) GetGuildVanityURL(guildID Snowflake) (ret *resource.PartialInvite, err error)

func (*Client) GetGuildVoiceRegions

func (c *Client) GetGuildVoiceRegions(id Snowflake) (ret []*resource.VoiceRegion, err error)

func (*Client) GetGuildWebhooks

func (c *Client) GetGuildWebhooks(guildID Snowflake) (ret []*resource.Webhook, err error)

func (*Client) GetInvite

func (c *Client) GetInvite(inviteCode string, withCounts bool) (invite *resource.Invite, err error)

Invite

func (*Client) GetPinnedMessages

func (c *Client) GetPinnedMessages(channelID Snowflake) (ret []*resource.Message, err error)

func (*Client) GetReaction

func (c *Client) GetReaction(channelID, messageID Snowflake, emoji interface{}, params rest.URLParameters) (ret []*resource.User, err error)

func (*Client) GetUser

func (c *Client) GetUser(id Snowflake) (ret *resource.User, err error)

func (*Client) GetUserConnections

func (c *Client) GetUserConnections() (ret []*resource.UserConnection, err error)

func (*Client) GetUserDMs

func (c *Client) GetUserDMs() (ret []*resource.Channel, err error)

func (*Client) GetVoiceRegions

func (c *Client) GetVoiceRegions() (ret []*resource.VoiceRegion, err error)

Voice

func (*Client) GetWebhook

func (c *Client) GetWebhook(id Snowflake) (ret *resource.Webhook, err error)

func (*Client) GetWebhookWithToken

func (c *Client) GetWebhookWithToken(id Snowflake, token string) (ret *resource.Webhook, err error)

func (*Client) GroupDMAddRecipient

func (c *Client) GroupDMAddRecipient(channelID, userID Snowflake, params *rest.GroupDMAddRecipientParams) (err error)

func (*Client) GroupDMRemoveRecipient

func (c *Client) GroupDMRemoveRecipient(channelID, userID Snowflake) (err error)

func (*Client) GuildChan

func (c *Client) GuildChan(guildID Snowflake) <-chan *resource.Guild

state/caching module

func (*Client) LeaveGuild

func (c *Client) LeaveGuild(id Snowflake) (err error)

func (*Client) MemberChan

func (c *Client) MemberChan(guildID, userID Snowflake) <-chan *resource.Member

func (*Client) MembersChan

func (c *Client) MembersChan(guildID Snowflake) <-chan map[Snowflake]*resource.Member

func (*Client) ModifyChannel

func (c *Client) ModifyChannel(changes *rest.ModifyChannelParams) (ret *resource.Channel, err error)

func (*Client) ModifyCurrentUser

func (c *Client) ModifyCurrentUser(params *rest.ModifyCurrentUserParams) (ret *resource.User, err error)

func (*Client) ModifyCurrentUserNick

func (c *Client) ModifyCurrentUserNick(id Snowflake, params *rest.ModifyCurrentUserNickParams) (nick string, err error)

func (*Client) ModifyGuild

func (c *Client) ModifyGuild(id Snowflake, params *rest.ModifyGuildParams) (ret *resource.Guild, err error)

func (*Client) ModifyGuildEmbed

func (c *Client) ModifyGuildEmbed(guildID Snowflake, params *resource.GuildEmbed) (ret *resource.GuildEmbed, err error)

func (*Client) ModifyGuildEmoji

func (c *Client) ModifyGuildEmoji(guildID, emojiID Snowflake) (ret *resource.Emoji, err error)

func (*Client) ModifyGuildIntegration

func (c *Client) ModifyGuildIntegration(guildID, integrationID Snowflake, params *rest.ModifyGuildIntegrationParams) (err error)

func (*Client) ModifyGuildMember

func (c *Client) ModifyGuildMember(guildID, userID Snowflake, params *rest.ModifyGuildMemberParams) (err error)

func (*Client) ModifyGuildRole

func (c *Client) ModifyGuildRole(guildID, roleID Snowflake, params *rest.ModifyGuildRoleParams) (ret []*resource.Role, err error)

func (*Client) ModifyGuildRolePositions

func (c *Client) ModifyGuildRolePositions(guildID Snowflake, params *rest.ModifyGuildRolePositionsParams) (ret []*resource.Role, err error)

func (*Client) ModifyWebhook

func (c *Client) ModifyWebhook(newWebhook *resource.Webhook) (ret *resource.Webhook, err error)

func (*Client) ModifyWebhookWithToken

func (c *Client) ModifyWebhookWithToken(newWebhook *resource.Webhook) (ret *resource.Webhook, err error)

func (*Client) MsgChan

func (c *Client) MsgChan(msgID Snowflake) <-chan *resource.Message

func (*Client) RateLimiter

func (c *Client) RateLimiter() httd.RateLimiter

func (*Client) RemoveGuildBan

func (c *Client) RemoveGuildBan(guildID, userID Snowflake) (err error)

func (*Client) RemoveGuildMember

func (c *Client) RemoveGuildMember(guildID, userID Snowflake) (err error)

func (*Client) RemoveGuildMemberRole

func (c *Client) RemoveGuildMemberRole(guildID, userID, roleID Snowflake) (err error)

func (*Client) Req

func (c *Client) Req() httd.Requester

func (*Client) State

func (c *Client) State() state.Cacher

func (*Client) String

func (c *Client) String() string

func (*Client) SyncGuildIntegration

func (c *Client) SyncGuildIntegration(guildID, integrationID Snowflake) (err error)

func (*Client) TriggerTypingIndicator

func (c *Client) TriggerTypingIndicator(channelID Snowflake) (err error)

func (*Client) UserChan

func (c *Client) UserChan(userID Snowflake) <-chan *UserChan

type Config

type Config struct {
	Token      string
	HTTPClient *http.Client

	APIVersion  int    // eg. version 6. 0 defaults to lowest supported api version
	APIEncoding string // eg. json, use const. defaults to json

	CancelRequestWhenRateLimited bool

	LoadAllMembers   bool
	LoadAllChannels  bool
	LoadAllRoles     bool
	LoadAllPresences bool

	Debug bool
}

type Dispatch

type Dispatch struct {
	// contains filtered or unexported fields
}

func NewDispatch

func NewDispatch() *Dispatch

func (*Dispatch) AddHandler

func (d *Dispatch) AddHandler(evtName string, listener interface{})

func (*Dispatch) AddHandlerOnce

func (d *Dispatch) AddHandlerOnce(evtName string, listener interface{})

func (*Dispatch) AllChan

func (d *Dispatch) AllChan() <-chan interface{}

func (*Dispatch) ChannelCreateChan

func (d *Dispatch) ChannelCreateChan() <-chan *ChannelCreateBox

func (*Dispatch) ChannelDeleteChan

func (d *Dispatch) ChannelDeleteChan() <-chan *ChannelDeleteBox

func (*Dispatch) ChannelPinsUpdateChan

func (d *Dispatch) ChannelPinsUpdateChan() <-chan *ChannelPinsUpdateBox

func (*Dispatch) ChannelUpdateChan

func (d *Dispatch) ChannelUpdateChan() <-chan *ChannelUpdateBox

func (*Dispatch) GuildBanAddChan

func (d *Dispatch) GuildBanAddChan() <-chan *GuildBanAddBox

func (*Dispatch) GuildBanRemoveChan

func (d *Dispatch) GuildBanRemoveChan() <-chan *GuildBanRemoveBox

func (*Dispatch) GuildCreateChan

func (d *Dispatch) GuildCreateChan() <-chan *GuildCreateBox

func (*Dispatch) GuildDeleteChan

func (d *Dispatch) GuildDeleteChan() <-chan *GuildDeleteBox

func (*Dispatch) GuildEmojisUpdateChan

func (d *Dispatch) GuildEmojisUpdateChan() <-chan *GuildEmojisUpdateBox

func (*Dispatch) GuildIntegrationsUpdateChan

func (d *Dispatch) GuildIntegrationsUpdateChan() <-chan *GuildIntegrationsUpdateBox

func (*Dispatch) GuildMemberAddChan

func (d *Dispatch) GuildMemberAddChan() <-chan *GuildMemberAddBox

func (*Dispatch) GuildMemberRemoveChan

func (d *Dispatch) GuildMemberRemoveChan() <-chan *GuildMemberRemoveBox

func (*Dispatch) GuildMemberUpdateChan

func (d *Dispatch) GuildMemberUpdateChan() <-chan *GuildMemberUpdateBox

func (*Dispatch) GuildMembersChunkChan

func (d *Dispatch) GuildMembersChunkChan() <-chan *GuildMembersChunkBox

func (*Dispatch) GuildRoleCreateChan

func (d *Dispatch) GuildRoleCreateChan() <-chan *GuildRoleCreateBox

func (*Dispatch) GuildRoleDeleteChan

func (d *Dispatch) GuildRoleDeleteChan() <-chan *GuildRoleDeleteBox

func (*Dispatch) GuildRoleUpdateChan

func (d *Dispatch) GuildRoleUpdateChan() <-chan *GuildRoleUpdateBox

func (*Dispatch) GuildUpdateChan

func (d *Dispatch) GuildUpdateChan() <-chan *GuildUpdateBox

func (*Dispatch) MessageCreateChan

func (d *Dispatch) MessageCreateChan() <-chan *MessageCreateBox

func (*Dispatch) MessageDeleteBulkChan

func (d *Dispatch) MessageDeleteBulkChan() <-chan *MessageDeleteBulkBox

func (*Dispatch) MessageDeleteChan

func (d *Dispatch) MessageDeleteChan() <-chan *MessageDeleteBox

func (*Dispatch) MessageReactionAddChan

func (d *Dispatch) MessageReactionAddChan() <-chan *MessageReactionAddBox

func (*Dispatch) MessageReactionRemoveAllChan

func (d *Dispatch) MessageReactionRemoveAllChan() <-chan *MessageReactionRemoveAllBox

func (*Dispatch) MessageReactionRemoveChan

func (d *Dispatch) MessageReactionRemoveChan() <-chan *MessageReactionRemoveBox

func (*Dispatch) MessageUpdateChan

func (d *Dispatch) MessageUpdateChan() <-chan *MessageUpdateBox

func (*Dispatch) PresenceUpdateChan

func (d *Dispatch) PresenceUpdateChan() <-chan *PresenceUpdateBox

func (*Dispatch) ReadyChan

func (d *Dispatch) ReadyChan() <-chan *ReadyBox

func (*Dispatch) ResumedChan

func (d *Dispatch) ResumedChan() <-chan *ResumedBox

func (*Dispatch) TypingStartChan

func (d *Dispatch) TypingStartChan() <-chan *TypingStartBox

func (*Dispatch) UserUpdateChan

func (d *Dispatch) UserUpdateChan() <-chan *UserUpdateBox

func (*Dispatch) VoiceServerUpdateChan

func (d *Dispatch) VoiceServerUpdateChan() <-chan *VoiceServerUpdateBox

func (*Dispatch) VoiceStateUpdateChan

func (d *Dispatch) VoiceStateUpdateChan() <-chan *VoiceStateUpdateBox

func (*Dispatch) WebhooksUpdateChan

func (d *Dispatch) WebhooksUpdateChan() <-chan *WebhooksUpdateBox

type EventCallback

type EventCallback = func(session Session, box interface{})

type EvtDispatcher

type EvtDispatcher interface {
	AllChan() <-chan interface{} // any event
	ReadyChan() <-chan *ReadyBox
	ResumedChan() <-chan *ResumedBox
	ChannelCreateChan() <-chan *ChannelCreateBox
	ChannelUpdateChan() <-chan *ChannelUpdateBox
	ChannelDeleteChan() <-chan *ChannelDeleteBox
	ChannelPinsUpdateChan() <-chan *ChannelPinsUpdateBox
	GuildCreateChan() <-chan *GuildCreateBox
	GuildUpdateChan() <-chan *GuildUpdateBox
	GuildDeleteChan() <-chan *GuildDeleteBox
	GuildBanAddChan() <-chan *GuildBanAddBox
	GuildBanRemoveChan() <-chan *GuildBanRemoveBox
	GuildEmojisUpdateChan() <-chan *GuildEmojisUpdateBox
	GuildIntegrationsUpdateChan() <-chan *GuildIntegrationsUpdateBox
	GuildMemberAddChan() <-chan *GuildMemberAddBox
	GuildMemberRemoveChan() <-chan *GuildMemberRemoveBox
	GuildMemberUpdateChan() <-chan *GuildMemberUpdateBox
	GuildMembersChunkChan() <-chan *GuildMembersChunkBox
	GuildRoleUpdateChan() <-chan *GuildRoleUpdateBox
	GuildRoleCreateChan() <-chan *GuildRoleCreateBox
	GuildRoleDeleteChan() <-chan *GuildRoleDeleteBox
	MessageCreateChan() <-chan *MessageCreateBox
	MessageUpdateChan() <-chan *MessageUpdateBox
	MessageDeleteChan() <-chan *MessageDeleteBox
	MessageDeleteBulkChan() <-chan *MessageDeleteBulkBox
	MessageReactionAddChan() <-chan *MessageReactionAddBox
	MessageReactionRemoveChan() <-chan *MessageReactionRemoveBox
	MessageReactionRemoveAllChan() <-chan *MessageReactionRemoveAllBox
	PresenceUpdateChan() <-chan *PresenceUpdateBox
	TypingStartChan() <-chan *TypingStartBox
	UserUpdateChan() <-chan *UserUpdateBox
	VoiceStateUpdateChan() <-chan *VoiceStateUpdateBox
	VoiceServerUpdateChan() <-chan *VoiceServerUpdateBox
	WebhooksUpdateChan() <-chan *WebhooksUpdateBox

	AddHandler(evtName string, listener interface{})
	AddHandlerOnce(evtName string, listener interface{})
}

type GuildBanAddCallback

type GuildBanAddCallback = func(session Session, gba *GuildBanAddBox)

type GuildBanRemoveCallback

type GuildBanRemoveCallback = func(session Session, gbr *GuildBanRemoveBox)

type GuildCreateCallback

type GuildCreateCallback = func(session Session, gc *GuildCreateBox)

Guild in general

type GuildDeleteCallback

type GuildDeleteCallback = func(session Session, gd *GuildDeleteBox)

type GuildEmojisUpdateCallback

type GuildEmojisUpdateCallback = func(session Session, geu *GuildEmojisUpdateBox)

type GuildIntegrationsUpdateCallback

type GuildIntegrationsUpdateCallback = func(session Session, giu *GuildIntegrationsUpdateBox)

type GuildMemberAddCallback

type GuildMemberAddCallback = func(session Session, gma *GuildMemberAddBox)

Guild Member

type GuildMemberRemoveCallback

type GuildMemberRemoveCallback = func(session Session, gmr *GuildMemberRemoveBox)

type GuildMemberUpdateCallback

type GuildMemberUpdateCallback = func(session Session, gmu *GuildMemberUpdateBox)

type GuildMembersChunkCallback

type GuildMembersChunkCallback = func(session Session, gmc *GuildMembersChunkBox)

type GuildRoleCreateCallback

type GuildRoleCreateCallback = func(session Session, grc *GuildRoleCreateBox)

Guild role

type GuildRoleDeleteCallback

type GuildRoleDeleteCallback = func(session Session, grd *GuildRoleDeleteBox)

type GuildRoleUpdateCallback

type GuildRoleUpdateCallback = func(session Session, gru *GuildRoleUpdateBox)

type GuildUpdateCallback

type GuildUpdateCallback = func(session Session, gu *GuildUpdateBox)

type HelloCallback

type HelloCallback = func(session Session, h *HelloBox)

socket

type InvalidSessionCallback

type InvalidSessionCallback = func(session Session, is *InvalidSessionBox)

type MessageCreateCallback

type MessageCreateCallback = func(session Session, mc *MessageCreateBox)

message

type MessageDeleteBulkCallback

type MessageDeleteBulkCallback = func(session Session, mdb *MessageDeleteBulkBox)

type MessageDeleteCallback

type MessageDeleteCallback = func(session Session, md *MessageDeleteBox)

type MessageReactionAddCallback

type MessageReactionAddCallback = func(session Session, mra *MessageReactionAddBox)

message reaction

type MessageReactionRemoveAllCallback

type MessageReactionRemoveAllCallback = func(session Session, mrra *MessageReactionRemoveAllBox)

type MessageReactionRemoveCallback

type MessageReactionRemoveCallback = func(session Session, mrr *MessageReactionRemoveBox)

type MessageUpdateCallback

type MessageUpdateCallback = func(session Session, mu *MessageUpdateBox)

type PresenceUpdateCallback

type PresenceUpdateCallback = func(session Session, pu *PresenceUpdateBox)

presence

type ReadyCallback

type ReadyCallback = func(session Session, r *ReadyBox)

type ResumedCallback

type ResumedCallback = func(session Session, r *ResumedBox)

type Session

type Session interface {

	// Request For interacting with Discord. Sending messages, creating channels, guilds, etc.
	// To read object state such as guilds, State() should be used in stead. However some data
	// might not exist in the state. If so it should be requested. Note that this only holds http
	// CRUD operation and not the actual rest endpoints for discord (See Rest()).
	Req() httd.Requester

	// Event let's developers listen for specific events, event groups, or every event as one listener.
	// Supports both channels and callbacks
	Evt() EvtDispatcher

	// State reflects the latest changes received from Discord gateway.
	// Should be used instead of requesting objects.
	State() state.Cacher

	// RateLimiter the ratelimiter for the discord REST API
	RateLimiter() httd.RateLimiter

	// Discord Gateway, web socket
	//
	Connect() error
	Disconnect() error

	// event callbacks
	AddListener(evtName string, callback interface{})
	AddListenerOnce(evtName string, callback interface{})

	// all discord REST functions
	// TODO: support caching for each
	// Audit-log
	GetGuildAuditLogs(guildID Snowflake, params *rest.AuditLogParams) (log *resource.AuditLog, err error)
	// Channel
	GetChannel(id Snowflake) (ret *resource.Channel, err error)
	ModifyChannel(changes *rest.ModifyChannelParams) (ret *resource.Channel, err error)
	DeleteChannel(id Snowflake) (err error)
	EditChannelPermissions(chanID, overwriteID Snowflake, params *rest.EditChannelPermissionsParams) (err error)
	GetChannelInvites(id Snowflake) (ret []*resource.Invite, err error)
	CreateChannelInvites(id Snowflake, params *rest.CreateChannelInvitesParams) (ret *resource.Invite, err error)
	DeleteChannelPermission(channelID, overwriteID Snowflake) (err error)
	TriggerTypingIndicator(channelID Snowflake) (err error)
	GetPinnedMessages(channelID Snowflake) (ret []*resource.Message, err error)
	AddPinnedChannelMessage(channelID, msgID Snowflake) (err error)
	DeletePinnedChannelMessage(channelID, msgID Snowflake) (err error)
	GroupDMAddRecipient(channelID, userID Snowflake, params *rest.GroupDMAddRecipientParams) (err error)
	GroupDMRemoveRecipient(channelID, userID Snowflake) (err error)
	GetChannelMessages(channelID Snowflake, params rest.URLParameters) (ret []*resource.Message, err error)
	GetChannelMessage(channelID, messageID Snowflake) (ret *resource.Message, err error)
	CreateChannelMessage(channelID Snowflake, params *rest.CreateMessageParams) (ret *resource.Message, err error)
	EditMessage(chanID, msgID Snowflake, params *rest.EditMessageParams) (ret *resource.Message, err error)
	DeleteMessage(channelID, msgID Snowflake) (err error)
	BulkDeleteMessages(chanID Snowflake, params *rest.BulkDeleteMessagesParams) (err error)
	CreateReaction(channelID, messageID Snowflake, emoji interface{}) (ret *resource.Reaction, err error)
	DeleteOwnReaction(channelID, messageID Snowflake, emoji interface{}) (err error)
	DeleteUserReaction(channelID, messageID, userID Snowflake, emoji interface{}) (err error)
	GetReaction(channelID, messageID Snowflake, emoji interface{}, params rest.URLParameters) (ret []*resource.User, err error)
	DeleteAllReactions(channelID, messageID Snowflake) (err error)
	// Emoji
	GetGuildEmojis(id Snowflake) (ret []*resource.Emoji, err error)
	GetGuildEmoji(guildID, emojiID Snowflake) (ret *resource.Emoji, err error)
	CreateGuildEmoji(guildID Snowflake) (ret *resource.Emoji, err error)
	ModifyGuildEmoji(guildID, emojiID Snowflake) (ret *resource.Emoji, err error)
	DeleteGuildEmoji(guildID, emojiID Snowflake) (err error)
	// Guild
	CreateGuild(params *rest.CreateGuildParams) (ret *resource.Guild, err error)
	GetGuild(id Snowflake) (ret *resource.Guild, err error)
	ModifyGuild(id Snowflake, params *rest.ModifyGuildParams) (ret *resource.Guild, err error)
	DeleteGuild(id Snowflake) (err error)
	GetGuildChannels(id Snowflake) (ret []*resource.Channel, err error)
	CreateGuildChannel(id Snowflake, params *rest.CreateGuildChannelParams) (ret *resource.Channel, err error)
	GetGuildMember(guildID, userID Snowflake) (ret *resource.Member, err error)
	GetGuildMembers(guildID, after Snowflake, limit int) (ret []*resource.Member, err error)
	AddGuildMember(guildID, userID Snowflake, params *rest.AddGuildMemberParams) (ret *resource.Member, err error)
	ModifyGuildMember(guildID, userID Snowflake, params *rest.ModifyGuildMemberParams) (err error)
	ModifyCurrentUserNick(id Snowflake, params *rest.ModifyCurrentUserNickParams) (nick string, err error)
	AddGuildMemberRole(guildID, userID, roleID Snowflake) (err error)
	RemoveGuildMemberRole(guildID, userID, roleID Snowflake) (err error)
	RemoveGuildMember(guildID, userID Snowflake) (err error)
	GetGuildBans(id Snowflake) (ret []*resource.Ban, err error)
	GetGuildBan(guildID, userID Snowflake) (ret *resource.Ban, err error)
	CreateGuildBan(guildID, userID Snowflake, params *rest.CreateGuildBanParams) (err error)
	RemoveGuildBan(guildID, userID Snowflake) (err error)
	GetGuildRoles(guildID Snowflake) (ret []*resource.Role, err error)
	CreateGuildRole(id Snowflake, params *rest.CreateGuildRoleParams) (ret *resource.Role, err error)
	ModifyGuildRolePositions(guildID Snowflake, params *rest.ModifyGuildRolePositionsParams) (ret []*resource.Role, err error)
	ModifyGuildRole(guildID, roleID Snowflake, params *rest.ModifyGuildRoleParams) (ret []*resource.Role, err error)
	DeleteGuildRole(guildID, roleID Snowflake) (err error)
	GetGuildPruneCount(id Snowflake, params *rest.GuildPruneParams) (ret *resource.GuildPruneCount, err error)
	BeginGuildPrune(id Snowflake, params *rest.GuildPruneParams) (ret *resource.GuildPruneCount, err error)
	GetGuildVoiceRegions(id Snowflake) (ret []*resource.VoiceRegion, err error)
	GetGuildInvites(id Snowflake) (ret []*resource.Invite, err error)
	GetGuildIntegrations(id Snowflake) (ret []*resource.Integration, err error)
	CreateGuildIntegration(guildID Snowflake, params *rest.CreateGuildIntegrationParams) (err error)
	ModifyGuildIntegration(guildID, integrationID Snowflake, params *rest.ModifyGuildIntegrationParams) (err error)
	DeleteGuildIntegration(guildID, integrationID Snowflake) (err error)
	SyncGuildIntegration(guildID, integrationID Snowflake) (err error)
	GetGuildEmbed(guildID Snowflake) (ret *resource.GuildEmbed, err error)
	ModifyGuildEmbed(guildID Snowflake, params *resource.GuildEmbed) (ret *resource.GuildEmbed, err error)
	GetGuildVanityURL(guildID Snowflake) (ret *resource.PartialInvite, err error)
	// Invite
	GetInvite(inviteCode string, withCounts bool) (invite *resource.Invite, err error)
	DeleteInvite(inviteCode string) (invite *resource.Invite, err error)
	// User
	GetCurrentUser() (ret *resource.User, err error)
	GetUser(id Snowflake) (ret *resource.User, err error)
	ModifyCurrentUser(params *rest.ModifyCurrentUserParams) (ret *resource.User, err error)
	GetCurrentUserGuilds(params *rest.GetCurrentUserGuildsParams) (ret []*resource.Guild, err error)
	LeaveGuild(id Snowflake) (err error)
	GetUserDMs() (ret []*resource.Channel, err error)
	CreateDM(recipientID Snowflake) (ret *resource.Channel, err error)
	CreateGroupDM(params *rest.CreateGroupDMParams) (ret *resource.Channel, err error)
	GetUserConnections() (ret []*resource.UserConnection, err error)
	// Voice
	GetVoiceRegions() (ret []*resource.VoiceRegion, err error)
	// Webhook
	CreateWebhook(channelID Snowflake, params *rest.CreateWebhookParams) (ret *resource.Webhook, err error)
	GetChannelWebhooks(channelID Snowflake) (ret []*resource.Webhook, err error)
	GetGuildWebhooks(guildID Snowflake) (ret []*resource.Webhook, err error)
	GetWebhook(id Snowflake) (ret *resource.Webhook, err error)
	GetWebhookWithToken(id Snowflake, token string) (ret *resource.Webhook, err error)
	ModifyWebhook(newWebhook *resource.Webhook) (ret *resource.Webhook, err error)
	ModifyWebhookWithToken(newWebhook *resource.Webhook) (ret *resource.Webhook, err error)
	DeleteWebhook(webhookID Snowflake) (err error)
	DeleteWebhookWithToken(id Snowflake, token string) (err error)
	ExecuteWebhook(params *rest.ExecuteWebhookParams, wait bool, URLSuffix string) (err error)
	ExecuteSlackWebhook(params *rest.ExecuteWebhookParams, wait bool) (err error)
	ExecuteGitHubWebhook(params *rest.ExecuteWebhookParams, wait bool) (err error)

	// same as above. Except these returns a channel
	// WARNING: none below should be assumed to be working.
	GuildChan(guildID Snowflake) <-chan *resource.Guild
	ChannelChan(channelID Snowflake) <-chan *resource.Channel
	ChannelsChan(guildID Snowflake) <-chan map[Snowflake]*resource.Channel
	MsgChan(msgID Snowflake) <-chan *resource.Message
	UserChan(userID Snowflake) <-chan *UserChan
	MemberChan(guildID, userID Snowflake) <-chan *resource.Member
	MembersChan(guildID Snowflake) <-chan map[Snowflake]*resource.Member
}

Session the discord api is split in two. socket for keeping the client up to date, and http api for requests.

func NewSession

func NewSession(conf *Config) (Session, error)

func NewSessionMustCompile

func NewSessionMustCompile(conf *Config) Session

type TypingStartCallback

type TypingStartCallback = func(session Session, ts *TypingStartBox)

typing start

type UserChan

type UserChan struct {
	User  *resource.User
	Err   error
	Cache bool
}

type UserUpdateCallback

type UserUpdateCallback = func(session Session, uu *UserUpdateBox)

user update

type VoiceServerUpdateCallback

type VoiceServerUpdateCallback = func(session Session, vsu *VoiceServerUpdateBox)

type VoiceStateUpdateCallback

type VoiceStateUpdateCallback = func(session Session, vsu *VoiceStateUpdateBox)

voice

type WebhooksUpdateCallback

type WebhooksUpdateCallback = func(session Session, wu *WebhooksUpdateBox)

webhook

Directories

Path Synopsis
Package description
Package description
resource ...
resource ...
endpoint
endpoint holds all discord urls for the REST endpoints
endpoint holds all discord urls for the REST endpoints

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL