Skip to content

Commit

Permalink
feat: 查找消息库和获取群管理信息
Browse files Browse the repository at this point in the history
  • Loading branch information
rehiy committed Mar 25, 2024
1 parent 78a68f6 commit 63c18c3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/gorilla/websocket v1.5.1
github.com/importcjj/sensitive v0.0.0-20200106142752-42d1c505be7b
github.com/mitchellh/mapstructure v1.5.0
github.com/opentdp/go-helper v0.7.1
github.com/opentdp/go-helper v0.7.2-0.20240325030235-ea01c8238bf8
github.com/rehiy/one-llm v0.2.0
go.nanomsg.org/mangos/v3 v3.4.2
google.golang.org/protobuf v1.33.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
github.com/opentdp/go-helper v0.7.1 h1:FpZfZXFvAEctImRUWr0G2SMD/XOoppJgwEA33d+Qeoc=
github.com/opentdp/go-helper v0.7.1/go.mod h1:bRR6EpSuQNNNwgCSWwwuO90Lh1lUG+PnMa6PFS41mF8=
github.com/opentdp/go-helper v0.7.2-0.20240325030235-ea01c8238bf8 h1:eS7ubuAmMFIDH9RFIeRrApFwjOix5lCDyz6kHuxAsCA=
github.com/opentdp/go-helper v0.7.2-0.20240325030235-ea01c8238bf8/go.mod h1:bRR6EpSuQNNNwgCSWwwuO90Lh1lUG+PnMa6PFS41mF8=
github.com/pelletier/go-toml/v2 v2.2.0 h1:QLgLl2yMN7N+ruc31VynXs1vhMZa7CeHHejIeBAsoHo=
github.com/pelletier/go-toml/v2 v2.2.0/go.mod h1:1t835xjRzz80PqgE6HHgN2JOsmgYu/h4qDAS4n929Rs=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down
47 changes: 47 additions & 0 deletions wclient/helper.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package wclient

import (
"fmt"
"strconv"
"strings"
"time"

"github.com/opentdp/go-helper/dborm"
Expand Down Expand Up @@ -90,3 +93,47 @@ func ImageTop10(roomid string, day int64) []*TopItem {
return result

}

// 获取群管理信息

func ChatRoomInfo(roomid string) map[string]string {

info := map[string]string{}

// 获取群主
sql1 := fmt.Sprintf(`SELECT * FROM ChatRoom WHERE ChatRoomName = '%s';`, roomid)
res1 := wc.CmdClient.DbSqlQuery("MicroMsg.db", sql1)
if len(res1) > 0 {
info["owner"] = res1[0]["Reserved2"].(string)
}

// 获取群公告
sql2 := fmt.Sprintf(`SELECT * FROM ChatRoomInfo WHERE ChatRoomName = '%s';`, roomid)
res2 := wc.CmdClient.DbSqlQuery("MicroMsg.db", sql2)
if len(res2) > 0 {
info["announcement"] = res1[0]["Announcement"].(string)
}

return info

}

// 查找消息数据库
// return string 消息数据库
func FindMsgDb() string {
maxIndex, maxDbName := -1, ""
dbList := wc.CmdClient.GetDbNames()
for _, dbName := range dbList {
if strings.HasPrefix(dbName, "MSG") && strings.HasSuffix(dbName, ".db") {
msgdb := strings.TrimSuffix(dbName, ".db")
parts := strings.Split(msgdb, "MSG")
if len(parts) == 2 {
x, err := strconv.Atoi(parts[1])
if err == nil && x > maxIndex {
maxIndex, maxDbName = x, dbName
}
}
}
}
return maxDbName
}

0 comments on commit 63c18c3

Please sign in to comment.