fix telegram filterPlaintextMessages

This commit is contained in:
c9s 2022-06-13 11:29:33 +08:00
parent eba6706b92
commit e3a894eb7e
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54

View File

@ -2,6 +2,7 @@ package telegramnotifier
import ( import (
"fmt" "fmt"
"reflect"
"strconv" "strconv"
"time" "time"
@ -55,18 +56,20 @@ func (n *Notifier) Notify(obj interface{}, args ...interface{}) {
func filterPlaintextMessages(args []interface{}) (texts []string, pureArgs []interface{}) { func filterPlaintextMessages(args []interface{}) (texts []string, pureArgs []interface{}) {
var firstObjectOffset = -1 var firstObjectOffset = -1
for idx, arg := range args { for idx, arg := range args {
switch a := arg.(type) { rt := reflect.TypeOf(arg)
if rt.Kind() == reflect.Ptr {
switch a := arg.(type) {
case types.PlainText:
texts = append(texts, a.PlainText())
if firstObjectOffset == -1 {
firstObjectOffset = idx
}
case types.PlainText: case types.Stringer:
texts = append(texts, a.PlainText()) texts = append(texts, a.String())
if firstObjectOffset == -1 { if firstObjectOffset == -1 {
firstObjectOffset = idx firstObjectOffset = idx
} }
case types.Stringer:
texts = append(texts, a.String())
if firstObjectOffset == -1 {
firstObjectOffset = idx
} }
} }
} }