diff --git a/cmd/nourybot/commands.go b/cmd/nourybot/commands.go index 5c0638a..e794cf9 100644 --- a/cmd/nourybot/commands.go +++ b/cmd/nourybot/commands.go @@ -253,6 +253,10 @@ func (app *application) handleCommand(message twitch.PrivateMessage) { if userLevel >= 100 { reply = app.Environment } + case "timers": + if userLevel >= 100 { + app.DebugChannelTimers(message.Channel) + } } // -------------------------------- @@ -299,9 +303,9 @@ func (app *application) handleCommand(message twitch.PrivateMessage) { if userLevel >= 500 { app.DeleteTimer(cmdParams[2], message) } - case "list": - if userLevel >= 0 { - reply = app.ListChannelTimer(message.Channel) + case "edit": + if userLevel >= 500 { + app.EditTimer(cmdParams[2], cmdParams[3], message) } } @@ -387,24 +391,6 @@ type command struct { // Optional is [] // Required is < > var helpText = map[string]command{ - "command add": { - Alias: nil, - Description: "Adds a channel command to the database.", - Level: "250", - Usage: "()add command ", - }, - "command edit level": { - Alias: nil, - Description: "Edits the required level of a channel command with the given name.", - Level: "250", - Usage: "()command edit level ", - }, - "command delete": { - Alias: nil, - Description: "Deletes the channel command with the given name.", - Level: "250", - Usage: "()command delete ", - }, "bttv": { Alias: []string{"bttv", "betterttv"}, Description: "Returns the search URL for a given BTTV emote.", @@ -423,6 +409,24 @@ var helpText = map[string]command{ Level: "0", Usage: "()coin", }, + "command add": { + Alias: nil, + Description: "Adds a channel command to the database.", + Level: "250", + Usage: "()add command ", + }, + "command edit level": { + Alias: nil, + Description: "Edits the required level of a channel command with the given name.", + Level: "250", + Usage: "()command edit level ", + }, + "command delete": { + Alias: nil, + Description: "Deletes the channel command with the given name.", + Level: "250", + Usage: "()command delete ", + }, "commands": { Alias: nil, Description: "Returns a link to the commands in the channel.", @@ -435,6 +439,30 @@ var helpText = map[string]command{ Level: "0", Usage: "()currency to ", }, + "debug env": { + Alias: nil, + Description: "Returns the environment currently running in.", + Level: "100", + Usage: "()debug env", + }, + "debug user": { + Alias: nil, + Description: "Returns additional information about a user.", + Level: "100", + Usage: "()debug user ", + }, + "debug command": { + Alias: nil, + Description: "Returns additional informations about a command.", + Level: "100", + Usage: "()debug command ", + }, + "debug timers": { + Alias: nil, + Description: "Returns a list of timers currently running in the channel with additional informations.", + Level: "100", + Usage: "()debug timers", + }, "duckduckgo": { Alias: []string{"duckduckgo", "ddg"}, Description: "Returns the duckduckgo search URL for a given query.", @@ -579,11 +607,11 @@ var helpText = map[string]command{ Level: "500", Usage: "()timer delete ", }, - "timer list": { + "timer edit": { Alias: nil, - Description: "Lists all timers from the channel.", - Level: "0", - Usage: "()timer list", + Description: "Edits a timer from the channel.", + Level: "500", + Usage: "()timer edit ", }, "timers": { Alias: nil, diff --git a/cmd/nourybot/timer.go b/cmd/nourybot/timer.go index facc72f..7e61e7a 100644 --- a/cmd/nourybot/timer.go +++ b/cmd/nourybot/timer.go @@ -121,7 +121,7 @@ func (app *application) EditTimer(name, repeat string, message twitch.PrivateMes identifier := old.Identifier app.Scheduler.RemoveJob(identifier) - err = app.Models.Timers.Delete(name) + err = app.Models.Timers.Delete(identifier) if err != nil { app.Log.Errorw("Error deleting timer from database", "name", name, @@ -354,7 +354,7 @@ func (app *application) DeleteTimer(name string, message twitch.PrivateMessage) app.Send(message.Channel, reply, message) } -func (app *application) ListChannelTimer(channel string) string { +func (app *application) DebugChannelTimers(channel string) string { timer, err := app.Models.Timers.GetChannelTimer(channel) if err != nil { app.Log.Errorw("Error trying to retrieve all timers from database", err) @@ -375,9 +375,51 @@ func (app *application) ListChannelTimer(channel string) string { t = fmt.Sprintf( "Name: \t%v\n"+ + "ID: \t%v\n"+ + "Identifier: \t%v\n"+ "Text: \t%v\n"+ "Repeat: \t%v\n"+ "\n", + v.Name, v.ID, v.Identifier, v.Text, v.Repeat, + ) + + // Add new value to the slice + ts = append(ts, t) + + } + + reply, err := app.uploadPaste(strings.Join(ts, "")) + if err != nil { + app.Log.Errorw("Error trying to retrieve all timers from database", err) + return "" + } + + return reply +} +func (app *application) ListChannelTimer(channel string) string { + timer, err := app.Models.Timers.GetChannelTimer(channel) + if err != nil { + app.Log.Errorw("Error trying to retrieve all timers from database", err) + return "" + } + + // The slice of timers is only used to log them at + // the start so it looks a bit nicer. + var ts []string + + // Iterate over all timers and then add them onto the scheduler. + for i, v := range timer { + // idk why this works but it does so no touchy touchy. + // https://github.com/robfig/cron/issues/420#issuecomment-940949195 + i, v := i, v + _ = i + var t string + + t = fmt.Sprintf( + "Name: %v\n"+ + "Text: %v\n"+ + "Repeat: %v\n"+ + "\n", v.Name, v.Text, v.Repeat, )