mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2025-12-19 13:59:39 +08:00
feat:添加舔狗日记和修复睡眠管理的问题 (#152)
* feat:添加舔狗日记和修复睡眠管理的问题 * fix:修lint * fix:修改铅笔小说网址 * fix:修改铅笔小说网址
This commit is contained in:
parent
2c545e7b7f
commit
2f3823abe2
@ -361,6 +361,8 @@ print("run[CQ:image,file="+j["img"]+"]")
|
|||||||
- api早上8点更新,推荐定时在8点30后。配合插件`job`中的记录在"cron"触发的指令使用
|
- api早上8点更新,推荐定时在8点30后。配合插件`job`中的记录在"cron"触发的指令使用
|
||||||
- [x] /启用 zaobao
|
- [x] /启用 zaobao
|
||||||
- [x] /禁用 zaobao
|
- [x] /禁用 zaobao
|
||||||
|
- **舔狗日记** `import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/tiangou"`
|
||||||
|
- [x] 舔狗日记
|
||||||
```
|
```
|
||||||
记录在"00 9 * * *"触发的指令
|
记录在"00 9 * * *"触发的指令
|
||||||
今日早报
|
今日早报
|
||||||
|
|||||||
1
main.go
1
main.go
@ -100,6 +100,7 @@ import (
|
|||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/setutime" // 来份涩图
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/setutime" // 来份涩图
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/shadiao" // 沙雕app
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/shadiao" // 沙雕app
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/shindan" // 测定
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/shindan" // 测定
|
||||||
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tiangou" // 舔狗日记
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tracemoe" // 搜番
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tracemoe" // 搜番
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/translation" // 翻译
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/translation" // 翻译
|
||||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/vtb_quotation" // vtb语录
|
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/vtb_quotation" // vtb语录
|
||||||
|
|||||||
@ -25,14 +25,14 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
websiteURL = "https://www.23qb.net"
|
websiteURL = "https://www.23qb.com"
|
||||||
websiteTitle = "铅笔小说"
|
websiteTitle = "铅笔小说"
|
||||||
errorTitle = "出现错误!"
|
errorTitle = "出现错误!"
|
||||||
username = "zerobot"
|
username = "zerobot"
|
||||||
password = "123456"
|
password = "123456"
|
||||||
submit = "%26%23160%3B%B5%C7%26%23160%3B%26%23160%3B%C2%BC%26%23160%3B"
|
submit = "%26%23160%3B%B5%C7%26%23160%3B%26%23160%3B%C2%BC%26%23160%3B"
|
||||||
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
|
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36"
|
||||||
loginURL = websiteURL + "/login.php?do=submit&jumpurl=https%3A%2F%2Fwww.23qb.net%2F"
|
loginURL = websiteURL + "/login.php?do=submit&jumpurl=https%3A%2F%2Fwww.23qb.com%2F"
|
||||||
searchURL = websiteURL + "/saerch.php"
|
searchURL = websiteURL + "/saerch.php"
|
||||||
idReg = `/(\d+)/`
|
idReg = `/(\d+)/`
|
||||||
)
|
)
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
// Package model 睡眠管理数据库
|
package sleepmanage
|
||||||
package model
|
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
@ -10,11 +9,14 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SleepDB 睡眠数据库
|
// sdb 睡眠数据库全局变量
|
||||||
type SleepDB gorm.DB
|
var sdb *sleepdb
|
||||||
|
|
||||||
// Initialize 初始化
|
// sleepdb 睡眠数据库结构体
|
||||||
func Initialize(dbpath string) *SleepDB {
|
type sleepdb gorm.DB
|
||||||
|
|
||||||
|
// initialize 初始化
|
||||||
|
func initialize(dbpath string) *sleepdb {
|
||||||
var err error
|
var err error
|
||||||
if _, err = os.Stat(dbpath); err != nil || os.IsNotExist(err) {
|
if _, err = os.Stat(dbpath); err != nil || os.IsNotExist(err) {
|
||||||
// 生成文件
|
// 生成文件
|
||||||
@ -29,27 +31,18 @@ func Initialize(dbpath string) *SleepDB {
|
|||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
gdb.AutoMigrate(&SleepManage{})
|
gdb.AutoMigrate(&SleepManage{})
|
||||||
return (*SleepDB)(gdb)
|
return (*sleepdb)(gdb)
|
||||||
}
|
|
||||||
|
|
||||||
// Open 打开
|
|
||||||
func Open(dbpath string) (*SleepDB, error) {
|
|
||||||
db, err := gorm.Open("sqlite3", dbpath)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return (*SleepDB)(db), nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close 关闭
|
// Close 关闭
|
||||||
func (sdb *SleepDB) Close() error {
|
func (sdb *sleepdb) Close() error {
|
||||||
db := (*gorm.DB)(sdb)
|
db := (*gorm.DB)(sdb)
|
||||||
return db.Close()
|
return db.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SleepManage 睡眠信息
|
// SleepManage 睡眠信息
|
||||||
type SleepManage struct {
|
type SleepManage struct {
|
||||||
gorm.Model
|
ID uint `gorm:"primary_key"`
|
||||||
GroupID int64 `gorm:"column:group_id"`
|
GroupID int64 `gorm:"column:group_id"`
|
||||||
UserID int64 `gorm:"column:user_id"`
|
UserID int64 `gorm:"column:user_id"`
|
||||||
SleepTime time.Time `gorm:"column:sleep_time"`
|
SleepTime time.Time `gorm:"column:sleep_time"`
|
||||||
@ -60,8 +53,8 @@ func (SleepManage) TableName() string {
|
|||||||
return "sleep_manage"
|
return "sleep_manage"
|
||||||
}
|
}
|
||||||
|
|
||||||
// Sleep 更新睡眠时间
|
// sleep 更新睡眠时间
|
||||||
func (sdb *SleepDB) Sleep(gid, uid int64) (position int, awakeTime time.Duration) {
|
func (sdb *sleepdb) sleep(gid, uid int64) (position int, awakeTime time.Duration) {
|
||||||
db := (*gorm.DB)(sdb)
|
db := (*gorm.DB)(sdb)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
var today time.Time
|
var today time.Time
|
||||||
@ -92,8 +85,8 @@ func (sdb *SleepDB) Sleep(gid, uid int64) (position int, awakeTime time.Duration
|
|||||||
return position, awakeTime
|
return position, awakeTime
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetUp 更新起床时间
|
// getUp 更新起床时间
|
||||||
func (sdb *SleepDB) GetUp(gid, uid int64) (position int, sleepTime time.Duration) {
|
func (sdb *sleepdb) getUp(gid, uid int64) (position int, sleepTime time.Duration) {
|
||||||
db := (*gorm.DB)(sdb)
|
db := (*gorm.DB)(sdb)
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
today := now.Add(-time.Hour*time.Duration(-6+now.Hour()) - time.Minute*time.Duration(now.Minute()) - time.Second*time.Duration(now.Second()))
|
today := now.Add(-time.Hour*time.Duration(-6+now.Hour()) - time.Minute*time.Duration(now.Minute()) - time.Second*time.Duration(now.Second()))
|
||||||
@ -12,8 +12,6 @@ import (
|
|||||||
control "github.com/FloatTech/zbputils/control"
|
control "github.com/FloatTech/zbputils/control"
|
||||||
|
|
||||||
"github.com/FloatTech/zbputils/control/order"
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
|
|
||||||
"github.com/FloatTech/ZeroBot-Plugin/plugin/sleep_manage/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
@ -22,15 +20,13 @@ func init() {
|
|||||||
Help: "sleepmanage\n- 早安\n- 晚安",
|
Help: "sleepmanage\n- 早安\n- 晚安",
|
||||||
PrivateDataFolder: "sleep",
|
PrivateDataFolder: "sleep",
|
||||||
})
|
})
|
||||||
dbfile := engine.DataFolder() + "manage.db"
|
go func() {
|
||||||
|
sdb = initialize(engine.DataFolder() + "manage.db")
|
||||||
|
log.Println("[sleepmanage]加载sleepmanage数据库")
|
||||||
|
}()
|
||||||
engine.OnFullMatch("早安", isMorning, zero.OnlyGroup).SetBlock(true).
|
engine.OnFullMatch("早安", isMorning, zero.OnlyGroup).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
db, err := model.Open(dbfile)
|
position, getUpTime := sdb.getUp(ctx.Event.GroupID, ctx.Event.UserID)
|
||||||
if err != nil {
|
|
||||||
log.Errorln(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
position, getUpTime := db.GetUp(ctx.Event.GroupID, ctx.Event.UserID)
|
|
||||||
log.Println(position, getUpTime)
|
log.Println(position, getUpTime)
|
||||||
hour, minute, second := timeDuration(getUpTime)
|
hour, minute, second := timeDuration(getUpTime)
|
||||||
if (hour == 0 && minute == 0 && second == 0) || hour >= 24 {
|
if (hour == 0 && minute == 0 && second == 0) || hour >= 24 {
|
||||||
@ -38,16 +34,10 @@ func init() {
|
|||||||
} else {
|
} else {
|
||||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(fmt.Sprintf("早安成功!你的睡眠时长为%d时%d分%d秒,你是今天第%d个起床的", hour, minute, second, position)))
|
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(fmt.Sprintf("早安成功!你的睡眠时长为%d时%d分%d秒,你是今天第%d个起床的", hour, minute, second, position)))
|
||||||
}
|
}
|
||||||
db.Close()
|
|
||||||
})
|
})
|
||||||
engine.OnFullMatch("晚安", isEvening, zero.OnlyGroup).SetBlock(true).
|
engine.OnFullMatch("晚安", isEvening, zero.OnlyGroup).SetBlock(true).
|
||||||
Handle(func(ctx *zero.Ctx) {
|
Handle(func(ctx *zero.Ctx) {
|
||||||
db, err := model.Open(dbfile)
|
position, sleepTime := sdb.sleep(ctx.Event.GroupID, ctx.Event.UserID)
|
||||||
if err != nil {
|
|
||||||
log.Errorln(err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
position, sleepTime := db.Sleep(ctx.Event.GroupID, ctx.Event.UserID)
|
|
||||||
log.Println(position, sleepTime)
|
log.Println(position, sleepTime)
|
||||||
hour, minute, second := timeDuration(sleepTime)
|
hour, minute, second := timeDuration(sleepTime)
|
||||||
if (hour == 0 && minute == 0 && second == 0) || hour >= 24 {
|
if (hour == 0 && minute == 0 && second == 0) || hour >= 24 {
|
||||||
@ -55,7 +45,6 @@ func init() {
|
|||||||
} else {
|
} else {
|
||||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(fmt.Sprintf("晚安成功!你的清醒时长为%d时%d分%d秒,你是今天第%d个睡觉的", hour, minute, second, position)))
|
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(fmt.Sprintf("晚安成功!你的清醒时长为%d时%d分%d秒,你是今天第%d个睡觉的", hour, minute, second, position)))
|
||||||
}
|
}
|
||||||
db.Close()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
54
plugin/tiangou/tiangou.go
Normal file
54
plugin/tiangou/tiangou.go
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
// Package tiangou 舔狗日记
|
||||||
|
package tiangou
|
||||||
|
|
||||||
|
import (
|
||||||
|
sql "github.com/FloatTech/sqlite"
|
||||||
|
"github.com/FloatTech/zbputils/control"
|
||||||
|
"github.com/FloatTech/zbputils/control/order"
|
||||||
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
|
"github.com/FloatTech/zbputils/file"
|
||||||
|
"github.com/sirupsen/logrus"
|
||||||
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
|
)
|
||||||
|
|
||||||
|
type tiangou struct {
|
||||||
|
ID uint32 `db:"id"`
|
||||||
|
Text string `db:"text"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var db = &sql.Sqlite{}
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
en := control.Register("tiangou", order.AcquirePrio(), &control.Options{
|
||||||
|
DisableOnDefault: false,
|
||||||
|
Help: "舔狗日记\n" +
|
||||||
|
"- 舔狗日记",
|
||||||
|
PublicDataFolder: "Tiangou",
|
||||||
|
})
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
dbpath := en.DataFolder()
|
||||||
|
db.DBPath = dbpath + "tiangou.db"
|
||||||
|
_, err := file.GetLazyData(db.DBPath, false, true)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
err = db.Create("tiangou", &tiangou{})
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
c, _ := db.Count("tiangou")
|
||||||
|
logrus.Infoln("[tiangou]加载", c, "条舔狗日记")
|
||||||
|
}()
|
||||||
|
|
||||||
|
en.OnFullMatch("舔狗日记").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||||
|
var t tiangou
|
||||||
|
err := db.Pick("tiangou", &t)
|
||||||
|
if err != nil {
|
||||||
|
ctx.SendChain(message.Text("ERROR:", err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.SendChain(message.Text(t.Text))
|
||||||
|
})
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user