mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
新插件event, 好友申请群聊邀请事件处理 (#403)
This commit is contained in:
parent
fafe24f1e4
commit
b834307178
12
README.md
12
README.md
@ -556,6 +556,18 @@ print("run[CQ:image,file="+j["img"]+"]")
|
|||||||
|
|
||||||
- [x] xxx疫情
|
- [x] xxx疫情
|
||||||
|
|
||||||
|
</details>
|
||||||
|
<details>
|
||||||
|
<summary>好友申请及群聊邀请事件处理</summary>
|
||||||
|
|
||||||
|
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/event"`
|
||||||
|
|
||||||
|
- [x] [开启|关闭]自动同意[申请|邀请|主人]
|
||||||
|
|
||||||
|
- [x] [同意|拒绝][申请|邀请][flag]
|
||||||
|
|
||||||
|
- flag跟随事件一起发送, 默认同意主人的事件
|
||||||
|
|
||||||
</details>
|
</details>
|
||||||
<details>
|
<details>
|
||||||
<summary>渲染任意文字到图片</summary>
|
<summary>渲染任意文字到图片</summary>
|
||||||
|
|||||||
1
main.go
1
main.go
@ -77,6 +77,7 @@ import (
|
|||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/drift_bottle" // 漂流瓶
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/drift_bottle" // 漂流瓶
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/emojimix" // 合成emoji
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/emojimix" // 合成emoji
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/epidemic" // 城市疫情查询
|
_ "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/font" // 渲染任意文字到图片
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/fortune" // 运势
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/fortune" // 运势
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/funny" // 笑话
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/funny" // 笑话
|
||||||
|
|||||||
155
plugin/event/event.go
Normal file
155
plugin/event/event.go
Normal 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))
|
||||||
|
})
|
||||||
|
}
|
||||||
@ -21,7 +21,7 @@ import (
|
|||||||
|
|
||||||
const bed = "https://gitcode.net/u011570312/OguraHyakuninIsshu/-/raw/master/"
|
const bed = "https://gitcode.net/u011570312/OguraHyakuninIsshu/-/raw/master/"
|
||||||
|
|
||||||
// nolint: asciicheck
|
//nolint: asciicheck
|
||||||
type line struct {
|
type line struct {
|
||||||
番号, 歌人, 上の句, 下の句, 上の句ひらがな, 下の句ひらがな string
|
番号, 歌人, 上の句, 下の句, 上の句ひらがな, 下の句ひらがな string
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import (
|
|||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
//反并发
|
// 反并发
|
||||||
"github.com/wdvxdr1123/ZeroBot/extension/single"
|
"github.com/wdvxdr1123/ZeroBot/extension/single"
|
||||||
// 数据库
|
// 数据库
|
||||||
sql "github.com/FloatTech/sqlite"
|
sql "github.com/FloatTech/sqlite"
|
||||||
@ -28,8 +28,8 @@ import (
|
|||||||
"github.com/FloatTech/zbputils/img/text"
|
"github.com/FloatTech/zbputils/img/text"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint: asciicheck
|
|
||||||
// nolint: asciicheck
|
// nolint: asciicheck
|
||||||
|
//nolint: asciicheck
|
||||||
var (
|
var (
|
||||||
民政局 = &婚姻登记{
|
民政局 = &婚姻登记{
|
||||||
db: &sql.Sqlite{},
|
db: &sql.Sqlite{},
|
||||||
|
|||||||
@ -1,351 +1,351 @@
|
|||||||
package qqwife
|
package qqwife
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
sql "github.com/FloatTech/sqlite"
|
sql "github.com/FloatTech/sqlite"
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
|
||||||
// 画图
|
// 画图
|
||||||
"github.com/Coloured-glaze/gg"
|
"github.com/Coloured-glaze/gg"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint: asciicheck
|
//nolint: asciicheck
|
||||||
// nolint: asciicheck
|
// nolint: asciicheck
|
||||||
type 婚姻登记 struct {
|
type 婚姻登记 struct {
|
||||||
db *sql.Sqlite
|
db *sql.Sqlite
|
||||||
dbmu sync.RWMutex
|
dbmu sync.RWMutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// 结婚证信息
|
// 结婚证信息
|
||||||
type userinfo struct {
|
type userinfo struct {
|
||||||
User int64 // 用户身份证
|
User int64 // 用户身份证
|
||||||
Target int64 // 对象身份证号
|
Target int64 // 对象身份证号
|
||||||
Username string // 户主名称
|
Username string // 户主名称
|
||||||
Targetname string // 对象名称
|
Targetname string // 对象名称
|
||||||
Updatetime string // 登记时间
|
Updatetime string // 登记时间
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 民政局的当前时间
|
// 民政局的当前时间
|
||||||
type updateinfo struct {
|
type updateinfo struct {
|
||||||
GID int64
|
GID int64
|
||||||
Updatetime string // 登记时间
|
Updatetime string // 登记时间
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sql *婚姻登记) 开门时间(gid int64) (ok bool, err error) {
|
func (sql *婚姻登记) 开门时间(gid int64) (ok bool, err error) {
|
||||||
sql.dbmu.Lock()
|
sql.dbmu.Lock()
|
||||||
defer sql.dbmu.Unlock()
|
defer sql.dbmu.Unlock()
|
||||||
ok = false
|
ok = false
|
||||||
err = sql.db.Create("updateinfo", &updateinfo{})
|
err = sql.db.Create("updateinfo", &updateinfo{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
gidstr := strconv.FormatInt(gid, 10)
|
gidstr := strconv.FormatInt(gid, 10)
|
||||||
dbinfo := updateinfo{}
|
dbinfo := updateinfo{}
|
||||||
// 获取表格更新的时间
|
// 获取表格更新的时间
|
||||||
err = sql.db.Find("updateinfo", &dbinfo, "where gid is "+gidstr)
|
err = sql.db.Find("updateinfo", &dbinfo, "where gid is "+gidstr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 如果没有登记过就记录
|
// 如果没有登记过就记录
|
||||||
err = sql.db.Insert("updateinfo", &updateinfo{
|
err = sql.db.Insert("updateinfo", &updateinfo{
|
||||||
GID: gid,
|
GID: gid,
|
||||||
Updatetime: time.Now().Format("2006/01/02"),
|
Updatetime: time.Now().Format("2006/01/02"),
|
||||||
})
|
})
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 开门了就拿新的花名册
|
// 开门了就拿新的花名册
|
||||||
if time.Now().Format("2006/01/02") == dbinfo.Updatetime {
|
if time.Now().Format("2006/01/02") == dbinfo.Updatetime {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = sql.db.Drop(gidstr)
|
err = sql.db.Drop(gidstr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
updateinfo := updateinfo{
|
updateinfo := updateinfo{
|
||||||
GID: gid,
|
GID: gid,
|
||||||
Updatetime: time.Now().Format("2006/01/02"),
|
Updatetime: time.Now().Format("2006/01/02"),
|
||||||
}
|
}
|
||||||
err = sql.db.Insert("updateinfo", &updateinfo)
|
err = sql.db.Insert("updateinfo", &updateinfo)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
ok = true
|
ok = true
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sql *婚姻登记) 清理花名册(gid string) error {
|
func (sql *婚姻登记) 清理花名册(gid string) error {
|
||||||
sql.dbmu.Lock()
|
sql.dbmu.Lock()
|
||||||
defer sql.dbmu.Unlock()
|
defer sql.dbmu.Unlock()
|
||||||
grouplist, err := sql.db.ListTables()
|
grouplist, err := sql.db.ListTables()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if gid != "0" {
|
if gid != "0" {
|
||||||
grouplist = []string{gid}
|
grouplist = []string{gid}
|
||||||
}
|
}
|
||||||
for _, gid := range grouplist {
|
for _, gid := range grouplist {
|
||||||
err = sql.db.Drop(gid)
|
err = sql.db.Drop(gid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
gidint, _ := strconv.ParseInt(gid, 10, 64)
|
gidint, _ := strconv.ParseInt(gid, 10, 64)
|
||||||
updateinfo := updateinfo{
|
updateinfo := updateinfo{
|
||||||
GID: gidint,
|
GID: gidint,
|
||||||
Updatetime: time.Now().Format("2006/01/02"),
|
Updatetime: time.Now().Format("2006/01/02"),
|
||||||
}
|
}
|
||||||
err = sql.db.Insert("updateinfo", &updateinfo)
|
err = sql.db.Insert("updateinfo", &updateinfo)
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sql *婚姻登记) 查户口(gid, uid int64) (info userinfo, status string, err error) {
|
func (sql *婚姻登记) 查户口(gid, uid int64) (info userinfo, status string, err error) {
|
||||||
sql.dbmu.Lock()
|
sql.dbmu.Lock()
|
||||||
defer sql.dbmu.Unlock()
|
defer sql.dbmu.Unlock()
|
||||||
gidstr := strconv.FormatInt(gid, 10)
|
gidstr := strconv.FormatInt(gid, 10)
|
||||||
uidstr := strconv.FormatInt(uid, 10)
|
uidstr := strconv.FormatInt(uid, 10)
|
||||||
status = "单"
|
status = "单"
|
||||||
err = sql.db.Create(gidstr, &userinfo{})
|
err = sql.db.Create(gidstr, &userinfo{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
status = "错"
|
status = "错"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = sql.db.Find(gidstr, &info, "where user = "+uidstr)
|
err = sql.db.Find(gidstr, &info, "where user = "+uidstr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
status = "攻"
|
status = "攻"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = sql.db.Find(gidstr, &info, "where target = "+uidstr)
|
err = sql.db.Find(gidstr, &info, "where target = "+uidstr)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
status = "受"
|
status = "受"
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sql *婚姻登记) 登记(gid, uid, target int64, username, targetname string) error {
|
func (sql *婚姻登记) 登记(gid, uid, target int64, username, targetname string) error {
|
||||||
sql.dbmu.Lock()
|
sql.dbmu.Lock()
|
||||||
defer sql.dbmu.Unlock()
|
defer sql.dbmu.Unlock()
|
||||||
gidstr := strconv.FormatInt(gid, 10)
|
gidstr := strconv.FormatInt(gid, 10)
|
||||||
err := sql.db.Create(gidstr, &userinfo{})
|
err := sql.db.Create(gidstr, &userinfo{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
updatetime := time.Now().Format("2006/01/02")
|
updatetime := time.Now().Format("2006/01/02")
|
||||||
// 填写夫妻信息
|
// 填写夫妻信息
|
||||||
uidinfo := userinfo{
|
uidinfo := userinfo{
|
||||||
User: uid,
|
User: uid,
|
||||||
Username: username,
|
Username: username,
|
||||||
Target: target,
|
Target: target,
|
||||||
Targetname: targetname,
|
Targetname: targetname,
|
||||||
Updatetime: updatetime,
|
Updatetime: updatetime,
|
||||||
}
|
}
|
||||||
// 民政局登记数据
|
// 民政局登记数据
|
||||||
err = sql.db.Insert(gidstr, &uidinfo)
|
err = sql.db.Insert(gidstr, &uidinfo)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sql *婚姻登记) 离婚休妻(gid, wife int64) error {
|
func (sql *婚姻登记) 离婚休妻(gid, wife int64) error {
|
||||||
sql.dbmu.Lock()
|
sql.dbmu.Lock()
|
||||||
defer sql.dbmu.Unlock()
|
defer sql.dbmu.Unlock()
|
||||||
gidstr := strconv.FormatInt(gid, 10)
|
gidstr := strconv.FormatInt(gid, 10)
|
||||||
wifestr := strconv.FormatInt(wife, 10)
|
wifestr := strconv.FormatInt(wife, 10)
|
||||||
return sql.db.Del(gidstr, "where target = "+wifestr)
|
return sql.db.Del(gidstr, "where target = "+wifestr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sql *婚姻登记) 离婚休夫(gid, husband int64) error {
|
func (sql *婚姻登记) 离婚休夫(gid, husband int64) error {
|
||||||
sql.dbmu.Lock()
|
sql.dbmu.Lock()
|
||||||
defer sql.dbmu.Unlock()
|
defer sql.dbmu.Unlock()
|
||||||
gidstr := strconv.FormatInt(gid, 10)
|
gidstr := strconv.FormatInt(gid, 10)
|
||||||
husbandstr := strconv.FormatInt(husband, 10)
|
husbandstr := strconv.FormatInt(husband, 10)
|
||||||
return sql.db.Del(gidstr, "where user = "+husbandstr)
|
return sql.db.Del(gidstr, "where user = "+husbandstr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sql *婚姻登记) 花名册(gid int64) (list [][4]string, number int, err error) {
|
func (sql *婚姻登记) 花名册(gid int64) (list [][4]string, number int, err error) {
|
||||||
sql.dbmu.Lock()
|
sql.dbmu.Lock()
|
||||||
defer sql.dbmu.Unlock()
|
defer sql.dbmu.Unlock()
|
||||||
gidstr := strconv.FormatInt(gid, 10)
|
gidstr := strconv.FormatInt(gid, 10)
|
||||||
err = sql.db.Create(gidstr, &userinfo{})
|
err = sql.db.Create(gidstr, &userinfo{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
number, err = sql.db.Count(gidstr)
|
number, err = sql.db.Count(gidstr)
|
||||||
if err != nil || number <= 0 {
|
if err != nil || number <= 0 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var info userinfo
|
var info userinfo
|
||||||
list = make([][4]string, 0, number)
|
list = make([][4]string, 0, number)
|
||||||
err = sql.db.FindFor(gidstr, &info, "GROUP BY user", func() error {
|
err = sql.db.FindFor(gidstr, &info, "GROUP BY user", func() error {
|
||||||
if info.Target == 0 {
|
if info.Target == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
dbinfo := [4]string{
|
dbinfo := [4]string{
|
||||||
info.Username,
|
info.Username,
|
||||||
strconv.FormatInt(info.User, 10),
|
strconv.FormatInt(info.User, 10),
|
||||||
info.Targetname,
|
info.Targetname,
|
||||||
strconv.FormatInt(info.Target, 10),
|
strconv.FormatInt(info.Target, 10),
|
||||||
}
|
}
|
||||||
list = append(list, dbinfo)
|
list = append(list, dbinfo)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if len(list) == 0 {
|
if len(list) == 0 {
|
||||||
number = 0
|
number = 0
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func slicename(name string, canvas *gg.Context) (resultname string) {
|
func slicename(name string, canvas *gg.Context) (resultname string) {
|
||||||
usermane := []rune(name) // 将每个字符单独放置
|
usermane := []rune(name) // 将每个字符单独放置
|
||||||
widthlen := 0
|
widthlen := 0
|
||||||
numberlen := 0
|
numberlen := 0
|
||||||
for i, v := range usermane {
|
for i, v := range usermane {
|
||||||
width, _ := canvas.MeasureString(string(v)) // 获取单个字符的宽度
|
width, _ := canvas.MeasureString(string(v)) // 获取单个字符的宽度
|
||||||
widthlen += int(width)
|
widthlen += int(width)
|
||||||
if widthlen > 350 {
|
if widthlen > 350 {
|
||||||
break // 总宽度不能超过350
|
break // 总宽度不能超过350
|
||||||
}
|
}
|
||||||
numberlen = i
|
numberlen = i
|
||||||
}
|
}
|
||||||
if widthlen > 350 {
|
if widthlen > 350 {
|
||||||
resultname = string(usermane[:numberlen-1]) + "......" // 名字切片
|
resultname = string(usermane[:numberlen-1]) + "......" // 名字切片
|
||||||
} else {
|
} else {
|
||||||
resultname = name
|
resultname = name
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// 以群号和昵称为限制
|
// 以群号和昵称为限制
|
||||||
func cdcheck(ctx *zero.Ctx) *rate.Limiter {
|
func cdcheck(ctx *zero.Ctx) *rate.Limiter {
|
||||||
limitID := strconv.FormatInt(ctx.Event.GroupID, 10) + strconv.FormatInt(ctx.Event.UserID, 10) + "1"
|
limitID := strconv.FormatInt(ctx.Event.GroupID, 10) + strconv.FormatInt(ctx.Event.UserID, 10) + "1"
|
||||||
return skillCD.Load(limitID)
|
return skillCD.Load(limitID)
|
||||||
}
|
}
|
||||||
func cdcheck2(ctx *zero.Ctx) *rate.Limiter {
|
func cdcheck2(ctx *zero.Ctx) *rate.Limiter {
|
||||||
limitID := strconv.FormatInt(ctx.Event.GroupID, 10) + strconv.FormatInt(ctx.Event.UserID, 10) + "2"
|
limitID := strconv.FormatInt(ctx.Event.GroupID, 10) + strconv.FormatInt(ctx.Event.UserID, 10) + "2"
|
||||||
return skillCD.Load(limitID)
|
return skillCD.Load(limitID)
|
||||||
}
|
}
|
||||||
func cdcheck3(ctx *zero.Ctx) *rate.Limiter {
|
func cdcheck3(ctx *zero.Ctx) *rate.Limiter {
|
||||||
limitID := strconv.FormatInt(ctx.Event.GroupID, 10) + strconv.FormatInt(ctx.Event.UserID, 10) + "3"
|
limitID := strconv.FormatInt(ctx.Event.GroupID, 10) + strconv.FormatInt(ctx.Event.UserID, 10) + "3"
|
||||||
return skillCD.Load(limitID)
|
return skillCD.Load(limitID)
|
||||||
}
|
}
|
||||||
func iscding(ctx *zero.Ctx) {
|
func iscding(ctx *zero.Ctx) {
|
||||||
ctx.SendChain(message.Text("你的技能现在正在CD中"))
|
ctx.SendChain(message.Text("你的技能现在正在CD中"))
|
||||||
}
|
}
|
||||||
func iscding2(ctx *zero.Ctx) {
|
func iscding2(ctx *zero.Ctx) {
|
||||||
ctx.SendChain(message.Text("打灭,禁止离婚 (你的技能正在CD中)"))
|
ctx.SendChain(message.Text("打灭,禁止离婚 (你的技能正在CD中)"))
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注入判断 是否为单身
|
// 注入判断 是否为单身
|
||||||
func checkdog(ctx *zero.Ctx) bool {
|
func checkdog(ctx *zero.Ctx) bool {
|
||||||
// 得先判断用户是否存在才行在,再重置
|
// 得先判断用户是否存在才行在,再重置
|
||||||
fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
|
fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("额,你的target好像不存在?"))
|
ctx.SendChain(message.Text("额,你的target好像不存在?"))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// 判断是否需要重置
|
// 判断是否需要重置
|
||||||
gid := ctx.Event.GroupID
|
gid := ctx.Event.GroupID
|
||||||
ok, err := 民政局.开门时间(gid)
|
ok, err := 民政局.开门时间(gid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("群状态查询失败\n[error]", err))
|
ctx.SendChain(message.Text("群状态查询失败\n[error]", err))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if ok {
|
if ok {
|
||||||
return true // 重置后也全是单身
|
return true // 重置后也全是单身
|
||||||
}
|
}
|
||||||
// 获取用户信息
|
// 获取用户信息
|
||||||
uid := ctx.Event.UserID
|
uid := ctx.Event.UserID
|
||||||
uidtarget, uidstatus, err := 民政局.查户口(gid, uid)
|
uidtarget, uidstatus, err := 民政局.查户口(gid, uid)
|
||||||
switch {
|
switch {
|
||||||
case uidstatus == "错":
|
case uidstatus == "错":
|
||||||
ctx.SendChain(message.Text("用户状态查询失败\n[error]", err))
|
ctx.SendChain(message.Text("用户状态查询失败\n[error]", err))
|
||||||
return false
|
return false
|
||||||
case uidstatus != "单" && (uidtarget.Target == 0 || uidtarget.User == 0): // 如果是单身贵族
|
case uidstatus != "单" && (uidtarget.Target == 0 || uidtarget.User == 0): // 如果是单身贵族
|
||||||
ctx.SendChain(message.Text("今天的你是单身贵族噢"))
|
ctx.SendChain(message.Text("今天的你是单身贵族噢"))
|
||||||
return false
|
return false
|
||||||
case (uidstatus == "攻" && uidtarget.Target == fiancee) ||
|
case (uidstatus == "攻" && uidtarget.Target == fiancee) ||
|
||||||
(uidstatus == "受" && uidtarget.User == fiancee):
|
(uidstatus == "受" && uidtarget.User == fiancee):
|
||||||
ctx.SendChain(message.Text("笨蛋!你们已经在一起了!"))
|
ctx.SendChain(message.Text("笨蛋!你们已经在一起了!"))
|
||||||
return false
|
return false
|
||||||
case uidstatus == "攻": // 如果如为攻
|
case uidstatus == "攻": // 如果如为攻
|
||||||
ctx.SendChain(message.Text("笨蛋~你家里还有个吃白饭的w"))
|
ctx.SendChain(message.Text("笨蛋~你家里还有个吃白饭的w"))
|
||||||
return false
|
return false
|
||||||
case uidstatus == "受": // 如果为受
|
case uidstatus == "受": // 如果为受
|
||||||
ctx.SendChain(message.Text("该是0就是0,当0有什么不好"))
|
ctx.SendChain(message.Text("该是0就是0,当0有什么不好"))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
fianceeinfo, fianceestatus, err := 民政局.查户口(gid, fiancee)
|
fianceeinfo, fianceestatus, err := 民政局.查户口(gid, fiancee)
|
||||||
switch {
|
switch {
|
||||||
case fianceestatus == "错":
|
case fianceestatus == "错":
|
||||||
ctx.SendChain(message.Text("对象状态查询失败\n[error]", err))
|
ctx.SendChain(message.Text("对象状态查询失败\n[error]", err))
|
||||||
case fianceestatus == "单": // 如果为单身狗
|
case fianceestatus == "单": // 如果为单身狗
|
||||||
return true
|
return true
|
||||||
case fianceestatus != "单" && (fianceeinfo.Target == 0 || fianceeinfo.User == 0): // 如果是单身贵族
|
case fianceestatus != "单" && (fianceeinfo.Target == 0 || fianceeinfo.User == 0): // 如果是单身贵族
|
||||||
ctx.SendChain(message.Text("今天的ta是单身贵族噢"))
|
ctx.SendChain(message.Text("今天的ta是单身贵族噢"))
|
||||||
case fianceestatus == "攻": // 如果如为攻
|
case fianceestatus == "攻": // 如果如为攻
|
||||||
ctx.SendChain(message.Text("他有别的女人了,你该放下了"))
|
ctx.SendChain(message.Text("他有别的女人了,你该放下了"))
|
||||||
case fianceestatus == "受": // 如果为受
|
case fianceestatus == "受": // 如果为受
|
||||||
ctx.SendChain(message.Text("ta被别人娶了,你来晚力"))
|
ctx.SendChain(message.Text("ta被别人娶了,你来晚力"))
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注入判断 是否满足小三要求
|
// 注入判断 是否满足小三要求
|
||||||
func checkcp(ctx *zero.Ctx) bool {
|
func checkcp(ctx *zero.Ctx) bool {
|
||||||
// 得先判断用户是否存在才行在,再重置
|
// 得先判断用户是否存在才行在,再重置
|
||||||
fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
|
fiancee, err := strconv.ParseInt(ctx.State["regex_matched"].([]string)[2], 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("额,你的target好像不存在?"))
|
ctx.SendChain(message.Text("额,你的target好像不存在?"))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// 判断是否需要重置
|
// 判断是否需要重置
|
||||||
gid := ctx.Event.GroupID
|
gid := ctx.Event.GroupID
|
||||||
ok, err := 民政局.开门时间(gid)
|
ok, err := 民政局.开门时间(gid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.SendChain(message.Text("群状态查询失败\n[error]", err))
|
ctx.SendChain(message.Text("群状态查询失败\n[error]", err))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if ok {
|
if ok {
|
||||||
ctx.SendChain(message.Text("ta现在还是单身哦,快向ta表白吧!"))
|
ctx.SendChain(message.Text("ta现在还是单身哦,快向ta表白吧!"))
|
||||||
return false // 重置后也全是单身
|
return false // 重置后也全是单身
|
||||||
}
|
}
|
||||||
uid := ctx.Event.UserID
|
uid := ctx.Event.UserID
|
||||||
fianceeinfo, fianceestatus, err := 民政局.查户口(gid, fiancee)
|
fianceeinfo, fianceestatus, err := 民政局.查户口(gid, fiancee)
|
||||||
switch {
|
switch {
|
||||||
case fianceestatus == "错":
|
case fianceestatus == "错":
|
||||||
ctx.SendChain(message.Text("对象状态查询失败\n[error]", err))
|
ctx.SendChain(message.Text("对象状态查询失败\n[error]", err))
|
||||||
return false
|
return false
|
||||||
case fianceestatus == "单": // 如果为单身狗
|
case fianceestatus == "单": // 如果为单身狗
|
||||||
if fiancee == uid {
|
if fiancee == uid {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
ctx.SendChain(message.Text("ta现在还是单身哦,快向ta表白吧!"))
|
ctx.SendChain(message.Text("ta现在还是单身哦,快向ta表白吧!"))
|
||||||
return false
|
return false
|
||||||
case fianceestatus != "单" && (fianceeinfo.Target == 0 || fianceeinfo.User == 0): // 如果是单身贵族
|
case fianceestatus != "单" && (fianceeinfo.Target == 0 || fianceeinfo.User == 0): // 如果是单身贵族
|
||||||
ctx.SendChain(message.Text("今天的ta是单身贵族噢"))
|
ctx.SendChain(message.Text("今天的ta是单身贵族噢"))
|
||||||
return false
|
return false
|
||||||
case (fianceestatus == "攻" && fianceeinfo.Target == fiancee) ||
|
case (fianceestatus == "攻" && fianceeinfo.Target == fiancee) ||
|
||||||
(fianceestatus == "受" && fianceeinfo.User == fiancee):
|
(fianceestatus == "受" && fianceeinfo.User == fiancee):
|
||||||
ctx.SendChain(message.Text("笨蛋!你们已经在一起了!"))
|
ctx.SendChain(message.Text("笨蛋!你们已经在一起了!"))
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
// 获取用户信息
|
// 获取用户信息
|
||||||
uidtarget, uidstatus, err := 民政局.查户口(gid, uid)
|
uidtarget, uidstatus, err := 民政局.查户口(gid, uid)
|
||||||
switch {
|
switch {
|
||||||
case uidstatus == "错":
|
case uidstatus == "错":
|
||||||
ctx.SendChain(message.Text("用户状态查询失败\n[error]", err))
|
ctx.SendChain(message.Text("用户状态查询失败\n[error]", err))
|
||||||
case uidstatus == "单": // 如果为单身狗
|
case uidstatus == "单": // 如果为单身狗
|
||||||
return true
|
return true
|
||||||
case uidstatus != "单" && (uidtarget.Target == 0 || uidtarget.User == 0): // 如果是单身贵族
|
case uidstatus != "单" && (uidtarget.Target == 0 || uidtarget.User == 0): // 如果是单身贵族
|
||||||
ctx.SendChain(message.Text("今天的你是单身贵族噢"))
|
ctx.SendChain(message.Text("今天的你是单身贵族噢"))
|
||||||
case uidstatus == "攻": // 如果如为攻
|
case uidstatus == "攻": // 如果如为攻
|
||||||
ctx.SendChain(message.Text("打灭,不给纳小妾!"))
|
ctx.SendChain(message.Text("打灭,不给纳小妾!"))
|
||||||
case uidstatus == "受": // 如果为受
|
case uidstatus == "受": // 如果为受
|
||||||
ctx.SendChain(message.Text("该是0就是0,当0有什么不好"))
|
ctx.SendChain(message.Text("该是0就是0,当0有什么不好"))
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user