mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-20 06:20:08 +08:00
✨✨ 翻牌改为抽取最近发言的人
This commit is contained in:
parent
5cb6608e17
commit
3405c1c45a
@ -6,11 +6,13 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
"sort"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
|
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
timer "github.com/FloatTech/ZeroBot-Plugin-Timer"
|
timer "github.com/FloatTech/ZeroBot-Plugin-Timer"
|
||||||
@ -46,6 +48,7 @@ const (
|
|||||||
|
|
||||||
var (
|
var (
|
||||||
config Config
|
config Config
|
||||||
|
limit = rate.NewManager(time.Minute*5, 2)
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() { // 插件主体
|
func init() { // 插件主体
|
||||||
@ -282,18 +285,48 @@ func init() { // 插件主体
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
// 随机点名
|
// 随机点名
|
||||||
zero.OnFullMatchGroup([]string{"翻牌"}).SetBlock(true).SetPriority(40).
|
zero.OnFullMatchGroup([]string{"翻牌"}, zero.OnlyGroup).SetBlock(true).SetPriority(40).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
if ctx.Event.GroupID > 0 {
|
if !limit.Load(ctx.Event.UserID).Acquire() {
|
||||||
list := ctx.GetGroupMemberList(ctx.Event.GroupID)
|
ctx.SendChain(message.Text("少女祈祷中......"))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 无缓存获取群员列表
|
||||||
|
list := ctx.CallAction("get_group_member_list", zero.Params{
|
||||||
|
"group_id": ctx.Event.GroupID,
|
||||||
|
"no_cache": true,
|
||||||
|
}).Data
|
||||||
|
temp := list.Array()
|
||||||
|
sort.SliceStable(temp, func(i, j int) bool {
|
||||||
|
return temp[i].Get("last_sent_time").Int() < temp[j].Get("last_sent_time").Int()
|
||||||
|
})
|
||||||
|
max := func(a, b int) int {
|
||||||
|
if a > b {
|
||||||
|
return a
|
||||||
|
}
|
||||||
|
return b
|
||||||
|
}
|
||||||
|
temp = temp[max(0, len(temp)-10):]
|
||||||
rand.Seed(time.Now().UnixNano())
|
rand.Seed(time.Now().UnixNano())
|
||||||
randIndex := fmt.Sprint(rand.Intn(int(list.Get("#").Int())))
|
who := temp[rand.Intn(len(temp))]
|
||||||
randCard := list.Get(randIndex + ".card").String()
|
if who.Get("user_id").Int() == ctx.Event.SelfID {
|
||||||
if randCard == "" {
|
ctx.SendChain(message.Text("幸运儿居然是我自己"))
|
||||||
randCard = list.Get(randIndex + ".nickname").String()
|
return
|
||||||
}
|
}
|
||||||
ctx.Send(randCard + ",就是你啦!")
|
if who.Get("user_id").Int() == ctx.Event.UserID {
|
||||||
|
ctx.SendChain(message.Text("哎呀,就是你自己了"))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
nick := who.Get("card").Str
|
||||||
|
if nick == "" {
|
||||||
|
nick = who.Get("nickname").Str
|
||||||
|
}
|
||||||
|
ctx.SendChain(
|
||||||
|
message.Text(
|
||||||
|
nick,
|
||||||
|
" 就是你啦!",
|
||||||
|
),
|
||||||
|
)
|
||||||
})
|
})
|
||||||
// 入群欢迎
|
// 入群欢迎
|
||||||
zero.OnNotice().SetBlock(false).FirstPriority().
|
zero.OnNotice().SetBlock(false).FirstPriority().
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user