forked from pothtonswer/discordmuffin
Some improvements to comments.
This commit is contained in:
parent
10044d50e8
commit
abe55ecca7
6 changed files with 135 additions and 99 deletions
13
endpoints.go
13
endpoints.go
|
@ -1,7 +1,16 @@
|
||||||
|
// Discordgo - Go bindings for Discord
|
||||||
|
// Available at https://github.com/bwmarrin/discordgo
|
||||||
|
|
||||||
|
// Copyright 2015 Bruce Marriner <bruce@sqls.net>. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// This file contains variables for all known Discord end points. All functions
|
||||||
|
// throughout the discordgo package use these variables for all connections
|
||||||
|
// to Discord. These are all exported and you may modify them if needed.
|
||||||
|
|
||||||
package discordgo
|
package discordgo
|
||||||
|
|
||||||
// All known Discord endpoints.
|
|
||||||
// Please let me know if you know of any others.
|
|
||||||
var (
|
var (
|
||||||
STATUS = "https://status.discordapp.com/api/v2/"
|
STATUS = "https://status.discordapp.com/api/v2/"
|
||||||
SM = STATUS + "scheduled-maintenances/"
|
SM = STATUS + "scheduled-maintenances/"
|
||||||
|
|
58
restapi.go
58
restapi.go
|
@ -1,10 +1,12 @@
|
||||||
/******************************************************************************
|
// Discordgo - Go bindings for Discord
|
||||||
* A Discord API for Golang.
|
// Available at https://github.com/bwmarrin/discordgo
|
||||||
* See discord.go for more information.
|
|
||||||
*
|
// Copyright 2015 Bruce Marriner <bruce@sqls.net>. All rights reserved.
|
||||||
* This file contains functions for interacting with the Discord HTTP REST API
|
// Use of this source code is governed by a BSD-style
|
||||||
* at the lowest level.
|
// license that can be found in the LICENSE file.
|
||||||
*/
|
|
||||||
|
// This file contains functions for interacting with the Discord REST/JSON API
|
||||||
|
// at the lowest level.
|
||||||
|
|
||||||
package discordgo
|
package discordgo
|
||||||
|
|
||||||
|
@ -60,9 +62,9 @@ func (s *Session) Request(method, urlStr, body string) (response []byte, err err
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************************************
|
// ------------------------------------------------------------------------------------------------
|
||||||
* Functions specific to this session.
|
// Functions specific to Discord Sessions
|
||||||
*/
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Login asks the Discord server for an authentication token
|
// Login asks the Discord server for an authentication token
|
||||||
func (s *Session) Login(email string, password string) (token string, err error) {
|
func (s *Session) Login(email string, password string) (token string, err error) {
|
||||||
|
@ -85,9 +87,9 @@ func (s *Session) Logout() (err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************************************
|
// ------------------------------------------------------------------------------------------------
|
||||||
* Functions related to a specific user
|
// Functions specific to Discord Users
|
||||||
*/
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// User returns the user details of the given userID
|
// User returns the user details of the given userID
|
||||||
// userID : A user ID or "@me" which is a shortcut of current user ID
|
// userID : A user ID or "@me" which is a shortcut of current user ID
|
||||||
|
@ -151,9 +153,9 @@ func (s *Session) UserGuilds(userID string) (st []Guild, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************************************
|
// ------------------------------------------------------------------------------------------------
|
||||||
* Functions related to a specific guild
|
// Functions specific to Discord Guilds
|
||||||
*/
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Guild returns a Guild structure of a specific Guild.
|
// Guild returns a Guild structure of a specific Guild.
|
||||||
// guildID : The ID of a Guild
|
// guildID : The ID of a Guild
|
||||||
|
@ -285,9 +287,9 @@ func (s *Session) GuildInviteCreate(guildID string, i Invite) (st Invite, err er
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************************************
|
// ------------------------------------------------------------------------------------------------
|
||||||
* Functions related to a specific channel
|
// Functions specific to Discord Channels
|
||||||
*/
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Channel returns a Channel strucutre of a specific Channel.
|
// Channel returns a Channel strucutre of a specific Channel.
|
||||||
// channelID : The ID of the Channel you want returend.
|
// channelID : The ID of the Channel you want returend.
|
||||||
|
@ -420,9 +422,9 @@ func (s *Session) ChannelInviteCreate(channelID string, i Invite) (st Invite, er
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************************************
|
// ------------------------------------------------------------------------------------------------
|
||||||
* Functions related to an invite
|
// Functions specific to Discord Invites
|
||||||
*/
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Invite returns an Invite structure of the given invite
|
// Invite returns an Invite structure of the given invite
|
||||||
// inviteID : The invite code (or maybe xkcdpass?)
|
// inviteID : The invite code (or maybe xkcdpass?)
|
||||||
|
@ -449,9 +451,9 @@ func (s *Session) InviteAccept(inviteID string) (st Invite, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************************************
|
// ------------------------------------------------------------------------------------------------
|
||||||
* Functions related to Voice/Audio
|
// Functions specific to Discord Voice
|
||||||
*/
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// VoiceRegions returns the voice server regions
|
// VoiceRegions returns the voice server regions
|
||||||
func (s *Session) VoiceRegions() (st []VoiceRegion, err error) {
|
func (s *Session) VoiceRegions() (st []VoiceRegion, err error) {
|
||||||
|
@ -469,9 +471,9 @@ func (s *Session) VoiceICE() (st VoiceICE, err error) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************************************
|
// ------------------------------------------------------------------------------------------------
|
||||||
* Functions related to Websockets
|
// Functions specific to Discord Websockets
|
||||||
*/
|
// ------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
// Gateway returns the a websocket Gateway address
|
// Gateway returns the a websocket Gateway address
|
||||||
func (s *Session) Gateway() (gateway string, err error) {
|
func (s *Session) Gateway() (gateway string, err error) {
|
||||||
|
|
123
structs.go
123
structs.go
|
@ -1,3 +1,14 @@
|
||||||
|
// Discordgo - Go bindings for Discord
|
||||||
|
// Available at https://github.com/bwmarrin/discordgo
|
||||||
|
|
||||||
|
// Copyright 2015 Bruce Marriner <bruce@sqls.net>. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// This file contains all structures for the discordgo package. These
|
||||||
|
// may be moved about later into seperate files but I find it easier to have
|
||||||
|
// them all located together.
|
||||||
|
|
||||||
package discordgo
|
package discordgo
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -8,7 +19,59 @@ import (
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
)
|
)
|
||||||
|
|
||||||
// TODO: Eventually everything here gets moved to a better place.
|
// A Session represents a connection to the Discord REST API.
|
||||||
|
// token : The authentication token returned from Discord
|
||||||
|
// Debug : If set to ture debug logging will be displayed.
|
||||||
|
type Session struct {
|
||||||
|
Token string // Authentication token for this session
|
||||||
|
Debug bool // Debug for printing JSON request/responses
|
||||||
|
Cache int // number in X to cache some responses
|
||||||
|
SessionID string // from websocket READY packet
|
||||||
|
|
||||||
|
// Settable Callback functions for Websocket Events
|
||||||
|
OnEvent func(*Session, Event) // should Event be *Event?
|
||||||
|
OnReady func(*Session, Ready)
|
||||||
|
OnTypingStart func(*Session, TypingStart)
|
||||||
|
OnMessageCreate func(*Session, Message)
|
||||||
|
OnMessageUpdate func(*Session, Message)
|
||||||
|
OnMessageDelete func(*Session, MessageDelete)
|
||||||
|
OnMessageAck func(*Session, MessageAck)
|
||||||
|
OnPresenceUpdate func(*Session, PresenceUpdate)
|
||||||
|
OnVoiceStateUpdate func(*Session, VoiceState)
|
||||||
|
OnChannelCreate func(*Session, Channel)
|
||||||
|
OnChannelUpdate func(*Session, Channel)
|
||||||
|
OnChannelDelete func(*Session, Channel)
|
||||||
|
OnGuildCreate func(*Session, Guild)
|
||||||
|
OnGuildUpdate func(*Session, Guild)
|
||||||
|
OnGuildDelete func(*Session, Guild)
|
||||||
|
OnGuildMemberAdd func(*Session, Member)
|
||||||
|
OnGuildMemberRemove func(*Session, Member)
|
||||||
|
OnGuildMemberDelete func(*Session, Member) // which is it?
|
||||||
|
OnGuildMemberUpdate func(*Session, Member)
|
||||||
|
OnGuildRoleCreate func(*Session, GuildRole)
|
||||||
|
OnGuildRoleUpdate func(*Session, GuildRole)
|
||||||
|
OnGuildRoleDelete func(*Session, GuildRoleDelete)
|
||||||
|
OnGuildIntegrationsUpdate func(*Session, GuildIntegrationsUpdate)
|
||||||
|
|
||||||
|
wsConn *websocket.Conn
|
||||||
|
//TODO, add bools for like.
|
||||||
|
// are we connnected to websocket?
|
||||||
|
// have we authenticated to login?
|
||||||
|
// lets put all the general session
|
||||||
|
// tracking and infos here.. clearly
|
||||||
|
|
||||||
|
// Everything below here is used for Voice testing.
|
||||||
|
// This stuff is almost guarenteed to change a lot
|
||||||
|
// and is even a bit hackish right now.
|
||||||
|
VwsConn *websocket.Conn // new for voice
|
||||||
|
VSessionID string
|
||||||
|
VToken string
|
||||||
|
VEndpoint string
|
||||||
|
VGuildID string
|
||||||
|
VChannelID string
|
||||||
|
Vop2 VoiceOP2
|
||||||
|
UDPConn *net.UDPConn
|
||||||
|
}
|
||||||
|
|
||||||
// A Message stores all data related to a specific Discord message.
|
// A Message stores all data related to a specific Discord message.
|
||||||
type Message struct {
|
type Message struct {
|
||||||
|
@ -152,60 +215,6 @@ type Member struct {
|
||||||
Roles []string `json:"roles"`
|
Roles []string `json:"roles"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Session represents a connection to the Discord REST API.
|
|
||||||
// token : The authentication token returned from Discord
|
|
||||||
// Debug : If set to ture debug logging will be displayed.
|
|
||||||
type Session struct {
|
|
||||||
Token string // Authentication token for this session
|
|
||||||
Debug bool // Debug for printing JSON request/responses
|
|
||||||
Cache int // number in X to cache some responses
|
|
||||||
SessionID string // from websocket READY packet
|
|
||||||
|
|
||||||
// Settable Callback functions for Websocket Events
|
|
||||||
OnEvent func(*Session, Event) // should Event be *Event?
|
|
||||||
OnReady func(*Session, Ready)
|
|
||||||
OnTypingStart func(*Session, TypingStart)
|
|
||||||
OnMessageCreate func(*Session, Message)
|
|
||||||
OnMessageUpdate func(*Session, Message)
|
|
||||||
OnMessageDelete func(*Session, MessageDelete)
|
|
||||||
OnMessageAck func(*Session, MessageAck)
|
|
||||||
OnPresenceUpdate func(*Session, PresenceUpdate)
|
|
||||||
OnVoiceStateUpdate func(*Session, VoiceState)
|
|
||||||
OnChannelCreate func(*Session, Channel)
|
|
||||||
OnChannelUpdate func(*Session, Channel)
|
|
||||||
OnChannelDelete func(*Session, Channel)
|
|
||||||
OnGuildCreate func(*Session, Guild)
|
|
||||||
OnGuildUpdate func(*Session, Guild)
|
|
||||||
OnGuildDelete func(*Session, Guild)
|
|
||||||
OnGuildMemberAdd func(*Session, Member)
|
|
||||||
OnGuildMemberRemove func(*Session, Member)
|
|
||||||
OnGuildMemberDelete func(*Session, Member) // which is it?
|
|
||||||
OnGuildMemberUpdate func(*Session, Member)
|
|
||||||
OnGuildRoleCreate func(*Session, GuildRole)
|
|
||||||
OnGuildRoleUpdate func(*Session, GuildRole)
|
|
||||||
OnGuildRoleDelete func(*Session, GuildRoleDelete)
|
|
||||||
OnGuildIntegrationsUpdate func(*Session, GuildIntegrationsUpdate)
|
|
||||||
|
|
||||||
wsConn *websocket.Conn
|
|
||||||
//TODO, add bools for like.
|
|
||||||
// are we connnected to websocket?
|
|
||||||
// have we authenticated to login?
|
|
||||||
// lets put all the general session
|
|
||||||
// tracking and infos here.. clearly
|
|
||||||
|
|
||||||
// Everything below here is used for Voice testing.
|
|
||||||
// This stuff is almost guarenteed to change a lot
|
|
||||||
// and is even a bit hackish right now.
|
|
||||||
VwsConn *websocket.Conn // new for voice
|
|
||||||
VSessionID string
|
|
||||||
VToken string
|
|
||||||
VEndpoint string
|
|
||||||
VGuildID string
|
|
||||||
VChannelID string
|
|
||||||
Vop2 VoiceOP2
|
|
||||||
UDPConn *net.UDPConn
|
|
||||||
}
|
|
||||||
|
|
||||||
// A User stores all data for an individual Discord user.
|
// A User stores all data for an individual Discord user.
|
||||||
type User struct {
|
type User struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
|
@ -216,6 +225,7 @@ type User struct {
|
||||||
//Discriminator int `json:"discriminator,string"` // TODO: See below
|
//Discriminator int `json:"discriminator,string"` // TODO: See below
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Research issue.
|
||||||
// Discriminator sometimes comes as a string
|
// Discriminator sometimes comes as a string
|
||||||
// and sometimes it comes as a int. Weird.
|
// and sometimes it comes as a int. Weird.
|
||||||
// to avoid errors I've just commented it out
|
// to avoid errors I've just commented it out
|
||||||
|
@ -265,9 +275,6 @@ type Ready struct {
|
||||||
Guilds []Guild
|
Guilds []Guild
|
||||||
}
|
}
|
||||||
|
|
||||||
// ReadState might need to move? Gives me the read status
|
|
||||||
// of all my channels when first connecting. I think :)
|
|
||||||
|
|
||||||
// A ReadState stores data on the read state of channels.
|
// A ReadState stores data on the read state of channels.
|
||||||
type ReadState struct {
|
type ReadState struct {
|
||||||
MentionCount int
|
MentionCount int
|
||||||
|
|
12
util.go
12
util.go
|
@ -1,5 +1,13 @@
|
||||||
// this file has small funcs used without the pacakge
|
// Discordgo - Go bindings for Discord
|
||||||
// or, one.. util, maybe I'll have more later :)
|
// Available at https://github.com/bwmarrin/discordgo
|
||||||
|
|
||||||
|
// Copyright 2015 Bruce Marriner <bruce@sqls.net>. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// This file contains utility functions for the discordgo package. These
|
||||||
|
// functions are not exported and are likely to change substantially in
|
||||||
|
// the future to match specific needs of the discordgo package itself.
|
||||||
|
|
||||||
package discordgo
|
package discordgo
|
||||||
|
|
||||||
|
|
12
voice.go
12
voice.go
|
@ -1,6 +1,14 @@
|
||||||
|
// Discordgo - Go bindings for Discord
|
||||||
|
// Available at https://github.com/bwmarrin/discordgo
|
||||||
|
|
||||||
|
// Copyright 2015 Bruce Marriner <bruce@sqls.net>. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
// This file contains experimental functions for interacting with the Discord
|
||||||
|
// Voice websocket and UDP connections.
|
||||||
|
//
|
||||||
// EVERYTHING in this file is very experimental and will change.
|
// EVERYTHING in this file is very experimental and will change.
|
||||||
// these structs and functions setup a voice websocket and
|
|
||||||
// create the voice UDP connection.
|
|
||||||
|
|
||||||
package discordgo
|
package discordgo
|
||||||
|
|
||||||
|
|
16
wsapi.go
16
wsapi.go
|
@ -1,10 +1,12 @@
|
||||||
/******************************************************************************
|
// Discordgo - Go bindings for Discord
|
||||||
* A Discord API for Golang.
|
// Available at https://github.com/bwmarrin/discordgo
|
||||||
* See discord.go for more information.
|
|
||||||
*
|
// Copyright 2015 Bruce Marriner <bruce@sqls.net>. All rights reserved.
|
||||||
* This file contains low level functions for interacting
|
// Use of this source code is governed by a BSD-style
|
||||||
* with the Discord Websocket interface.
|
// license that can be found in the LICENSE file.
|
||||||
*/
|
|
||||||
|
// This file contains low level functions for interacting with the Discord
|
||||||
|
// data websocket interface.
|
||||||
|
|
||||||
package discordgo
|
package discordgo
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue