mirror of
https://github.com/lyx0/nourybot-matrix.git
synced 2024-11-13 19:49:54 +01:00
40 lines
851 B
Go
40 lines
851 B
Go
|
package main
|
||
|
|
||
|
import (
|
||
|
"strings"
|
||
|
|
||
|
"github.com/lyx0/nourybot-matrix/internal/commands"
|
||
|
"maunium.net/go/mautrix/event"
|
||
|
)
|
||
|
|
||
|
func (app *Application) ParseCommand(evt *event.Event) {
|
||
|
commandName := strings.ToLower(strings.SplitN(evt.Content.AsMessage().Body, " ", 2)[0][1:])
|
||
|
app.Log.Info().Msgf("Command: %s", commandName)
|
||
|
|
||
|
switch commandName {
|
||
|
case "xd":
|
||
|
app.SendText(evt, "XD !")
|
||
|
return
|
||
|
|
||
|
case "ping":
|
||
|
if resp, err := commands.Ping(); err != nil {
|
||
|
app.Log.Error().Err(err).Msg("Failed to send Ping")
|
||
|
app.SendText(evt, "Something went wrong.")
|
||
|
return
|
||
|
} else {
|
||
|
app.SendText(evt, resp)
|
||
|
return
|
||
|
}
|
||
|
|
||
|
case "xkcd":
|
||
|
if resp, err := commands.Xkcd(); err != nil {
|
||
|
app.Log.Error().Err(err).Msg("Failed to send Ping")
|
||
|
app.SendText(evt, "Something went wrong.")
|
||
|
return
|
||
|
} else {
|
||
|
app.SendText(evt, resp)
|
||
|
return
|
||
|
}
|
||
|
}
|
||
|
}
|