Skip to content
This repository was archived by the owner on Mar 5, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
239 commits
Select commit Hold shift + click to select a range
fba1241
Merge branch 'retry' into yagpdb
jogramming Sep 20, 2016
d765aef
Add Owner bool and Permissions bits to guild struct
jogramming Sep 20, 2016
4841e21
Move token to its own SelfUser struct
jogramming Sep 20, 2016
3dcf17b
Track presences
jogramming Sep 22, 2016
7cd492d
Update everything presence
jogramming Sep 25, 2016
8b8ed7c
Merge branch 'msg-timestamps-missing' into yagpdb
jogramming Sep 25, 2016
f9bf9b9
Merge exising presences
jogramming Sep 25, 2016
58b5c61
Merge branch 'request-members' into yagpdb
jogramming Sep 25, 2016
c6a89a1
Merge branch 'develop' into yagpdb
jogramming Sep 28, 2016
4011f66
Merge branch 'develop' into yagpdb
jogramming Sep 30, 2016
1cf0ef2
Remove presence on MemberRemove
jogramming Sep 30, 2016
c8d2f97
Added function to retrieve presence
jogramming Sep 30, 2016
f3a7dfd
cant patch game
jogramming Oct 4, 2016
e54eb9f
Merge branch 'develop' into yagpdb
jogramming Oct 14, 2016
c315279
Merge branch 'develop' into yagpdb
jogramming Oct 17, 2016
0927a1d
Merge branch 'develop' into yagpdb
jogramming Nov 5, 2016
f74704e
Merge branch 'develop' into yagpdb
jogramming Nov 7, 2016
39fbbfe
patch memberadd
jogramming Nov 7, 2016
4ff0f4d
Merge branch 'develop' into yagpdb
jogramming Nov 18, 2016
0c0f504
Merge branch 'develop' into yagpdb
jogramming Nov 29, 2016
7d45e12
Merge branch 'develop' into yagpdb
jogramming Dec 1, 2016
f8dd4b5
Merge branch 'develop' into yagpdb
jogramming Dec 1, 2016
6e1805e
Stuff
jogramming Dec 10, 2016
5e9c3b5
Updated userguilds to new api
jogramming Dec 10, 2016
82a0f86
Merge branch 'develop' into yagpdb
jogramming Dec 10, 2016
0fdda5d
Aaaaa
jogramming Dec 10, 2016
ef5b3ba
staff stuff stiff soff
jogramming Dec 10, 2016
4c85f9c
Merge branch 'userguilds' into yagpdb
jogramming Dec 10, 2016
e849ffe
keep deleted messages
jogramming Dec 19, 2016
f293036
Merge branch 'develop' into yagpdb
jogramming Dec 26, 2016
d4e5067
Merge branch 'develop' into yagpdb
jogramming Dec 28, 2016
c20f8ee
Fix all found race conditions and export Voie.Connected
jogramming Dec 29, 2016
89ff473
Merge branch 'voice-improv' into yagpdb
jogramming Dec 29, 2016
4005bf3
Fix all found race conditions and export Voie.Connected
jogramming Dec 29, 2016
ecbdb6d
Merge branch 'voice-improv' into yagpdb
jogramming Dec 29, 2016
1d18138
Aa
jogramming Dec 29, 2016
774a8a9
Fix all found race conditions and export Voie.Connected
jogramming Dec 29, 2016
9d0687a
Merge branch 'voice-improv' into yagpdb
jogramming Jan 3, 2017
d282b57
Fix all found race conditions and export Voie.Connected
jogramming Dec 29, 2016
13be7da
Merge branch 'fix-data-races' into yagpdb
jogramming Jan 3, 2017
0159819
Handle heartbeat ack
jogramming Jan 14, 2017
3274085
Merge branch 'develop' into yagpdb
jogramming Jan 16, 2017
7df084e
Fix leaking tickers
jogramming Jan 23, 2017
6905315
Merge branch 'sinking-boat' into yagpdb
jogramming Jan 23, 2017
40d3e14
Added reason go GuildBanCreate
jogramming Apr 28, 2017
5fce710
Merge branch 'develop' into yagpdb
jogramming Apr 29, 2017
1da0ccd
Merge branch 'develop' into yagpdb
jogramming May 17, 2017
ad66c26
not needed
jogramming May 17, 2017
533d301
Merge branch 'develop' into yagpdb
jogramming May 29, 2017
1934b7b
Add GatewayBot
jogramming Jun 4, 2017
cd66230
Fix comment for GatewayBot
jogramming Jun 9, 2017
49bfec2
Merge branch 'feature-gatewaybot' into yagpdb
jogramming Jun 18, 2017
083631d
Merge branch 'develop' into yagpdb
jogramming Jul 3, 2017
d3ebee4
Merge branch 'develop' into yagpdb
jogramming Jul 3, 2017
6fed016
Merge branch 'develop' into yagpdb
jogramming Jul 11, 2017
3f28b77
Add error code constants
jogramming Jul 31, 2017
8d8fd3f
Spaceee
jogramming Jul 31, 2017
43eaceb
Merge branch 'develop' into yagpdb
jogramming Jul 31, 2017
44557f6
Merge branch 'develop' into yagpdb
jogramming Aug 19, 2017
1b45821
Change all string ids to int64 ids
jogramming Aug 23, 2017
b893850
Merge branch 'develop' into yagpdb
jogramming Sep 26, 2017
ef7e40c
Use retryable http client
jogramming Sep 27, 2017
7f5cd82
Merge branch 'develop' into yagpdb
jogramming Feb 3, 2018
08c7d72
Merge branch 'develop' into yagpdb
jogramming Feb 3, 2018
a50c2d6
Update event.go
Nov 19, 2017
e261ef9
Update logging.go
Nov 19, 2017
d7768d1
Update restapi.go
Nov 19, 2017
b1b3fac
Update restapi.go
Nov 19, 2017
752c256
Update structs.go
Nov 19, 2017
996e48f
Update voice.go
Nov 19, 2017
4e58852
Update wsapi.go
Nov 19, 2017
20cb1c7
Update main.go
Nov 19, 2017
bd0e234
Rewrite gateway implementation
jogramming Nov 24, 2017
dd71947
Merge branch 'develop' into feasture-wsrewrite
jogramming Feb 11, 2018
bf1a794
Update status setting
jogramming Feb 11, 2018
aa87a78
Merge branch 'feasture-wsrewrite' into yagpdb
jogramming Feb 11, 2018
7fb2203
Remove debug logging, fix deadlock
jogramming Feb 12, 2018
766b90b
Merge branch 'feasture-wsrewrite' into yagpdb
jogramming Feb 12, 2018
d7ecf8e
Merge branch 'yagpdb' of https://github.com/jonas747/discordgo into y…
jogramming Feb 13, 2018
0c4e096
Fix voice
jogramming Feb 15, 2018
f6040a0
Trigger reconnect after 5 missed acks
jogramming Feb 16, 2018
1272a08
Remove unused stuff
jogramming Feb 16, 2018
dc8c3ca
Fix shards dyign and failing to reconnect
jogramming Feb 16, 2018
de4cc27
Merge branch 'feasture-wsrewrite' into yagpdb
jogramming Feb 16, 2018
4557997
Retry connection to gateway if it fails, send resume event, move some…
jogramming Feb 19, 2018
c36e83d
Fix some logging
jogramming Feb 20, 2018
a38d526
Fix failing to reconnect when errors occurs while reading into interm…
jogramming Feb 20, 2018
6872300
Merge branch 'feasture-wsrewrite' into yagpdb
jogramming Feb 20, 2018
d0a414f
Fix dead connections hindering reconnects
jogramming Feb 27, 2018
e70e4e7
Merge branch 'feasture-wsrewrite' into yagpdb
jogramming Feb 27, 2018
78ead69
Fix failing to resume on read errors
jogramming Feb 28, 2018
703054d
Merge branch 'feasture-wsrewrite' into yagpdb
jogramming Feb 28, 2018
11c284c
Add the ability to pull heartbeat stats
jogramming Mar 2, 2018
6e8112b
Merge branch 'feasture-wsrewrite' into yagpdb
jogramming Mar 2, 2018
693db76
Merge branch 'develop' into feature-int-ids
jogramming Mar 26, 2018
12bd7c4
Compiles again now
jogramming Mar 26, 2018
8dba0a8
Fix tests
jogramming Mar 26, 2018
9fdcc29
Merge branch 'feature-int-ids' into yagpdb
jogramming Mar 26, 2018
fc1435b
Compiles again now
jogramming Mar 26, 2018
1d7f4b2
Update after arg in GuildMembers(...)
jogramming Mar 26, 2018
ba053a9
Update after arg in GuildMembers(...)
jogramming Mar 26, 2018
9b29b60
Update presence roles to idslice
jogramming Mar 26, 2018
a4d864b
Update presence roles to idslice
jogramming Mar 26, 2018
f4e0810
Update ChannelMessages to integer args
jogramming Mar 26, 2018
effea97
Update ChannelMessages to integer args
jogramming Mar 26, 2018
3902832
Update some structs to integer ids
jogramming Mar 27, 2018
b6b46a5
Update some structs to integer ids
jogramming Mar 27, 2018
f3d1886
Change reaction emoji id's back to strings, since they're unicode som…
jogramming Mar 29, 2018
71fe108
Merge branch 'feature-int-ids' into yagpdb
jogramming Mar 29, 2018
0b68d7e
Change []IDSlice to IDSlice in presence struct
jogramming Mar 29, 2018
ad57e87
Merge branch 'feature-int-ids' into yagpdb
jogramming Mar 29, 2018
6d46d67
Remove debug logging in IDSlice.MarshalJson
jogramming Apr 2, 2018
8641c87
Fix tests following bd0e23477a6f489eb56b7345256607d49d01316d
LoganK May 13, 2018
e4caf3e
Support qualified emojis as reaction inputs
LoganK May 13, 2018
c39728e
Support for non-custom, named emojis as reaction inputs
LoganK May 13, 2018
7101652
Merge pull request #1 from LoganK/test_fix
jogramming May 13, 2018
36742cb
Merge pull request #2 from LoganK/qualified_emoji
jogramming May 18, 2018
4b79747
Fix handling resume multiple times
jogramming May 23, 2018
03c93cc
Added setter and getter for session info
jogramming Jul 9, 2018
7991ade
Fix parsing int slices incorrectly
jogramming Jul 13, 2018
c0cf577
Support new version of go-retryablehttp
jogramming Jul 25, 2018
ffe446c
Split up audit log struct
jogramming Aug 6, 2018
9d60263
updated to new version of gobwas/ws
jogramming Aug 6, 2018
c0db52b
Sync with upstream
jogramming Aug 21, 2018
d53078d
Fix Reaction.GuildID being a string instead of int64
jogramming Aug 21, 2018
42688a6
added module support
jogramming Aug 25, 2018
2d77ef6
added exported method to get even interface from type
jogramming Sep 3, 2018
81cd8e9
voice: time out instead of waiting for the initial handshake forever
jogramming Sep 10, 2018
8ff2c20
Merge branch 'yagpdb' of https://github.com/jonas747/discordgo into y…
jogramming Sep 10, 2018
c3b8ae4
GatewayStatus now implements stringer
jogramming Sep 11, 2018
1912ad1
added RequestGuildMembers gateway request
jogramming Sep 12, 2018
32266a4
added more dynamic decoding capability for presence updates
jogramming Sep 16, 2018
53d15a2
remove unused user fields, (maybe create a seperate type for users wi…
jogramming Sep 22, 2018
4875e24
add identify ratelimiting
jogramming Sep 23, 2018
46c422d
add back message.GuildID
jogramming Sep 25, 2018
4ad52de
Switch to gojay for the Event struct, reuse event object and the RawM…
jogramming Oct 10, 2018
9c4a9d3
use a reusable json decoder to minimize allocations during the second…
jogramming Oct 10, 2018
4b8ad95
switch to my gojay fork
jogramming Oct 10, 2018
496c5c2
force remove voice connections if theres errors from the voice connec…
jogramming Oct 10, 2018
f365619
fix up gateway implementation a bit, remove all those random panic an…
jogramming Oct 11, 2018
8465c32
ratelimit sending on gateway
jogramming Oct 11, 2018
87c2649
voice: fix unmarshaling of events
jogramming Oct 11, 2018
7e86ebb
added ChannelVoiceLeave
jogramming Oct 11, 2018
700bab7
no longer strip '–Variation Selector-16' symbol in EmojiName.String
jogramming Oct 13, 2018
af8cfcc
fix custom ratelimit for reactions
jogramming Oct 15, 2018
fcadd83
add option to set max concurrent requests
jogramming Nov 2, 2018
0f3cc39
throw away intermediery buffers when they exeed a specified size (100…
jogramming Nov 15, 2018
66ac50d
update to new retryablehttp api
jogramming Nov 28, 2018
109b262
gateway: break out of stop loop if connection is dead
jogramming Dec 2, 2018
fb48608
rest: retry on gateway timeout
jogramming Dec 2, 2018
d0dc2f1
add webhook_id to message
jogramming Dec 3, 2018
49be46c
gateway: send beat from op1 in a goroutine
jogramming Dec 3, 2018
38df413
fix example
jogramming Dec 29, 2018
afcc293
gateway: log the error when an error occurs opening the gateway conne…
jogramming Dec 29, 2018
1bf6f44
only throw away big buffers when they're not needed, as opposed to al…
jogramming Dec 29, 2018
0dda9e1
add request.GetBody for times when http requests are retried internally
jogramming Dec 31, 2018
ef18e40
gateway: fix being unable to retrieve gateway status while rattelimit…
jogramming Dec 31, 2018
a57bc1c
add more permissions to PermissionAll
jogramming Mar 8, 2019
9747fc3
add utility helpers to guild
jogramming Mar 28, 2019
4c1b716
export MemberPermissions and make it work with nil channel
jogramming Mar 28, 2019
184b876
use TimeStamp for member.JoinedAt
jogramming Apr 8, 2019
3038bd8
added GuildChannelCreateWithOverwrites
jogramming Apr 8, 2019
9ef5d46
added parent_id to GuildChannelCreateWithOverwrites
jogramming Apr 8, 2019
1a87c4b
omitempty ChannelEdit.Position
jogramming Apr 11, 2019
46c329e
timeout http requests after 5 seconds
jogramming Apr 24, 2019
f393d6f
double context deadling for rest requests
jogramming May 1, 2019
6c75812
have voice session inhetir logging level, return ErrTimeoutWaitingFor…
jogramming May 1, 2019
21fa802
add proper rest request loop
jogramming May 3, 2019
ba2a01f
remove rest deadline as it interfers with REST retrying
jogramming May 3, 2019
1e4ab55
add SessionStartLimit to GatewayBotResponse
jogramming May 8, 2019
5a5964a
add before and after and to MessageReactions
jogramming May 8, 2019
c88af4b
Added generic GuildEvent and ChannelEvent interfaces
jogramming May 26, 2019
f270b46
buncho smallish improvements
jogramming May 26, 2019
427ee95
Added rest method GuildBan
jogramming Jun 26, 2019
02baa67
add gojay marshalling for the most popular event, presence updates
jogramming Jul 15, 2019
fc4ab74
add guild_subscriptions
jogramming Jul 20, 2019
2c9991b
added gojay unmarshaler for typingstart
jogramming Jul 20, 2019
b9b050e
add rate_limit_per_user to channel type
jogramming Jul 30, 2019
b1a1fbe
added rate_limit_per_user to ChannelÈdit
jogramming Jul 30, 2019
33f980e
fix bad stuff with last commit
jogramming Jul 30, 2019
71120c3
new ratelimter method: SetGlobalTriggered, sets the global ratelimit
jogramming Aug 15, 2019
e0c3556
fix tests
jogramming Aug 15, 2019
56a8692
GetWaitTime: return the greatest wait time between gloabl and per route
jogramming Aug 15, 2019
282c623
added exposed HandleEvent function
jogramming Aug 15, 2019
a93d8f4
Use pointer for ratelimit event
jogramming Aug 17, 2019
c64838e
add global field to TooManyRequests
jogramming Aug 17, 2019
0234999
include bucket in rate limit event
jogramming Aug 17, 2019
1e8da06
ratelimit: check if a global is triggered while in the ccr queue
jogramming Aug 17, 2019
d4daad7
ratelimit: enable millisecond precision ratelimits, use X-Ratelimit-R…
jogramming Aug 22, 2019
d11d60a
change away from retryablehttp since were using our own retry handlin…
jogramming Aug 28, 2019
325928b
fix error hadnling in resthandler
jogramming Aug 28, 2019
17c4957
remove debug logging
jogramming Aug 28, 2019
80e1420
added new channel types
jogramming Aug 31, 2019
e4929f0
added go.mod and go.sum
jogramming Sep 6, 2019
b7b20fc
if auth failes, don't reonnect
jogramming Sep 11, 2019
935848e
add member to message struct
jogramming Sep 12, 2019
a577c5f
more reliable tracking of voice connections
jogramming Oct 13, 2019
4fff8f8
fix voice connections
jogramming Oct 16, 2019
fcfc23d
fix potential deadlock
jogramming Oct 16, 2019
3a104c9
rest: include ratelimit bucket in request context
jogramming Oct 22, 2019
1057001
mark the token as invalid when we get UNAUTHORIZED
jogramming Nov 24, 2019
b121c04
add the mulieple activies slice
jogramming Dec 3, 2019
8cabfe9
Added .Message.Pinned
Satty9361 Jan 5, 2020
39296d2
Merge pull request #3 from Satty9361/patch-1
jogramming Jan 22, 2020
9b73c59
update session info when connecting
jogramming Jan 28, 2020
7f37b72
update session info when connecting
jogramming Jan 28, 2020
25c2508
Ability to edit away embeds : V2
Satty9361 Jan 28, 2020
ca8000b
Package Update
Satty9361 Jan 28, 2020
79327e1
added shardID as a param to ratelimit identifies
jogramming Feb 2, 2020
b70a749
Merge pull request #5 from Satty9361/patch-3
jogramming Feb 7, 2020
b961a56
added custom gateway logger
jogramming Feb 8, 2020
f5086d6
Merge branch 'yagpdb' of github.com:jonas747/discordgo into yagpdb
jogramming Feb 8, 2020
c737928
redid custom gateway logger
jogramming Feb 8, 2020
43d83ac
Getter Function for marshalnil field
Satty9361 Feb 15, 2020
edbefb7
Merge pull request #6 from Satty9361/patch-4
jogramming Feb 15, 2020
4090ad4
update emoji codemap
jogramming Feb 26, 2020
d90f08b
add new invite events
jogramming Feb 26, 2020
25c18fd
Move interfaces to types to fix build
jogramming Feb 26, 2020
14b9c57
added allowed_mentions
jogramming Mar 9, 2020
3e264f3
New endpoint to delete all reactions of particular emoji
Satty9361 Mar 13, 2020
6f12aab
fix typo
Satty9361 Mar 14, 2020
3451006
Formatting
Satty9361 Mar 14, 2020
a78545f
remove allowed mentions from message as it's not needed
jogramming Mar 16, 2020
7be849e
fix bad close frames?
jogramming Apr 3, 2020
da29c90
fix close frames for good
jogramming Apr 3, 2020
faaa8ce
Merge pull request #7 from Satty9361/patch-5
jogramming Apr 3, 2020
6a8d839
Merge pull request #8 from Satty9361/patch-6
jogramming Apr 3, 2020
f74e48b
disconnect with close code 4000 to avoid getting the session removed
jogramming Apr 5, 2020
10b0093
Merge branch 'yagpdb' of github.com:jonas747/discordgo into yagpdb
jogramming Apr 5, 2020
2daeae6
Update request guild members
jogramming Apr 11, 2020
739af36
fix not able to add the :hash: reaction, use percent encoding for the…
jogramming Apr 27, 2020
7ba92dc
added RequestMembersComplex and new fields (nonce, count and index) f…
jogramming Apr 29, 2020
12d6529
add o7 close message cause why not
jogramming Apr 29, 2020
d2abbc1
change int64 -> null.Int64
Satty9361 May 26, 2020
53ef61c
Defining a nullIntID datatype to deal with nullable ID fields.
Satty9361 Jun 28, 2020
e18cacf
patch GuildMemberMove to use nullIntID
Satty9361 Jun 28, 2020
1035c8c
Update packages - types.go
Satty9361 Jun 28, 2020
c61becc
Update packages restapi.go
Satty9361 Jun 28, 2020
7c385a2
change int -> int64 for consistency
Satty9361 Jun 28, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 41 additions & 3 deletions discord.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@
package discordgo

import (
"context"
"errors"
"fmt"
"github.com/hashicorp/go-cleanhttp"
"log"
"net/http"
"strconv"
"strings"
"time"
)

Expand Down Expand Up @@ -56,10 +61,15 @@ func New(args ...interface{}) (s *Session, err error) {
ShouldReconnectOnError: true,
ShardID: 0,
ShardCount: 1,
MaxRestRetries: 3,
Client: &http.Client{Timeout: (20 * time.Second)},
sequence: new(int64),
MaxRestRetries: 10,
Client: cleanhttp.DefaultPooledClient(),
LastHeartbeatAck: time.Now().UTC(),
tokenInvalid: new(int32),
}

s.GatewayManager = &GatewayConnectionManager{
session: s,
voiceConnections: make(map[int64]*VoiceConnection),
}

// If no arguments are passed return the empty Session interface.
Expand Down Expand Up @@ -144,3 +154,31 @@ func New(args ...interface{}) (s *Session, err error) {

return
}

func CheckRetry(_ context.Context, resp *http.Response, err error) (bool, error) {
if err != nil {
return true, err
}

return false, nil
}

type retryableLogger struct{}

func (r *retryableLogger) Printf(format string, args ...interface{}) {
s := fmt.Sprintf(format, args...)

if strings.Contains(s, "[DEBUG]") {
return
}

if strings.HasSuffix(s, "\n") {
s = s[:len(s)-1]
}

log.Println(s)
}

func StrID(id int64) string {
return strconv.FormatInt(id, 10)
}
21 changes: 12 additions & 9 deletions discord_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"os"
"runtime"
"strconv"
"sync/atomic"
"testing"
"time"
Expand All @@ -15,13 +16,18 @@ var (
dg *Session // Stores a global discordgo user session
dgBot *Session // Stores a global discordgo bot session

envToken = os.Getenv("DGU_TOKEN") // Token to use when authenticating the user account
envBotToken = os.Getenv("DGB_TOKEN") // Token to use when authenticating the bot account
envGuild = os.Getenv("DG_GUILD") // Guild ID to use for tests
envChannel = os.Getenv("DG_CHANNEL") // Channel ID to use for tests
envAdmin = os.Getenv("DG_ADMIN") // User ID of admin user to use for tests
envToken = os.Getenv("DGU_TOKEN") // Token to use when authenticating the user account
envBotToken = os.Getenv("DGB_TOKEN") // Token to use when authenticating the bot account
envGuild = parseID(os.Getenv("DG_GUILD")) // Guild ID to use for tests
envChannel = parseID(os.Getenv("DG_CHANNEL")) // Channel ID to use for tests
envAdmin = parseID(os.Getenv("DG_ADMIN")) // User ID of admin user to use for tests
)

func parseID(str string) int64 {
id, _ := strconv.ParseInt(str, 10, 64)
return id
}

func init() {
fmt.Println("Init is being called.")
if envBotToken != "" {
Expand Down Expand Up @@ -103,12 +109,9 @@ func TestOpenClose(t *testing.T) {
// this is totally gross.
start := time.Now()
for {
d.RLock()
if d.DataReady {
d.RUnlock()
if d.GatewayManager.Status() == GatewayStatusReady {
break
}
d.RUnlock()

if time.Since(start) > 10*time.Second {
t.Fatal("DataReady never became true.yy")
Expand Down
Loading