mirror of
https://github.com/Mrs4s/MiraiGo.git
synced 2025-05-04 11:07:40 +08:00
feature anonymous mute. close #84
This commit is contained in:
parent
b79826706e
commit
d360670837
@ -2,6 +2,7 @@ package client
|
||||
|
||||
import (
|
||||
"crypto/md5"
|
||||
"encoding/base64"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
@ -447,6 +448,10 @@ func (c *QQClient) parseGroupMessage(m *msg.Message) *message.GroupMessage {
|
||||
sender = &message.Sender{
|
||||
Uin: 80000000,
|
||||
Nickname: string(anonInfo.AnonNick),
|
||||
AnonymousInfo: &message.AnonymousInfo{
|
||||
AnonymousId: base64.StdEncoding.EncodeToString(anonInfo.AnonId),
|
||||
AnonymousNick: string(anonInfo.AnonNick),
|
||||
},
|
||||
IsFriend: false,
|
||||
}
|
||||
} else {
|
||||
|
@ -1,12 +1,16 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/Mrs4s/MiraiGo/binary"
|
||||
"github.com/Mrs4s/MiraiGo/binary/jce"
|
||||
"github.com/Mrs4s/MiraiGo/client/pb/oidb"
|
||||
"github.com/Mrs4s/MiraiGo/protocol/packets"
|
||||
"github.com/Mrs4s/MiraiGo/utils"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tidwall/gjson"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sync"
|
||||
)
|
||||
@ -211,6 +215,28 @@ func (g *GroupInfo) MuteAll(mute bool) {
|
||||
}
|
||||
}
|
||||
|
||||
func (g *GroupInfo) MuteAnonymous(id, nick string, seconds int32) error {
|
||||
payload := fmt.Sprintf("anony_id=%v&group_code=%v&seconds=%v&anony_nick=%v&bkn=%v", url.QueryEscape(id), g.Code, seconds, nick, g.client.getCSRFToken())
|
||||
rsp, err := utils.HttpPostBytesWithCookie("https://qqweb.qq.com/c/anonymoustalk/blacklist", []byte(payload), g.client.getCookies(), "application/x-www-form-urlencoded")
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "failed to request blacklist")
|
||||
}
|
||||
j := gjson.ParseBytes(rsp)
|
||||
if r := j.Get("retcode"); r.Exists() {
|
||||
if r.Int() != 0 {
|
||||
return errors.Errorf("retcode %v", r.Int())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if r := j.Get("cgicode"); r.Exists() {
|
||||
if r.Int() != 0 {
|
||||
return errors.Errorf("retcode %v", r.Int())
|
||||
}
|
||||
return nil
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *GroupInfo) Quit() {
|
||||
if g.SelfPermission() != Owner {
|
||||
g.client.quitGroup(g.Code)
|
||||
|
@ -70,10 +70,16 @@ type (
|
||||
}
|
||||
|
||||
Sender struct {
|
||||
Uin int64
|
||||
Nickname string
|
||||
CardName string
|
||||
IsFriend bool
|
||||
Uin int64
|
||||
Nickname string
|
||||
CardName string
|
||||
AnonymousInfo *AnonymousInfo
|
||||
IsFriend bool
|
||||
}
|
||||
|
||||
AnonymousInfo struct {
|
||||
AnonymousId string
|
||||
AnonymousNick string
|
||||
}
|
||||
|
||||
IMessageElement interface {
|
||||
|
@ -63,13 +63,17 @@ func HttpPostBytes(url string, data []byte) ([]byte, error) {
|
||||
return body, nil
|
||||
}
|
||||
|
||||
func HttpPostBytesWithCookie(url string, data []byte, cookie string) ([]byte, error) {
|
||||
func HttpPostBytesWithCookie(url string, data []byte, cookie string, contentType ...string) ([]byte, error) {
|
||||
t := "application/json"
|
||||
if len(contentType) > 0 {
|
||||
t = contentType[0]
|
||||
}
|
||||
req, err := http.NewRequest("POST", url, bytes.NewReader(data))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req.Header["User-Agent"] = []string{"Dalvik/2.1.0 (Linux; U; Android 7.1.2; PCRT00 Build/N2G48H)"}
|
||||
req.Header["Content-Type"] = []string{"application/json"}
|
||||
req.Header["Content-Type"] = []string{t}
|
||||
if cookie != "" {
|
||||
req.Header["Cookie"] = []string{cookie}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user