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 (
"fmt"
"reflect"
"strconv"
"time"
@ -55,18 +56,20 @@ func (n *Notifier) Notify(obj interface{}, args ...interface{}) {
func filterPlaintextMessages(args []interface{}) (texts []string, pureArgs []interface{}) {
var firstObjectOffset = -1
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:
texts = append(texts, a.PlainText())
if firstObjectOffset == -1 {
firstObjectOffset = idx
}
case types.Stringer:
texts = append(texts, a.String())
if firstObjectOffset == -1 {
firstObjectOffset = idx
case types.Stringer:
texts = append(texts, a.String())
if firstObjectOffset == -1 {
firstObjectOffset = idx
}
}
}
}