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

Beta130 #303

Merged
merged 9 commits into from
Jan 15, 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
4 changes: 4 additions & 0 deletions Processor/ProcessC2CMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
privateMsg.Echo = echostr
//用向应用端(如果支持)发送echo,来确定客户端的send_msg对应的触发词原文
echo.AddMsgIDv3(AppIDString, echostr, messageText)
}
// 将当前s和appid和message进行映射
echo.AddMsgID(AppIDString, s, data.ID)
Expand Down Expand Up @@ -220,6 +222,8 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error {
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
groupMsg.Echo = echostr
//用向应用端(如果支持)发送echo,来确定客户端的send_msg对应的触发词原文
echo.AddMsgIDv3(AppIDString, echostr, messageText)
}
// 获取MasterID数组
masterIDs := config.GetMasterID()
Expand Down
6 changes: 6 additions & 0 deletions Processor/ProcessChannelDirectMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
privateMsg.Echo = echostr
//用向应用端(如果支持)发送echo,来确定客户端的send_msg对应的触发词原文
echo.AddMsgIDv3(AppIDString, echostr, messageText)
}
// 将当前s和appid和message进行映射
echo.AddMsgID(AppIDString, s, data.ID)
Expand Down Expand Up @@ -218,6 +220,8 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
onebotMsg.Echo = echostr
//用向应用端(如果支持)发送echo,来确定客户端的send_msg对应的触发词原文
echo.AddMsgIDv3(AppIDString, echostr, messageText)
}
// 获取MasterID数组
masterIDs := config.GetMasterID()
Expand Down Expand Up @@ -368,6 +372,8 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData)
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
groupMsg.Echo = echostr
//用向应用端(如果支持)发送echo,来确定客户端的send_msg对应的触发词原文
echo.AddMsgIDv3(AppIDString, echostr, messageText)
}
// 获取MasterID数组
masterIDs := config.GetMasterID()
Expand Down
4 changes: 4 additions & 0 deletions Processor/ProcessGroupMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
groupMsg.Echo = echostr
//用向应用端(如果支持)发送echo,来确定客户端的send_msg对应的触发词原文
echo.AddMsgIDv3(AppIDString, echostr, messageText)
}
// 获取MasterID数组
masterIDs := config.GetMasterID()
Expand Down Expand Up @@ -167,6 +169,8 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error {
echo.AddMsgType(AppIDString, GroupID64, "group")
//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(GroupID64, 10), data.ID, time.Now())
//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(userid64, 10), data.ID, time.Now())
// 调试
PrintStructWithFieldNames(groupMsg)

Expand Down
13 changes: 12 additions & 1 deletion Processor/ProcessGuildATMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
SubType: "channel",
Time: t.Unix(),
Avatar: data.Author.Avatar,
Echo: echostr,
}
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
onebotMsg.Echo = echostr
//用向应用端(如果支持)发送echo,来确定客户端的send_msg对应的触发词原文
echo.AddMsgIDv3(AppIDString, echostr, messageText)
}
// 获取MasterID数组
masterIDs := config.GetMasterID()
Expand Down Expand Up @@ -106,6 +111,8 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
//todo 完善频道转换
//懒message_id池
echo.AddLazyMessageId(data.ChannelID, data.ID, time.Now())
//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(userid64, 10), data.ID, time.Now())

//调试
PrintStructWithFieldNames(onebotMsg)
Expand Down Expand Up @@ -226,6 +233,8 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
groupMsg.Echo = echostr
//用向应用端(如果支持)发送echo,来确定客户端的send_msg对应的触发词原文
echo.AddMsgIDv3(AppIDString, echostr, messageText)
}
// 获取MasterID数组
masterIDs := config.GetMasterID()
Expand Down Expand Up @@ -257,6 +266,8 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error {
echo.AddMsgType(AppIDString, ChannelID64, "guild")
//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(ChannelID64, 10), data.ID, time.Now())
//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(userid64, 10), data.ID, time.Now())

//调试
PrintStructWithFieldNames(groupMsg)
Expand Down
8 changes: 8 additions & 0 deletions Processor/ProcessGuildNormalMessage.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
onebotMsg.Echo = echostr
//用向应用端(如果支持)发送echo,来确定客户端的send_msg对应的触发词原文
echo.AddMsgIDv3(AppIDString, echostr, messageText)
}
// 获取MasterID数组
masterIDs := config.GetMasterID()
Expand Down Expand Up @@ -109,6 +111,8 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
//todo 完善频道ob信息
//懒message_id池
echo.AddLazyMessageId(data.ChannelID, data.ID, time.Now())
//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(userid64, 10), data.ID, time.Now())

//调试
PrintStructWithFieldNames(onebotMsg)
Expand Down Expand Up @@ -225,6 +229,8 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
// 根据条件判断是否添加Echo字段
if config.GetTwoWayEcho() {
groupMsg.Echo = echostr
//用向应用端(如果支持)发送echo,来确定客户端的send_msg对应的触发词原文
echo.AddMsgIDv3(AppIDString, echostr, messageText)
}
// 获取MasterID数组
masterIDs := config.GetMasterID()
Expand Down Expand Up @@ -268,6 +274,8 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error {
echo.AddMsgType(AppIDString, ChannelID64, "guild")
//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(ChannelID64, 10), data.ID, time.Now())
//懒message_id池
echo.AddLazyMessageId(strconv.FormatInt(userid64, 10), data.ID, time.Now())

//调试
PrintStructWithFieldNames(groupMsg)
Expand Down
76 changes: 66 additions & 10 deletions Processor/Processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,18 @@ type OnebotPrivateMessage struct {
IsBindedUserId bool `json:"is_binded_user_id,omitempty"` //当前用户号号是否是binded后的
}

// onebotv11标准扩展
type OnebotInteractionNotice struct {
GroupID int64 `json:"group_id,omitempty"`
NoticeType string `json:"notice_type,omitempty"`
PostType string `json:"post_type,omitempty"`
SelfID int64 `json:"self_id,omitempty"`
SubType string `json:"sub_type,omitempty"`
Time int64 `json:"time,omitempty"`
UserID int64 `json:"user_id,omitempty"`
Data *dto.WSInteractionData `json:"data,omitempty"`
}

type PrivateSender struct {
Nickname string `json:"nickname"`
UserID int64 `json:"user_id"` // Can be either string or int depending on logic
Expand All @@ -123,19 +135,63 @@ func FoxTimestamp() int64 {

// ProcessInlineSearch 处理内联查询
func (p *Processors) ProcessInlineSearch(data *dto.WSInteractionData) error {
//ctx := context.Background() // 或从更高级别传递一个上下文
// 转换appid
var userid64 int64
var GroupID64 int64
var err error
var fromgid, fromuid string
if data.GroupOpenID != "" {
fromgid = data.GroupOpenID
fromuid = data.GroupMemberOpenID
} else {
fromgid = data.ChannelID
fromuid = "0"
}
if config.GetIdmapPro() {
//将真实id转为int userid64
GroupID64, userid64, err = idmap.StoreIDv2Pro(fromgid, fromuid)
if err != nil {
mylog.Fatalf("Error storing ID: %v", err)
}
//当参数不全
_, _ = idmap.StoreIDv2(fromgid)
_, _ = idmap.StoreIDv2(fromuid)
if !config.GetHashIDValue() {
mylog.Fatalf("避坑日志:你开启了高级id转换,请设置hash_id为true,并且删除idmaps并重启")
}
} else {
// 映射str的GroupID到int
GroupID64, err = idmap.StoreIDv2(fromgid)
if err != nil {
mylog.Errorf("failed to convert ChannelID to int: %v", err)
return nil
}
// 映射str的userid到int
userid64, err = idmap.StoreIDv2(fromuid)
if err != nil {
mylog.Printf("Error storing ID: %v", err)
return nil
}
}
notice := &OnebotInteractionNotice{
GroupID: GroupID64,
NoticeType: "interaction",
PostType: "notice",
SelfID: int64(p.Settings.AppID),
SubType: "create",
Time: time.Now().Unix(),
UserID: userid64,
Data: data,
}

// 在这里处理内联查询
// 这可能涉及解析查询、调用某些API、获取结果并格式化为响应
// ...
//调试
PrintStructWithFieldNames(notice)

// 示例:发送响应
// response := "Received your interaction!" // 创建响应消息
// err := p.api.PostInteractionResponse(ctx, response) // 替换为您的OpenAPI方法
// if err != nil {
// return err
// }
// Convert OnebotGroupMessage to map and send
noticeMap := structToMap(notice)

//上报信息到onebotv11应用端(正反ws)
p.BroadcastMessageToAll(noticeMap)
return nil
}

Expand Down
34 changes: 22 additions & 12 deletions botgo/dto/interaction.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
package dto

import "encoding/json"

// Interaction 互动行为对象
type Interaction struct {
ID string `json:"id,omitempty"` // 互动行为唯一标识
ApplicationID string `json:"application_id,omitempty"` // 应用ID
Type InteractionType `json:"type,omitempty"` // 互动类型
Data *InteractionData `json:"data,omitempty"` // 互动数据
GuildID string `json:"guild_id,omitempty"` // 频道 ID
ChannelID string `json:"channel_id,omitempty"` // 子频道 ID
Version uint32 `json:"version,omitempty"` // 版本,默认为 1
ID string `json:"id,omitempty"` // 平台方事件 ID
Type InteractionType `json:"type,omitempty"` // 消息按钮: 11, 单聊快捷菜单: 12
Scene string `json:"scene,omitempty"` // 事件发生的场景
ChatType int `json:"chat_type,omitempty"` // 频道场景: 0, 群聊场景: 1, 单聊场景: 2
Timestamp string `json:"timestamp,omitempty"` // 触发时间 RFC 3339 格式
GuildID string `json:"guild_id,omitempty"` // 频道的 openid
ChannelID string `json:"channel_id,omitempty"` // 文字子频道的 openid
UserOpenID string `json:"user_openid,omitempty"` // 单聊按钮触发的用户 openid
GroupOpenID string `json:"group_openid,omitempty"` // 群的 openid
GroupMemberOpenID string `json:"group_member_openid,omitempty"` // 群成员 openid
Data *InteractionData `json:"data,omitempty"` // 互动数据
Version uint32 `json:"version,omitempty"` // 版本,默认为 1
ApplicationID string `json:"application_id,omitempty"` // 机器人的 appid
}

// InteractionType 互动类型
Expand All @@ -25,9 +29,15 @@ const (

// InteractionData 互动数据
type InteractionData struct {
Name string `json:"name,omitempty"` // 标题
Type InteractionDataType `json:"type,omitempty"` // 数据类型,不同数据类型对应不同的 resolved 数据
Resolved json.RawMessage `json:"resolved,omitempty"` // 跟不同的互动类型和数据类型有关系的数据
Name string `json:"name,omitempty"` // 标题
Type InteractionDataType `json:"type,omitempty"` // 数据类型
Resolved struct {
ButtonData string `json:"button_data,omitempty"` // 操作按钮的 data 字段值
ButtonID string `json:"button_id,omitempty"` // 操作按钮的 id 字段值
UserID string `json:"user_id,omitempty"` // 操作的用户 userid
FeatureID string `json:"feature_id,omitempty"` // 操作按钮的 feature id
MessageID string `json:"message_id,omitempty"` // 操作的消息 id
} `json:"resolved,omitempty"`
}

// InteractionDataType 互动数据类型
Expand Down
12 changes: 8 additions & 4 deletions botgo/dto/keyboard/keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,23 @@ type RenderData struct {

// Action 按纽点击操作
type Action struct {
Type ActionType `json:"type,omitempty"` // 操作类型
Type ActionType `json:"type,omitempty"` // 操作类型 设置 0 跳转按钮:http 或 小程序 客户端识别 scheme,设置 1 回调按钮:回调后台接口, data 传给后台,设置 2 指令按钮:自动在输入框插入 @bot data
Permission *Permission `json:"permission,omitempty"` // 可操作
ClickLimit uint32 `json:"click_limit,omitempty"` // 可点击的次数, 默认不限
Data string `json:"data,omitempty"` // 操作相关数据
AtBotShowChannelList bool `json:"at_bot_show_channel_list,omitempty"` // false:当前 true:弹出展示子频道选择器
UnsupportTips string `json:"unsupport_tips"` //2024-1-12 新增字段
AnChor int `json:"anchor"` //本字段仅在指令按钮下有效,设置后后会忽略 action.enter 配置。设置为 1 时 ,点击按钮自动唤起启手Q选图器,其他值暂无效果。(仅支持手机端版本 8983+ 的单聊场景,桌面端不支持)
Enter bool `json:"enter"` //指令按钮可用,点击按钮后直接自动发送 data,默认 false。支持版本 8983
Reply bool `json:"reply"` //指令按钮可用,指令是否带引用回复本消息,默认 false。支持版本 8983
}

// Permission 按纽操作权限
type Permission struct {
// Type 操作权限类型
// Type 操作权限类型 0 指定用户可操作,1 仅管理者可操作,2 所有人可操作,3 指定身份组可操作(仅频道可用)
Type PermissionType `json:"type,omitempty"`
// SpecifyRoleIDs 身份组
// SpecifyRoleIDs 身份组(仅频道可用)
SpecifyRoleIDs []string `json:"specify_role_ids,omitempty"`
// SpecifyUserIDs 指定 UserID
// SpecifyUserIDs 指定 UserID 有权限的用户 id 的列表
SpecifyUserIDs []string `json:"specify_user_ids,omitempty"`
}
61 changes: 61 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,11 @@ type Settings struct {
WhiteEnable []bool `yaml:"white_enable"`
IdentifyAppids []int64 `yaml:"identify_appids"`
TransFormApiIds bool `yaml:"transform_api_ids"`
CustomTemplateID string `yaml:"custom_template_id"`
KeyBoardID string `yaml:"keyboard_id"`
Uin int64 `yaml:"uin"`
VwhitePrefixMode bool `yaml:"v_white_prefix_mode"`
Enters []string `yaml:"enters"`
}

// LoadConfig 从文件中加载配置并初始化单例配置
Expand Down Expand Up @@ -1650,3 +1655,59 @@ func GetTransFormApiIds() bool {
}
return instance.Settings.TransFormApiIds
}

// 获取 CustomTemplateID 的值
func GetCustomTemplateID() string {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to get CustomTemplateID.")
return ""
}
return instance.Settings.CustomTemplateID
}

// 获取 KeyBoardIDD 的值
func GetKeyBoardID() string {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to get KeyBoardID.")
return ""
}
return instance.Settings.KeyBoardID
}

// 获取Uin String
func GetUinStr() string {
mu.Lock()
defer mu.Unlock()
if instance != nil {
return fmt.Sprintf("%d", instance.Settings.Uin)
}
return "0"
}

// 获取 VV GetVwhitePrefixMode 的值
func GetVwhitePrefixMode() bool {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to VwhitePrefixMode value.")
return false
}
return instance.Settings.VwhitePrefixMode
}

// 获取Enters的值
func GetEnters() []string {
mu.Lock()
defer mu.Unlock()
if instance != nil {
return instance.Settings.Enters
}
return nil // 返回nil,如果instance为nil
}
9 changes: 9 additions & 0 deletions echo/echo.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@ func AddMsgIDv3(appid string, s string, msgID string) {
globalEchoMapping.msgIDMapping[key] = msgID
}

// GetMsgIDv3 返回给定appid和s的msgID
func GetMsgIDv3(appid string, s string) string {
key := globalEchoMapping.GenerateKeyv3(appid, s)
globalEchoMapping.mu.Lock()
defer globalEchoMapping.mu.Unlock()

return globalEchoMapping.msgIDMapping[key]
}

// 添加group和userid对应的messageid
func AddMsgIDv2(appid string, groupid int64, userid int64, msgID string) {
key := globalEchoMapping.GenerateKeyv2(appid, groupid, userid)
Expand Down
Loading
Loading