mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 22:00:11 +08:00
parent
d3e587f935
commit
ba7c6cb0a0
@ -64,6 +64,7 @@ func init() {
|
|||||||
"- 取消b站动态订阅[uid|name]\n" +
|
"- 取消b站动态订阅[uid|name]\n" +
|
||||||
"- 取消b站直播订阅[uid|name]\n" +
|
"- 取消b站直播订阅[uid|name]\n" +
|
||||||
"- b站推送列表\n" +
|
"- b站推送列表\n" +
|
||||||
|
"- [开启|关闭]艾特全体\n" +
|
||||||
"Tips: 需要配合job一起使用, 全局只需要设置一个, 无视响应状态推送, 下为例子\n" +
|
"Tips: 需要配合job一起使用, 全局只需要设置一个, 无视响应状态推送, 下为例子\n" +
|
||||||
"记录在\"@every 5m\"触发的指令)\n" +
|
"记录在\"@every 5m\"触发的指令)\n" +
|
||||||
"拉取b站推送",
|
"拉取b站推送",
|
||||||
@ -74,6 +75,23 @@ func init() {
|
|||||||
dbpath := en.DataFolder()
|
dbpath := en.DataFolder()
|
||||||
dbfile := dbpath + "push.db"
|
dbfile := dbpath + "push.db"
|
||||||
bdb = initializePush(dbfile)
|
bdb = initializePush(dbfile)
|
||||||
|
en.OnFullMatch(`开启艾特全体`, zero.UserOrGrpAdmin, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
|
gid := ctx.Event.GroupID
|
||||||
|
if err := changeAtAll(gid, 1); err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.SendChain(message.Text("已开启艾特全体Oo"))
|
||||||
|
})
|
||||||
|
|
||||||
|
en.OnFullMatch(`关闭艾特全体`, zero.UserOrGrpAdmin, zero.OnlyGroup).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
|
gid := ctx.Event.GroupID
|
||||||
|
if err := changeAtAll(gid, 0); err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR: ", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.SendChain(message.Text("已关闭艾特全体Oo"))
|
||||||
|
})
|
||||||
|
|
||||||
en.OnRegex(`^添加[B|b]站订阅\s?(.{1,25})$`, zero.UserOrGrpAdmin, getPara).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
en.OnRegex(`^添加[B|b]站订阅\s?(.{1,25})$`, zero.UserOrGrpAdmin, getPara).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
buid, _ := strconv.ParseInt(ctx.State["uid"].(string), 10, 64)
|
buid, _ := strconv.ParseInt(ctx.State["uid"].(string), 10, 64)
|
||||||
@ -92,6 +110,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
ctx.SendChain(message.Text("已添加" + name + "的订阅"))
|
ctx.SendChain(message.Text("已添加" + name + "的订阅"))
|
||||||
})
|
})
|
||||||
|
|
||||||
en.OnRegex(`^取消[B|b]站订阅\s?(.{1,25})$`, zero.UserOrGrpAdmin, getPara).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
en.OnRegex(`^取消[B|b]站订阅\s?(.{1,25})$`, zero.UserOrGrpAdmin, getPara).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
buid, _ := strconv.ParseInt(ctx.State["uid"].(string), 10, 64)
|
buid, _ := strconv.ParseInt(ctx.State["uid"].(string), 10, 64)
|
||||||
name, err := getName(buid)
|
name, err := getName(buid)
|
||||||
@ -143,6 +162,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
ctx.SendChain(message.Text("已取消" + name + "的直播订阅"))
|
ctx.SendChain(message.Text("已取消" + name + "的直播订阅"))
|
||||||
})
|
})
|
||||||
|
|
||||||
en.OnRegex(`^[B|b]站推送列表$`, zero.UserOrGrpAdmin).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
en.OnRegex(`^[B|b]站推送列表$`, zero.UserOrGrpAdmin).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||||
gid := ctx.Event.GroupID
|
gid := ctx.Event.GroupID
|
||||||
if gid == 0 {
|
if gid == 0 {
|
||||||
@ -189,6 +209,14 @@ func init() {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func changeAtAll(groupId int64, b int) (err error) {
|
||||||
|
bpMap := map[string]any{
|
||||||
|
"group_id": groupId,
|
||||||
|
"at_all": b,
|
||||||
|
}
|
||||||
|
return bdb.updateAtAll(bpMap)
|
||||||
|
}
|
||||||
|
|
||||||
// 取得uid的名字
|
// 取得uid的名字
|
||||||
func getName(buid int64) (name string, err error) {
|
func getName(buid int64) (name string, err error) {
|
||||||
var ok bool
|
var ok bool
|
||||||
@ -466,6 +494,9 @@ func sendLive(ctx *zero.Ctx) error {
|
|||||||
time.Sleep(time.Millisecond * 100)
|
time.Sleep(time.Millisecond * 100)
|
||||||
switch {
|
switch {
|
||||||
case gid > 0:
|
case gid > 0:
|
||||||
|
if res := bdb.getAtAll(gid); res == 1 {
|
||||||
|
msg = append([]message.MessageSegment{message.AtAll()}, msg...)
|
||||||
|
}
|
||||||
ctx.SendGroupMessage(gid, msg)
|
ctx.SendGroupMessage(gid, msg)
|
||||||
case gid < 0:
|
case gid < 0:
|
||||||
ctx.SendPrivateMessage(-gid, msg)
|
ctx.SendPrivateMessage(-gid, msg)
|
||||||
|
|||||||
@ -33,6 +33,15 @@ func (bilibiliup) TableName() string {
|
|||||||
return "bilibili_up"
|
return "bilibili_up"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type bilibiliAt struct {
|
||||||
|
GroupID int64 `gorm:"column:group_id;primary_key" json:"group_id"`
|
||||||
|
AtAll int64 `gorm:"column:at_all;default:0" json:"at_all"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bilibiliAt) TableName() string {
|
||||||
|
return "bilibili_at"
|
||||||
|
}
|
||||||
|
|
||||||
// initializePush 初始化bilibilipushdb数据库
|
// initializePush 初始化bilibilipushdb数据库
|
||||||
func initializePush(dbpath string) *bilibilipushdb {
|
func initializePush(dbpath string) *bilibilipushdb {
|
||||||
var err error
|
var err error
|
||||||
@ -48,7 +57,7 @@ func initializePush(dbpath string) *bilibilipushdb {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
gdb.AutoMigrate(&bilibilipush{}).AutoMigrate(&bilibiliup{})
|
gdb.AutoMigrate(&bilibilipush{}).AutoMigrate(&bilibiliup{}).AutoMigrate(&bilibiliAt{})
|
||||||
return (*bilibilipushdb)(gdb)
|
return (*bilibilipushdb)(gdb)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -130,6 +139,35 @@ func (bdb *bilibilipushdb) getAllPushByGroup(groupID int64) (bpl []bilibilipush)
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (bdb *bilibilipushdb) getAtAll(groupID int64) (res int64) {
|
||||||
|
db := (*gorm.DB)(bdb)
|
||||||
|
var bpl bilibiliAt
|
||||||
|
db.Model(&bilibilipush{}).Find(&bpl, "group_id = ?", groupID)
|
||||||
|
res = bpl.AtAll
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (bdb *bilibilipushdb) updateAtAll(bpMap map[string]any) (err error) {
|
||||||
|
db := (*gorm.DB)(bdb)
|
||||||
|
bp := bilibiliAt{}
|
||||||
|
data, err := json.Marshal(&bpMap)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = json.Unmarshal(data, &bp)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = db.Model(&bilibiliAt{}).First(&bp, "group_id = ?", bp.GroupID).Error; err != nil {
|
||||||
|
if gorm.IsRecordNotFoundError(err) {
|
||||||
|
err = db.Model(&bilibiliAt{}).Create(&bp).Error
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
err = db.Model(&bilibiliAt{}).Where("group_id = ?", bp.GroupID).Update(bpMap).Error
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (bdb *bilibilipushdb) insertBilibiliUp(buid int64, name string) {
|
func (bdb *bilibilipushdb) insertBilibiliUp(buid int64, name string) {
|
||||||
db := (*gorm.DB)(bdb)
|
db := (*gorm.DB)(bdb)
|
||||||
bu := bilibiliup{
|
bu := bilibiliup{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user