From d8436afd6c9499665677a3b06a2cf563c0a54c09 Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Sun, 7 May 2023 00:45:31 +0200 Subject: [PATCH] implement a helper function to return the help text for a provided command --- cmd/nourybot/commands.go | 11 ++++++++--- internal/commands/help.go | 25 +++++++++++++++++++++++++ internal/commands/phonetic.go | 12 ------------ 3 files changed, 33 insertions(+), 15 deletions(-) create mode 100644 internal/commands/help.go diff --git a/cmd/nourybot/commands.go b/cmd/nourybot/commands.go index 9555246..40c5621 100644 --- a/cmd/nourybot/commands.go +++ b/cmd/nourybot/commands.go @@ -63,9 +63,14 @@ func (app *Application) ParseCommand(evt *event.Event) { case "phonetic": if msgLen == 1 { - resp := commands.PhoneticExplanation() - app.SendText(evt, resp) - return + if resp, err := commands.Help(commandName); err != nil { + app.Log.Error().Err(err).Msg("failed to handle help->phonetic command") + app.SendText(evt, "Something went wrong.") + return + } else { + app.SendText(evt, resp) + return + } } else { msg := evt.Content.AsMessage().Body[9:len(evt.Content.AsMessage().Body)] if resp, err := commands.Phonetic(msg); err != nil { diff --git a/internal/commands/help.go b/internal/commands/help.go new file mode 100644 index 0000000..0b27539 --- /dev/null +++ b/internal/commands/help.go @@ -0,0 +1,25 @@ +package commands + +func Help(cn string) (string, error) { + switch cn { + case "phonetic": + if resp, err := phonetic(); err != nil { + return "", ErrInternalServerError + } else { + return resp, nil + } + } + return "this shouldnt happen xD", nil +} + +func phonetic() (string, error) { + // This might look like complete ass depending on the + // matrix clients font. Looks fine on my Element client. + help := ` +| Ё | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | Ъ | + | Я | Ш | Е | Р | Т | Ы | У | И | О | П | Ю | Щ | Э | + | А | С | Д | Ф | Г | Ч | Й | К | Л | Ь | Ж | + | З | Х | Ц | В | Б | Н | М | ; | : | + ` + return help, nil +} diff --git a/internal/commands/phonetic.go b/internal/commands/phonetic.go index f83e130..3a67cd9 100644 --- a/internal/commands/phonetic.go +++ b/internal/commands/phonetic.go @@ -73,18 +73,6 @@ var cm = map[string]string{ "M": "М", } -func PhoneticExplanation() string { - // This might look like complete ass depending on the - // matrix clients font. Looks fine on my Element client. - help := ` -| Ё | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 0 | - | Ъ | - | Я | Ш | Е | Р | Т | Ы | У | И | О | П | Ю | Щ | Э | - | А | С | Д | Ф | Г | Ч | Й | К | Л | Ь | Ж | - | З | Х | Ц | В | Б | Н | М | ; | : | - ` - return help -} - func Phonetic(message string) (string, error) { var ts string