go-bot/test/test.go

76 lines
1.6 KiB
Go
Raw Normal View History

package main
import (
"bufio"
"fmt"
"go-bot/config"
"os"
"strings"
"time"
"github.com/imroc/req/v3"
)
func main() {
for {
reader := bufio.NewReader(os.Stdin)
cfg := config.GetConfig()
fmt.Print("输入指令:")
raw_msg, _ := reader.ReadString('\n')
// 去除末尾的换行符
raw_msg = strings.TrimRight(raw_msg, "\r\n")
if raw_msg == "" {
raw_msg = "!ping"
}
if raw_msg == "!exit" {
break
}
// parms := strings.Fields(raw_msg)
message := map[string]interface{}{
"post_type": "message",
"message_type": "group",
"time": float64(time.Now().Unix()),
"group_id": float64(874769998),
"message_id": float64(time.Now().Unix()),
"raw_message": raw_msg,
"sender": map[string]interface{}{
"user_id": float64(794508986),
"nickname": "111",
"card": "",
"role": "owner",
},
"message_seq": float64(time.Now().Unix()),
"user_id": float64(794508986),
}
fmt.Println("message:", message)
// jsonData, err := json.MarshalIndent(message, "", " ")
// if err != nil {
// log.Fatal(err)
// }
// file, err := os.Create("message.json")
// if err != nil {
// log.Fatal(err)
// }
// defer file.Close()
// _, err = file.Write(jsonData)
// if err != nil {
// log.Fatal(err)
// }
url := "http://" + cfg["APIURL"].(string)
client := req.C()
_, err := client.R().
SetBodyJsonMarshal(message).
Post(url)
if err != nil {
fmt.Println("Error:", err)
}
// worker := workers.NewWorker(parms, "794508986", "874769998", "111", "222", raw_msg)
// fmt.Println("TestPermission:", worker.CheckPermission())
// message := worker.GetMsg()
}
}