MCPcopy Index your code
hub / github.com/FloatTech/ZeroBot-Plugin / init

Function init

plugin/chess/chess.go:40–173  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

38)
39
40func init() {
41 // 初始化临时文件夹
42 tempFileDir = path.Join(engine.DataFolder(), "temp")
43 err := os.MkdirAll(tempFileDir, 0750)
44 if err != nil {
45 panic(err)
46 }
47 // 初始化数据库
48 dbFilePath := engine.DataFolder() + "chess.db"
49 initDatabase(dbFilePath)
50 // 注册指令
51 engine.OnFullMatchGroup([]string{"下棋", "chess"}, zero.OnlyGroup).SetBlock(true).Limit(limit.LimitByGroup).
52 Handle(func(ctx *zero.Ctx) {
53 if ctx.Event.Sender == nil {
54 return
55 }
56 userUin := ctx.Event.UserID
57 userName := ctx.Event.Sender.NickName
58 groupCode := ctx.Event.GroupID
59 replyMessage, err := game(groupCode, userUin, userName)
60 if err != nil {
61 ctx.SendChain(message.Text("ERROR: ", err))
62 return
63 }
64 ctx.Send(replyMessage)
65 })
66
67 engine.OnFullMatchGroup([]string{"认输", "resign"}, zero.OnlyGroup).SetBlock(true).Limit(limit.LimitByGroup).
68 Handle(func(ctx *zero.Ctx) {
69 userUin := ctx.Event.UserID
70 groupCode := ctx.Event.GroupID
71 replyMessage, err := resign(groupCode, userUin)
72 if err != nil {
73 ctx.SendChain(message.Text("ERROR: ", err))
74 return
75 }
76 ctx.Send(replyMessage)
77 })
78
79 engine.OnFullMatchGroup([]string{"和棋", "draw"}, zero.OnlyGroup).SetBlock(true).Limit(limit.LimitByGroup).
80 Handle(func(ctx *zero.Ctx) {
81 userUin := ctx.Event.UserID
82 groupCode := ctx.Event.GroupID
83 replyMessage, err := draw(groupCode, userUin)
84 if err != nil {
85 ctx.SendChain(message.Text("ERROR: ", err))
86 return
87 }
88 ctx.Send(replyMessage)
89 })
90
91 engine.OnFullMatchGroup([]string{"中断", "abort"}, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).Limit(limit.LimitByGroup).
92 Handle(func(ctx *zero.Ctx) {
93 groupCode := ctx.Event.GroupID
94 replyMessage, err := abort(groupCode)
95 if err != nil {
96 ctx.SendChain(message.Text("ERROR: ", err))
97 return

Callers

nothing calls this directly

Calls 10

initDatabaseFunction · 0.85
gameFunction · 0.85
resignFunction · 0.85
abortFunction · 0.85
blindfoldFunction · 0.85
playFunction · 0.85
getRankingFunction · 0.85
cleanUserRateFunction · 0.85
drawFunction · 0.70
rateFunction · 0.70

Tested by

no test coverage detected