Some improvements to comments.

This commit is contained in:
Bruce Marriner 2015-11-23 09:45:40 -06:00
parent 10044d50e8
commit abe55ecca7
6 changed files with 135 additions and 99 deletions

View file

@ -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
// All known Discord endpoints.
// Please let me know if you know of any others.
var (
STATUS = "https://status.discordapp.com/api/v2/"
SM = STATUS + "scheduled-maintenances/"

View file

@ -1,10 +1,12 @@
/******************************************************************************
* A Discord API for Golang.
* See discord.go for more information.
*
* This file contains functions for interacting with the Discord HTTP REST API
* at the lowest level.
*/
// 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 functions for interacting with the Discord REST/JSON API
// at the lowest level.
package discordgo
@ -60,9 +62,9 @@ func (s *Session) Request(method, urlStr, body string) (response []byte, err err
return
}
/***************************************************************************************************
* Functions specific to this session.
*/
// ------------------------------------------------------------------------------------------------
// Functions specific to Discord Sessions
// ------------------------------------------------------------------------------------------------
// Login asks the Discord server for an authentication token
func (s *Session) Login(email string, password string) (token string, err error) {
@ -85,9 +87,9 @@ func (s *Session) Logout() (err error) {
return
}
/***************************************************************************************************
* Functions related to a specific user
*/
// ------------------------------------------------------------------------------------------------
// Functions specific to Discord Users
// ------------------------------------------------------------------------------------------------
// User returns the user details of the given userID
// 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
}
/***************************************************************************************************
* Functions related to a specific guild
*/
// ------------------------------------------------------------------------------------------------
// Functions specific to Discord Guilds
// ------------------------------------------------------------------------------------------------
// Guild returns a Guild structure of a specific Guild.
// guildID : The ID of a Guild
@ -285,9 +287,9 @@ func (s *Session) GuildInviteCreate(guildID string, i Invite) (st Invite, err er
return
}
/***************************************************************************************************
* Functions related to a specific channel
*/
// ------------------------------------------------------------------------------------------------
// Functions specific to Discord Channels
// ------------------------------------------------------------------------------------------------
// Channel returns a Channel strucutre of a specific Channel.
// 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
}
/***************************************************************************************************
* Functions related to an invite
*/
// ------------------------------------------------------------------------------------------------
// Functions specific to Discord Invites
// ------------------------------------------------------------------------------------------------
// Invite returns an Invite structure of the given invite
// inviteID : The invite code (or maybe xkcdpass?)
@ -449,9 +451,9 @@ func (s *Session) InviteAccept(inviteID string) (st Invite, err error) {
return
}
/***************************************************************************************************
* Functions related to Voice/Audio
*/
// ------------------------------------------------------------------------------------------------
// Functions specific to Discord Voice
// ------------------------------------------------------------------------------------------------
// VoiceRegions returns the voice server regions
func (s *Session) VoiceRegions() (st []VoiceRegion, err error) {
@ -469,9 +471,9 @@ func (s *Session) VoiceICE() (st VoiceICE, err error) {
return
}
/***************************************************************************************************
* Functions related to Websockets
*/
// ------------------------------------------------------------------------------------------------
// Functions specific to Discord Websockets
// ------------------------------------------------------------------------------------------------
// Gateway returns the a websocket Gateway address
func (s *Session) Gateway() (gateway string, err error) {

View file

@ -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
import (
@ -8,7 +19,59 @@ import (
"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.
type Message struct {
@ -152,60 +215,6 @@ type Member struct {
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.
type User struct {
ID string `json:"id"`
@ -216,6 +225,7 @@ type User struct {
//Discriminator int `json:"discriminator,string"` // TODO: See below
}
// TODO: Research issue.
// Discriminator sometimes comes as a string
// and sometimes it comes as a int. Weird.
// to avoid errors I've just commented it out
@ -265,9 +275,6 @@ type Ready struct {
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.
type ReadState struct {
MentionCount int

12
util.go
View file

@ -1,5 +1,13 @@
// this file has small funcs used without the pacakge
// or, one.. util, maybe I'll have more later :)
// 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 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

View file

@ -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.
// these structs and functions setup a voice websocket and
// create the voice UDP connection.
package discordgo

View file

@ -1,10 +1,12 @@
/******************************************************************************
* A Discord API for Golang.
* See discord.go for more information.
*
* This file contains low level functions for interacting
* with the Discord Websocket interface.
*/
// 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 low level functions for interacting with the Discord
// data websocket interface.
package discordgo