diff --git a/Processor/ProcessC2CMessage.go b/Processor/ProcessC2CMessage.go index 44ab46fe..10f83f66 100644 --- a/Processor/ProcessC2CMessage.go +++ b/Processor/ProcessC2CMessage.go @@ -71,9 +71,11 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error { SubType: "friend", Time: time.Now().Unix(), Avatar: "", //todo 同上 - Echo: echostr, } - + // 根据条件判断是否添加Echo字段 + if config.GetTwoWayEcho() { + privateMsg.Echo = echostr + } // 将当前s和appid和message进行映射 echo.AddMsgID(AppIDString, s, data.ID) echo.AddMsgType(AppIDString, s, "group_private") @@ -131,7 +133,10 @@ func (p *Processors) ProcessC2CMessage(data *dto.WSC2CMessageData) error { SubType: "normal", Time: time.Now().Unix(), Avatar: "", - Echo: echostr, + } + // 根据条件判断是否添加Echo字段 + if config.GetTwoWayEcho() { + groupMsg.Echo = echostr } // 获取MasterID数组 masterIDs := config.GetMasterID() diff --git a/Processor/ProcessChannelDirectMessage.go b/Processor/ProcessChannelDirectMessage.go index f2990992..56dbb1e3 100644 --- a/Processor/ProcessChannelDirectMessage.go +++ b/Processor/ProcessChannelDirectMessage.go @@ -87,9 +87,11 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData) SubType: "friend", Time: time.Now().Unix(), Avatar: data.Author.Avatar, - Echo: echostr, } - + // 根据条件判断是否添加Echo字段 + if config.GetTwoWayEcho() { + privateMsg.Echo = echostr + } // 将当前s和appid和message进行映射 echo.AddMsgID(AppIDString, s, data.ID) echo.AddMsgType(AppIDString, s, "guild_private") @@ -147,7 +149,10 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData) SubType: "channel", Time: t.Unix(), Avatar: data.Author.Avatar, - Echo: echostr, + } + // 根据条件判断是否添加Echo字段 + if config.GetTwoWayEcho() { + onebotMsg.Echo = echostr } // 获取MasterID数组 masterIDs := config.GetMasterID() @@ -236,7 +241,10 @@ func (p *Processors) ProcessChannelDirectMessage(data *dto.WSDirectMessageData) SubType: "normal", Time: time.Now().Unix(), Avatar: data.Author.Avatar, - Echo: echostr, + } + // 根据条件判断是否添加Echo字段 + if config.GetTwoWayEcho() { + groupMsg.Echo = echostr } // 获取MasterID数组 masterIDs := config.GetMasterID() diff --git a/Processor/ProcessGroupMessage.go b/Processor/ProcessGroupMessage.go index 8bb836b4..0de1b65a 100644 --- a/Processor/ProcessGroupMessage.go +++ b/Processor/ProcessGroupMessage.go @@ -70,7 +70,10 @@ func (p *Processors) ProcessGroupMessage(data *dto.WSGroupATMessageData) error { SubType: "normal", Time: time.Now().Unix(), Avatar: "", - Echo: echostr, + } + // 根据条件判断是否添加Echo字段 + if config.GetTwoWayEcho() { + groupMsg.Echo = echostr } // 获取MasterID数组 masterIDs := config.GetMasterID() diff --git a/Processor/ProcessGuildATMessage.go b/Processor/ProcessGuildATMessage.go index 037ad539..222fc0ac 100644 --- a/Processor/ProcessGuildATMessage.go +++ b/Processor/ProcessGuildATMessage.go @@ -155,7 +155,10 @@ func (p *Processors) ProcessGuildATMessage(data *dto.WSATMessageData) error { SubType: "normal", Time: time.Now().Unix(), Avatar: data.Author.Avatar, - Echo: echostr, + } + // 根据条件判断是否添加Echo字段 + if config.GetTwoWayEcho() { + groupMsg.Echo = echostr } // 获取MasterID数组 masterIDs := config.GetMasterID() diff --git a/Processor/ProcessGuildNormalMessage.go b/Processor/ProcessGuildNormalMessage.go index 81b3daa6..11e01514 100644 --- a/Processor/ProcessGuildNormalMessage.go +++ b/Processor/ProcessGuildNormalMessage.go @@ -62,7 +62,10 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error { SubType: "channel", Time: t.Unix(), Avatar: data.Author.Avatar, - Echo: echostr, + } + // 根据条件判断是否添加Echo字段 + if config.GetTwoWayEcho() { + onebotMsg.Echo = echostr } // 获取MasterID数组 masterIDs := config.GetMasterID() @@ -154,7 +157,10 @@ func (p *Processors) ProcessGuildNormalMessage(data *dto.WSMessageData) error { SubType: "normal", Time: time.Now().Unix(), Avatar: data.Author.Avatar, - Echo: echostr, + } + // 根据条件判断是否添加Echo字段 + if config.GetTwoWayEcho() { + groupMsg.Echo = echostr } // 获取MasterID数组 masterIDs := config.GetMasterID() diff --git a/config/config.go b/config/config.go index dafd4df9..df7fea6f 100644 --- a/config/config.go +++ b/config/config.go @@ -57,6 +57,7 @@ type Settings struct { SandBoxMode bool `yaml:"sandbox_mode"` Title string `yaml:"title"` HashID bool `yaml:"hash_id"` + TwoWayEcho bool `yaml:"twoway_echo"` } // LoadConfig 从文件中加载配置并初始化单例配置 @@ -390,6 +391,18 @@ func GetLotusValue() bool { return instance.Settings.Lotus } +// 获取双向ehco +func GetTwoWayEcho() bool { + mu.Lock() + defer mu.Unlock() + + if instance == nil { + mylog.Println("Warning: instance is nil when trying to get lotus value.") + return false + } + return instance.Settings.TwoWayEcho +} + // 获取HashID func GetHashIDValue() bool { mu.Lock() diff --git a/template/config_template.go b/template/config_template.go index aaa59b9e..7856fb45 100644 --- a/template/config_template.go +++ b/template/config_template.go @@ -56,6 +56,7 @@ settings: sandbox_mode : false #默认false 如果你只希望沙箱频道使用,请改为true title : "Gensokyo © 2023 - Hoshinonyaruko" #程序的标题 如果多个机器人 可根据标题区分 hash_id : false #使用hash来进行idmaps转换,可以让user_id不是123开始的递增值 + twoway_echo : false #是否采用双向echo,根据机器人选择,獭獭\早苗 true 红色问答\椛椛 或者其他 请使用 false ` const Logo = ` ' diff --git a/template/config_template.yml b/template/config_template.yml index c7e627fc..c29c14dc 100644 --- a/template/config_template.yml +++ b/template/config_template.yml @@ -47,4 +47,5 @@ settings: develop_bot_id : "1234" #开发者环境需自行获取botid 填入 用户请不要设置这两行...开发者调试用 sandbox_mode : false #默认false 如果你只希望沙箱频道使用,请改为true title : "Gensokyo © 2023 - Hoshinonyaruko" #程序的标题 如果多个机器人 可根据标题区分 - hash_id : false #使用hash来进行idmaps转换,可以让user_id不是123开始的递增值 \ No newline at end of file + hash_id : false #使用hash来进行idmaps转换,可以让user_id不是123开始的递增值 + twoway_echo : false #是否采用双向echo,根据机器人选择,獭獭\早苗 true 红色问答\椛椛 或者其他 请使用 false \ No newline at end of file