Skip to content

Commit

Permalink
fix issue#1
Browse files Browse the repository at this point in the history
  • Loading branch information
dustin-ward committed Nov 26, 2023
1 parent b0d6f0c commit 5317355
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 7 deletions.
5 changes: 3 additions & 2 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
)

var s *discordgo.Session
var C *map[string]*data.Channel
var C map[string]*data.Channel
var crn *cron.Cron
var adminPerm int64 = 0

Expand Down Expand Up @@ -108,7 +108,7 @@ func InitSession() (*discordgo.Session, error) {
if _, err := os.Stat("./channels.json"); errors.Is(err, os.ErrNotExist) {
log.Println("Info: no channel config file found")

*C = make(map[string]*data.Channel, 3)
C = make(map[string]*data.Channel, 3)
} else {
// Read channel configs from file (Not an ideal storage method...)
b, err := os.ReadFile("./channels.json")
Expand All @@ -127,6 +127,7 @@ func InitSession() (*discordgo.Session, error) {
}

func TakeDown() error {
log.Println("Shutting Down...")
crn.Stop()

// Save channel configurations
Expand Down
2 changes: 1 addition & 1 deletion bot/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func configure(s *discordgo.Session, i *discordgo.InteractionCreate) {
}

// Add to local memory
(*C)[i.GuildID] = &ch
C[i.GuildID] = &ch

// Write to file
b, err := json.Marshal(C)
Expand Down
2 changes: 1 addition & 1 deletion bot/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func problemNotification() {
day := time.Now().AddDate(0, 0, 1).Day()

// For each registered channel
for _, ch := range *C {
for _, ch := range C {
if ch.NotificationsOn {
log.Println("Info: sending day", day, "notification in channel", ch.ChannelId)

Expand Down
2 changes: 1 addition & 1 deletion bot/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func getChannel(guildId string) (*data.Channel, error) {
ch, ok := (*C)[guildId]
ch, ok := C[guildId]
if !ok {
return nil, fmt.Errorf("channel not found")
}
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func main() {
log.Fatal("Fatal:", fmt.Errorf("main: %w", err))
}
defer Session.Close()
log.Println("Session initialized for", len(*bot.C), "servers")
log.Println("Session initialized for", len(bot.C), "servers")

// Register commands
r, err := bot.RegisterCommands()
Expand All @@ -51,7 +51,7 @@ func main() {
}

// Continually fetch advent of code data every 15 minutes
for _, ch := range *bot.C {
for _, ch := range bot.C {
go func(channel *data.Channel) {
for {
log.Println("Attempting to fetch data for leaderboard " + channel.Leaderboard + "...")
Expand Down

0 comments on commit 5317355

Please sign in to comment.