MCPcopy Create free account
hub / github.com/FloatTech/ZeroBot-Plugin-Playground / getPara

Function getPara

plugin/vote/vote.go:131–171  ·  view source on GitHub ↗
(ctx *zero.Ctx)

Source from the content-addressed store, hash-verified

129}
130
131func getPara(ctx *zero.Ctx) bool {
132 next := zero.NewFutureEvent("message", 999, false, ctx.CheckSession())
133 recv, cancel := next.Repeat()
134 i := 0
135 paras := [2]int{}
136 ctx.SendChain(message.Text("请输入投票模式序号\n1. 可重复投票\n2. 不可重复投票"))
137 for {
138 select {
139 case <-time.After(time.Second * 120):
140 ctx.SendChain(message.Text("未输入,退出投票"))
141 cancel()
142 return false
143 case c := <-recv:
144 msg := c.Event.Message.ExtractPlainText()
145 num, err := strconv.Atoi(msg)
146 if err != nil {
147 ctx.SendChain(message.Text("请输入数字!"))
148 continue
149 }
150 switch i {
151 case 0:
152 if num <= 0 || num > 2 {
153 ctx.SendChain(message.Text("投票模式非法!"))
154 continue
155 }
156 paras[0] = num
157 ctx.SendChain(message.Text("请输入投票时间(单位秒,至少3秒)"))
158 case 1:
159 if num < 3 {
160 ctx.SendChain(message.Text("投票时间非法!"))
161 continue
162 }
163 cancel()
164 paras[1] = num
165 ctx.State["vote_paras"] = paras
166 return true
167 }
168 i++
169 }
170 }
171}
172
173func rankByVote(voteMap map[int]int) pairlist {
174 pl := make(pairlist, len(voteMap))

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected