Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes to appease go static checker #1589

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
11 changes: 6 additions & 5 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func registerInterfaceProvider(eh EventInterfaceProvider) {
// fmt.Errorf("event %s already registered", eh.Type())
}
registeredInterfaceProviders[eh.Type()] = eh
return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary return removed

}

// eventHandlerInstance is a wrapper around an event handler, as functions
Expand Down Expand Up @@ -102,12 +101,14 @@ func (s *Session) addEventHandlerOnce(eventHandler EventHandler) func() {
// to a struct corresponding to the event for which you want to listen.
//
// eg:
// Session.AddHandler(func(s *discordgo.Session, m *discordgo.MessageCreate) {
// })
//
// Session.AddHandler(func(s *discordgo.Session, m *discordgo.MessageCreate) {
// })
//
// or:
// Session.AddHandler(func(s *discordgo.Session, m *discordgo.PresenceUpdate) {
// })
//
// 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://discord.com/developers/docs/topics/gateway#event-names
Expand Down
2 changes: 0 additions & 2 deletions oauth2_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,4 @@ func ExampleApplication() {
// Delete the application we created.
err = dg.ApplicationDelete(ap.ID)
log.Printf("Delete: err: %+v\n", err)

return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary return removed

}
4 changes: 2 additions & 2 deletions ratelimit.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (r *RateLimiter) GetWaitTime(b *Bucket, minRemaining int) time.Duration {
// If we ran out of calls and the reset time is still ahead of us
// then we need to take it easy and relax a little
if b.Remaining < minRemaining && b.reset.After(time.Now()) {
return b.reset.Sub(time.Now())
return time.Until(b.reset)
}

// Check for global ratelimits
Expand Down Expand Up @@ -124,7 +124,7 @@ func (b *Bucket) Release(headers http.Header) error {

// Check if the bucket uses a custom ratelimiter
if rl := b.customRateLimit; rl != nil {
if time.Now().Sub(b.lastReset) >= rl.reset {
if time.Since(b.lastReset) >= rl.reset {
b.Remaining = rl.requests - 1
b.lastReset = time.Now()
}
Expand Down
6 changes: 3 additions & 3 deletions restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ func (s *Session) RequestWithLockedBucket(method, urlStr, contentType string, b
}
case http.StatusUnauthorized:
if strings.Index(s.Token, "Bot ") != 0 {
s.log(LogInformational, ErrUnauthorized.Error())
s.log(LogInformational, "%s", ErrUnauthorized.Error())
err = ErrUnauthorized
}
fallthrough
Expand Down Expand Up @@ -1579,7 +1579,7 @@ func (s *Session) GuildTemplateCreate(guildID string, data *GuildTemplateParams,
return
}

err = unmarshal(body, &st)
unmarshal(body, &st)
return
}

Expand Down Expand Up @@ -3600,7 +3600,7 @@ func (s *Session) Entitlements(appID string, filterOptions *EntitlementFilterOpt
if filterOptions.UserID != "" {
queryParams.Set("user_id", filterOptions.UserID)
}
if filterOptions.SkuIDs != nil && len(filterOptions.SkuIDs) > 0 {
if len(filterOptions.SkuIDs) > 0 {
queryParams.Set("sku_ids", strings.Join(filterOptions.SkuIDs, ","))
}
if filterOptions.Before != nil {
Expand Down
4 changes: 2 additions & 2 deletions restapi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func TestUserChannelCreate(t *testing.T) {

_, err := dg.UserChannelCreate(envAdmin)
if err != nil {
t.Errorf(err.Error())
t.Errorf("%s", err.Error())
}

// TODO make sure the channel was added
Expand All @@ -108,7 +108,7 @@ func TestUserGuilds(t *testing.T) {

_, err := dg.UserGuilds(10, "", "", false)
if err != nil {
t.Errorf(err.Error())
t.Errorf("%s", err.Error())
}
}

Expand Down
9 changes: 5 additions & 4 deletions state.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,9 @@ func (s *State) GuildRemove(guild *Guild) error {

// Guild gets a guild by ID.
// Useful for querying if @me is in a guild:
// _, err := discordgo.Session.State.Guild(guildID)
// isInGuild := err == nil
//
// _, err := discordgo.Session.State.Guild(guildID)
// isInGuild := err == nil
func (s *State) Guild(guildID string) (*Guild, error) {
if s == nil {
return nil, ErrNilState
Expand Down Expand Up @@ -1061,7 +1062,7 @@ func (s *State) OnInterface(se *Session, i interface{}) (err error) {
oldCopy := *old
t.BeforeUpdate = &oldCopy
}
err = s.ChannelAdd(t.Channel)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error value is never used

s.ChannelAdd(t.Channel)
}
case *ChannelDelete:
if s.TrackChannels {
Expand All @@ -1078,7 +1079,7 @@ func (s *State) OnInterface(se *Session, i interface{}) (err error) {
oldCopy := *old
t.BeforeUpdate = &oldCopy
}
err = s.ChannelAdd(t.Channel)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error value is never used

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to fix the shadowing rather than its consequences.

s.ChannelAdd(t.Channel)
}
case *ThreadDelete:
if s.TrackThreads {
Expand Down
7 changes: 3 additions & 4 deletions voice.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,8 +501,6 @@ func (v *VoiceConnection) onEvent(message []byte) {
default:
v.log(LogDebug, "unknown voice operation, %d, %s", e.Operation, string(e.RawData))
}

return
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary return removed

}

type voiceHeartbeatOp struct {
Expand Down Expand Up @@ -787,7 +785,8 @@ func (v *VoiceConnection) opusSender(udpConn *net.UDPConn, close <-chan struct{}
sequence++
}

if (timestamp + uint32(size)) >= 0xFFFFFFFF {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The value given is greater than the max value of Uint32 which is impossible. Instead, we should check for integer ovrflow.

// Check for overflow and reset timestamp if needed
if (timestamp + uint32(size)) < timestamp {
timestamp = 0
} else {
timestamp += uint32(size)
Expand Down Expand Up @@ -920,7 +919,7 @@ func (v *VoiceConnection) reconnect() {
wait = 600
}

if v.session.DataReady == false || v.session.wsConn == nil {
if !v.session.DataReady || v.session.wsConn == nil {
v.log(LogInformational, "cannot reconnect to channel %s with unready session", v.ChannelID)
continue
}
Expand Down
26 changes: 13 additions & 13 deletions wsapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (s *Session) HeartbeatLatency() time.Duration {
// heartbeat sends regular heartbeats to Discord so it knows the client
// is still connected. If you do not send these heartbeats Discord will
// disconnect the websocket connection after a few seconds.
func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{}, heartbeatIntervalMsec time.Duration) {
func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{}, heartbeatInterval time.Duration) {

s.log(LogInformational, "called")

Expand All @@ -284,7 +284,7 @@ func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{}
}

var err error
ticker := time.NewTicker(heartbeatIntervalMsec * time.Millisecond)
ticker := time.NewTicker(heartbeatInterval * time.Millisecond)
defer ticker.Stop()

for {
Expand All @@ -297,7 +297,7 @@ func (s *Session) heartbeat(wsConn *websocket.Conn, listening <-chan interface{}
s.LastHeartbeatSent = time.Now().UTC()
err = wsConn.WriteJSON(heartbeatOp{1, sequence})
s.wsMutex.Unlock()
if err != nil || time.Now().UTC().Sub(last) > (heartbeatIntervalMsec*FailedHeartbeatAcks) {
if err != nil || time.Now().UTC().Sub(last) > (heartbeatInterval*FailedHeartbeatAcks) {
if err != nil {
s.log(LogError, "error sending heartbeat to gateway %s, %s", s.gateway, err)
} else {
Expand Down Expand Up @@ -697,16 +697,16 @@ type voiceChannelJoinOp struct {

// ChannelVoiceJoin joins the session user to a voice channel.
//
// gID : Guild ID of the channel to join.
// cID : Channel ID of the channel to join.
// mute : If true, you will be set to muted upon joining.
// deaf : If true, you will be set to deafened upon joining.
// gID : Guild ID of the channel to join.
// cID : Channel ID of the channel to join.
// mute : If true, you will be set to muted upon joining.
// deaf : If true, you will be set to deafened upon joining.
func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool) (voice *VoiceConnection, err error) {

s.log(LogInformational, "called")

s.RLock()
voice, _ = s.VoiceConnections[gID]
voice = s.VoiceConnections[gID]
s.RUnlock()

if voice == nil {
Expand Down Expand Up @@ -744,10 +744,10 @@ func (s *Session) ChannelVoiceJoin(gID, cID string, mute, deaf bool) (voice *Voi
//
// This should only be used when the VoiceServerUpdate will be intercepted and used elsewhere.
//
// gID : Guild ID of the channel to join.
// cID : Channel ID of the channel to join, leave empty to disconnect.
// mute : If true, you will be set to muted upon joining.
// deaf : If true, you will be set to deafened upon joining.
// gID : Guild ID of the channel to join.
// cID : Channel ID of the channel to join, leave empty to disconnect.
// mute : If true, you will be set to muted upon joining.
// deaf : If true, you will be set to deafened upon joining.
func (s *Session) ChannelVoiceJoinManual(gID, cID string, mute, deaf bool) (err error) {

s.log(LogInformational, "called")
Expand Down Expand Up @@ -843,7 +843,7 @@ func (s *Session) identify() error {

// TODO: This is a temporary block of code to help
// maintain backwards compatibility
if s.Compress == false {
if !s.Compress {
s.Identify.Compress = false
}

Expand Down
Loading