Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Beta63 #190

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Processor/ProcessC2CMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,12 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
Sender: Sender{
Nickname: "",
UserID: userid64,
TinyID: "",
Card: "",
Sex: "0",
Age: 0,
Area: "",
Level: "0",
},
SubType: "normal",
Time: time.Now().Unix(),
Expand Down
11 changes: 11 additions & 0 deletions Processor/ProcessChannelDirectMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
Nickname: data.Member.Nick,
TinyID: "",
UserID: userid64,
Card: data.Member.Nick,
Sex: "0",
Age: 0,
Area: "",
Level: "0",
},
SubType: "channel",
Time: t.Unix(),
Expand Down Expand Up @@ -310,6 +315,12 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
Sender: Sender{
Nickname: data.Member.Nick,
UserID: userid64,
TinyID: "",
Card: data.Member.Nick,
Sex: "0",
Age: 0,
Area: "",
Level: "0",
},
SubType: "normal",
Time: time.Now().Unix(),
Expand Down
5 changes: 5 additions & 0 deletions Processor/ProcessGroupMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
Sender: Sender{
Nickname: "",
UserID: userid64,
Card: "",
Sex: "0",
Age: 0,
Area: "",
Level: "0",
},
SubType: "normal",
Time: time.Now().Unix(),
Expand Down
10 changes: 10 additions & 0 deletions Processor/ProcessGuildATMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
Nickname: data.Member.Nick,
TinyID: "",
UserID: userid64,
Card: data.Member.Nick,
Sex: "0",
Age: 0,
Area: "",
Level: "0",
},
SubType: "channel",
Time: t.Unix(),
Expand Down Expand Up @@ -181,6 +186,11 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
Sender: Sender{
Nickname: data.Member.Nick,
UserID: userid64,
Card: data.Member.Nick,
Sex: "0",
Age: 0,
Area: "",
Level: "0",
},
SubType: "normal",
Time: time.Now().Unix(),
Expand Down
10 changes: 10 additions & 0 deletions Processor/ProcessGuildNormalMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
Nickname: data.Member.Nick,
TinyID: "",
UserID: userid64,
Card: data.Member.Nick,
Sex: "0",
Age: 0,
Area: "",
Level: "0",
},
SubType: "channel",
Time: t.Unix(),
Expand Down Expand Up @@ -185,6 +190,11 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
Sender: Sender{
Nickname: data.Member.Nick,
UserID: userid64,
Card: data.Member.Nick,
Sex: "0",
Age: 0,
Area: "",
Level: "0",
},
SubType: "normal",
Time: time.Now().Unix(),
Expand Down
6 changes: 6 additions & 0 deletions Processor/Processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ type Sender struct {
TinyID string `json:"tiny_id"`
UserID int64 `json:"user_id"`
Role string `json:"role,omitempty"`
Card string `json:"card,omitempty"`
Sex string `json:"sex,omitempty"`
Age int32 `json:"age,omitempty"`
Area string `json:"area,omitempty"`
Level string `json:"level,omitempty"`
Title string `json:"title,omitempty"`
}

// 频道信息事件
Expand Down
1 change: 1 addition & 0 deletions handlers/get_group_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func handleGetGroupInfo(client callapi.Client, api openapi.OpenAPI, apiv2 openap
//用GroupID给ChannelID赋值,因为我们是把频道虚拟成了群
ChannelID := params.GroupID
// 使用RetrieveRowByIDv2还原真实的ChannelID
mylog.Printf("测试:%v", ChannelID.(string))
RChannelID, err := idmap.RetrieveRowByIDv2(ChannelID.(string))
if err != nil {
mylog.Printf("error retrieving real ChannelID: %v", err)
Expand Down
38 changes: 36 additions & 2 deletions handlers/get_group_member_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package handlers

import (
"context"
"strconv"
"time"

"github.com/hoshinonyaruko/gensokyo/callapi"
Expand Down Expand Up @@ -43,10 +44,43 @@ func getGroupMemberList(client callapi.Client, api openapi.OpenAPI, apiv2 openap

switch msgType {
case "group":
mylog.Printf("getGroupMemberList(频道): 目前暂未开放该能力")
mylog.Printf("getGroupMemberList(group): 开始从本地获取群成员列表")
// 实现的功能
var members []MemberList

// 使用 message.Params.GroupID.(string) 作为 id 来调用 FindSubKeysById
userIDs, err := idmap.FindSubKeysById(message.Params.GroupID.(string))
if err != nil {
mylog.Printf("Error retrieving user IDs: %v", err)
return // 或者处理错误
}

// 获取当前时间的前一天,并转换为10位时间戳
yesterday := time.Now().AddDate(0, 0, -1).Unix()

for _, userID := range userIDs {
member := MemberList{
UserID: userID,
GroupID: message.Params.GroupID.(string),
Nickname: "", // 根据需要填充或保留为空
JoinTime: strconv.FormatInt(yesterday, 10),
Role: "admin", // 默认权限,可以根据需要修改
}

members = append(members, member)
}
mylog.Printf("member message.Echors: %+v\n", message.Echo)

responseJSON := buildResponse(members, message.Echo)
mylog.Printf("getGroupMemberList(群): %s\n", responseJSON)

err = client.SendMessage(responseJSON)
if err != nil {
mylog.Printf("Error sending message via client: %v", err)
}
return
case "private":
mylog.Printf("getGroupMemberList(频道): 目前暂未适配私聊虚拟群场景获取虚拟群列表能力")
mylog.Printf("getGroupMemberList(private): 目前暂未适配私聊虚拟群场景获取虚拟群列表能力")
return
case "guild":
//要把group_id还原成guild_id
Expand Down
29 changes: 29 additions & 0 deletions idmap/service.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package idmap

import (
"bytes"
"crypto/md5"
"encoding/binary"
"encoding/hex"
Expand Down Expand Up @@ -1009,3 +1010,31 @@ func FindKeysBySubAndType(sub string, typeSuffix string) ([]string, error) {

return ids, nil
}
// 取相同前缀下的所有key的:后边 比如取群成员列表
func FindSubKeysById(id string) ([]string, error) {
var subKeys []string

err := db.View(func(tx *bolt.Tx) error {
b := tx.Bucket([]byte("ids"))
if b == nil {
return fmt.Errorf("bucket %s not found", "ids")
}

c := b.Cursor()
prefix := []byte(id + ":")
for k, _ := c.Seek(prefix); k != nil && bytes.HasPrefix(k, prefix); k, _ = c.Next() {
keyParts := bytes.Split(k, []byte(":"))
if len(keyParts) == 2 {
subKeys = append(subKeys, string(keyParts[1]))
}
}

return nil
})

if err != nil {
return nil, err
}

return subKeys, nil
}
Loading