帮助选择困难症

This commit is contained in:
Chendihe4975 2021-09-12 17:52:30 +08:00
parent c70dbd219c
commit 629d3c1fa8
3 changed files with 38 additions and 0 deletions

View File

@ -131,6 +131,8 @@
- [x] 来张 [xxx]
- **拼音首字母释义工具** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_nbnhhsh"`
- [x] ?? [缩写]
- **选择困难症帮手** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin_choose"`
- [x] 选择[选择项1]还是[选项2]还是[更多选项]
- **TODO...**
## 使用方法

View File

@ -22,6 +22,7 @@ import (
_ "github.com/tdf1939/ZeroBot-Plugin-Gif/plugin_gif" // 制图
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_ai_false" // 服务器监控
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_choose" // 选择困难症帮手
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_hs" // 炉石
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_minecraft" // MCSManager
_ "github.com/FloatTech/ZeroBot-Plugin/plugin_music" // 点歌

35
plugin_choose/choose.go Normal file
View File

@ -0,0 +1,35 @@
package choose
import (
"math/rand"
"strconv"
"strings"
"github.com/FloatTech/ZeroBot-Plugin/control"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)
func init() {
engine := control.Register("choose", &control.Options{
DisableOnDefault: false,
Help: "choose\n" +
"- 选择可口可乐还是百事可乐\n" +
"- 选择肯德基还是麦当劳还是必胜客\n",
})
engine.OnPrefix("选择").SetBlock(true).FirstPriority().Handle(handle)
}
func handle(ctx *zero.Ctx) {
rawOptions := strings.Split(ctx.State["args"].(string), "还是")
var options = make([]string, 0)
for count, option := range rawOptions {
options = append(options, strconv.Itoa(count+1)+", "+option)
}
result := rawOptions[rand.Intn(len(rawOptions))]
name := ctx.Event.Sender.NickName
ctx.SendChain(message.Text("> ", name, "\n",
"你的选项有:", "\n",
strings.Join(options, "\n"), "\n",
"你最终会选: ", result,
))
}