mirror of
https://github.com/lyx0/nourybot-matrix.git
synced 2024-11-13 19:49:54 +01:00
implement a helper function to return the help text for a provided command
This commit is contained in:
parent
56fdcfc78e
commit
d8436afd6c
3 changed files with 33 additions and 15 deletions
|
@ -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 {
|
||||
|
|
25
internal/commands/help.go
Normal file
25
internal/commands/help.go
Normal file
|
@ -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
|
||||
}
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue