Skip to content

Commit

Permalink
impr: (config.go) Use shared bot.Ctx
Browse files Browse the repository at this point in the history
  • Loading branch information
5HT2 committed Jul 21, 2022
1 parent 973da6a commit d3ee8e3
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
5 changes: 2 additions & 3 deletions bot/config.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package bot

import (
"context"
"encoding/json"
"fmt"
"github.com/diamondburned/arikawa/v3/discord"
Expand Down Expand Up @@ -148,7 +147,7 @@ func SaveConfig() {
// Using USER_ID, USER_TAG and USER_USERNAME as replacements for the discord.Activity name are all supported.
// Setting URL is only useful for a Twitch or YouTube discord.StreamingActivity.
// The activity type uint8 is derived from its position in the list, eg, 0 == discord.GameActivity and 2 == discord.ListeningActivity.
func LoadActivityStatus(ctx context.Context) {
func LoadActivityStatus() {
name := ""
url := ""
var activityType uint8 = 0
Expand All @@ -162,7 +161,7 @@ func LoadActivityStatus(ctx context.Context) {
name = strings.ReplaceAll(name, "USER_TAG", fmt.Sprintf("%v", User.Tag()))
name = strings.ReplaceAll(name, "USER_USERNAME", fmt.Sprintf("%v", User.Username))

if err := Client.Gateway().Send(ctx, &gateway.UpdatePresenceCommand{
if err := Client.Gateway().Send(Ctx, &gateway.UpdatePresenceCommand{
Activities: []discord.Activity{{Name: name, URL: url, Type: discord.ActivityType(activityType)}},
}); err != nil {
log.Printf("error loading activity status: %v\n", err)
Expand Down
2 changes: 2 additions & 0 deletions bot/shared.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bot

import (
"context"
"github.com/diamondburned/arikawa/v3/discord"
"github.com/diamondburned/arikawa/v3/state"
"github.com/go-co-op/gocron"
Expand All @@ -20,6 +21,7 @@ var (

HttpClient = http.Client{Timeout: 5 * time.Second}
Client state.State
Ctx = context.Background()
User *discord.User
PermissionsHex = 278404582480 // this is currently only used in base.go, but it is in shared.go because it is bot-level and should be set by the person maintaining the bot code
Scheduler = gocron.NewScheduler(getTimeZone())
Expand Down
7 changes: 3 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"bufio"
"context"
"flag"
"github.com/5HT2/taro-bot/bot"
"github.com/5HT2/taro-bot/cmd"
Expand Down Expand Up @@ -63,12 +62,12 @@ func main() {
go cmd.UpdateMemberCache(e)
})

if err := c.Open(context.Background()); err != nil {
if err := c.Open(bot.Ctx); err != nil {
log.Fatalln("Failed to connect:", err)
}

// Cancel context when SIGINT / SIGKILL / SIGTERM. SIGTERM is used by `docker stop`
ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt, os.Kill, syscall.SIGTERM)
ctx, cancel := signal.NotifyContext(bot.Ctx, os.Interrupt, os.Kill, syscall.SIGTERM)
defer cancel()

if err := c.Open(ctx); err != nil {
Expand Down Expand Up @@ -96,7 +95,7 @@ func main() {
go plugins.RegisterAll(*pluginDir, *pluginList)

// Set up the bots status
go bot.LoadActivityStatus(ctx)
go bot.LoadActivityStatus()

// Now we can start the routine-based tasks
go bot.SetupConfigSaving()
Expand Down

0 comments on commit d3ee8e3

Please sign in to comment.