Skip to content
This repository has been archived by the owner on Oct 28, 2020. It is now read-only.

Commit

Permalink
bot: prevent bot from reconnecting
Browse files Browse the repository at this point in the history
  • Loading branch information
sarisia committed Apr 25, 2020
1 parent 6ff8608 commit 805f82c
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 7 deletions.
2 changes: 2 additions & 0 deletions aria/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ func newBot(
if err != nil {
return nil, fmt.Errorf("failed to initialize discord bot: %w", err)
}
// disable auto reconnect to control retry interval by own
s.ShouldReconnectOnError = false
b.Session = s
b.AddHandler(b.onMessage)
b.AddHandler(b.onReady)
Expand Down
12 changes: 6 additions & 6 deletions aria/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ func (l *launcher) launch(parent context.Context) {

func (l *launcher) launchBot(ctx context.Context, errChan chan<- error) {
var start time.Time
b, err := newBot(l.config, l.cliToBot, l.botToCli, l.stream)
if err != nil {
errChan <- fmt.Errorf("failed to initialize bot: %w", err)
return
}

for {
if time.Now().Sub(start) < 5*time.Minute {
log.Printf("bot cooldown: 1min...")
Expand All @@ -91,12 +97,6 @@ func (l *launcher) launchBot(ctx context.Context, errChan chan<- error) {
}
}

b, err := newBot(l.config, l.cliToBot, l.botToCli, l.stream)
if err != nil {
errChan <- fmt.Errorf("failed to initialize bot: %w", err)
return
}

select {
case <-ctx.Done():
log.Printf("stopped: bot")
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/aria-music/aria-discord-go
go 1.14

require (
github.com/bwmarrin/discordgo v0.20.3
github.com/bwmarrin/discordgo v0.20.2
github.com/gorilla/websocket v1.4.2 // indirect
github.com/klauspost/compress v1.10.4 // indirect
golang.org/x/crypto v0.0.0-20200420201142-3c4aac89819a // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/bwmarrin/discordgo v0.20.2 h1:nA7jiTtqUA9lT93WL2jPjUp8ZTEInRujBdx1C9gkr20=
github.com/bwmarrin/discordgo v0.20.2/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q=
github.com/bwmarrin/discordgo v0.20.3 h1:AxjcHGbyBFSC0a3Zx5nDQwbOjU7xai5dXjRnZ0YB7nU=
github.com/bwmarrin/discordgo v0.20.3/go.mod h1:O9S4p+ofTFwB02em7jkpkV8M3R0/PUVOwN61zSZ0r4Q=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
Expand Down

0 comments on commit 805f82c

Please sign in to comment.