diff --git a/dice/dice.go b/dice/dice.go index 8f554728..23c490a2 100644 --- a/dice/dice.go +++ b/dice/dice.go @@ -64,8 +64,8 @@ type ExtInfo struct { Version string `yaml:"-" json:"version" jsbind:"version"` // 版本 // 作者 // 更新时间 - AutoActive bool `yaml:"-" json:"-"` // 是否自动开启 - CmdMap CmdMapCls `yaml:"-" json:"-" jsbind:"cmdMap"` // 指令集合 + AutoActive bool `yaml:"-" json:"-" jsbind:"autoActive"` // 是否自动开启 + CmdMap CmdMapCls `yaml:"-" json:"-" jsbind:"cmdMap"` // 指令集合 Brief string `yaml:"-" json:"-"` ActiveOnPrivate bool `yaml:"-" json:"-"` diff --git a/dice/gocqhttp_helper.go b/dice/gocqhttp_helper.go index 1cb74651..551e1d3c 100644 --- a/dice/gocqhttp_helper.go +++ b/dice/gocqhttp_helper.go @@ -4,11 +4,11 @@ import ( "encoding/json" "errors" "fmt" - "io/ioutil" "math/rand" "os" "path/filepath" "regexp" + "runtime" "runtime/debug" "sealdice-core/utils/procs" "strings" @@ -238,7 +238,7 @@ func GenerateDeviceJsonAndroid(dice *Dice, protocol int) (string, []byte, error) if _, err := os.Stat("./my_device.json"); err == nil { dice.Logger.Info("检测到my_device.json,将使用该文件中的设备信息") // file exists - data, err := ioutil.ReadFile("./my_device.json") + data, err := os.ReadFile("./my_device.json") if err == nil { deviceJson := deviceFile{} err = json.Unmarshal(data, &deviceJson) @@ -522,6 +522,9 @@ func GoCqHttpServe(dice *Dice, conn *EndPointInfo, password string, protocol int p := procs.NewProcess(fmt.Sprintf(`"%s" faststart`, gocqhttpExePath)) p.Dir = workDir + if runtime.GOOS == "android" { + p.Env = os.Environ() + } chQrCode := make(chan int, 1) riskCount := 0 isSeldKilling := false diff --git a/dice/platform_adapter_discord.go b/dice/platform_adapter_discord.go index 92ac7d18..fac9a176 100644 --- a/dice/platform_adapter_discord.go +++ b/dice/platform_adapter_discord.go @@ -206,7 +206,7 @@ func (pa *PlatformAdapterDiscord) sendToChannelRaw(channelId string, text string }) msgSend.Files = files if msgSend.Content != "" { - msgSend.Content = "```\n" + msgSend.Content + "\n```" + msgSend.Content = antiMarkdownFormat(msgSend.Content) } _, err = pa.IntentSession.ChannelMessageSendComplex(id, msgSend) msgSend = &discordgo.MessageSend{Content: ""} @@ -219,14 +219,10 @@ func (pa *PlatformAdapterDiscord) sendToChannelRaw(channelId string, text string Reader: f.Stream, }) msgSend.Files = files - if msgSend.Content != "" { - msgSend.Content = "```\n" + msgSend.Content + "\n```" - } _, err = pa.IntentSession.ChannelMessageSendComplex(id, msgSend) msgSend = &discordgo.MessageSend{Content: ""} case *TTSElement: if msgSend.Content != "" || msgSend.Files != nil { - msgSend.Content = "```\n" + msgSend.Content + "\n```" _, err = pa.IntentSession.ChannelMessageSendComplex(id, msgSend) } if err != nil { @@ -253,7 +249,6 @@ func (pa *PlatformAdapterDiscord) sendToChannelRaw(channelId string, text string } } if msgSend.Content != "" || msgSend.Files != nil { - msgSend.Content = "```\n" + msgSend.Content + "\n```" _, err = pa.IntentSession.ChannelMessageSendComplex(id, msgSend) } if err != nil { diff --git a/dice/platform_adapter_kook.go b/dice/platform_adapter_kook.go index b43f6e6e..439f31f3 100644 --- a/dice/platform_adapter_kook.go +++ b/dice/platform_adapter_kook.go @@ -290,7 +290,7 @@ func (pa *PlatformAdapterKook) SendToChannelRaw(id string, text string, private switch e := element.(type) { case *TextElement: //goldmark.DefaultParser().Parse(txt.NewReader([]byte(e.Content))) - msgb.Content += "```\n" + e.Content + "\n```" + msgb.Content += antiMarkdownFormat(e.Content) case *ImageElement: if msgb.Content != "``````" && msgb.Content != "" { err = pa.MessageCreateRaw(msgb, id, private) @@ -348,7 +348,7 @@ func (pa *PlatformAdapterKook) SendToChannelRaw(id string, text string, private case *AtElement: msgb.Content = msgb.Content + fmt.Sprintf("(met)%s(met)", e.Target) case *TTSElement: - msgb.Content += "```\n" + e.Content + "\n```" + msgb.Content += antiMarkdownFormat(e.Content) case *ReplyElement: msgb.Quote = e.Target } @@ -361,6 +361,38 @@ func (pa *PlatformAdapterKook) SendToChannelRaw(id string, text string, private } } +func antiMarkdownFormat(text string) string { + text = strings.ReplaceAll(text, "\\", "\\\\") + text = strings.ReplaceAll(text, "_", "\\_") + text = strings.ReplaceAll(text, "~", "\\~") + //text = strings.ReplaceAll(text, "|", "\\|") + //text = strings.ReplaceAll(text, ">", "\\>") + //text = strings.ReplaceAll(text, "<", "\\<") + text = strings.ReplaceAll(text, "`", "\\`") + //text = strings.ReplaceAll(text, "#", "\\#") + //text = strings.ReplaceAll(text, "+", "\\+") + //text = strings.ReplaceAll(text, "-", "\\-") + //text = strings.ReplaceAll(text, "=", "\\=") + //text = strings.ReplaceAll(text, "{", "\\{") + //text = strings.ReplaceAll(text, "}", "\\}") + text = strings.ReplaceAll(text, ".", "\\.") + text = strings.ReplaceAll(text, "!", "\\!") + text = strings.ReplaceAll(text, "(", "\\(") + text = strings.ReplaceAll(text, ")", "\\)") + text = strings.ReplaceAll(text, "[", "\\[") + text = strings.ReplaceAll(text, "]", "\\]") + text = strings.ReplaceAll(text, "*", "\\*") + //text = strings.ReplaceAll(text, ":", "\\:") + //text = strings.ReplaceAll(text, "\"", "\\\"") + //text = strings.ReplaceAll(text, "'", "\\'") + //text = strings.ReplaceAll(text, "/", "\\/") + //text = strings.ReplaceAll(text, "@", "\\@") + //text = strings.ReplaceAll(text, "%", "\\%") + //text = strings.ReplaceAll(text, ",", "\\,") + //text = strings.ReplaceAll(text, " ", "\\ ") + return text +} + func (pa *PlatformAdapterKook) MessageCreateRaw(base kook.MessageCreateBase, id string, isPrivate bool) error { bot := pa.IntentSession var err error diff --git a/main.go b/main.go index 6001cdaa..2618e5e2 100644 --- a/main.go +++ b/main.go @@ -139,6 +139,7 @@ func main() { Delay int64 `long:"delay"` JustForTest bool `long:"just-for-test"` DBCheck bool `long:"db-check" description:"检查数据库是否有问题"` + ShowEnv bool `long:"show-env" description:"显示环境变量"` } //dice.SetDefaultNS([]string{"114.114.114.114:53", "8.8.8.8:53"}, false) @@ -155,6 +156,12 @@ func main() { model.DBCheck("data/default") return } + if opts.ShowEnv { + for i, e := range os.Environ() { + println(i, e) + } + return + } deleteOldWrongFile() if opts.Delay != 0 { diff --git a/utils/procs/procs.go b/utils/procs/procs.go index 67388944..5e411f99 100644 --- a/utils/procs/procs.go +++ b/utils/procs/procs.go @@ -17,6 +17,7 @@ type Process struct { StdIn io.WriteCloser Cmd *exec.Cmd Dir string + Env []string // show stdout, return value will be written to stdin OutputHandler OutHandler } @@ -44,7 +45,9 @@ func (p *Process) Start() error { if p.Dir != "" { cmd.Dir = p.Dir } - + if p.Env != nil { + cmd.Env = p.Env + } p.Cmd = cmd stdin, err := cmd.StdinPipe() if err != nil {