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

Commit

Permalink
cmd: restart
Browse files Browse the repository at this point in the history
  • Loading branch information
sarisia committed Apr 26, 2020
1 parent 805f82c commit 82450c8
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions aria/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ func newBot(
b.addCmdHandler("playnext", b.cmdPlayNext)
b.addCmdHandler("like", b.cmdLike)
b.addCmdHandler("save", b.cmdSave)
b.addCmdHandler("restart", b.cmdRestart)

// register aria packet handlers
b.addPacketHandler(onState)
Expand Down Expand Up @@ -144,7 +145,6 @@ func (b *bot) run(parent context.Context) {
b.cancel = cancel

wg := sync.WaitGroup{}
defer wg.Wait()

if err := b.Open(); err != nil {
log.Printf("failed to open Discord connection")
Expand Down Expand Up @@ -234,7 +234,7 @@ func (b *bot) onMessage(s *discordgo.Session, m *discordgo.MessageCreate) {
b.RLock()
if m.Author.ID == b.botUser.ID {
// if author is bot, delete after 30s
go b.deleteMessageAfter(m.Message, 30*time.Second, false)
b.deleteMessageAfter(m.Message, 30*time.Second, false)
return
}
b.RUnlock()
Expand Down
4 changes: 4 additions & 0 deletions aria/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,10 @@ func (b *bot) cmdVersion(m *discordgo.Message, _ []string) {
}
}

func (b *bot) cmdRestart(_ *discordgo.Message, _ []string) {
b.cancel()
}

// utility functions

func newEmbed() (e *discordgo.MessageEmbed) {
Expand Down
12 changes: 6 additions & 6 deletions aria/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,6 @@ 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 @@ -97,6 +91,12 @@ 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
8 changes: 6 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
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 h1:s+21KNqlpePfkah2I+gwHF8xmJWRjooY+5248k6m4A0=
github.com/gobwas/httphead v0.0.0-20180130184737-2c6c146eadee/go.mod h1:L0fX3K22YWvt/FAX9NnzrNzcI4wNYi9Yku4O0LKYflo=
github.com/gobwas/pool v0.2.0 h1:QEmUOlnSjWtnpRGHF3SauEiOsy82Cup83Vf2LcMlnc8=
github.com/gobwas/pool v0.2.0/go.mod h1:q8bcK0KcYlCgd9e7WYLm9LpyS+YeLd8JVDW6WezmKEw=
github.com/gobwas/ws v1.0.2 h1:CoAavW/wd/kulfZmSIBt6p24n4j7tHgNVCjsfHVNUbo=
github.com/gobwas/ws v1.0.2/go.mod h1:szmBTxLgaFppYjEmNtny/v3w89xOydFnnZMcgRRu/EM=
github.com/golang/protobuf v1.3.5 h1:F768QJ1E9tib+q5Sc8MkdJi1RxLTbRcTf8LJV56aRls=
github.com/golang/protobuf v1.3.5/go.mod h1:6O5/vntMXwX2lRkT1hjjk0nAC1IDOTvTlVgjlRvqsdk=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/gorilla/websocket v1.4.0/go.mod h1:E7qHFY5m1UJ88s3WnNqhKjPHQ0heANvMoAMk2YaljkQ=
github.com/gorilla/websocket v1.4.1 h1:q7AeDBpnBk8AogcD4DSag/Ukw/KV+YhzLj2bP5HvKCM=
Expand All @@ -29,6 +32,7 @@ golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f h1:gWF768j/LaZugp8dyS4UwsslY
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
nhooyr.io/websocket v1.8.5 h1:DCqbsbyRh43Ky0pWkdbWXF6z6MS2W8LqJ4ym3F+fw3I=
nhooyr.io/websocket v1.8.5/go.mod h1:szdAKb/TINbpD/bAZy4Ydj5xgVo2BOLNPIi/mcAOGrU=

0 comments on commit 82450c8

Please sign in to comment.