123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- package main
- import (
- "encoding/json"
- "log"
- "os"
- "strings"
- "github.com/JamZYM/golagrange/api"
- "github.com/JamZYM/golagrange/function"
- "github.com/joho/godotenv"
- )
- var TTS_id int = 0
- 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)
- } else if strings.HasPrefix(msg_text, "/tts ") {
- TTS_id++
- function.Func_TTS(connBot, user_id, msg_text, false, TTS_id-1)
- TTS_id = TTS_id % 10
- }
- }
- } else if msg["message_type"].(string) == "group" {
- group_id := int(msg["group_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, "/tts ") {
- TTS_id++
- function.Func_TTS(connBot, group_id, msg_text, true, TTS_id-1)
- TTS_id = TTS_id % 10
- }
- }
- }
- }
- 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)
- }
|