fix timer edit function. add additional entrys to command help text

This commit is contained in:
lyx0 2023-12-17 23:15:21 +01:00
parent c4a05a2619
commit 47e5c74615
2 changed files with 97 additions and 27 deletions

View file

@ -253,6 +253,10 @@ func (app *application) handleCommand(message twitch.PrivateMessage) {
if userLevel >= 100 { if userLevel >= 100 {
reply = app.Environment 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 { if userLevel >= 500 {
app.DeleteTimer(cmdParams[2], message) app.DeleteTimer(cmdParams[2], message)
} }
case "list": case "edit":
if userLevel >= 0 { if userLevel >= 500 {
reply = app.ListChannelTimer(message.Channel) app.EditTimer(cmdParams[2], cmdParams[3], message)
} }
} }
@ -387,24 +391,6 @@ type command struct {
// Optional is [] // Optional is []
// Required is < > // Required is < >
var helpText = map[string]command{ var helpText = map[string]command{
"command add": {
Alias: nil,
Description: "Adds a channel command to the database.",
Level: "250",
Usage: "()add command <command name> <command text>",
},
"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 name> <new command level>",
},
"command delete": {
Alias: nil,
Description: "Deletes the channel command with the given name.",
Level: "250",
Usage: "()command delete <command name>",
},
"bttv": { "bttv": {
Alias: []string{"bttv", "betterttv"}, Alias: []string{"bttv", "betterttv"},
Description: "Returns the search URL for a given BTTV emote.", Description: "Returns the search URL for a given BTTV emote.",
@ -423,6 +409,24 @@ var helpText = map[string]command{
Level: "0", Level: "0",
Usage: "()coin", Usage: "()coin",
}, },
"command add": {
Alias: nil,
Description: "Adds a channel command to the database.",
Level: "250",
Usage: "()add command <command name> <command text>",
},
"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 name> <new command level>",
},
"command delete": {
Alias: nil,
Description: "Deletes the channel command with the given name.",
Level: "250",
Usage: "()command delete <command name>",
},
"commands": { "commands": {
Alias: nil, Alias: nil,
Description: "Returns a link to the commands in the channel.", Description: "Returns a link to the commands in the channel.",
@ -435,6 +439,30 @@ var helpText = map[string]command{
Level: "0", Level: "0",
Usage: "()currency <curr> to <curr>", Usage: "()currency <curr> to <curr>",
}, },
"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 <username>",
},
"debug command": {
Alias: nil,
Description: "Returns additional informations about a command.",
Level: "100",
Usage: "()debug command <command name>",
},
"debug timers": {
Alias: nil,
Description: "Returns a list of timers currently running in the channel with additional informations.",
Level: "100",
Usage: "()debug timers",
},
"duckduckgo": { "duckduckgo": {
Alias: []string{"duckduckgo", "ddg"}, Alias: []string{"duckduckgo", "ddg"},
Description: "Returns the duckduckgo search URL for a given query.", Description: "Returns the duckduckgo search URL for a given query.",
@ -579,11 +607,11 @@ var helpText = map[string]command{
Level: "500", Level: "500",
Usage: "()timer delete <name>", Usage: "()timer delete <name>",
}, },
"timer list": { "timer edit": {
Alias: nil, Alias: nil,
Description: "Lists all timers from the channel.", Description: "Edits a timer from the channel.",
Level: "0", Level: "500",
Usage: "()timer list", Usage: "()timer edit <name> <repeat> <text>",
}, },
"timers": { "timers": {
Alias: nil, Alias: nil,

View file

@ -121,7 +121,7 @@ func (app *application) EditTimer(name, repeat string, message twitch.PrivateMes
identifier := old.Identifier identifier := old.Identifier
app.Scheduler.RemoveJob(identifier) app.Scheduler.RemoveJob(identifier)
err = app.Models.Timers.Delete(name) err = app.Models.Timers.Delete(identifier)
if err != nil { if err != nil {
app.Log.Errorw("Error deleting timer from database", app.Log.Errorw("Error deleting timer from database",
"name", name, "name", name,
@ -354,7 +354,7 @@ func (app *application) DeleteTimer(name string, message twitch.PrivateMessage)
app.Send(message.Channel, reply, message) 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) timer, err := app.Models.Timers.GetChannelTimer(channel)
if err != nil { if err != nil {
app.Log.Errorw("Error trying to retrieve all timers from database", err) 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( t = fmt.Sprintf(
"Name: \t%v\n"+ "Name: \t%v\n"+
"ID: \t%v\n"+
"Identifier: \t%v\n"+
"Text: \t%v\n"+ "Text: \t%v\n"+
"Repeat: \t%v\n"+ "Repeat: \t%v\n"+
"\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, v.Name, v.Text, v.Repeat,
) )