Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
iopred committed Nov 2, 2018
2 parents 73f6772 + a040eae commit efc0516
Show file tree
Hide file tree
Showing 19 changed files with 851 additions and 200 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
language: go
go:
- 1.7.x
- 1.8.x
- 1.9.x
- 1.10.x
- 1.11.x
install:
- go get github.com/bwmarrin/discordgo
- go get -v .
- go get -v github.com/golang/lint/golint
- go get -v golang.org/x/lint/golint
script:
- diff <(gofmt -d .) <(echo -n)
- go vet -x ./...
Expand Down
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# DiscordGo
# DiscordGo

[![GoDoc](https://godoc.org/github.com/bwmarrin/discordgo?status.svg)](https://godoc.org/github.com/bwmarrin/discordgo) [![Go report](http://goreportcard.com/badge/bwmarrin/discordgo)](http://goreportcard.com/report/bwmarrin/discordgo) [![Build Status](https://travis-ci.org/bwmarrin/discordgo.svg?branch=master)](https://travis-ci.org/bwmarrin/discordgo) [![Discord Gophers](https://img.shields.io/badge/Discord%20Gophers-%23discordgo-blue.svg)](https://discord.gg/0f1SbxBZjYoCtNPP) [![Discord API](https://img.shields.io/badge/Discord%20API-%23go_discordgo-blue.svg)](https://discord.gg/0SBTUU1wZTWT6sqd)

Expand All @@ -15,11 +15,11 @@ to add the official DiscordGo test bot **dgo** to your server. This provides
indispensable help to this project.

* See [dgVoice](https://github.com/bwmarrin/dgvoice) package for an example of
additional voice helper functions and features for DiscordGo
additional voice helper functions and features for DiscordGo.

* See [dca](https://github.com/bwmarrin/dca) for an **experimental** stand alone
tool that wraps `ffmpeg` to create opus encoded audio appropriate for use with
Discord (and DiscordGo)
Discord (and DiscordGo).

**For help with this package or general Go discussion, please join the [Discord
Gophers](https://discord.gg/0f1SbxBZjYq9jLBk) chat server.**
Expand All @@ -39,9 +39,9 @@ the breaking changes get documented before pushing to master.

*So, what should you use?*

If you can accept the constant changing nature of *develop* then it is the
If you can accept the constant changing nature of *develop*, it is the
recommended branch to use. Otherwise, if you want to tail behind development
slightly and have a more stable package with documented releases then use *master*
slightly and have a more stable package with documented releases, use *master*.

### Installing

Expand Down Expand Up @@ -96,10 +96,10 @@ that information in a nice format.
## Examples

Below is a list of examples and other projects using DiscordGo. Please submit
an issue if you would like your project added or removed from this list
an issue if you would like your project added or removed from this list.

- [DiscordGo Examples](https://github.com/bwmarrin/discordgo/tree/master/examples) A collection of example programs written with DiscordGo
- [Awesome DiscordGo](https://github.com/bwmarrin/discordgo/wiki/Awesome-DiscordGo) A curated list of high quality projects using DiscordGo
- [DiscordGo Examples](https://github.com/bwmarrin/discordgo/tree/master/examples) - A collection of example programs written with DiscordGo
- [Awesome DiscordGo](https://github.com/bwmarrin/discordgo/wiki/Awesome-DiscordGo) - A curated list of high quality projects using DiscordGo

## Troubleshooting
For help with common problems please reference the
Expand All @@ -114,7 +114,7 @@ Contributions are very welcomed, however please follow the below guidelines.
discussed.
- Fork the develop branch and make your changes.
- Try to match current naming conventions as closely as possible.
- This package is intended to be a low level direct mapping of the Discord API
- This package is intended to be a low level direct mapping of the Discord API,
so please avoid adding enhancements outside of that scope without first
discussing it.
- Create a Pull Request with your changes against the develop branch.
Expand All @@ -127,4 +127,4 @@ comparison and list of other Discord API libraries.

## Special Thanks

[Chris Rhodes](https://github.com/iopred) - For the DiscordGo logo and tons of PRs
[Chris Rhodes](https://github.com/iopred) - For the DiscordGo logo and tons of PRs.
4 changes: 2 additions & 2 deletions discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
// license that can be found in the LICENSE file.

// This file contains high level helper functions and easy entry points for the
// entire discordgo package. These functions are beling developed and are very
// experimental at this point. They will most likley change so please use the
// entire discordgo package. These functions are being developed and are very
// experimental at this point. They will most likely change so please use the
// low level functions if that's a problem.

// Package discordgo provides Discord binding for Go
Expand Down
28 changes: 19 additions & 9 deletions endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

package discordgo

import "strconv"

// APIVersion is the Discord API version used for the REST and Websocket API.
var APIVersion = "6"

Expand Down Expand Up @@ -61,14 +63,18 @@ var (
EndpointUser = func(uID string) string { return EndpointUsers + uID }
EndpointUserAvatar = func(uID, aID string) string { return EndpointCDNAvatars + uID + "/" + aID + ".png" }
EndpointUserAvatarAnimated = func(uID, aID string) string { return EndpointCDNAvatars + uID + "/" + aID + ".gif" }
EndpointUserSettings = func(uID string) string { return EndpointUsers + uID + "/settings" }
EndpointUserGuilds = func(uID string) string { return EndpointUsers + uID + "/guilds" }
EndpointUserGuild = func(uID, gID string) string { return EndpointUsers + uID + "/guilds/" + gID }
EndpointUserGuildSettings = func(uID, gID string) string { return EndpointUsers + uID + "/guilds/" + gID + "/settings" }
EndpointUserChannels = func(uID string) string { return EndpointUsers + uID + "/channels" }
EndpointUserDevices = func(uID string) string { return EndpointUsers + uID + "/devices" }
EndpointUserConnections = func(uID string) string { return EndpointUsers + uID + "/connections" }
EndpointUserNotes = func(uID string) string { return EndpointUsers + "@me/notes/" + uID }
EndpointDefaultUserAvatar = func(uDiscriminator string) string {
uDiscriminatorInt, _ := strconv.Atoi(uDiscriminator)
return EndpointCDN + "embed/avatars/" + strconv.Itoa(uDiscriminatorInt%5) + ".png"
}
EndpointUserSettings = func(uID string) string { return EndpointUsers + uID + "/settings" }
EndpointUserGuilds = func(uID string) string { return EndpointUsers + uID + "/guilds" }
EndpointUserGuild = func(uID, gID string) string { return EndpointUsers + uID + "/guilds/" + gID }
EndpointUserGuildSettings = func(uID, gID string) string { return EndpointUsers + uID + "/guilds/" + gID + "/settings" }
EndpointUserChannels = func(uID string) string { return EndpointUsers + uID + "/channels" }
EndpointUserDevices = func(uID string) string { return EndpointUsers + uID + "/devices" }
EndpointUserConnections = func(uID string) string { return EndpointUsers + uID + "/connections" }
EndpointUserNotes = func(uID string) string { return EndpointUsers + "@me/notes/" + uID }

EndpointGuild = func(gID string) string { return EndpointGuilds + gID }
EndpointGuildChannels = func(gID string) string { return EndpointGuilds + gID + "/channels" }
Expand All @@ -88,6 +94,9 @@ var (
EndpointGuildIcon = func(gID, hash string) string { return EndpointCDNIcons + gID + "/" + hash + ".png" }
EndpointGuildSplash = func(gID, hash string) string { return EndpointCDNSplashes + gID + "/" + hash + ".png" }
EndpointGuildWebhooks = func(gID string) string { return EndpointGuilds + gID + "/webhooks" }
EndpointGuildAuditLogs = func(gID string) string { return EndpointGuilds + gID + "/audit-logs" }
EndpointGuildEmojis = func(gID string) string { return EndpointGuilds + gID + "/emojis" }
EndpointGuildEmoji = func(gID, eID string) string { return EndpointGuilds + gID + "/emojis/" + eID }

EndpointChannel = func(cID string) string { return EndpointChannels + cID }
EndpointChannelPermissions = func(cID string) string { return EndpointChannels + cID + "/permissions" }
Expand Down Expand Up @@ -127,7 +136,8 @@ var (

EndpointIntegrationsJoin = func(iID string) string { return EndpointAPI + "integrations/" + iID + "/join" }

EndpointEmoji = func(eID string) string { return EndpointAPI + "emojis/" + eID + ".png" }
EndpointEmoji = func(eID string) string { return EndpointAPI + "emojis/" + eID + ".png" }
EndpointEmojiAnimated = func(eID string) string { return EndpointAPI + "emojis/" + eID + ".gif" }

EndpointOauth2 = EndpointAPI + "oauth2/"
EndpointApplications = EndpointOauth2 + "applications"
Expand Down
11 changes: 10 additions & 1 deletion event.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,23 @@ func (s *Session) addEventHandlerOnce(eventHandler EventHandler) func() {

// AddHandler allows you to add an event handler that will be fired anytime
// the Discord WSAPI event that matches the function fires.
// events.go contains all the Discord WSAPI events that can be fired.
// The first parameter is a *Session, and the second parameter is a pointer
// to a struct corresponding to the event for which you want to listen.
//
// eg:
// Session.AddHandler(func(s *discordgo.Session, m *discordgo.MessageCreate) {
// })
//
// or:
// Session.AddHandler(func(s *discordgo.Session, m *discordgo.PresenceUpdate) {
// })
//
// List of events can be found at this page, with corresponding names in the
// library for each event: https://discordapp.com/developers/docs/topics/gateway#event-names
// There are also synthetic events fired by the library internally which are
// available for handling, like Connect, Disconnect, and RateLimit.
// events.go contains all of the Discord WSAPI and synthetic events that can be handled.
//
// The return value of this method is a function, that when called will remove the
// event handler.
func (s *Session) AddHandler(handler interface{}) func() {
Expand Down
24 changes: 24 additions & 0 deletions eventhandlers.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type ChannelDelete struct {
type ChannelPinsUpdate struct {
LastPinTimestamp string `json:"last_pin_timestamp"`
ChannelID string `json:"channel_id"`
GuildID string `json:"guild_id,omitempty"`
}

// GuildCreate is the data for a GuildCreate event.
Expand Down Expand Up @@ -212,6 +213,7 @@ type RelationshipRemove struct {
type TypingStart struct {
UserID string `json:"user_id"`
ChannelID string `json:"channel_id"`
GuildID string `json:"guild_id,omitempty"`
Timestamp int `json:"timestamp"`
}

Expand Down Expand Up @@ -250,4 +252,11 @@ type VoiceStateUpdate struct {
type MessageDeleteBulk struct {
Messages []string `json:"ids"`
ChannelID string `json:"channel_id"`
GuildID string `json:"guild_id"`
}

// WebhooksUpdate is the data for a WebhooksUpdate event
type WebhooksUpdate struct {
GuildID string `json:"guild_id"`
ChannelID string `json:"channel_id"`
}
6 changes: 6 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module github.com/bwmarrin/discordgo

require (
github.com/gorilla/websocket v1.4.0
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/gorilla/websocket v1.4.0 h1:WDFjx/TMzVgy9VdMMQi2K2Emtwi2QcUQsztZ/zLaH/Q=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16 h1:y6ce7gCWtnH+m3dCjzQ1PCuwl28DDIc3VNnvY29DlIA=
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
69 changes: 54 additions & 15 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,20 +32,59 @@ const (

// A Message stores all data related to a specific Discord message.
type Message struct {
ID string `json:"id"`
ChannelID string `json:"channel_id"`
Content string `json:"content"`
Timestamp Timestamp `json:"timestamp"`
EditedTimestamp Timestamp `json:"edited_timestamp"`
MentionRoles []string `json:"mention_roles"`
Tts bool `json:"tts"`
MentionEveryone bool `json:"mention_everyone"`
Author *User `json:"author"`
Attachments []*MessageAttachment `json:"attachments"`
Embeds []*MessageEmbed `json:"embeds"`
Mentions []*User `json:"mentions"`
Reactions []*MessageReactions `json:"reactions"`
Type MessageType `json:"type"`
// The ID of the message.
ID string `json:"id"`

// The ID of the channel in which the message was sent.
ChannelID string `json:"channel_id"`

// The ID of the guild in which the message was sent.
GuildID string `json:"guild_id,omitempty"`

// The content of the message.
Content string `json:"content"`

// The time at which the messsage was sent.
// CAUTION: this field may be removed in a
// future API version; it is safer to calculate
// the creation time via the ID.
Timestamp Timestamp `json:"timestamp"`

// The time at which the last edit of the message
// occurred, if it has been edited.
EditedTimestamp Timestamp `json:"edited_timestamp"`

// The roles mentioned in the message.
MentionRoles []string `json:"mention_roles"`

// Whether the message is text-to-speech.
Tts bool `json:"tts"`

// Whether the message mentions everyone.
MentionEveryone bool `json:"mention_everyone"`

// The author of the message. This is not guaranteed to be a
// valid user (webhook-sent messages do not possess a full author).
Author *User `json:"author"`

// A list of attachments present in the message.
Attachments []*MessageAttachment `json:"attachments"`

// A list of embeds present in the message. Multiple
// embeds can currently only be sent by webhooks.
Embeds []*MessageEmbed `json:"embeds"`

// A list of users mentioned in the message.
Mentions []*User `json:"mentions"`

// A list of reactions to the message.
Reactions []*MessageReactions `json:"reactions"`

// The type of the message.
Type MessageType `json:"type"`

// The webhook ID of the message, if it was generated by a webhook
WebhookID string `json:"webhook_id"`
}

// File stores info about files you e.g. send in messages.
Expand Down Expand Up @@ -237,7 +276,7 @@ func (m *Message) ContentWithMoreMentionsReplaced(s *Session) (content string, e
continue
}

content = strings.Replace(content, "<&"+role.ID+">", "@"+role.Name, -1)
content = strings.Replace(content, "<@&"+role.ID+">", "@"+role.Name, -1)
}

content = patternChannels.ReplaceAllStringFunc(content, func(mention string) string {
Expand Down
3 changes: 1 addition & 2 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ func TestContentWithMoreMentionsReplaced(t *testing.T) {
Username: "User Name",
}

s.StateEnabled = true
s.State.GuildAdd(&Guild{ID: "guild"})
s.State.RoleAdd("guild", &Role{
ID: "role",
Expand All @@ -30,7 +29,7 @@ func TestContentWithMoreMentionsReplaced(t *testing.T) {
ID: "channel",
})
m := &Message{
Content: "<&role> <@!user> <@user> <#channel>",
Content: "<@&role> <@!user> <@user> <#channel>",
ChannelID: "channel",
MentionRoles: []string{"role"},
Mentions: []*User{user},
Expand Down
2 changes: 1 addition & 1 deletion oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func ExampleApplication() {

// Authentication Token pulled from environment variable DG_TOKEN
// Authentication Token pulled from environment variable DGU_TOKEN
Token := os.Getenv("DGU_TOKEN")
if Token == "" {
return
Expand Down
Loading

0 comments on commit efc0516

Please sign in to comment.