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

Beta340 #344

Merged
merged 4 commits into from
Mar 7, 2024
Merged
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
3 changes: 3 additions & 0 deletions Processor/ProcessGroupDelBot.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package Processor

import (
"fmt"
"strconv"

"github.com/hoshinonyaruko/gensokyo/config"
Expand Down Expand Up @@ -50,6 +51,8 @@ func (p *Processors) ProcessGroupDelBot(data *dto.GroupAddBotEvent) error {
return nil
}
mylog.Printf("Bot被[%v]从群[%v]移出", userid64, GroupID64)
//从数据库删除群数据(仅删除类型缓存,再次加入会刷新)
idmap.DeleteConfigv2(fmt.Sprint(GroupID64), "type")
Notice = GroupNoticeEvent{
GroupID: GroupID64,
NoticeType: "group_decrease",
Expand Down
13 changes: 13 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ type Settings struct {
PutInteractionDelay int `yaml:"put_interaction_delay"`
ImgUpApiVtv2 bool `yaml:"img_up_api_ntv2"`
Fix11300 bool `yaml:"fix_11300"`
LotusWithoutIdmaps bool `yaml:"lotus_without_idmaps"`
}

// LoadConfig 从文件中加载配置并初始化单例配置
Expand Down Expand Up @@ -1883,3 +1884,15 @@ func GetFix11300() bool {
}
return instance.Settings.Fix11300
}

// 获取LotusWithoutIdmaps开关
func GetLotusWithoutIdmaps() bool {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to LotusWithoutIdmaps value.")
return false
}
return instance.Settings.LotusWithoutIdmaps
}
12 changes: 10 additions & 2 deletions handlers/get_group_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,28 @@ func GetGroupList(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.Open
}
// 将channel信息转换为Group对象并添加到groups
for _, channel := range channels {
//转换ChannelID64
// 转换ChannelID64
ChannelID64, err := idmap.StoreIDv2(channel.ID)
if err != nil {
mylog.Printf("Error storing ID: %v", err)
}

// 根据channel.Type添加前缀
groupName := channel.Name
if channel.Type == dto.ChannelTypeText {
groupName = "&" + groupName
}

channelGroup := Group{
GroupCreateTime: 0, // 频道没有直接对应的创建时间字段
GroupID: ChannelID64,
GroupLevel: 0, // 频道没有直接对应的级别字段
GroupMemo: "", // 频道没有直接对应的描述字段
GroupName: channel.Name,
GroupName: groupName,
MaxMemberCount: 0, // 频道没有直接对应的最大成员数字段
MemberCount: 0, // 频道没有直接对应的成员数字段
}

groupList.Data = append(groupList.Data, channelGroup)
}
}
Expand Down
39 changes: 34 additions & 5 deletions handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,47 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
// 当 message.Echo 是字符串类型时执行此块
msgType = echo.GetMsgTypeByKey(echoStr)
}
if msgType == "" {
// 检查GroupID是否为0
checkZeroGroupID := func(id interface{}) bool {
switch v := id.(type) {
case int:
return v != 0
case int64:
return v != 0
case string:
return v != "0" // 检查字符串形式的0
default:
return true // 如果不是int、int64或string,假定它不为0
}
}

// 检查UserID是否为0
checkZeroUserID := func(id interface{}) bool {
switch v := id.(type) {
case int:
return v != 0
case int64:
return v != 0
case string:
return v != "0" // 同样检查字符串形式的0
default:
return true // 如果不是int、int64或string,假定它不为0
}
}

if msgType == "" && message.Params.GroupID != nil && checkZeroGroupID(message.Params.GroupID) {
msgType = GetMessageTypeByGroupid(config.GetAppIDStr(), message.Params.GroupID)
}
if msgType == "" {
if msgType == "" && message.Params.UserID != nil && checkZeroUserID(message.Params.UserID) {
msgType = GetMessageTypeByUserid(config.GetAppIDStr(), message.Params.UserID)
}
if msgType == "" {
if msgType == "" && message.Params.GroupID != nil && checkZeroGroupID(message.Params.GroupID) {
msgType = GetMessageTypeByGroupidV2(message.Params.GroupID)
}
if msgType == "" {
if msgType == "" && message.Params.UserID != nil && checkZeroUserID(message.Params.UserID) {
msgType = GetMessageTypeByUseridV2(message.Params.UserID)
}

mylog.Printf("send_group_msg获取到信息类型:%v", msgType)
var idInt64 int64
var err error
Expand Down Expand Up @@ -493,7 +522,7 @@ func HandleSendGroupMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openap
echo.AddMsgType(config.GetAppIDStr(), idInt64, tryMessageTypes[echo.GetMapping(idInt64)-1])
delay := config.GetSendDelay()
time.Sleep(time.Duration(delay) * time.Millisecond)
HandleSendGroupMsg(client, api, apiv2, messageCopy)
retmsg, _ = HandleSendGroupMsg(client, api, apiv2, messageCopy)
}
return retmsg, nil
}
Expand Down
37 changes: 33 additions & 4 deletions handlers/send_guild_channel_forum.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,47 @@ func HandleSendGuildChannelForum(client callapi.Client, api openapi.OpenAPI, api
// 当 message.Echo 是字符串类型时执行此块
msgType = echo.GetMsgTypeByKey(echoStr)
}
if msgType == "" {
// 检查GroupID是否为0
checkZeroGroupID := func(id interface{}) bool {
switch v := id.(type) {
case int:
return v != 0
case int64:
return v != 0
case string:
return v != "0" // 检查字符串形式的0
default:
return true // 如果不是int、int64或string,假定它不为0
}
}

// 检查UserID是否为0
checkZeroUserID := func(id interface{}) bool {
switch v := id.(type) {
case int:
return v != 0
case int64:
return v != 0
case string:
return v != "0" // 同样检查字符串形式的0
default:
return true // 如果不是int、int64或string,假定它不为0
}
}

if msgType == "" && message.Params.GroupID != nil && checkZeroGroupID(message.Params.GroupID) {
msgType = GetMessageTypeByGroupid(config.GetAppIDStr(), message.Params.GroupID)
}
if msgType == "" {
if msgType == "" && message.Params.UserID != nil && checkZeroUserID(message.Params.UserID) {
msgType = GetMessageTypeByUserid(config.GetAppIDStr(), message.Params.UserID)
}
if msgType == "" {
if msgType == "" && message.Params.GroupID != nil && checkZeroGroupID(message.Params.GroupID) {
msgType = GetMessageTypeByGroupidV2(message.Params.GroupID)
}
if msgType == "" {
if msgType == "" && message.Params.UserID != nil && checkZeroUserID(message.Params.UserID) {
msgType = GetMessageTypeByUseridV2(message.Params.UserID)
}

//当不转换频道信息时(不支持频道私聊)
if msgType == "" {
msgType = "forum"
Expand Down
36 changes: 32 additions & 4 deletions handlers/send_guild_channel_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,44 @@ func HandleSendGuildChannelMsg(client callapi.Client, api openapi.OpenAPI, apiv2
// 当 message.Echo 是字符串类型时执行此块
msgType = echo.GetMsgTypeByKey(echoStr)
}
if msgType == "" {
// 检查GroupID是否为0
checkZeroGroupID := func(id interface{}) bool {
switch v := id.(type) {
case int:
return v != 0
case int64:
return v != 0
case string:
return v != "0" // 检查字符串形式的0
default:
return true // 如果不是int、int64或string,假定它不为0
}
}

// 检查UserID是否为0
checkZeroUserID := func(id interface{}) bool {
switch v := id.(type) {
case int:
return v != 0
case int64:
return v != 0
case string:
return v != "0" // 同样检查字符串形式的0
default:
return true // 如果不是int、int64或string,假定它不为0
}
}

if msgType == "" && message.Params.GroupID != nil && checkZeroGroupID(message.Params.GroupID) {
msgType = GetMessageTypeByGroupid(config.GetAppIDStr(), message.Params.GroupID)
}
if msgType == "" {
if msgType == "" && message.Params.UserID != nil && checkZeroUserID(message.Params.UserID) {
msgType = GetMessageTypeByUserid(config.GetAppIDStr(), message.Params.UserID)
}
if msgType == "" {
if msgType == "" && message.Params.GroupID != nil && checkZeroGroupID(message.Params.GroupID) {
msgType = GetMessageTypeByGroupidV2(message.Params.GroupID)
}
if msgType == "" {
if msgType == "" && message.Params.UserID != nil && checkZeroUserID(message.Params.UserID) {
msgType = GetMessageTypeByUseridV2(message.Params.UserID)
}
//当不转换频道信息时(不支持频道私聊)
Expand Down
60 changes: 52 additions & 8 deletions handlers/send_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,72 @@ func HandleSendMsg(client callapi.Client, api openapi.OpenAPI, apiv2 openapi.Ope
// 当 message.Echo 是字符串类型时执行此块
msgType = echo.GetMsgTypeByKey(echoStr)
}
if msgType == "" {
// 检查GroupID是否为0
checkZeroGroupID := func(id interface{}) bool {
switch v := id.(type) {
case int:
return v != 0
case int64:
return v != 0
case string:
return v != "0" // 检查字符串形式的0
default:
return true // 如果不是int、int64或string,假定它不为0
}
}

// 检查UserID是否为0
checkZeroUserID := func(id interface{}) bool {
switch v := id.(type) {
case int:
return v != 0
case int64:
return v != 0
case string:
return v != "0" // 同样检查字符串形式的0
default:
return true // 如果不是int、int64或string,假定它不为0
}
}

if msgType == "" && message.Params.GroupID != nil && checkZeroGroupID(message.Params.GroupID) {
msgType = GetMessageTypeByGroupid(config.GetAppIDStr(), message.Params.GroupID)
}
if msgType == "" {
if msgType == "" && message.Params.UserID != nil && checkZeroUserID(message.Params.UserID) {
msgType = GetMessageTypeByUserid(config.GetAppIDStr(), message.Params.UserID)
}
if msgType == "" {
if msgType == "" && message.Params.GroupID != nil && checkZeroGroupID(message.Params.GroupID) {
msgType = GetMessageTypeByGroupidV2(message.Params.GroupID)
}
if msgType == "" {
if msgType == "" && message.Params.UserID != nil && checkZeroUserID(message.Params.UserID) {
msgType = GetMessageTypeByUseridV2(message.Params.UserID)
}

var idInt64, idInt642 int64
var err error

var tempErr error

if message.Params.GroupID != "" {
idInt64, err = ConvertToInt64(message.Params.GroupID)
idInt642, err = ConvertToInt64(message.Params.UserID)
idInt64, tempErr = ConvertToInt64(message.Params.GroupID)
if tempErr != nil {
err = tempErr
}
idInt642, tempErr = ConvertToInt64(message.Params.UserID)
if tempErr != nil {
err = tempErr
}

} else if message.Params.UserID != "" {
idInt64, err = ConvertToInt64(message.Params.UserID)
idInt642, err = ConvertToInt64(message.Params.GroupID)
idInt64, tempErr = ConvertToInt64(message.Params.UserID)
if tempErr != nil {
err = tempErr
}
idInt642, tempErr = ConvertToInt64(message.Params.GroupID)
if tempErr != nil {
err = tempErr
}

}

//设置递归 对直接向gsk发送action时有效果
Expand Down
40 changes: 32 additions & 8 deletions handlers/send_private_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,44 @@ func HandleSendPrivateMsg(client callapi.Client, api openapi.OpenAPI, apiv2 open
// 当 message.Echo 是字符串类型时执行此块
msgType = echo.GetMsgTypeByKey(echoStr)
}
// 检查GroupID是否为0
checkZeroGroupID := func(id interface{}) bool {
switch v := id.(type) {
case int:
return v != 0
case int64:
return v != 0
case string:
return v != "0" // 检查字符串形式的0
default:
return true // 如果不是int、int64或string,假定它不为0
}
}

//如果获取不到 就用user_id获取信息类型
if msgType == "" {
// 检查UserID是否为0
checkZeroUserID := func(id interface{}) bool {
switch v := id.(type) {
case int:
return v != 0
case int64:
return v != 0
case string:
return v != "0" // 同样检查字符串形式的0
default:
return true // 如果不是int、int64或string,假定它不为0
}
}

if msgType == "" && message.Params.UserID != nil && checkZeroUserID(message.Params.UserID) {
msgType = GetMessageTypeByUserid(config.GetAppIDStr(), message.Params.UserID)
}
//顺序,私聊优先从UserID推断类型会更准确
if msgType == "" {
if msgType == "" && message.Params.GroupID != nil && checkZeroGroupID(message.Params.GroupID) {
msgType = GetMessageTypeByGroupid(config.GetAppIDStr(), message.Params.GroupID)
}
//新增 内存获取不到从数据库获取
if msgType == "" {
if msgType == "" && message.Params.UserID != nil && checkZeroUserID(message.Params.UserID) {
msgType = GetMessageTypeByUseridV2(message.Params.UserID)
}
if msgType == "" {
if msgType == "" && message.Params.GroupID != nil && checkZeroGroupID(message.Params.GroupID) {
msgType = GetMessageTypeByGroupidV2(message.Params.GroupID)
}
var idInt64 int64
Expand Down Expand Up @@ -292,7 +316,7 @@ func HandleSendPrivateMsg(client callapi.Client, api openapi.OpenAPI, apiv2 open
echo.AddMsgType(config.GetAppIDStr(), idInt64, tryMessageTypes[echo.GetMapping(idInt64)-1])
delay := config.GetSendDelay()
time.Sleep(time.Duration(delay) * time.Millisecond)
HandleSendPrivateMsg(client, api, apiv2, messageCopy)
retmsg, _ = HandleSendPrivateMsg(client, api, apiv2, messageCopy)
}
return retmsg, nil
}
Expand Down
Loading
Loading