load command help text into redis at start

This commit is contained in:
lyx0 2023-04-13 20:48:11 +02:00
parent 39288bfd1c
commit 202513ee3e
3 changed files with 16 additions and 1 deletions

View file

@ -502,6 +502,20 @@ var helpText = map[string]string{
"xkcd": "Returns a link to the latest xkcd comic. Example usage: ()xkcd", "xkcd": "Returns a link to the latest xkcd comic. Example usage: ()xkcd",
} }
func (app *Application) loadCommandHelp() {
for k, v := range helpText {
err := app.Rdb.HSet(ctx, "command-help", k, v).Err()
if err != nil {
app.Logger.Panic(err)
}
}
commandHelpText := app.Rdb.HGetAll(ctx, "command-help").Val()
app.Logger.Infow("Successfully loaded command help text into redis",
"commandHelpText", commandHelpText,
)
}
// Help checks if a help text for a given command exists and replies with it. // Help checks if a help text for a given command exists and replies with it.
func (app *Application) commandHelp(target, name, username string) { func (app *Application) commandHelp(target, name, username string) {
// Check if the `helpText` map has an entry for `name`. If it does return it's value entry // Check if the `helpText` map has an entry for `name`. If it does return it's value entry

View file

@ -210,6 +210,8 @@ func main() {
// Start time // Start time
common.StartTime() common.StartTime()
app.loadCommandHelp()
// Join the channels in the database. // Join the channels in the database.
app.InitialJoin() app.InitialJoin()

View file

@ -262,7 +262,6 @@ func (app *Application) InitialTimers() {
if _, err := app.Rdb.Pipelined(ctx, func(rdb redis.Pipeliner) error { if _, err := app.Rdb.Pipelined(ctx, func(rdb redis.Pipeliner) error {
rdb.HSet(ctx, cronName, "timer-id", v.ID) rdb.HSet(ctx, cronName, "timer-id", v.ID)
rdb.HSet(ctx, cronName, "timer-name", v.Name) rdb.HSet(ctx, cronName, "timer-name", v.Name)
rdb.HSet(ctx, cronName, "timer-cronname", cronName)
rdb.HSet(ctx, cronName, "timer-text", v.Text) rdb.HSet(ctx, cronName, "timer-text", v.Text)
rdb.HSet(ctx, cronName, "timer-channel", v.Channel) rdb.HSet(ctx, cronName, "timer-channel", v.Channel)
rdb.HSet(ctx, cronName, "timer-repeat", v.Repeat) rdb.HSet(ctx, cronName, "timer-repeat", v.Repeat)