Skip to content

Commit

Permalink
✨ 添加qq空间表白墙 (#489)
Browse files Browse the repository at this point in the history
  • Loading branch information
guohuiyuan committed Nov 13, 2022
1 parent 743e550 commit 4075c92
Show file tree
Hide file tree
Showing 9 changed files with 561 additions and 4 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,22 @@ NeteaseCloudMusicApi项目地址:https://binaryify.github.io/NeteaseCloudMusicAp
- [x] 重置花名册


</details>
<details>
<summary>qq空间表白墙</summary>

`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/qzone"`

- [x] 登录QQ空间 (Cookie过期很快, 要经常登录)

- [x] 发说说[xxx]

- [x] (匿名)发表白墙[xxx]

- [x] [ 同意 | 拒绝 ]表白墙 1,2,3 (最后一个参数是表白墙的序号数组, 用英文逗号连接)

- [x] 查看[ 等待 | 同意 | 拒绝 | 所有 ]表白墙 0 (最后一个参数是页码, 建议私聊审稿)

</details>
<details>
<summary>Real-CUGAN清晰术</summary>
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.19
require (
github.com/Baidu-AIP/golang-sdk v1.1.1
github.com/Coloured-glaze/gg v1.3.4
github.com/FloatTech/AnimeAPI v1.5.2-0.20221110071402-5672d8466e21
github.com/FloatTech/AnimeAPI v1.5.2-0.20221112090201-4a200d6330d5
github.com/FloatTech/floatbox v0.0.0-20221110070748-e0d0b3af3e57
github.com/FloatTech/sqlite v0.5.1
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/Coloured-glaze/gg v1.3.4 h1:l31zIF/HaVwkzjrj+A56RGQoSKyKuR1IWtIrqXGFStI=
github.com/Coloured-glaze/gg v1.3.4/go.mod h1:Ih5NLNNDHOy3RJbB0EPqGTreIzq/H02TGThIagh8HJg=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/FloatTech/AnimeAPI v1.5.2-0.20221110071402-5672d8466e21 h1:Ao45y4vcH2n5Qx1DPyDPc2Wmt7Lol4/MwY1ZknBhGw4=
github.com/FloatTech/AnimeAPI v1.5.2-0.20221110071402-5672d8466e21/go.mod h1:D3VwaTmT25UM+x/0AULJtJw4Mzyhob5YOa90J5QAX/w=
github.com/FloatTech/AnimeAPI v1.5.2-0.20221112090201-4a200d6330d5 h1:1SpesC37urPid5ChljT7fnq+kyJLDrCuHva9usiJptU=
github.com/FloatTech/AnimeAPI v1.5.2-0.20221112090201-4a200d6330d5/go.mod h1:D3VwaTmT25UM+x/0AULJtJw4Mzyhob5YOa90J5QAX/w=
github.com/FloatTech/floatbox v0.0.0-20221110070748-e0d0b3af3e57 h1:1H1QSxBPqq7o4S5/xtl0cI/GOqaiajoBg+156cuK1e4=
github.com/FloatTech/floatbox v0.0.0-20221110070748-e0d0b3af3e57/go.mod h1:72tI2fKLhrNpuj4AlE2HSjJOAtEnUEKOx/+dEYSc4FE=
github.com/FloatTech/sqlite v0.5.1 h1:IjTdnqMVIVIoIEFXhvh/KKBfYxFvG0tk7Rghz65/DAU=
Expand Down
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ import (
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nsfw" // nsfw图片识别
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/omikuji" // 浅草寺求签
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/qqwife" // 一群一天一夫一妻制群老婆
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/qzone" // qq空间表白墙
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/realcugan" // realcugan清晰术
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/reborn" // 投胎
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/runcode" // 在线运行代码
Expand Down
12 changes: 12 additions & 0 deletions plugin/aipaint/aipaint.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"net/url"
"os"
"regexp"
"strconv"
"strings"
Expand Down Expand Up @@ -62,6 +63,17 @@ func init() { // 插件主体
PrivateDataFolder: "aipaint",
})
datapath = file.BOTPATH + "/" + engine.DataFolder()
if file.IsNotExist(cfg.file) {
s := serverConfig{}
data, err := json.Marshal(s)
if err != nil {
panic(err)
}
err = os.WriteFile(cfg.file, data, 0666)
if err != nil {
panic(err)
}
}
engine.OnPrefixGroup([]string{`ai绘图`, `生成色图`, `生成涩图`, `ai画图`}).SetBlock(true).
Handle(func(ctx *zero.Ctx) {
err := cfg.load()
Expand Down
11 changes: 10 additions & 1 deletion plugin/bilibili/bilibili.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ var (
3: "Superchat",
4: "进入直播间",
5: "标题变动",
6: "分区变动",
7: "直播中止",
8: "直播继续",
}
cfg = bz.NewCookieConfig("data/Bilibili/config.json")
)
Expand Down Expand Up @@ -492,13 +495,19 @@ func init() {
canvas.DrawString(t, moveW, danmuNow)
canvas.SetColor(color.Black)
moveW += l + dz
case 4, 5:
case 4, 5, 6, 7, 8:
t = danmakuTypeMap[danItem.Type]
canvas.SetRGB255(0, 128, 0)
l, _ = canvas.MeasureString(t)
canvas.DrawString(t, moveW, danmuNow)
canvas.SetColor(color.Black)
moveW += l + dz
default:
canvas.SetRGB255(0, 128, 0)
l, _ = canvas.MeasureString("未知类型" + strconv.Itoa(int(danItem.Type)))
canvas.DrawString(t, moveW, danmuNow)
canvas.SetColor(color.Black)
moveW += l + dz
}
if moveW > mcw {
mcw = moveW
Expand Down
18 changes: 18 additions & 0 deletions plugin/qzone/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# qq空间表白墙

## 参考

* [opq-osc/OPQBot](https://github.com/opq-osc/OPQBot) QQ空间发表说说流程
* [【Ono】QQ空间协议分析----扫码登录----【1】](https://www.52pojie.cn/thread-1022123-1-1.html) QQ空间扫码登录流程

## 优化点
- [ ] 匿名头像背景颜色优化
- [ ] 转发消息生成图片气泡背景板
- [x] 查看说说消息分页 (优先)
- [ ] 加zbp水印 (优先)
- [ ] 发表白墙互动优化, 监听对话
- [ ] 自动审核稿
- [x] 一次同意多条说说并发送 (优先)
- [ ] 拒绝说说的时候可发送拒绝消息
- [ ] 表白墙接入钱包 (待定)

132 changes: 132 additions & 0 deletions plugin/qzone/model.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package qzone

import (
"fmt"
"os"

_ "github.com/fumiama/sqlite3" // use sql
"github.com/jinzhu/gorm"
)

// qdb qq空间数据库全局变量
var qdb *qzonedb

// qzonedb qq空间数据库结构体
type qzonedb gorm.DB

// initialize 初始化
func initialize(dbpath string) *qzonedb {
var err error
if _, err = os.Stat(dbpath); err != nil || os.IsNotExist(err) {
// 生成文件
f, err := os.Create(dbpath)
if err != nil {
return nil
}
defer f.Close()
}
qdb, err := gorm.Open("sqlite3", dbpath)
if err != nil {
panic(err)
}
qdb.AutoMigrate(&qzoneConfig{}).AutoMigrate(&emotion{})
return (*qzonedb)(qdb)
}

// qzoneConfig qq空间初始化信息
type qzoneConfig struct {
ID uint `gorm:"primary_key;AUTO_INCREMENT"`
QQ int64 `gorm:"column:qq;unique;not null"`
Cookie string `gorm:"column:cookie;type:varchar(1024)"`
}

// TableName 表名
func (qzoneConfig) TableName() string {
return "qzone_config"
}

func (qdb *qzonedb) insertOrUpdate(qq int64, cookie string) (err error) {
db := (*gorm.DB)(qdb)
qc := qzoneConfig{
QQ: qq,
Cookie: cookie,
}
var oqc qzoneConfig
err = db.Take(&oqc, "qq = ?", qc.QQ).Error
if err != nil {
if gorm.IsRecordNotFoundError(err) {
err = db.Create(&qc).Error
}
return
}
err = db.Model(&oqc).Updates(qc).Error
return
}

func (qdb *qzonedb) getByUin(qq int64) (qc qzoneConfig, err error) {
db := (*gorm.DB)(qdb)
err = db.Take(&qc, "qq = ?", qq).Error
return
}

// emotion 说说信息
type emotion struct {
gorm.Model
Anonymous bool `gorm:"column:anonymous"`
QQ int64 `gorm:"column:qq"`
Msg string `gorm:"column:msg"`
Status int `gorm:"column:status"` // 1-审核中,2-同意,3-拒绝
Tag string `gorm:"column:tag"`
}

func (e emotion) textBrief() (t string) {
t = fmt.Sprintf("序号: %v\nQQ: %v\n创建时间: %v\n", e.ID, e.QQ, e.CreatedAt.Format("2006-01-02 15:04:05"))
switch e.Status {
case 1:
t += "状态: 审核中\n"
case 2:
t += "状态: 同意\n"
case 3:
t += "状态: 拒绝\n"
}
if e.Anonymous {
t += "匿名: 是"
} else {
t += "匿名: 否"
}
return
}

// TableName 表名
func (emotion) TableName() string {
return "emotion"
}

func (qdb *qzonedb) saveEmotion(e emotion) (id int64, err error) {
db := (*gorm.DB)(qdb)
err = db.Create(&e).Error
id = int64(e.ID)
return
}

func (qdb *qzonedb) getEmotionByIDList(idList []int64) (el []emotion, err error) {
db := (*gorm.DB)(qdb)
err = db.Find(&el, "id in (?)", idList).Error
return
}

func (qdb *qzonedb) getLoveEmotionByStatus(status int, pageNum int) (el []emotion, err error) {
db := (*gorm.DB)(qdb)
if status == 0 {
err = db.Order("created_at desc").Limit(5).Offset(pageNum*5).Find(&el, "tag like ?", "%"+loveTag+"%").Error
return
}
err = db.Order("created_at desc").Limit(5).Offset(pageNum*5).Find(&el, "status = ? and tag like ?", status, "%"+loveTag+"%").Error
return
}

func (qdb *qzonedb) updateEmotionStatusByIDList(idList []int64, status int) (err error) {
db := (*gorm.DB)(qdb)
err = db.Model(&emotion{}).Where("id in (?)", idList).Update("status", status).Error
return
}

0 comments on commit 4075c92

Please sign in to comment.