mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
fix timer edit function. add additional entrys to command help text
This commit is contained in:
parent
c4a05a2619
commit
47e5c74615
|
@ -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 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": {
|
||||
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 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": {
|
||||
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 <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": {
|
||||
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 <name>",
|
||||
},
|
||||
"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 <name> <repeat> <text>",
|
||||
},
|
||||
"timers": {
|
||||
Alias: nil,
|
||||
|
|
|
@ -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,
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in a new issue