github.com/fumiama/NanoBot@v0.0.0-20231122134259-c22d8183efca/example/handler/main.go (about) 1 package main 2 3 import ( 4 "strings" 5 6 nano "github.com/fumiama/NanoBot" 7 log "github.com/sirupsen/logrus" 8 ) 9 10 func main() { 11 log.SetLevel(log.DebugLevel) 12 nano.OpenAPI = nano.SandboxAPI 13 nano.Run(nil, &nano.Bot{ 14 AppID: "你的AppID", 15 Token: "你的Token", 16 Secret: "你的Secret, 可以不填 (QQ群Bot必须填写)", 17 Intents: nano.IntentGuildPublic, 18 Handler: &nano.Handler{ 19 OnAtMessageCreate: func(s uint32, bot *nano.Bot, d *nano.Message) { 20 u := "" 21 if len(d.Attachments) > 0 { 22 u = d.Attachments[0].URL 23 if !strings.HasPrefix(u, "http") { 24 u = "http://" + u 25 } 26 } 27 _, err := bot.PostMessageToChannel(d.ChannelID, &nano.MessagePost{ 28 Content: "您发送了: " + d.Content, 29 Image: u, 30 ReplyMessageID: d.ID, 31 MessageReference: &nano.MessageReference{ 32 MessageID: d.ID, 33 }, 34 }) 35 if err != nil { 36 bot.PostMessageToChannel(d.ChannelID, &nano.MessagePost{ 37 Content: "[ERROR]: " + err.Error(), 38 ReplyMessageID: d.ID, 39 }) 40 } 41 }, 42 }, 43 }) 44 }