12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- package main
- import (
- "encoding/json"
- "log"
- "os"
- "strings"
- "github.com/JamZYM/golagrange/api"
- "github.com/JamZYM/golagrange/function"
- "github.com/joho/godotenv"
- )
- func msgProccess(msg map[string]interface{}, connBot api.WsBot) {
- // fmt.Println(msg)
- if msg["message_type"].(string) == "private" {
- user_id := int(msg["user_id"].(float64))
- msg_type := msg["message"].([]interface{})[0].(map[string]interface{})["type"].(string)
- if msg_type == "text" {
- msg_text := msg["message"].([]interface{})[0].(map[string]interface{})["data"].(map[string]interface{})["text"].(string)
- if strings.HasPrefix(msg_text, "/bvdl ") {
- function.Func_bvdl(msg_text, connBot, user_id)
- } else if msg_text == "/serverStatus" {
- function.Func_serverStatus(connBot, user_id)
- }
- }
- }
- }
- func main() {
- err := godotenv.Load()
- if err != nil {
- log.Fatal("Error loading .env file")
- }
- connBot := api.WebsocketBot(os.Getenv("HOST"), os.Getenv("PORT"), os.Getenv("PATH"))
- defer connBot.Wsconn.Close()
- for {
- _, messageBytes, err := connBot.Wsconn.ReadMessage()
- if err != nil {
- log.Println("read:", err)
- return
- }
- var message map[string]interface{}
- json.Unmarshal(messageBytes, &message)
- if message["post_type"] == "message" {
- go msgProccess(message, connBot)
- } else if message["post_type"] == "meta_event" {
- }
- }
- // connBot.Send_private_msg(2945340446, "Hello, world!")
- // err = connBot.Upload_private_file(2945340446, "/home/jam/Documents/College/大学学习/大创/基于gm_Id方法的跨阻放大器设计_林佳辉.pdf", "基于gm_Id方法的跨阻放大器设计_林佳辉.pdf")
- // fmt.Println(err)
- }
|