mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
✨ 优化代码结构
This commit is contained in:
parent
dec42cc72b
commit
7a8c915e62
10
README.md
10
README.md
@ -481,6 +481,16 @@ print("run[CQ:image,file="+j["img"]+"]")
|
|||||||
|
|
||||||
- [x] 注:不显式限制时,私聊发送可在所有群抽到,群聊发送仅可在本群抽到,默认频道为 global
|
- [x] 注:不显式限制时,私聊发送可在所有群抽到,群聊发送仅可在本群抽到,默认频道为 global
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>一群一天一夫一妻制群老婆</summary>
|
||||||
|
|
||||||
|
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/qqwife"`
|
||||||
|
|
||||||
|
- [x] 娶群友
|
||||||
|
|
||||||
|
- [x] 群老婆列表
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
<details>
|
<details>
|
||||||
<summary>合成emoji</summary>
|
<summary>合成emoji</summary>
|
||||||
|
|||||||
1
main.go
1
main.go
@ -96,6 +96,7 @@ import (
|
|||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/novel" // 铅笔小说网搜索
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/novel" // 铅笔小说网搜索
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nsfw" // nsfw图片识别
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nsfw" // nsfw图片识别
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/omikuji" // 浅草寺求签
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/omikuji" // 浅草寺求签
|
||||||
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/qqwife" // 一群一天一夫一妻制群老婆
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/reborn" // 投胎
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/reborn" // 投胎
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/runcode" // 在线运行代码
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/runcode" // 在线运行代码
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/saucenao" // 以图搜图
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/saucenao" // 以图搜图
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
// Package qqwife 娶群友 基于“翻牌”和江林大佬的“群老婆”插件魔改作品
|
// Package qqwife 娶群友 基于“翻牌”和江林大佬的“群老婆”插件魔改作品
|
||||||
package qqwife
|
package qqwife
|
||||||
|
|
||||||
import (
|
import (
|
||||||
@ -18,128 +18,126 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
setcp = make(map[int64]int64, 60) //初始化中间的map元素,虽然取了30个人数,以防万一翻个倍储存
|
qqwifegroup = make(map[int64]map[int64]int64, 64) // 64个群的预算大小
|
||||||
qqwifegroup = make(map[int64]map[int64]int64, 50) //50个群的预算大小
|
|
||||||
lastdate time.Time
|
lastdate time.Time
|
||||||
rock sync.Mutex
|
mu sync.Mutex
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
engine := control.Register("qqwife", &control.Options{
|
engine := control.Register("qqwife", &control.Options{
|
||||||
DisableOnDefault: false,
|
DisableOnDefault: false,
|
||||||
Help: "一群一天一夫一妻制群老婆\n" +
|
Help: "一群一天一夫一妻制群老婆\n" +
|
||||||
"-娶群友",
|
"- 娶群友\n" +
|
||||||
|
"- 群老婆列表",
|
||||||
})
|
})
|
||||||
engine.OnFullMatch("娶群友", zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByUser).
|
engine.OnFullMatch("娶群友", zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByUser).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
rock.Lock()
|
mu.Lock()
|
||||||
defer rock.Unlock()
|
defer mu.Unlock()
|
||||||
if time.Now().Day() != lastdate.Day() {
|
if time.Now().Day() != lastdate.Day() {
|
||||||
qqwifegroup = make(map[int64]map[int64]int64, 50) //跨天就重新初始化数据
|
qqwifegroup = make(map[int64]map[int64]int64, 64) // 跨天就重新初始化数据
|
||||||
}
|
}
|
||||||
//先判断是否已经娶过或者被娶
|
// 先判断是否已经娶过或者被娶
|
||||||
groupid := ctx.Event.GroupID
|
gid := ctx.Event.GroupID
|
||||||
uid := ctx.Event.UserID
|
uid := ctx.Event.UserID
|
||||||
var status string
|
// 如果娶过
|
||||||
//如果娶过
|
wife, ok := qqwifegroup[gid][uid]
|
||||||
userinfo, ok := qqwifegroup[groupid][uid]
|
|
||||||
if ok {
|
if ok {
|
||||||
ctx.SendChain(
|
ctx.SendChain(
|
||||||
message.At(uid),
|
message.At(uid),
|
||||||
message.Text("今天你的群老婆是"),
|
message.Text("今天你的群老婆是"),
|
||||||
message.Image("http://q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(userinfo, 10)+"&s=640"),
|
message.Image("http:// q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(wife, 10)+"&s=640"),
|
||||||
message.Text(
|
message.Text(
|
||||||
"\n",
|
"\n",
|
||||||
"[", ctx.CardOrNickName(userinfo), "]",
|
"[", ctx.CardOrNickName(wife), "]",
|
||||||
"(", strconv.FormatInt(userinfo, 10), ")哒",
|
"(", wife, ")哒",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//如果被娶过
|
// 如果被娶过
|
||||||
for k, v := range qqwifegroup[groupid] {
|
for husband, wife := range qqwifegroup[gid] {
|
||||||
if v == uid { //如果为0且是在本群抽的就输出
|
if wife == uid { // 如果为0且是在本群抽的就输出
|
||||||
ctx.SendChain(
|
ctx.SendChain(
|
||||||
message.At(uid),
|
message.At(uid),
|
||||||
message.Text("今天你被娶了,群老公是"),
|
message.Text("今天你被娶了,群老公是"),
|
||||||
message.Image("http://q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(k, 10)+"&s=640"),
|
message.Image("http:// q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(husband, 10)+"&s=640"),
|
||||||
message.Text(
|
message.Text(
|
||||||
"\n",
|
"\n",
|
||||||
"[", ctx.CardOrNickName(k), "]",
|
"[", ctx.CardOrNickName(husband), "]",
|
||||||
"(", strconv.FormatInt(k, 10), ")哒",
|
"(", husband, ")哒",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 无缓存获取群员列表
|
// 无缓存获取群员列表
|
||||||
temp := ctx.GetThisGroupMemberListNoCache().Array()
|
temp := ctx.GetThisGroupMemberListNoCache().Array()
|
||||||
sort.SliceStable(temp, func(i, j int) bool {
|
sort.SliceStable(temp, func(i, j int) bool {
|
||||||
return temp[i].Get("last_sent_time").Int() < temp[j].Get("last_sent_time").Int()
|
return temp[i].Get("last_sent_time").Int() < temp[j].Get("last_sent_time").Int()
|
||||||
})
|
})
|
||||||
temp = temp[math.Max(0, len(temp)-30):]
|
temp = temp[math.Max(0, len(temp)-30):]
|
||||||
//将已经娶过的人剔除
|
// 将已经娶过的人剔除
|
||||||
var qqgrouplist = []int64{}
|
qqgrouplist := make([]int64, 0, len(temp))
|
||||||
if len(qqwifegroup) == 0 {
|
if len(qqwifegroup) == 0 {
|
||||||
for k := 0; k < len(temp); k++ {
|
for k := 0; k < len(temp); k++ {
|
||||||
qqgrouplist = append(qqgrouplist, temp[k].Get("user_id").Int())
|
qqgrouplist = append(qqgrouplist, temp[k].Get("user_id").Int())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for k := 0; k < len(temp); k++ {
|
for k := 0; k < len(temp); k++ {
|
||||||
_, ok := qqwifegroup[groupid][temp[k].Get("user_id").Int()]
|
_, ok := qqwifegroup[gid][temp[k].Get("user_id").Int()]
|
||||||
if !ok {
|
if !ok {
|
||||||
qqgrouplist = append(qqgrouplist, temp[k].Get("user_id").Int())
|
qqgrouplist = append(qqgrouplist, temp[k].Get("user_id").Int())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//没有人(只剩自己)的时候
|
// 没有人(只剩自己)的时候
|
||||||
if len(qqgrouplist) == 0 {
|
if len(qqgrouplist) == 0 {
|
||||||
ctx.SendChain(message.Text("噢,此时此刻你还是一只单身狗,等待下一次情缘吧"))
|
ctx.SendChain(message.Text("噢,此时此刻你还是一只单身狗,等待下一次情缘吧"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//随机抽娶
|
// 随机抽娶
|
||||||
who := qqgrouplist[rand.Intn(len(qqgrouplist))]
|
wife = qqgrouplist[rand.Intn(len(qqgrouplist))]
|
||||||
if who == uid { //如果是自己
|
if wife == uid { // 如果是自己
|
||||||
ctx.SendChain(message.Text("噢,此时此刻你还是一只单身狗,等待下一次情缘吧"))
|
ctx.SendChain(message.Text("噢,此时此刻你还是一只单身狗,等待下一次情缘吧"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
//绑定CP
|
// 绑定CP
|
||||||
setcp[uid] = who
|
if qqwifegroup[gid] == nil {
|
||||||
qqwifegroup[groupid] = setcp
|
qqwifegroup[gid] = make(map[int64]int64, 32)
|
||||||
//输出结果
|
}
|
||||||
|
qqwifegroup[gid][uid] = wife
|
||||||
|
// 输出结果
|
||||||
ctx.SendChain(
|
ctx.SendChain(
|
||||||
message.Text(status),
|
|
||||||
message.At(uid),
|
message.At(uid),
|
||||||
message.Text("今天你的群老婆是"),
|
message.Text("今天你的群老婆是"),
|
||||||
message.Image("http://q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(who, 10)+"&s=640"),
|
message.Image("http:// q4.qlogo.cn/g?b=qq&nk="+strconv.FormatInt(wife, 10)+"&s=640"),
|
||||||
message.Text(
|
message.Text(
|
||||||
"\n",
|
"\n",
|
||||||
"[", ctx.CardOrNickName(who), "]",
|
"[", ctx.CardOrNickName(wife), "]",
|
||||||
"(", strconv.FormatInt(who, 10), ")哒",
|
"(", wife, ")哒",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
//更新时间
|
// 更新时间
|
||||||
lastdate = time.Now()
|
lastdate = time.Now()
|
||||||
})
|
})
|
||||||
engine.OnFullMatch("群老婆列表", zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByUser).
|
engine.OnFullMatch("群老婆列表", zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByUser).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
var cplist = []string{"群老公←———→群老婆\n--------------------------"}
|
mu.Lock()
|
||||||
rock.Lock()
|
defer mu.Unlock()
|
||||||
defer rock.Unlock()
|
|
||||||
group, ok := qqwifegroup[ctx.Event.GroupID]
|
group, ok := qqwifegroup[ctx.Event.GroupID]
|
||||||
if !ok {
|
if !ok {
|
||||||
ctx.SendChain(message.Text("你群并没有任何的CP额"))
|
ctx.SendChain(message.Text("你群并没有任何的CP额"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for k, v := range group {
|
if len(group) == 0 {
|
||||||
if k != 0 {
|
ctx.SendChain(message.Text("你群并没有任何的CP额"))
|
||||||
husband := ctx.CardOrNickName(k)
|
return
|
||||||
wife := ctx.CardOrNickName(v)
|
}
|
||||||
cplist = append(cplist, husband+" & "+wife)
|
cplist := make([]string, 1, len(group)+1)
|
||||||
} else {
|
cplist[0] = "群老公←———→群老婆\n--------------------------"
|
||||||
ctx.SendChain(message.Text("你群并没有任何的CP额"))
|
for husband, wife := range group {
|
||||||
return
|
cplist = append(cplist, ctx.CardOrNickName(husband)+" & "+ctx.CardOrNickName(wife))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
ctx.SendChain(message.Text(strings.Join(cplist, "\n")))
|
ctx.SendChain(message.Text(strings.Join(cplist, "\n")))
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user