diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f6c32b15..9a0b0009 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -38,6 +38,8 @@ jobs: if: github.event.name == 'pull_request' with: go-version: '1.18' + version: 'v1.51.2' + args: '--timeout 9999s' only-new-issues: true skip-pkg-cache: true skip-build-cache: true @@ -46,4 +48,5 @@ jobs: uses: golangci/golangci-lint-action@v3 if: github.event.name != 'pull_request' with: - version: latest + version: 'v1.51.2' + args: '--timeout 9999s' 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..834a2d5f 100644 --- a/dice/platform_adapter_discord.go +++ b/dice/platform_adapter_discord.go @@ -190,7 +190,7 @@ func (pa *PlatformAdapterDiscord) sendToChannelRaw(channelId string, text string for _, element := range elem { switch e := element.(type) { case *TextElement: - msgSend.Content = msgSend.Content + e.Content + msgSend.Content = msgSend.Content + antiMarkdownFormat(e.Content) case *AtElement: if e.Target == "all" { msgSend.Content = msgSend.Content + "@everyone " @@ -205,9 +205,6 @@ func (pa *PlatformAdapterDiscord) sendToChannelRaw(channelId string, text string Reader: e.Stream, }) msgSend.Files = files - if msgSend.Content != "" { - msgSend.Content = "```\n" + msgSend.Content + "\n```" - } _, err = pa.IntentSession.ChannelMessageSendComplex(id, msgSend) msgSend = &discordgo.MessageSend{Content: ""} case *ImageElement: @@ -219,14 +216,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 +246,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 { @@ -309,6 +301,9 @@ func FormatDiceIdDiscord(diceDiscord string) string { func FormatDiceIdDiscordChannel(diceDiscord string) string { return fmt.Sprintf("DISCORD-CH-Group:%s", diceDiscord) } +func FormatDiceIdDiscordGuild(diceDiscord string) string { + return fmt.Sprintf("DISCORD-Guild:%s", diceDiscord) +} func ExtractDiscordUserId(id string) string { if strings.HasPrefix(id, "DISCORD:") { @@ -339,7 +334,8 @@ func (pa *PlatformAdapterDiscord) toStdMessage(m *discordgo.MessageCreate) *Mess msg.MessageType = "private" } else { msg.MessageType = "group" - msg.GroupId = FormatDiceIdDiscordChannel(m.ChannelID) + msg.GroupId = FormatDiceIdDiscordGuild(m.ChannelID) + msg.GuildId = ch.GuildID } send := new(SenderBase) send.UserId = FormatDiceIdDiscord(m.Author.ID) diff --git a/dice/platform_adapter_kook.go b/dice/platform_adapter_kook.go index b43f6e6e..a7649617 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 @@ -377,6 +409,10 @@ func FormatDiceIdKook(diceKook string) string { return fmt.Sprintf("KOOK:%s", diceKook) } +func FormatDiceIdKookGuild(diceKook string) string { + return fmt.Sprintf("KOOK-Guild:%s", diceKook) +} + func FormatDiceIdKookChannel(diceKook string) string { return fmt.Sprintf("KOOK-CH-Group:%s", diceKook) } @@ -495,6 +531,7 @@ func (pa *PlatformAdapterKook) toStdMessage(ctx *kook.KmarkdownMessageContext) * } else { msg.MessageType = "group" msg.GroupId = FormatDiceIdKookChannel(ctx.Common.TargetID) + msg.GuildId = FormatDiceIdKookGuild(ctx.Extra.GuildID) if pa.checkIfGuildAdmin(ctx) { send.GroupRole = "admin" } 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 {