-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix(kookin): 🚑 websocket write failed * docs: 🔥 ignore
- Loading branch information
Showing
6 changed files
with
47 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
conf.json | ||
session_id | ||
dist/ | ||
main | ||
main | ||
.idea/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,116 +1,20 @@ | ||
package client | ||
|
||
//import ( | ||
// | ||
// "bytes" | ||
// "encoding/json" | ||
// "fmt" | ||
// "github.com/tencent-connect/botgo/log" | ||
// "io" | ||
// "net/http" | ||
// "time" | ||
//) | ||
// | ||
////const QQApiUrl = "https://api.sgroup.qq.com" | ||
// | ||
//type QQClient struct { | ||
// http.Client | ||
// meta *BotMeta | ||
// accessToken string | ||
//} | ||
// | ||
//type BotMeta struct { | ||
// AppId string `json:"appId"` | ||
// AppSecret string `json:"clientSecret"` | ||
//} | ||
// | ||
//type KookClient struct { | ||
// http.Client | ||
// AccessToken string | ||
//} | ||
// | ||
//func NewQQClient(appId string, accessToken string) *QQClient { | ||
// client := &QQClient{ | ||
// http.Client{}, | ||
// &BotMeta{ | ||
// appId, | ||
// accessToken, | ||
// }, | ||
// "", | ||
// } | ||
// go client.flushToken() | ||
// | ||
// return client | ||
//} | ||
// | ||
//func (c *QQClient) Get(url string) ([]byte, error) { | ||
// | ||
// request, err := http.NewRequest("GET", url, nil) | ||
// if err != nil { | ||
// log.Errorf("Http request construct failed! err: %e", err) | ||
// return nil, err | ||
// } | ||
// request.Header.Set("Authorization", fmt.Sprintf("QQBot %s", c.accessToken)) | ||
// request.Header.Set("X-Union-Appid", c.meta.AppId) | ||
// return c.doRequestAndReadBody(request) | ||
//} | ||
// | ||
//func (c *QQClient) Post(url string, body any) ([]byte, error) { | ||
// bodyBytes, _ := json.Marshal(body) | ||
// buffer := bytes.NewBuffer(bodyBytes) | ||
// request, err := http.NewRequest("POST", url, buffer) | ||
// if err != nil { | ||
// log.Errorf("Http request construct failed! err: %e", err) | ||
// return nil, err | ||
// } | ||
// request.Header.Set("Authorization", fmt.Sprintf("QQBot %s", c.accessToken)) | ||
// request.Header.Set("X-Union-Appid", c.meta.AppId) | ||
// return c.doRequestAndReadBody(request) | ||
//} | ||
// | ||
//func (c *QQClient) doRequestAndReadBody(r *http.Request) ([]byte, error) { | ||
// resp, err := c.Do(r) | ||
// if err != nil { | ||
// log.Errorf("http request failed! err:%e", err) | ||
// return nil, err | ||
// } | ||
// defer resp.Body.Close() | ||
// data, err := io.ReadAll(resp.Body) | ||
// if err != nil { | ||
// log.Errorf("read response body failed! err:%e", err) | ||
// return nil, err | ||
// } | ||
// return data, nil | ||
//} | ||
// | ||
//func (c *QQClient) flushToken() { | ||
// // https://bots.qq.com/app/getAppAccessToken | ||
// log.Info("start flush token") | ||
// body, _ := json.Marshal(c.meta) | ||
// buffer := bytes.NewBuffer(body) | ||
// request, _ := http.NewRequest("POST", "https://bots.qq.com/app/getAppAccessToken", buffer) | ||
// request.Header.Add("Content-Type", "application/json") | ||
// for { | ||
// // 1min 尝试刷新一次 | ||
// resp, err := c.Do(request) | ||
// if err != nil { | ||
// log.Errorf("[QQClient] get access token failed") | ||
// continue | ||
// } | ||
// defer resp.Body.Close() | ||
// authInfoBytes, _ := io.ReadAll(resp.Body) | ||
// authInfo := make(map[string]string) | ||
// err = json.Unmarshal(authInfoBytes, &authInfo) | ||
// if err != nil { | ||
// log.Errorf("[QQClient] unmarshal resp body failed. resp: [%s]", string(authInfoBytes)) | ||
// continue | ||
// } | ||
// if value := authInfo["access_token"]; value != "" { | ||
// if c.accessToken != value { | ||
// log.Info("[QQClient] accessToken has flushed, new token is:", value) | ||
// c.accessToken = authInfo["access_token"] | ||
// } | ||
// } | ||
// <-time.After(1 * time.Minute) | ||
// } | ||
//} | ||
import ( | ||
"github.com/gorilla/websocket" | ||
"sync" | ||
) | ||
|
||
type WsClient struct { | ||
*websocket.Conn | ||
Status bool | ||
mutex sync.Mutex | ||
} | ||
|
||
func (client *WsClient) Lock() bool { | ||
return client.mutex.TryLock() | ||
} | ||
|
||
func (client *WsClient) Unlock() { | ||
client.mutex.Unlock() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters