diff --git a/go.mod b/go.mod index 758b6bc..09e909e 100644 --- a/go.mod +++ b/go.mod @@ -25,6 +25,7 @@ require ( github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 github.com/tidwall/gjson v1.9.1 // indirect github.com/tuotoo/qrcode v0.0.0-20190222102259-ac9c44189bf2 + golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d golang.org/x/net v0.0.0-20210614182718-04defd469f4e // indirect golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c // indirect gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect diff --git a/go.sum b/go.sum index 6ce95d6..2707e04 100644 --- a/go.sum +++ b/go.sum @@ -286,6 +286,7 @@ golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83/go.mod h1:jdWPYTVW3xRLrWP golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e h1:gsTQYXdTw2Gq7RBsWvlQ91b+aEQ6bXFUngBGuR8sPpI= golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d h1:RNPAfi2nHY7C2srAV8A49jpsYr0ADedCk1wq6fTMTvs= golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= diff --git a/im/tg/tg.go b/im/tg/tg.go index 79dd721..87b40a3 100644 --- a/im/tg/tg.go +++ b/im/tg/tg.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "image/png" - "log" "os" "regexp" "strings" @@ -116,29 +115,28 @@ func init() { } }) b.Handle(tb.OnSticker, func(m *tb.Message) { - buf := new(bytes.Buffer) buf.ReadFrom(m.Sticker.FileReader) img, err := webp.Decode(buf) if err != nil { - log.Printf("error while decoding sticker: %v\n", err) return } buf.Reset() imgBuf := buf err = png.Encode(imgBuf, img) - if err == nil { - - filename := fmt.Sprint(time.Now().UnixNano()) + ".image" - filepath := core.ExecPath + "/data/images/" + filename - f, err := os.Create(filepath) - if err == nil { - f.Write(imgBuf.Bytes()) - f.Close() - m.Text = fmt.Sprintf(`[TG:image,file=%s]`, filename) + m.Caption - Handler(m) - } + if err != nil { + return } + filename := fmt.Sprint(time.Now().UnixNano()) + ".image" + filepath := core.ExecPath + "/data/images/" + filename + f, err := os.Create(filepath) + if err != nil { + return + } + f.Write(imgBuf.Bytes()) + f.Close() + m.Text = fmt.Sprintf(`[TG:image,file=%s]`, filename) + m.Caption + Handler(m) }) b.Handle(tb.OnText, Handler) logs.Info("监听telegram机器人")