Skip to content

Commit

Permalink
Beta80 (#221)
Browse files Browse the repository at this point in the history
* beta77

* beta77

* beta77

* beta77

* beta79

* beta79

* beta79
  • Loading branch information
Hoshinonyaruko authored Dec 5, 2023
1 parent 78828cc commit d2e4713
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 16 deletions.
5 changes: 5 additions & 0 deletions Processor/ProcessC2CMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package Processor

import (
"fmt"
"log"
"strconv"
"time"
Expand Down Expand Up @@ -112,6 +113,8 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
echo.AddLazyMessageId(strconv.FormatInt(userid64, 10), data.ID, time.Now())
//储存类型
echo.AddMsgType(AppIDString, userid64, "group_private")
//储存当前群或频道号的类型
idmap.WriteConfigv2(fmt.Sprint(userid64), "type", "group_private")
//储存当前群或频道号的类型 私信不需要
//idmap.WriteConfigv2(data.ChannelID, "type", "group_private")

Expand Down Expand Up @@ -222,6 +225,8 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
echo.AddMsgID(AppIDString, userid64, data.ID)
//映射类型
echo.AddMsgType(AppIDString, userid64, "group_private")
//储存当前群或频道号的类型
idmap.WriteConfigv2(fmt.Sprint(userid64), "type", "group_private")
//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(userid64, 10), data.ID, time.Now())

Expand Down
4 changes: 4 additions & 0 deletions Processor/ProcessChannelDirectMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
//其实不需要用AppIDString,因为gensokyo是单机器人框架
echo.AddMsgID(AppIDString, userid64, data.ID)
echo.AddMsgType(AppIDString, userid64, "guild_private")
//储存当前群或频道号的类型
idmap.WriteConfigv2(fmt.Sprint(userid64), "type", "guild_private")
//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(userid64, 10), data.ID, time.Now())

Expand Down Expand Up @@ -224,6 +226,8 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
echo.AddMsgType(AppIDString, userid64, "guild_private")
//储存当前群或频道号的类型
idmap.WriteConfigv2(data.ChannelID, "type", "guild_private")
//储存当前群或频道号的类型
idmap.WriteConfigv2(fmt.Sprint(userid64), "type", "guild_private")
//todo 完善频道类型信息转换
//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(userid64, 10), data.ID, time.Now())
Expand Down
54 changes: 54 additions & 0 deletions handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ func handleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
if msgType == "" {
msgType = GetMessageTypeByGroupid(config.GetAppIDStr(), message.Params.GroupID)
}
//新增 内存获取不到从数据库获取
if msgType == "" {
msgType = GetMessageTypeByUseridV2(message.Params.UserID)
}
if msgType == "" {
msgType = GetMessageTypeByGroupidV2(message.Params.GroupID)
}
mylog.Printf("send_group_msg获取到信息类型:%v", msgType)
var idInt64 int64
var err error
Expand Down Expand Up @@ -836,6 +843,30 @@ func GetMessageTypeByUserid(appID string, userID interface{}) string {
return echo.GetMsgTypeByKey(key)
}

// 通过user_id获取类型
func GetMessageTypeByUseridV2(userID interface{}) string {
// 从appID和userID生成key
var userIDStr string
switch u := userID.(type) {
case int:
userIDStr = strconv.Itoa(u)
case int64:
userIDStr = strconv.FormatInt(u, 10)
case float64:
userIDStr = strconv.FormatFloat(u, 'f', 0, 64)
case string:
userIDStr = u
default:
// 可能需要处理其他类型或报错
return ""
}
msgtype, err := idmap.ReadConfigv2(userIDStr, "type")
if err != nil {
mylog.Printf("GetMessageTypeByUseridV2失败:%v", err)
}
return msgtype
}

// 通过group_id获取类型
func GetMessageTypeByGroupid(appID string, GroupID interface{}) string {
// 从appID和userID生成key
Expand All @@ -856,6 +887,29 @@ func GetMessageTypeByGroupid(appID string, GroupID interface{}) string {
return echo.GetMsgTypeByKey(key)
}

// 通过group_id获取类型
func GetMessageTypeByGroupidV2(GroupID interface{}) string {
// 从appID和userID生成key
var GroupIDStr string
switch u := GroupID.(type) {
case int:
GroupIDStr = strconv.Itoa(u)
case int64:
GroupIDStr = strconv.FormatInt(u, 10)
case string:
GroupIDStr = u
default:
// 可能需要处理其他类型或报错
return ""
}

msgtype, err := idmap.ReadConfigv2(GroupIDStr, "type")
if err != nil {
mylog.Printf("GetMessageTypeByGroupidV2失败:%v", err)
}
return msgtype
}

// uploadMedia 上传媒体并返回FileInfo
func uploadMedia(ctx context.Context, groupID string, richMediaMessage *dto.RichMediaMessage, apiv2 openapi.OpenAPI) (string, error) {
// 调用API来上传媒体
Expand Down
16 changes: 8 additions & 8 deletions handlers/send_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ func handleSendMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.Ope
}
//如果获取不到 就用group_id获取信息类型
if msgType == "" {
appID := config.GetAppIDStr()
groupID := message.Params.GroupID
mylog.Printf("appID: %s, GroupID: %v\n", appID, groupID)

msgType = GetMessageTypeByGroupid(appID, groupID)
mylog.Printf("msgType: %s\n", msgType)
msgType = GetMessageTypeByGroupid(config.GetAppIDStr(), message.Params.GroupID)
}

//如果获取不到 就用user_id获取信息类型
if msgType == "" {
msgType = GetMessageTypeByUserid(config.GetAppIDStr(), message.Params.UserID)
}

//新增 内存获取不到从数据库获取
if msgType == "" {
msgType = GetMessageTypeByUseridV2(message.Params.UserID)
}
if msgType == "" {
msgType = GetMessageTypeByGroupidV2(message.Params.GroupID)
}
var idInt64 int64
var err error

Expand Down
16 changes: 8 additions & 8 deletions handlers/send_private_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ func handleSendPrivateMsg(client callapi.Client, api openapi.OpenAPI, apiv2 open

//如果获取不到 就用group_id获取信息类型
if msgType == "" {
appID := config.GetAppIDStr()
groupID := message.Params.GroupID
mylog.Printf("appID: %s, GroupID: %v\n", appID, groupID)

msgType = GetMessageTypeByGroupid(appID, groupID)
mylog.Printf("msgType: %s\n", msgType)
msgType = GetMessageTypeByGroupid(config.GetAppIDStr(), message.Params.GroupID)
}

//如果获取不到 就用user_id获取信息类型
if msgType == "" {
msgType = GetMessageTypeByUserid(config.GetAppIDStr(), message.Params.UserID)
}

//新增 内存获取不到从数据库获取
if msgType == "" {
msgType = GetMessageTypeByUseridV2(message.Params.UserID)
}
if msgType == "" {
msgType = GetMessageTypeByGroupidV2(message.Params.GroupID)
}
var idInt64 int64
var err error

Expand Down

0 comments on commit d2e4713

Please sign in to comment.