Skip to content
This repository has been archived by the owner on Jul 27, 2024. It is now read-only.

Commit

Permalink
Merge pull request #7 from opq-osc/beta
Browse files Browse the repository at this point in the history
Beta
  • Loading branch information
mcoo authored May 23, 2021
2 parents beb80c0 + b8542c8 commit 641cf6a
Show file tree
Hide file tree
Showing 5 changed files with 133 additions and 26 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@
20210427 修复SocketIO数据畸形的问题,添加群上传功能
20210428 添加内置session 相关内容看Wiki
20210512 packet现在修改为传递指针,请注意
20210523 添加快捷发信息的函数
```
13 changes: 6 additions & 7 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"encoding/base64"
"fmt"
"github.com/mcoo/OPQBot"
"github.com/mcoo/OPQBot/qzone"
"github.com/mcoo/requests"
"io/ioutil"
"log"
Expand Down Expand Up @@ -36,12 +35,12 @@ func main() {
// m = map[string]interface{}{"reason": "消息违规"}
// return m
//}))
ck, _ := opqBot.GetUserCookie()
qz := qzone.NewQzoneManager(opqBot.QQ, ck)
f, _ := ioutil.ReadFile("./head.PNG")
u, _ := qz.UploadPic(base64.StdEncoding.EncodeToString(f))
bo, rich, _ := qzone.GetPicBoAndRichVal(u)
log.Println(qz.SendShuoShuoWithPic("发送图文测试", bo, rich))
//ck, _ := opqBot.GetUserCookie()
//qz := qzone.NewQzoneManager(opqBot.QQ, ck)
//f, _ := ioutil.ReadFile("./head.PNG")
//u, _ := qz.UploadPic(base64.StdEncoding.EncodeToString(f))
//bo, rich, _ := qzone.GetPicBoAndRichVal(u)
//log.Println(qz.SendShuoShuoWithPic("发送图文测试", bo, rich))
//lists,_ :=qz.GetShuoShuoList()
//infoReg,_ := regexp.Compile(`<div class="f-info">(.*?)</div>`)
//for _,v := range lists.Data.Data {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ require (
github.com/dop251/goja v0.0.0-20210427212725-462d53687b0d
github.com/goinggo/mapstructure v0.0.0-20140717182941-194205d9b4a9
github.com/gorilla/websocket v1.4.2
github.com/mcoo/requests v0.0.1-edited
)
github.com/mcoo/requests v0.0.2-edited
)
105 changes: 94 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,6 @@ import (
"encoding/base64"
"encoding/json"
"errors"
"github.com/goinggo/mapstructure"
gosocketio "github.com/mcoo/OPQBot/golang-socketio-edit"
"github.com/mcoo/OPQBot/golang-socketio-edit/transport"
"github.com/mcoo/OPQBot/session"
_ "github.com/mcoo/OPQBot/session/provider"
"github.com/mcoo/requests"
"io/ioutil"
"log"
"math/big"
Expand All @@ -24,6 +18,13 @@ import (
"strings"
"sync"
"time"

"github.com/goinggo/mapstructure"
gosocketio "github.com/mcoo/OPQBot/golang-socketio-edit"
"github.com/mcoo/OPQBot/golang-socketio-edit/transport"
"github.com/mcoo/OPQBot/session"
_ "github.com/mcoo/OPQBot/session/provider"
"github.com/mcoo/requests"
)

type BotManager struct {
Expand Down Expand Up @@ -154,13 +155,13 @@ func (b *BotManager) Start() error {
signal.Notify(interrupt, os.Interrupt, os.Kill)
go func() {
select {
case _ = <-interrupt:
case <-interrupt:
log.Println("程序被用户终止,正在进行释放资源操作!")
b.MaxRetryCount = 0
b.Done <- 1
b.Done <- 2
b.wg.Done()
case _ = <-restart:
case <-restart:
log.Println("程序重连尝试!")
b.Done <- 1
b.Done <- 2
Expand All @@ -180,7 +181,7 @@ func (b *BotManager) Start() error {
if len(b.myRecord) > 50 {
b.myRecordLocker.Lock()
for i, v := range b.myRecord {
if time.Now().Sub(time.Unix(int64(v.MsgTime), 0)) > time.Second*180 {
if time.Since(time.Unix(int64(v.MsgTime), 0)) > time.Second*180 {
delete(b.myRecord, i)
}
}
Expand Down Expand Up @@ -665,6 +666,20 @@ func (b *BotManager) KickGroupMember(groupID, userId int64) error {
return nil
}

// GetGroupMemberList 获取群成员列表
func (b *BotManager) GetGroupMemberList(groupID, LastUin int64) (GroupMemberList, error) {
var result GroupMemberList
res, err := requests.PostJson(b.OPQUrl+"/v1/LuaApiCaller?funcname=friendlist.GetTroopMemberListReq&qq="+strconv.FormatInt(b.QQ, 10), map[string]interface{}{"GroupUin": groupID, "LastUin": LastUin})
if err != nil {
return result, err
}
err = res.Json(&result)
if err != nil {
return result, err
}
return result, nil
}

// SetGroupNewNick 设置群名片
func (b *BotManager) SetGroupNewNick(newNick string, groupID, userId int64) error {
var result Result
Expand Down Expand Up @@ -713,7 +728,7 @@ func (b *BotManager) GetFriendList(startIndex int) (FriendList, error) {
return result, nil
}

// GetGroupList 获取好友列表
// GetGroupList 获取群列表
func (b *BotManager) GetGroupList(nextToken string) (GroupList, error) {
var result GroupList
res, err := requests.PostJson(b.OPQUrl+"/v1/LuaApiCaller?funcname=friendlist.GetTroopListReqV2&timeout=10&qq="+strconv.FormatInt(b.QQ, 10), map[string]interface{}{"NextToken": nextToken})
Expand Down Expand Up @@ -1184,7 +1199,75 @@ OuterLoop:
}
time.Sleep(time.Duration(b.delayed) * time.Millisecond)
}

}
}

// SendFriendTextMsg 发送文字信息给好友
func (b *BotManager) SendFriendTextMsg(FriendUin int64, Content string) {
b.Send(SendMsgPack{
SendToType: SendToTypeFriend,
ToUserUid: FriendUin,
Content: SendTypeTextMsgContent{
Content: Content,
},
})
}

// SendFriendPicMsg 发送图片信息给好友
func (b *BotManager) SendFriendPicMsg(FriendUin int64, Content string, Pic []byte) {
b.Send(SendMsgPack{
SendToType: SendToTypeFriend,
ToUserUid: FriendUin,
Content: SendTypePicMsgByBase64Content{
Content: Content,
Base64: base64.StdEncoding.EncodeToString(Pic),
Flash: false,
},
})
}

// SendGroupTextMsg 发送文字信息给群
func (b *BotManager) SendGroupTextMsg(GroupUin int64, Content string) {
b.Send(SendMsgPack{
SendToType: SendToTypeGroup,
ToUserUid: GroupUin,
Content: SendTypeTextMsgContent{
Content: Content,
},
})
}

// SendGroupPicMsg 发送图片信息给群
func (b *BotManager) SendGroupPicMsg(GroupUin int64, Content string, Pic []byte) {
b.Send(SendMsgPack{
SendToType: SendToTypeGroup,
ToUserUid: GroupUin,
Content: SendTypePicMsgByBase64Content{
Content: Content,
Base64: base64.StdEncoding.EncodeToString(Pic),
Flash: false,
},
})
}

// SendGroupJsonMsg 发送JSON信息给群
func (b *BotManager) SendGroupJsonMsg(GroupUin int64, Content string) {
b.Send(SendMsgPack{
SendToType: SendToTypeGroup,
ToUserUid: GroupUin,
Content: SendTypeJsonContent{
Content: Content,
},
})
}

// SendGroupXmlMsg 发送Xml信息给群
func (b *BotManager) SendGroupXmlMsg(GroupUin int64, Content string) {
b.Send(SendMsgPack{
SendToType: SendToTypeGroup,
ToUserUid: GroupUin,
Content: SendTypeXmlContent{
Content: Content,
},
})
}
36 changes: 30 additions & 6 deletions model.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ type GroupAdminSysNotifyPack struct {
Flag8 int `json:"Flag_8"`
GroupID int64 `json:"GroupId"`
GroupName string `json:"GroupName"`
ActionUin int `json:"ActionUin"`
ActionUin int64 `json:"ActionUin"`
ActionName string `json:"ActionName"`
ActionGroupCard string `json:"ActionGroupCard"`
Action int `json:"Action"`
Expand Down Expand Up @@ -373,19 +373,43 @@ type UserCardInfo struct {
type FriendFileResult struct {
FileName string `json:"FileName"`
FileSize int `json:"FileSize"`
FromUin int `json:"FromUin"`
FromUin int64 `json:"FromUin"`
URL string `json:"Url"`
}
type GroupFileResult struct {
Ret int `json:"Ret"`
URL string `json:"Url"`
}
type GroupMemberList struct {
Count int `json:"Count"`
GroupUin int64 `json:"GroupUin"`
LastUin int64 `json:"LastUin"`
MemberList []struct {
Age int `json:"Age"`
AutoRemark string `json:"AutoRemark"`
CreditLevel int `json:"CreditLevel"`
Email string `json:"Email"`
FaceID int `json:"FaceId"`
Gender int `json:"Gender"`
GroupAdmin int `json:"GroupAdmin"`
GroupCard string `json:"GroupCard"`
JoinTime int `json:"JoinTime"`
LastSpeakTime int `json:"LastSpeakTime"`
MemberLevel int `json:"MemberLevel"`
MemberUin int64 `json:"MemberUin"`
Memo string `json:"Memo"`
NickName string `json:"NickName"`
ShowName string `json:"ShowName"`
SpecialTitle string `json:"SpecialTitle"`
Status int `json:"Status"`
} `json:"MemberList"`
}

// FriendList 获取好友列表表单
type FriendList struct {
FriendCount int `json:"Friend_count"`
Friendlist []struct {
FriendUin int `json:"FriendUin"`
FriendUin int64 `json:"FriendUin"`
IsRemark bool `json:"IsRemark"`
NickName string `json:"NickName"`
OnlineStr string `json:"OnlineStr"`
Expand All @@ -402,8 +426,8 @@ type GroupList struct {
Count int `json:"Count"`
NextToken string `json:"NextToken"`
TroopList []struct {
GroupID int `json:"GroupId"`
GroupMemberCount int `json:"GroupMemberCount"`
GroupID int64 `json:"GroupId"`
GroupMemberCount int64 `json:"GroupMemberCount"`
GroupName string `json:"GroupName"`
GroupNotice string `json:"GroupNotice"`
GroupOwner int64 `json:"GroupOwner"`
Expand Down Expand Up @@ -433,7 +457,7 @@ type UserInfo struct {
Qzone int `json:"qzone"`
Realname string `json:"realname"`
Smartname string `json:"smartname"`
Uin int `json:"uin"`
Uin int64 `json:"uin"`
} `json:"data"`
Default int `json:"default"`
Message string `json:"message"`
Expand Down

0 comments on commit 641cf6a

Please sign in to comment.