diff --git a/go.mod b/go.mod index eb3df00..a461a91 100644 --- a/go.mod +++ b/go.mod @@ -3,12 +3,12 @@ module github.com/FloatTech/NanoBot-Plugin go 1.20 require ( - github.com/FloatTech/AnimeAPI v1.6.1-0.20230207081411-573533b18194 + github.com/FloatTech/AnimeAPI v1.6.1-0.20231016040616-78f012eba395 github.com/FloatTech/floatbox v0.0.0-20230827160415-f0865337a824 github.com/FloatTech/gg v1.1.2 github.com/FloatTech/imgfactory v0.2.1 github.com/FloatTech/zbpctrl v1.5.3-0.20230130095145-714ad318cd52 - github.com/fumiama/NanoBot v0.0.0-20231015152604-ce34c996ef31 + github.com/fumiama/NanoBot v0.0.0-20231016033425-415bd574f189 github.com/fumiama/go-base16384 v1.7.0 github.com/fumiama/unibase2n v0.0.0-20221020155353-02876e777430 github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 @@ -17,7 +17,7 @@ require ( ) require ( - github.com/FloatTech/sqlite v1.5.7 // indirect + github.com/FloatTech/sqlite v1.6.2 // indirect github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b // indirect github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e // indirect github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5 // indirect diff --git a/go.sum b/go.sum index 478662e..7cae1d4 100644 --- a/go.sum +++ b/go.sum @@ -1,13 +1,13 @@ -github.com/FloatTech/AnimeAPI v1.6.1-0.20230207081411-573533b18194 h1:+p85V0fdZNt3UoKreBeI6S3IOPvNmU5/Fnn39ipSkVk= -github.com/FloatTech/AnimeAPI v1.6.1-0.20230207081411-573533b18194/go.mod h1:LCiKZivPVazRRCnnADQfIBFZiIPHHCFqaCpwZWsFehI= +github.com/FloatTech/AnimeAPI v1.6.1-0.20231016040616-78f012eba395 h1:wrUbBkP4q+HLw/3K+65PBKLOLPXect8h1c/iY9HPiNU= +github.com/FloatTech/AnimeAPI v1.6.1-0.20231016040616-78f012eba395/go.mod h1:6vYu7bW5gPQsBnXB+I6yk+eJQaaAwusoQ/I/wQMwOAI= github.com/FloatTech/floatbox v0.0.0-20230827160415-f0865337a824 h1:w72fzQg1Y9+VLSRl7iKzaZ6fG3myyMJfpOSajcjaMDM= github.com/FloatTech/floatbox v0.0.0-20230827160415-f0865337a824/go.mod h1:FwQm6wk+b4wuW54KCKn3zccMX47Q5apnHD/Yakzv0fI= github.com/FloatTech/gg v1.1.2 h1:YolgOYg3uDHc1+g0bLtt6QuRA/pvLn+b9IBCIhOOX88= github.com/FloatTech/gg v1.1.2/go.mod h1:uzPzAeT35egARdRuu+1oyjU3CmTwCceoq3Vvje7LpcI= github.com/FloatTech/imgfactory v0.2.1 h1:XoVwy0Xu0AvTRtzlhv5teZcuZlAcHrYjeQ8MynJ/zlk= github.com/FloatTech/imgfactory v0.2.1/go.mod h1:QBJKHbzpE+x/9Wn7mXebWap/K/xUJSjgiaelAElwU9Q= -github.com/FloatTech/sqlite v1.5.7 h1:Bvo4LSojcZ6dVtbHrkqvt6z4v8e+sj0G5PSUIvdawsk= -github.com/FloatTech/sqlite v1.5.7/go.mod h1:zFbHzRfB+CJ+VidfjuVbrcin3DAz283F7hF1hIeHzpY= +github.com/FloatTech/sqlite v1.6.2 h1:FytbExjpvYalZxxITtmSenHiPGLPUvlz47LY/P0SCCw= +github.com/FloatTech/sqlite v1.6.2/go.mod h1:zFbHzRfB+CJ+VidfjuVbrcin3DAz283F7hF1hIeHzpY= github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b h1:tvciXWq2nuvTbFeJGLDNIdRX3BI546D3O7k7vrVueZw= github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs= github.com/FloatTech/zbpctrl v1.5.3-0.20230130095145-714ad318cd52 h1:BrStRXeosWh8L0iA/EjPd8w6xNexDkqki39ITZko/9Q= @@ -23,8 +23,8 @@ github.com/disintegration/imaging v1.6.2 h1:w1LecBlG2Lnp8B3jk5zSuNqd7b4DXhcjwek1 github.com/disintegration/imaging v1.6.2/go.mod h1:44/5580QXChDfwIclfc/PCwrr44amcmDAg8hxG0Ewe4= github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 h1:BBade+JlV/f7JstZ4pitd4tHhpN+w+6I+LyOS7B4fyU= github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4/go.mod h1:H7chHJglrhPPzetLdzBleF8d22WYOv7UM/lEKYiwlKM= -github.com/fumiama/NanoBot v0.0.0-20231015152604-ce34c996ef31 h1:HH/O1cfV/BoJjsUa7Gi93sow5vXf6afzQifgyRqIJt4= -github.com/fumiama/NanoBot v0.0.0-20231015152604-ce34c996ef31/go.mod h1:bWsAyGZKPf8jSYRArLUiGN3bLCzRQzI2tf31Ps9TRjw= +github.com/fumiama/NanoBot v0.0.0-20231016033425-415bd574f189 h1:BOw7aBHUfNP6m+F8c8qY+mzElp2tRuRVsFr8+efwjuE= +github.com/fumiama/NanoBot v0.0.0-20231016033425-415bd574f189/go.mod h1:bWsAyGZKPf8jSYRArLUiGN3bLCzRQzI2tf31Ps9TRjw= github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b h1:Zt3pFQditAdWTHCOVkiloc9ZauBoWrb37guFV4iIRvE= github.com/fumiama/bigfft v0.0.0-20211011143303-6e0bfa3c836b/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/fumiama/cron v1.3.0 h1:ZWlwuexF+HQHl3cYytEE5HNwD99q+3vNZF1GrEiXCFo= diff --git a/main.go b/main.go index b5c9ec4..abe11e5 100644 --- a/main.go +++ b/main.go @@ -34,8 +34,9 @@ func main() { appid := flag.String("a", "", "qq appid") secret := flag.String("s", "", "qq secret") debug := flag.Bool("d", false, "enable debug-level log output") - timeout := flag.Int("T", 60, "timeout (s)") + timeout := flag.Int("T", 60, "api timeout (s)") help := flag.Bool("h", false, "print this help") + sandbox := flag.Bool("b", false, "run in sandbox api") flag.Parse() if *help { fmt.Println("Usage:") @@ -56,6 +57,10 @@ func main() { sus = append(sus, s) } + if *sandbox { + nano.OpenAPI = nano.SandboxAPI + } + nano.OnMessageCommandGroup([]string{"help", "帮助", "menu", "菜单"}, nano.OnlyToMe).SetBlock(true). Handle(func(ctx *nano.Ctx) { _, _ = ctx.SendPlainMessage(false, kanban.Banner) diff --git a/plugin/runcode/code_runner.go b/plugin/runcode/code_runner.go index 229a3f5..3a2be28 100644 --- a/plugin/runcode/code_runner.go +++ b/plugin/runcode/code_runner.go @@ -12,7 +12,7 @@ import ( "github.com/FloatTech/NanoBot-Plugin/utils/ctxext" ) -var ro = runoob.NewRunOOB("b6365362a90ac2ac7098ba52c13e352b") +var ro = runoob.NewRunOOB("066417defb80d038228de76ec581a50a") func init() { nano.Register("runcode", &ctrl.Options[*nano.Ctx]{ @@ -26,31 +26,37 @@ func init() { "JavaScript || TypeScript || PHP || Shell \n" + "Kotlin || Rust || Erlang || Ruby || Swift \n" + "R || VB || Py2 || Perl || Pascal || Scala", - }).ApplySingle(ctxext.DefaultSingle).OnMessageRegex(`^>runcode(raw)?\s(.+?)\s([\s\S]+)$`).SetBlock(true).Limit(ctxext.LimitByUser). + }).ApplySingle(ctxext.DefaultSingle).OnMessageRegex(`^>runcode(raw)?\s(.+?)\s([\s\S]+)$`).SetBlock(true).Limit(ctxext.LimitByUser). Handle(func(ctx *nano.Ctx) { israw := ctx.State["regex_matched"].([]string)[1] != "" language := ctx.State["regex_matched"].([]string)[2] language = strings.ToLower(language) if _, exist := runoob.LangTable[language]; !exist { // 不支持语言 - _, _ = ctx.SendPlainMessage(false, "> "+ctx.Message.Author.Username+"\n语言不是受支持的编程语种呢~") + _, _ = ctx.SendPlainMessage(false, nano.MessageEscape("> "+ctx.Message.Author.Username+"\n语言不是受支持的编程语种呢~")) } else { // 执行运行 block := ctx.State["regex_matched"].([]string)[3] switch block { case "help": - _, _ = ctx.SendPlainMessage(false, "> "+ctx.Message.Author.Username+" "+language+"-template:\n>runcode "+language+"\n"+runoob.Templates[language]) + _, err := ctx.SendPlainMessage(false, nano.MessageEscape("> "+ctx.Message.Author.Username+" "+language+"-template:\n>runcode "+language+"\n"+runoob.Templates[language])) + if err != nil { + _, _ = ctx.SendPlainMessage(false, "ERROR: ", err) + } default: output, err := ro.Run(block, language, "") if err != nil { - output = "ERROR:\n" + err.Error() + output = "ERROR:\n" + nano.MessageEscape(err.Error()) } output = cutTooLong(strings.Trim(output, "\n")) if israw { - _, _ = ctx.SendPlainMessage(false, output) + _, err = ctx.SendPlainMessage(false, output) } else { head := "> " + ctx.Message.Author.Username + "\n" - _, _ = ctx.SendPlainMessage(false, head+output) + _, err = ctx.SendPlainMessage(false, nano.MessageEscape(head+output)) + } + if err != nil { + _, _ = ctx.SendPlainMessage(false, "ERROR: ", err) } } }