From 56fdcfc78e3ab9e15441e4060d9be69f9c3499cc Mon Sep 17 00:00:00 2001 From: lyx0 <66651385+lyx0@users.noreply.github.com> Date: Sun, 7 May 2023 00:30:24 +0200 Subject: [PATCH] add phonetic explanation --- cmd/nourybot/commands.go | 18 ++++++++++++------ internal/commands/phonetic.go | 12 ++++++++++++ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/cmd/nourybot/commands.go b/cmd/nourybot/commands.go index 61e1e6d..9555246 100644 --- a/cmd/nourybot/commands.go +++ b/cmd/nourybot/commands.go @@ -62,14 +62,20 @@ func (app *Application) ParseCommand(evt *event.Event) { } case "phonetic": - msg := evt.Content.AsMessage().Body[9:len(evt.Content.AsMessage().Body)] - if resp, err := commands.Phonetic(msg); err != nil { - app.Log.Error().Err(err).Msg("failed to handle phonetic command") - app.SendText(evt, "Something went wrong.") - return - } else { + if msgLen == 1 { + resp := commands.PhoneticExplanation() 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 { + app.Log.Error().Err(err).Msg("failed to handle phonetic command") + app.SendText(evt, "Something went wrong.") + return + } else { + app.SendText(evt, resp) + return + } } case "ping": diff --git a/internal/commands/phonetic.go b/internal/commands/phonetic.go index 3a67cd9..f83e130 100644 --- a/internal/commands/phonetic.go +++ b/internal/commands/phonetic.go @@ -73,6 +73,18 @@ 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