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

Beta404 #405

Merged
merged 7 commits into from
May 11, 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
24 changes: 24 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2256,3 +2256,27 @@ func GetGlobalGroupMsgReceiveMessage() string {
}
return ""
}

// 获取EntersAsBlock状态
func GetEntersAsBlock() bool {
mu.Lock()
defer mu.Unlock()

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

// 获取NativeMD状态
func GetNativeMD() bool {
mu.Lock()
defer mu.Unlock()

if instance == nil {
mylog.Println("Warning: instance is nil when trying to NativeMD.")
return false
}
return instance.Settings.NativeMD
}
36 changes: 26 additions & 10 deletions handlers/send_group_msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,7 @@ func auto_md(message callapi.ActionMessage, messageText string, richMediaMessage
mylog.Printf("获取图片宽高出错")
}
imgDesc := fmt.Sprintf("图片 #%dpx #%dpx", width, height)

// 将所有的\r\n替换为\r
messageText = strings.ReplaceAll(messageText, "\r\n", "\r")
// 将所有的\n替换为\r
Expand All @@ -1343,18 +1344,33 @@ func auto_md(message callapi.ActionMessage, messageText string, richMediaMessage
if !strings.HasPrefix(messageText, "\r") {
messageText = "\r" + messageText
}
// 创建 MarkdownParams 的实例
mdParams := []*dto.MarkdownParams{
{Key: "text_start", Values: []string{" "}}, //空着
{Key: "img_dec", Values: []string{imgDesc}},
{Key: "img_url", Values: []string{imgURL}},
{Key: "text_end", Values: []string{messageText}},
if config.GetEntersAsBlock() {
messageText = strings.ReplaceAll(messageText, "\r", " ")
}
// 组合模板 Markdown
md = &dto.Markdown{
CustomTemplateID: CustomTemplateID,
Params: mdParams,

// 根据配置决定如何生成Markdown内容
if !config.GetNativeMD() {
// 创建 MarkdownParams 的实例
mdParams := []*dto.MarkdownParams{
{Key: "text_start", Values: []string{" "}}, //空着
{Key: "img_dec", Values: []string{imgDesc}},
{Key: "img_url", Values: []string{imgURL}},
{Key: "text_end", Values: []string{messageText}},
}
// 组合模板 Markdown
md = &dto.Markdown{
CustomTemplateID: CustomTemplateID,
Params: mdParams,
}
} else {
// 使用原生Markdown格式
content := fmt.Sprintf(" %s![%s](%s)%s", " ", imgDesc, imgURL, messageText)
// 原生 Markdown
md = &dto.Markdown{
Content: content,
}
}

whiteList := matchedPrefix.WhiteList
// 创建 CustomKeyboard
customKeyboard := &keyboard.CustomKeyboard{
Expand Down
2 changes: 2 additions & 0 deletions structs/structs.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ type Settings struct {
//MD相关
CustomTemplateID string `yaml:"custom_template_id"`
KeyBoardID string `yaml:"keyboard_id"`
NativeMD bool `yaml:"native_md"`
EntersAsBlock bool `yaml:"enters_as_block"`
//发送行为修改
LazyMessageId bool `yaml:"lazy_message_id"`
RamDomSeq bool `yaml:"ramdom_seq"`
Expand Down
4 changes: 3 additions & 1 deletion template/config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ settings:
#MD相关
custom_template_id : "" #自动转换图文信息到md所需要的id *需要应用端支持双方向echo
keyboard_id : "" #自动转换图文信息到md所需要的按钮id *需要应用端支持双方向echo

native_md : false #自动转换图文信息到md,使用原生markdown能力.
enters_as_block : false #自动转换图文信息到md,\r \r\n \n 替换为空格.

#发送行为修改
lazy_message_id : false #false=message_id 条条准确对应 true=message_id 按时间范围随机对应(适合主动推送bot)前提,有足够多的活跃信息刷新id池
ramdom_seq : false #当多开gensokyo时,如果遇到群信息只能发出一条,请开启每个gsk的此项.(建议使用一个gsk连接多个应用)
Expand Down
Loading