multiple smaller fixes and improvements

This commit is contained in:
cubicroot 2022-02-11 22:10:05 +01:00
parent a1558f6f63
commit 728c84676c
4 changed files with 9 additions and 21 deletions

View file

@ -259,27 +259,15 @@ func (d *Dispatcher) respondToMessage(a *model.Application, body, formattedBody
// Extracts body and formatted body from a matrix message event
func bodiesFromMessage(message *event.Event) (body, formattedBody string, err error) {
if val, ok := message.Content.Raw["body"]; ok {
body, ok := val.(string)
if !ok {
return "", "", pberrors.ErrorMessageNotFound
}
formattedBody = body
} else {
msgContent := message.Content.AsMessage()
if msgContent == nil {
return "", "", pberrors.ErrorMessageNotFound
}
if val, ok := message.Content.Raw["formatted_body"]; ok {
body, ok := val.(string)
if !ok {
return "", "", pberrors.ErrorMessageNotFound
}
formattedBody = body
formattedBody = msgContent.FormattedBody
if formattedBody == "" {
formattedBody = msgContent.Body
}
return body, formattedBody, nil
return msgContent.Body, formattedBody, nil
}