新插件event, 好友申请群聊邀请事件处理 (#403)

This commit is contained in:
Jiang-Red 2022-09-10 11:01:24 +08:00 committed by GitHub
parent fafe24f1e4
commit b834307178
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 522 additions and 354 deletions

View File

@ -556,6 +556,18 @@ print("run[CQ:image,file="+j["img"]+"]")
- [x] xxx疫情
</details>
<details>
<summary>好友申请及群聊邀请事件处理</summary>
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/event"`
- [x] [开启|关闭]自动同意[申请|邀请|主人]
- [x] [同意|拒绝][申请|邀请][flag]
- flag跟随事件一起发送, 默认同意主人的事件
</details>
<details>
<summary>渲染任意文字到图片</summary>

View File

@ -77,6 +77,7 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/drift_bottle" // 漂流瓶
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/emojimix" // 合成emoji
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/epidemic" // 城市疫情查询
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/event" // 好友申请群聊邀请事件处理
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/font" // 渲染任意文字到图片
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/fortune" // 运势
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/funny" // 笑话

155
plugin/event/event.go Normal file
View File

@ -0,0 +1,155 @@
// Package event 好友申请以及群聊邀请事件处理
package event
import (
"strconv"
"time"
ctrl "github.com/FloatTech/zbpctrl"
"github.com/FloatTech/zbputils/control"
base14 "github.com/fumiama/go-base16384"
"github.com/sirupsen/logrus"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
)
func init() {
engine := control.Register("event", &ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
Help: "好友申请以及群聊邀请事件处理,默认发送给主人列表第一位\n" +
" - [开启|关闭]自动同意[申请|邀请|主人]\n" +
" - [同意|拒绝][申请|邀请][flag]\n" +
"flag跟随事件一起发送, 默认同意主人的事件",
})
engine.On("request/group/invite").SetBlock(true).
Handle(func(ctx *zero.Ctx) {
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
if ok {
su := zero.BotConfig.SuperUsers[0]
now := time.Unix(ctx.Event.Time, 0).Format("2006-01-02 15:04:05")
flag := ctx.Event.Flag
es := base14.EncodeString(flag)
comment := ctx.Event.Comment
userid := ctx.Event.UserID
username := ctx.CardOrNickName(userid)
data := c.GetData(-su)
groupid := ctx.Event.GroupID
groupname := ctx.GetGroupInfo(groupid, true).Name
logrus.Info("[event]收到来自[", username, "](", userid, ")的群聊邀请,群:[", groupname, "](", groupid, ")")
if data&2 == 2 || data&1 != 1 && zero.SuperUserPermission(ctx) {
ctx.SetGroupAddRequest(flag, "invite", true, "")
ctx.SendPrivateForwardMessage(su, message.Message{message.CustomNode(username, userid,
"已自动同意在"+now+"收到来自"+
"\n用户:["+username+"]("+strconv.FormatInt(userid, 10)+")的群聊邀请"+
"\n群聊:["+groupname+"]("+strconv.FormatInt(groupid, 10)+")"+
"\n验证信息:\n"+comment+
"\nflag:"+es)})
return
}
ctx.SendPrivateForwardMessage(su,
message.Message{message.CustomNode(username, userid,
"在"+now+"收到来自"+
"\n用户:["+username+"]("+strconv.FormatInt(userid, 10)+")的群聊邀请"+
"\n群聊:["+groupname+"]("+strconv.FormatInt(groupid, 10)+")"+
"\n验证信息:\n"+comment+
"\n请在下方复制flag并在前面加上:"+
"\n同意/拒绝邀请,来决定同意还是拒绝"),
message.CustomNode(username, userid, es)})
}
})
engine.On("request/friend").SetBlock(true).
Handle(func(ctx *zero.Ctx) {
c, ok := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
if ok {
su := zero.BotConfig.SuperUsers[0]
now := time.Unix(ctx.Event.Time, 0).Format("2006-01-02 15:04:05")
flag := ctx.Event.Flag
es := base14.EncodeString(flag)
comment := ctx.Event.Comment
userid := ctx.Event.UserID
username := ctx.CardOrNickName(userid)
data := c.GetData(-su)
logrus.Info("[event]收到来自[", username, "](", userid, ")的好友申请")
if data&4 == 4 || data&1 != 1 && zero.SuperUserPermission(ctx) {
ctx.SetFriendAddRequest(flag, true, "")
ctx.SendPrivateForwardMessage(su, message.Message{message.CustomNode(username, userid,
"已自动同意在"+now+"收到来自"+
"\n用户:["+username+"]("+strconv.FormatInt(userid, 10)+")"+
"\n的好友请求:"+comment+
"\nflag:"+es)})
return
}
ctx.SendPrivateForwardMessage(su,
message.Message{message.CustomNode(username, userid,
"在"+now+"收到来自"+
"\n用户:["+username+"]("+strconv.FormatInt(userid, 10)+")"+
"\n的好友请求:"+comment+
"\n请在下方复制flag并在前面加上:"+
"\n同意/拒绝申请,来决定同意还是拒绝"),
message.CustomNode(username, userid, es)})
}
})
engine.OnRegex(`^(同意|拒绝)(申请|邀请)\s*([一-踀]+[㴁-㴆]?)\s*(.*)$`, zero.SuperUserPermission, zero.OnlyPrivate).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
su := zero.BotConfig.SuperUsers[0]
cmd := ctx.State["regex_matched"].([]string)[1]
org := ctx.State["regex_matched"].([]string)[2]
flag := ctx.State["regex_matched"].([]string)[3]
other := ctx.State["regex_matched"].([]string)[4]
es := base14.DecodeString(flag)
switch cmd {
case "同意":
switch org {
case "申请":
ctx.SetFriendAddRequest(es, true, other)
ctx.SendPrivateMessage(su, message.Text("已", cmd, org))
case "邀请":
ctx.SetGroupAddRequest(es, "invite", true, "")
ctx.SendPrivateMessage(su, message.Text("已", cmd, org))
}
case "拒绝":
switch org {
case "申请":
ctx.SetFriendAddRequest(es, false, "")
ctx.SendPrivateMessage(su, message.Text("已", cmd, org))
case "邀请":
ctx.SetGroupAddRequest(es, "invite", false, other)
ctx.SendPrivateMessage(su, message.Text("已", cmd, org))
}
}
})
engine.OnRegex(`^(开启|关闭)自动同意(申请|邀请|主人)$`, zero.SuperUserPermission, zero.OnlyPrivate).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
c := ctx.State["manager"].(*ctrl.Control[*zero.Ctx])
su := zero.BotConfig.SuperUsers[0]
option := ctx.State["regex_matched"].([]string)[1]
from := ctx.State["regex_matched"].([]string)[2]
data := c.GetData(-su)
switch option {
case "开启":
switch from {
case "申请":
data |= 4
case "邀请":
data |= 2
case "主人":
data &= 7
}
case "关闭":
switch from {
case "申请":
data &= 3
case "邀请":
data &= 5
case "主人":
data |= 1
}
}
err := c.SetData(-su, data)
if err != nil {
ctx.SendChain(message.Text("ERROR:", err))
return
}
ctx.SendChain(message.Text("已设置自动同意" + from + "为" + option))
})
}

View File

@ -21,7 +21,7 @@ import (
const bed = "https://gitcode.net/u011570312/OguraHyakuninIsshu/-/raw/master/"
// nolint: asciicheck
//nolint: asciicheck
type line struct {
番号, 歌人, 上の句, 下の句, 上の句ひらがな, 下の句ひらがな string
}

View File

@ -14,7 +14,7 @@ import (
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/message"
//反并发
// 反并发
"github.com/wdvxdr1123/ZeroBot/extension/single"
// 数据库
sql "github.com/FloatTech/sqlite"
@ -28,8 +28,8 @@ import (
"github.com/FloatTech/zbputils/img/text"
)
//nolint: asciicheck
// nolint: asciicheck
//nolint: asciicheck
var (
民政局 = &婚姻登记{
db: &sql.Sqlite{},

View File

@ -1,351 +1,351 @@
package qqwife
import (
"strconv"
"sync"
"time"
sql "github.com/FloatTech/sqlite"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
// 画图
"github.com/Coloured-glaze/gg"
)
//nolint: asciicheck
// nolint: asciicheck
type 婚姻登记 struct {
db *sql.Sqlite
dbmu sync.RWMutex
}
// 结婚证信息
type userinfo struct {
User int64 // 用户身份证
Target int64 // 对象身份证号
Username string // 户主名称
Targetname string // 对象名称
Updatetime string // 登记时间
}
// 民政局的当前时间
type updateinfo struct {
GID int64
Updatetime string // 登记时间
}
func (sql *婚姻登记) 开门时间(gid int64) (ok bool, err error) {
sql.dbmu.Lock()
defer sql.dbmu.Unlock()
ok = false
err = sql.db.Create("updateinfo", &updateinfo{})
if err != nil {
return
}
gidstr := strconv.FormatInt(gid, 10)
dbinfo := updateinfo{}
// 获取表格更新的时间
err = sql.db.Find("updateinfo", &dbinfo, "where gid is "+gidstr)
if err != nil {
// 如果没有登记过就记录
err = sql.db.Insert("updateinfo", &updateinfo{
GID: gid,
Updatetime: time.Now().Format("2006/01/02"),
})
if err == nil {
ok = true
}
return
}
// 开门了就拿新的花名册
if time.Now().Format("2006/01/02") == dbinfo.Updatetime {
return
}
err = sql.db.Drop(gidstr)
if err != nil {
return
}
updateinfo := updateinfo{
GID: gid,
Updatetime: time.Now().Format("2006/01/02"),
}
err = sql.db.Insert("updateinfo", &updateinfo)
if err == nil {
ok = true
}
return
}
func (sql *婚姻登记) 清理花名册(gid string) error {
sql.dbmu.Lock()
defer sql.dbmu.Unlock()
grouplist, err := sql.db.ListTables()
if err != nil {
return err
}
if gid != "0" {
grouplist = []string{gid}
}
for _, gid := range grouplist {
err = sql.db.Drop(gid)
if err != nil {
continue
}
gidint, _ := strconv.ParseInt(gid, 10, 64)
updateinfo := updateinfo{
GID: gidint,
Updatetime: time.Now().Format("2006/01/02"),
}
err = sql.db.Insert("updateinfo", &updateinfo)
}
return err
}
func (sql *婚姻登记) 查户口(gid, uid int64) (info userinfo, status string, err error) {
sql.dbmu.Lock()
defer sql.dbmu.Unlock()
gidstr := strconv.FormatInt(gid, 10)
uidstr := strconv.FormatInt(uid, 10)
status = "单"
err = sql.db.Create(gidstr, &userinfo{})
if err != nil {
status = "错"
return
}
err = sql.db.Find(gidstr, &info, "where user = "+uidstr)
if err == nil {
status = "攻"
return
}
err = sql.db.Find(gidstr, &info, "where target = "+uidstr)
if err == nil {
status = "受"
}
return
}
func (sql *婚姻登记) 登记(gid, uid, target int64, username, targetname string) error {
sql.dbmu.Lock()
defer sql.dbmu.Unlock()
gidstr := strconv.FormatInt(gid, 10)
err := sql.db.Create(gidstr, &userinfo{})
if err != nil {
return err
}
updatetime := time.Now().Format("2006/01/02")
// 填写夫妻信息
uidinfo := userinfo{
User: uid,
Username: username,
Target: target,
Targetname: targetname,
Updatetime: updatetime,
}
// 民政局登记数据
err = sql.db.Insert(gidstr, &uidinfo)
return err
}
func (sql *婚姻登记) 离婚休妻(gid, wife int64) error {
sql.dbmu.Lock()
defer sql.dbmu.Unlock()
gidstr := strconv.FormatInt(gid, 10)
wifestr := strconv.FormatInt(wife, 10)
return sql.db.Del(gidstr, "where target = "+wifestr)
}
func (sql *婚姻登记) 离婚休夫(gid, husband int64) error {
sql.dbmu.Lock()
defer sql.dbmu.Unlock()
gidstr := strconv.FormatInt(gid, 10)
husbandstr := strconv.FormatInt(husband, 10)
return sql.db.Del(gidstr, "where user = "+husbandstr)
}
func (sql *婚姻登记) 花名册(gid int64) (list [][4]string, number int, err error) {
sql.dbmu.Lock()
defer sql.dbmu.Unlock()
gidstr := strconv.FormatInt(gid, 10)
err = sql.db.Create(gidstr, &userinfo{})
if err != nil {
return
}
number, err = sql.db.Count(gidstr)
if err != nil || number <= 0 {
return
}
var info userinfo
list = make([][4]string, 0, number)
err = sql.db.FindFor(gidstr, &info, "GROUP BY user", func() error {
if info.Target == 0 {
return nil
}
dbinfo := [4]string{
info.Username,
strconv.FormatInt(info.User, 10),
info.Targetname,
strconv.FormatInt(info.Target, 10),
}
list = append(list, dbinfo)
return nil
})
if len(list) == 0 {
number = 0
}
return
}
func slicename(name string, canvas *gg.Context) (resultname string) {
usermane := []rune(name) // 将每个字符单独放置
widthlen := 0
numberlen := 0
for i, v := range usermane {
width, _ := canvas.MeasureString(string(v)) // 获取单个字符的宽度
widthlen += int(width)
if widthlen > 350 {
break // 总宽度不能超过350
}
numberlen = i
}
if widthlen > 350 {
resultname = string(usermane[:numberlen-1]) + "......" // 名字切片
} else {
resultname = name
}
return
}
// 以群号和昵称为限制
func cdcheck(ctx *zero.Ctx) *rate.Limiter {
limitID := strconv.FormatInt(ctx.Event.GroupID, 10) + strconv.FormatInt(ctx.Event.UserID, 10) + "1"
return skillCD.Load(limitID)
}
func cdcheck2(ctx *zero.Ctx) *rate.Limiter {
limitID := strconv.FormatInt(ctx.Event.GroupID, 10) + strconv.FormatInt(ctx.Event.UserID, 10) + "2"
return skillCD.Load(limitID)
}
func cdcheck3(ctx *zero.Ctx) *rate.Limiter {
limitID := strconv.FormatInt(ctx.Event.GroupID, 10) + strconv.FormatInt(ctx.Event.UserID, 10) + "3"
return skillCD.Load(limitID)
}
func iscding(ctx *zero.Ctx) {
ctx.SendChain(message.Text("你的技能现在正在CD中"))
}
func iscding2(ctx *zero.Ctx) {
ctx.SendChain(message.Text("打灭,禁止离婚 (你的技能正在CD中)"))
}
// 注入判断 是否为单身
func checkdog(ctx *zero.Ctx) bool {
// 得先判断用户是否存在才行在,再重置
fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
if err != nil {
ctx.SendChain(message.Text("额你的target好像不存在"))
return false
}
// 判断是否需要重置
gid := ctx.Event.GroupID
ok, err := 民政局.开门时间(gid)
if err != nil {
ctx.SendChain(message.Text("群状态查询失败\n[error]", err))
return false
}
if ok {
return true // 重置后也全是单身
}
// 获取用户信息
uid := ctx.Event.UserID
uidtarget, uidstatus, err := 民政局.查户口(gid, uid)
switch {
case uidstatus == "错":
ctx.SendChain(message.Text("用户状态查询失败\n[error]", err))
return false
case uidstatus != "单" && (uidtarget.Target == 0 || uidtarget.User == 0): // 如果是单身贵族
ctx.SendChain(message.Text("今天的你是单身贵族噢"))
return false
case (uidstatus == "攻" && uidtarget.Target == fiancee) ||
(uidstatus == "受" && uidtarget.User == fiancee):
ctx.SendChain(message.Text("笨蛋!你们已经在一起了!"))
return false
case uidstatus == "攻": // 如果如为攻
ctx.SendChain(message.Text("笨蛋~你家里还有个吃白饭的w"))
return false
case uidstatus == "受": // 如果为受
ctx.SendChain(message.Text("该是0就是0当0有什么不好"))
return false
}
fianceeinfo, fianceestatus, err := 民政局.查户口(gid, fiancee)
switch {
case fianceestatus == "错":
ctx.SendChain(message.Text("对象状态查询失败\n[error]", err))
case fianceestatus == "单": // 如果为单身狗
return true
case fianceestatus != "单" && (fianceeinfo.Target == 0 || fianceeinfo.User == 0): // 如果是单身贵族
ctx.SendChain(message.Text("今天的ta是单身贵族噢"))
case fianceestatus == "攻": // 如果如为攻
ctx.SendChain(message.Text("他有别的女人了,你该放下了"))
case fianceestatus == "受": // 如果为受
ctx.SendChain(message.Text("ta被别人娶了你来晚力"))
}
return false
}
// 注入判断 是否满足小三要求
func checkcp(ctx *zero.Ctx) bool {
// 得先判断用户是否存在才行在,再重置
fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
if err != nil {
ctx.SendChain(message.Text("额你的target好像不存在"))
return false
}
// 判断是否需要重置
gid := ctx.Event.GroupID
ok, err := 民政局.开门时间(gid)
if err != nil {
ctx.SendChain(message.Text("群状态查询失败\n[error]", err))
return false
}
if ok {
ctx.SendChain(message.Text("ta现在还是单身哦快向ta表白吧"))
return false // 重置后也全是单身
}
uid := ctx.Event.UserID
fianceeinfo, fianceestatus, err := 民政局.查户口(gid, fiancee)
switch {
case fianceestatus == "错":
ctx.SendChain(message.Text("对象状态查询失败\n[error]", err))
return false
case fianceestatus == "单": // 如果为单身狗
if fiancee == uid {
return true
}
ctx.SendChain(message.Text("ta现在还是单身哦快向ta表白吧"))
return false
case fianceestatus != "单" && (fianceeinfo.Target == 0 || fianceeinfo.User == 0): // 如果是单身贵族
ctx.SendChain(message.Text("今天的ta是单身贵族噢"))
return false
case (fianceestatus == "攻" && fianceeinfo.Target == fiancee) ||
(fianceestatus == "受" && fianceeinfo.User == fiancee):
ctx.SendChain(message.Text("笨蛋!你们已经在一起了!"))
return false
}
// 获取用户信息
uidtarget, uidstatus, err := 民政局.查户口(gid, uid)
switch {
case uidstatus == "错":
ctx.SendChain(message.Text("用户状态查询失败\n[error]", err))
case uidstatus == "单": // 如果为单身狗
return true
case uidstatus != "单" && (uidtarget.Target == 0 || uidtarget.User == 0): // 如果是单身贵族
ctx.SendChain(message.Text("今天的你是单身贵族噢"))
case uidstatus == "攻": // 如果如为攻
ctx.SendChain(message.Text("打灭,不给纳小妾!"))
case uidstatus == "受": // 如果为受
ctx.SendChain(message.Text("该是0就是0当0有什么不好"))
}
return false
}
package qqwife
import (
"strconv"
"sync"
"time"
sql "github.com/FloatTech/sqlite"
zero "github.com/wdvxdr1123/ZeroBot"
"github.com/wdvxdr1123/ZeroBot/extension/rate"
"github.com/wdvxdr1123/ZeroBot/message"
// 画图
"github.com/Coloured-glaze/gg"
)
//nolint: asciicheck
// nolint: asciicheck
type 婚姻登记 struct {
db *sql.Sqlite
dbmu sync.RWMutex
}
// 结婚证信息
type userinfo struct {
User int64 // 用户身份证
Target int64 // 对象身份证号
Username string // 户主名称
Targetname string // 对象名称
Updatetime string // 登记时间
}
// 民政局的当前时间
type updateinfo struct {
GID int64
Updatetime string // 登记时间
}
func (sql *婚姻登记) 开门时间(gid int64) (ok bool, err error) {
sql.dbmu.Lock()
defer sql.dbmu.Unlock()
ok = false
err = sql.db.Create("updateinfo", &updateinfo{})
if err != nil {
return
}
gidstr := strconv.FormatInt(gid, 10)
dbinfo := updateinfo{}
// 获取表格更新的时间
err = sql.db.Find("updateinfo", &dbinfo, "where gid is "+gidstr)
if err != nil {
// 如果没有登记过就记录
err = sql.db.Insert("updateinfo", &updateinfo{
GID: gid,
Updatetime: time.Now().Format("2006/01/02"),
})
if err == nil {
ok = true
}
return
}
// 开门了就拿新的花名册
if time.Now().Format("2006/01/02") == dbinfo.Updatetime {
return
}
err = sql.db.Drop(gidstr)
if err != nil {
return
}
updateinfo := updateinfo{
GID: gid,
Updatetime: time.Now().Format("2006/01/02"),
}
err = sql.db.Insert("updateinfo", &updateinfo)
if err == nil {
ok = true
}
return
}
func (sql *婚姻登记) 清理花名册(gid string) error {
sql.dbmu.Lock()
defer sql.dbmu.Unlock()
grouplist, err := sql.db.ListTables()
if err != nil {
return err
}
if gid != "0" {
grouplist = []string{gid}
}
for _, gid := range grouplist {
err = sql.db.Drop(gid)
if err != nil {
continue
}
gidint, _ := strconv.ParseInt(gid, 10, 64)
updateinfo := updateinfo{
GID: gidint,
Updatetime: time.Now().Format("2006/01/02"),
}
err = sql.db.Insert("updateinfo", &updateinfo)
}
return err
}
func (sql *婚姻登记) 查户口(gid, uid int64) (info userinfo, status string, err error) {
sql.dbmu.Lock()
defer sql.dbmu.Unlock()
gidstr := strconv.FormatInt(gid, 10)
uidstr := strconv.FormatInt(uid, 10)
status = "单"
err = sql.db.Create(gidstr, &userinfo{})
if err != nil {
status = "错"
return
}
err = sql.db.Find(gidstr, &info, "where user = "+uidstr)
if err == nil {
status = "攻"
return
}
err = sql.db.Find(gidstr, &info, "where target = "+uidstr)
if err == nil {
status = "受"
}
return
}
func (sql *婚姻登记) 登记(gid, uid, target int64, username, targetname string) error {
sql.dbmu.Lock()
defer sql.dbmu.Unlock()
gidstr := strconv.FormatInt(gid, 10)
err := sql.db.Create(gidstr, &userinfo{})
if err != nil {
return err
}
updatetime := time.Now().Format("2006/01/02")
// 填写夫妻信息
uidinfo := userinfo{
User: uid,
Username: username,
Target: target,
Targetname: targetname,
Updatetime: updatetime,
}
// 民政局登记数据
err = sql.db.Insert(gidstr, &uidinfo)
return err
}
func (sql *婚姻登记) 离婚休妻(gid, wife int64) error {
sql.dbmu.Lock()
defer sql.dbmu.Unlock()
gidstr := strconv.FormatInt(gid, 10)
wifestr := strconv.FormatInt(wife, 10)
return sql.db.Del(gidstr, "where target = "+wifestr)
}
func (sql *婚姻登记) 离婚休夫(gid, husband int64) error {
sql.dbmu.Lock()
defer sql.dbmu.Unlock()
gidstr := strconv.FormatInt(gid, 10)
husbandstr := strconv.FormatInt(husband, 10)
return sql.db.Del(gidstr, "where user = "+husbandstr)
}
func (sql *婚姻登记) 花名册(gid int64) (list [][4]string, number int, err error) {
sql.dbmu.Lock()
defer sql.dbmu.Unlock()
gidstr := strconv.FormatInt(gid, 10)
err = sql.db.Create(gidstr, &userinfo{})
if err != nil {
return
}
number, err = sql.db.Count(gidstr)
if err != nil || number <= 0 {
return
}
var info userinfo
list = make([][4]string, 0, number)
err = sql.db.FindFor(gidstr, &info, "GROUP BY user", func() error {
if info.Target == 0 {
return nil
}
dbinfo := [4]string{
info.Username,
strconv.FormatInt(info.User, 10),
info.Targetname,
strconv.FormatInt(info.Target, 10),
}
list = append(list, dbinfo)
return nil
})
if len(list) == 0 {
number = 0
}
return
}
func slicename(name string, canvas *gg.Context) (resultname string) {
usermane := []rune(name) // 将每个字符单独放置
widthlen := 0
numberlen := 0
for i, v := range usermane {
width, _ := canvas.MeasureString(string(v)) // 获取单个字符的宽度
widthlen += int(width)
if widthlen > 350 {
break // 总宽度不能超过350
}
numberlen = i
}
if widthlen > 350 {
resultname = string(usermane[:numberlen-1]) + "......" // 名字切片
} else {
resultname = name
}
return
}
// 以群号和昵称为限制
func cdcheck(ctx *zero.Ctx) *rate.Limiter {
limitID := strconv.FormatInt(ctx.Event.GroupID, 10) + strconv.FormatInt(ctx.Event.UserID, 10) + "1"
return skillCD.Load(limitID)
}
func cdcheck2(ctx *zero.Ctx) *rate.Limiter {
limitID := strconv.FormatInt(ctx.Event.GroupID, 10) + strconv.FormatInt(ctx.Event.UserID, 10) + "2"
return skillCD.Load(limitID)
}
func cdcheck3(ctx *zero.Ctx) *rate.Limiter {
limitID := strconv.FormatInt(ctx.Event.GroupID, 10) + strconv.FormatInt(ctx.Event.UserID, 10) + "3"
return skillCD.Load(limitID)
}
func iscding(ctx *zero.Ctx) {
ctx.SendChain(message.Text("你的技能现在正在CD中"))
}
func iscding2(ctx *zero.Ctx) {
ctx.SendChain(message.Text("打灭,禁止离婚 (你的技能正在CD中)"))
}
// 注入判断 是否为单身
func checkdog(ctx *zero.Ctx) bool {
// 得先判断用户是否存在才行在,再重置
fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
if err != nil {
ctx.SendChain(message.Text("额你的target好像不存在"))
return false
}
// 判断是否需要重置
gid := ctx.Event.GroupID
ok, err := 民政局.开门时间(gid)
if err != nil {
ctx.SendChain(message.Text("群状态查询失败\n[error]", err))
return false
}
if ok {
return true // 重置后也全是单身
}
// 获取用户信息
uid := ctx.Event.UserID
uidtarget, uidstatus, err := 民政局.查户口(gid, uid)
switch {
case uidstatus == "错":
ctx.SendChain(message.Text("用户状态查询失败\n[error]", err))
return false
case uidstatus != "单" && (uidtarget.Target == 0 || uidtarget.User == 0): // 如果是单身贵族
ctx.SendChain(message.Text("今天的你是单身贵族噢"))
return false
case (uidstatus == "攻" && uidtarget.Target == fiancee) ||
(uidstatus == "受" && uidtarget.User == fiancee):
ctx.SendChain(message.Text("笨蛋!你们已经在一起了!"))
return false
case uidstatus == "攻": // 如果如为攻
ctx.SendChain(message.Text("笨蛋~你家里还有个吃白饭的w"))
return false
case uidstatus == "受": // 如果为受
ctx.SendChain(message.Text("该是0就是0当0有什么不好"))
return false
}
fianceeinfo, fianceestatus, err := 民政局.查户口(gid, fiancee)
switch {
case fianceestatus == "错":
ctx.SendChain(message.Text("对象状态查询失败\n[error]", err))
case fianceestatus == "单": // 如果为单身狗
return true
case fianceestatus != "单" && (fianceeinfo.Target == 0 || fianceeinfo.User == 0): // 如果是单身贵族
ctx.SendChain(message.Text("今天的ta是单身贵族噢"))
case fianceestatus == "攻": // 如果如为攻
ctx.SendChain(message.Text("他有别的女人了,你该放下了"))
case fianceestatus == "受": // 如果为受
ctx.SendChain(message.Text("ta被别人娶了你来晚力"))
}
return false
}
// 注入判断 是否满足小三要求
func checkcp(ctx *zero.Ctx) bool {
// 得先判断用户是否存在才行在,再重置
fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
if err != nil {
ctx.SendChain(message.Text("额你的target好像不存在"))
return false
}
// 判断是否需要重置
gid := ctx.Event.GroupID
ok, err := 民政局.开门时间(gid)
if err != nil {
ctx.SendChain(message.Text("群状态查询失败\n[error]", err))
return false
}
if ok {
ctx.SendChain(message.Text("ta现在还是单身哦快向ta表白吧"))
return false // 重置后也全是单身
}
uid := ctx.Event.UserID
fianceeinfo, fianceestatus, err := 民政局.查户口(gid, fiancee)
switch {
case fianceestatus == "错":
ctx.SendChain(message.Text("对象状态查询失败\n[error]", err))
return false
case fianceestatus == "单": // 如果为单身狗
if fiancee == uid {
return true
}
ctx.SendChain(message.Text("ta现在还是单身哦快向ta表白吧"))
return false
case fianceestatus != "单" && (fianceeinfo.Target == 0 || fianceeinfo.User == 0): // 如果是单身贵族
ctx.SendChain(message.Text("今天的ta是单身贵族噢"))
return false
case (fianceestatus == "攻" && fianceeinfo.Target == fiancee) ||
(fianceestatus == "受" && fianceeinfo.User == fiancee):
ctx.SendChain(message.Text("笨蛋!你们已经在一起了!"))
return false
}
// 获取用户信息
uidtarget, uidstatus, err := 民政局.查户口(gid, uid)
switch {
case uidstatus == "错":
ctx.SendChain(message.Text("用户状态查询失败\n[error]", err))
case uidstatus == "单": // 如果为单身狗
return true
case uidstatus != "单" && (uidtarget.Target == 0 || uidtarget.User == 0): // 如果是单身贵族
ctx.SendChain(message.Text("今天的你是单身贵族噢"))
case uidstatus == "攻": // 如果如为攻
ctx.SendChain(message.Text("打灭,不给纳小妾!"))
case uidstatus == "受": // 如果为受
ctx.SendChain(message.Text("该是0就是0当0有什么不好"))
}
return false
}