2024-04-02 20:29:25 +08:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bufio"
|
|
|
|
"fmt"
|
2024-07-02 18:16:26 +08:00
|
|
|
"go-bot/config"
|
2024-04-02 20:29:25 +08:00
|
|
|
"os"
|
|
|
|
"strings"
|
2024-07-02 18:16:26 +08:00
|
|
|
"time"
|
|
|
|
|
2024-09-08 16:46:05 +08:00
|
|
|
"github.com/imroc/req/v3"
|
2024-04-02 20:29:25 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2024-07-02 18:16:26 +08:00
|
|
|
|
2024-04-02 20:29:25 +08:00
|
|
|
for {
|
|
|
|
reader := bufio.NewReader(os.Stdin)
|
2024-07-02 18:16:26 +08:00
|
|
|
cfg := config.GetConfig()
|
|
|
|
fmt.Print("输入指令:")
|
2024-04-02 20:29:25 +08:00
|
|
|
raw_msg, _ := reader.ReadString('\n')
|
|
|
|
// 去除末尾的换行符
|
2024-07-02 18:16:26 +08:00
|
|
|
raw_msg = strings.TrimRight(raw_msg, "\r\n")
|
2024-06-30 21:56:34 +08:00
|
|
|
if raw_msg == "" {
|
2024-07-02 18:16:26 +08:00
|
|
|
raw_msg = "!ping"
|
|
|
|
}
|
|
|
|
if raw_msg == "!exit" {
|
|
|
|
break
|
2024-06-30 21:56:34 +08:00
|
|
|
}
|
2024-07-02 18:16:26 +08:00
|
|
|
// parms := strings.Fields(raw_msg)
|
2024-04-02 20:29:25 +08:00
|
|
|
|
2024-07-02 18:16:26 +08:00
|
|
|
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),
|
|
|
|
}
|
2024-04-02 20:29:25 +08:00
|
|
|
fmt.Println("message:", message)
|
2024-07-02 18:16:26 +08:00
|
|
|
// 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)
|
2024-09-08 16:46:05 +08:00
|
|
|
client := req.C()
|
|
|
|
_, err := client.R().
|
|
|
|
SetBodyJsonMarshal(message).
|
|
|
|
Post(url)
|
2024-07-02 18:16:26 +08:00
|
|
|
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()
|
2024-04-02 20:29:25 +08:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|