Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
* https://github.com/FloatTech/ZeroBot-Plugin:
  feat: add plugin 抽扑克牌 (FloatTech#906)
  fix(workflow): pr not work properly
  Revert "feat: add plugin 抽扑克! (FloatTech#903)" (FloatTech#905)
  feat: add plugin 抽扑克! (FloatTech#903)
  [dish] fix: 关键词搜寻功能 (FloatTech#904)
  修复 FullMatchRule 中调用 ctx.NickName() 的 panic 问题 (FloatTech#902)
  optimize: gif plugin for image cache (FloatTech#901) (fix FloatTech#900)
  Update guessmusic plugin (FloatTech#898)
  make lint happy
  add robbery plugin (FloatTech#893)
  [mcfish]  Add one click selling (FloatTech#894)
  • Loading branch information
YumeMichi committed May 15, 2024
2 parents c86ca47 + 3faabc4 commit 62894dd
Show file tree
Hide file tree
Showing 15 changed files with 406 additions and 44 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/pull.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ jobs:
go-version: '1.20'

- name: Check out code into the Go module directory
uses: actions/checkout@master
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: golangci-lint
uses: golangci/golangci-lint-action@master
Expand Down
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ run:

# output configuration options
output:
formats: ["colored-line-number"]
formats:
- format: "colored-line-number"
print-issued-lines: true
print-linter-name: true
uniq-by-line: true
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ print("run[CQ:image,file="+j["img"]+"]")

- [x] 钓鱼商店
- [x] 购买xxx [数量]
- [x] 出售xxx [数量]
- [x] 出售[xxx [数量]|所有垃圾]
- [x] 钓鱼背包
- [x] 装备[xx竿|三叉戟|美西螈]
- [x] 附魔[诱钓|海之眷顾]
Expand Down Expand Up @@ -1069,6 +1069,14 @@ print("run[CQ:image,file="+j["img"]+"]")

- [x] 解签

</details>
<details>
<summary>抽扑克</summary>

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

- [x] 抽扑克牌

</details>
<details>
<summary>一群一天一夫一妻制群老婆</summary>
Expand Down Expand Up @@ -1135,6 +1143,14 @@ print("run[CQ:image,file="+j["img"]+"]")

- 注:本插件来源于[tgbot](https://github.com/YukariChiba/tgbot/blob/main/modules/Reborn.py)

</details>
<details>
<summary>打劫</summary>

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

- [x] 打劫[对方Q号|@对方QQ]

</details>
<details>
<summary>在线代码运行</summary>
Expand Down
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,12 @@ import (
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/nsfw" // nsfw图片识别
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/nwife" // 本地老婆
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/omikuji" // 浅草寺求签
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/poker" // 抽扑克
// _ "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/robbery" // 打劫群友的ATRI币
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/runcode" // 在线运行代码
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/saucenao" // 以图搜图
// _ "github.com/FloatTech/ZeroBot-Plugin/plugin/score" // 分数
Expand Down
7 changes: 4 additions & 3 deletions plugin/dish/dish.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ func init() {
}

var d dish
if err := db.Find("dish", &d, fmt.Sprintf("WHERE name like %%%s%%", dishName)); err != nil {
if err := db.Find("dish", &d, fmt.Sprintf("WHERE name like '%%%s%%'", dishName)); err != nil {
ctx.SendChain(message.Text("客官,本店没有" + dishName))
return
}

Expand All @@ -86,7 +87,7 @@ func init() {
"原材料:%s\n"+
"步骤:\n"+
"%s",
name, dishName, d.Materials, d.Steps),
name, d.Name, d.Materials, d.Steps),
))
})

Expand All @@ -96,7 +97,7 @@ func init() {
return
}

name := ctx.NickName()
name := ctx.CardOrNickName(ctx.Event.UserID)
var d dish
if err := db.Pick("dish", &d); err != nil {
ctx.SendChain(message.Text("小店好像出错了,暂时端不出菜来惹"))
Expand Down
8 changes: 4 additions & 4 deletions plugin/gif/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,13 @@ func dlrange(prefix string, end int, wg *sync.WaitGroup, exit func(error)) []str
}

// 新的上下文
func newContext(user int64) *context {
func newContext(user int64, atUser int64) *context {
c := new(context)
c.usrdir = datapath + "users/" + strconv.FormatInt(user, 10) + `/`
c.usrdir = datapath + "users/" + strconv.FormatInt(atUser, 10) + `/`
_ = os.MkdirAll(c.usrdir, 0755)
c.headimgsdir = make([]string, 2)
c.headimgsdir[0] = c.usrdir + "0.gif"
c.headimgsdir[1] = c.usrdir + "1.gif"
c.headimgsdir[0] = datapath + "users/" + strconv.FormatInt(atUser, 10) + ".gif"
c.headimgsdir[1] = datapath + "users/" + strconv.FormatInt(user, 10) + ".gif"
return c
}

Expand Down
4 changes: 2 additions & 2 deletions plugin/gif/logo.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ func (cc *context) prepareLogos(s ...string) error {
for i, v := range s {
_, err := strconv.Atoi(v)
if err != nil {
err = file.DownloadTo("https://gchat.qpic.cn/gchatpic_new//--"+strings.ToUpper(v)+"/0", cc.usrdir+strconv.Itoa(i)+".gif")
err = file.DownloadTo("https://gchat.qpic.cn/gchatpic_new//--"+strings.ToUpper(v)+"/0", cc.headimgsdir[i])
} else {
err = file.DownloadTo("http://q4.qlogo.cn/g?b=qq&nk="+v+"&s=640", cc.usrdir+strconv.Itoa(i)+".gif")
err = file.DownloadTo("http://q4.qlogo.cn/g?b=qq&nk="+v+"&s=640", cc.headimgsdir[i])
}
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion plugin/gif/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,9 @@ func init() { // 插件主体
datapath = file.BOTPATH + "/" + en.DataFolder()
en.OnRegex(`^(` + strings.Join(cmd, "|") + `)[\s\S]*?(\[CQ:(image\,file=([0-9a-zA-Z]{32}).*|at.+?(\d{5,11}))\].*|(\d+))$`).
SetBlock(true).Handle(func(ctx *zero.Ctx) {
c := newContext(ctx.Event.UserID)
list := ctx.State["regex_matched"].([]string)
atUserID, _ := strconv.ParseInt(list[4]+list[5]+list[6], 10, 64)
c := newContext(ctx.Event.UserID, atUserID)
err := c.prepareLogos(list[4]+list[5]+list[6], strconv.FormatInt(ctx.Event.UserID, 10))
if err != nil {
ctx.SendChain(message.Text("ERROR: ", err))
Expand Down
78 changes: 50 additions & 28 deletions plugin/guessmusic/guessmusic.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,12 @@ func init() {
ctx.SendChain(message.Text(err))
return
}
// 猜歌环节-提供猜歌选项
files, err := os.ReadDir(pathOfMusic)
if err != nil {
return
}
getMusicSelect(ctx, files, musicName)
// 进行猜歌环节
ctx.SendChain(message.Record("file:///" + file.BOTPATH + "/" + outputPath + "0.wav"))
var next *zero.FutureEvent
Expand Down Expand Up @@ -221,26 +227,8 @@ func musicLottery(musicPath, listName string) (pathOfMusic, musicName string, er
}
return
}
// 进行随机抽取
if playlistID == 0 || !cfg.API {
musicName = getLocalMusic(files, 10)
} else {
switch rand.Intn(3) { // 三分二概率抽取API的
case 1:
musicName = getLocalMusic(files, 10)
default:
if cfg.APIURL == "" {
// 如果没有配置过API地址,尝试连接独角兽
musicName, err = downloadByOvooa(playlistID, pathOfMusic)
} else {
// 从API中抽取歌曲
musicName, err = drawByAPI(playlistID, pathOfMusic)
}
if err != nil {
musicName = getLocalMusic(files, 10)
}
}
}
// 只猜本地已经下好的歌曲
musicName = getLocalMusic(files, 10)
if musicName == "" {
err = errors.New("抽取歌曲轮空了,请重试")
}
Expand Down Expand Up @@ -295,15 +283,13 @@ func cutMusic(musicName, pathOfMusic, outputPath string) (err error) {
// 数据匹配(结果信息,答题次数,提示次数,是否结束游戏)
func gameMatch(c *zero.Ctx, beginner int64, musicInfo []string, answerTimes, tickTimes int) (message.MessageSegment, int, int, bool) {
answer := strings.Replace(c.Event.Message.String(), "-", "", 1)
// 大小写,简繁体转换
// 回答内容转小写,比对时再把标准答案转小写
answer = ConvertText(answer)
for i, element := range musicInfo {
musicInfo[i] = ConvertText(element)
}

switch {
case answer == "取消":
if c.Event.UserID == beginner {
return message.Text("游戏已取消,猜歌答案是\n", musicInfo[len(musicInfo)-1], "\n\n\n下面欣赏猜歌的歌曲"), answerTimes, tickTimes, true
return message.Text("游戏已取消,猜歌答案是\n", musicInfo[len(musicInfo)-1], "\n\n下面欣赏猜歌的歌曲"), answerTimes, tickTimes, true
}
return message.Text("你无权限取消"), answerTimes, tickTimes, false
case answer == "提示":
Expand All @@ -312,11 +298,11 @@ func gameMatch(c *zero.Ctx, beginner int64, musicInfo []string, answerTimes, tic
return message.Text("已经没有提示了哦"), answerTimes, tickTimes, false
}
return message.Text("再听这段音频,要仔细听哦"), answerTimes, tickTimes, false
case strings.Contains(musicInfo[0], answer) || strings.EqualFold(musicInfo[0], answer):
case strings.Contains(ConvertText(musicInfo[0]), answer) || strings.EqualFold(ConvertText(musicInfo[0]), answer):
return message.Text("太棒了,你猜对歌曲名了!答案是\n", musicInfo[len(musicInfo)-1], "\n\n下面欣赏猜歌的歌曲"), answerTimes, tickTimes, true
case strings.Contains(musicInfo[1], answer) || strings.EqualFold(musicInfo[1], answer):
case strings.Contains(ConvertText(musicInfo[1]), answer) || strings.EqualFold(ConvertText(musicInfo[1]), answer):
return message.Text("太棒了,你猜对歌手名了!答案是\n", musicInfo[len(musicInfo)-1], "\n\n下面欣赏猜歌的歌曲"), answerTimes, tickTimes, true
case len(musicInfo) == 4 && (strings.Contains(musicInfo[2], answer) || strings.EqualFold(musicInfo[2], answer)):
case len(musicInfo) == 4 && (strings.Contains(ConvertText(musicInfo[2]), answer) || strings.EqualFold(ConvertText(musicInfo[2]), answer)):
return message.Text("太棒了,你猜对相关信息了!答案是\n", musicInfo[len(musicInfo)-1], "\n\n下面欣赏猜歌的歌曲"), answerTimes, tickTimes, true
default:
answerTimes++
Expand All @@ -343,3 +329,39 @@ func ConvertText(input string) string {
}
return toLower
}

func getMusicSelect(ctx *zero.Ctx, files []fs.DirEntry, musicName string) {
// 生成音乐选项
var musicInfo []string
musicInfo = append(musicInfo, musicName)
for i := 1; i < 4; i++ {
musicInfo = append(musicInfo, getLocalMusic(files, 10))
for musicInfo[0] == musicInfo[i] {
musicInfo[i] = getLocalMusic(files, 10)
}
}
// 对调正确答案
j := rand.Intn(len(musicInfo))
musicInfo[0], musicInfo[j] = musicInfo[j], musicInfo[0]

musicNameSelect := "请选出正确歌曲:\n"
for i := 0; i < len(musicInfo); i++ {
// 解析歌曲信息
music := strings.Split(musicInfo[i], ".")
// 获取音乐后缀
musicType := music[len(music)-1]
if !strings.Contains(musictypelist, musicType) {
ctx.SendChain(message.Text("抽取到了歌曲:\n",
musicInfo[i], "\n该歌曲不是音乐后缀,请联系bot主人修改"))
}
// 获取音乐信息
musicInfo := strings.Split(strings.ReplaceAll(musicInfo[i], "."+musicType, ""), " - ")
infoNum := len(musicInfo)
if infoNum == 1 {
ctx.SendChain(message.Text("抽取到了歌曲:\n",
musicInfo[i], "\n该歌曲命名不符合命名规则,请联系bot主人修改"))
}
musicNameSelect += musicInfo[0] + " 歌手:" + musicInfo[1] + "\n"
}
ctx.SendChain(message.Text(musicNameSelect))
}
2 changes: 1 addition & 1 deletion plugin/guessmusic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ var (
cfg config
// 插件主体
engine = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
DisableOnDefault: false,
DisableOnDefault: true,
Brief: "猜歌插件",
Help: "------bot主人指令------\n" +
"- 设置猜歌歌库路径 [绝对路径]\n" +
Expand Down
22 changes: 21 additions & 1 deletion plugin/mcfish/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ var (
DisableOnDefault: false,
Brief: "钓鱼",
Help: "一款钓鱼模拟器\n----------指令----------\n" +
"- 钓鱼看板/钓鱼商店\n- 购买xxx\n- 购买xxx [数量]\n- 出售xxx\n- 出售xxx [数量]\n" +
"- 钓鱼看板/钓鱼商店\n- 购买xxx\n- 购买xxx [数量]\n- 出售xxx\n- 出售xxx [数量]\n- 出售所有垃圾\n" +
"- 钓鱼背包\n- 装备[xx竿|三叉戟|美西螈]\n- 附魔[诱钓|海之眷顾]\n- 修复鱼竿\n- 合成[xx竿|三叉戟]\n- 消除[绑定|宝藏]诅咒\n- 消除[绑定|宝藏]诅咒 [数量]\n" +
"- 进行钓鱼\n- 进行n次钓鱼\n- 当前装备概率明细\n" +
"规则V" + version + ":\n" +
Expand Down Expand Up @@ -530,6 +530,26 @@ func (sql *fishdb) getNumberFor(uid int64, thing string) (number int, err error)
return
}

// 获取用户的某类物品信息
func (sql *fishdb) getUserTypeInfo(uid int64, thingType string) (thingInfos []article, err error) {
name := strconv.FormatInt(uid, 10) + "Pack"
sql.Lock()
defer sql.Unlock()
userInfo := article{}
err = sql.db.Create(name, &userInfo)
if err != nil {
return
}
if !sql.db.CanFind(name, "where Type = '"+thingType+"'") {
return
}
err = sql.db.FindFor(name, &userInfo, "where Type = '"+thingType+"'", func() error {
thingInfos = append(thingInfos, userInfo)
return nil
})
return
}

/*********************************************************/
/************************商店相关函数***********************/
/*********************************************************/
Expand Down
71 changes: 71 additions & 0 deletions plugin/mcfish/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,77 @@ func init() {
}
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("出售成功,你赚到了", pice*number, msg)))
})
engine.OnRegex(`^出售所有垃圾`, getdb, refreshFish).SetBlock(true).Limit(limitSet).Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID

articles, err := dbdata.getUserTypeInfo(uid, "waste")
if err != nil {
ctx.SendChain(message.Text("[ERROR]:获取背包信息错误", err))
return
}
if len(articles) == 0 {
ctx.SendChain(message.Text("你的背包不存在该物品"))
return
}
if len(articles) > 1 {
msg := make(message.Message, 0, 3+len(articles))
msg = append(msg, message.Reply(ctx.Event.MessageID), message.Text("找到以下物品:\n"))
for i, info := range articles {
msg = append(msg, message.Text(
"[", i, "]", info.Name, " 数量: ", info.Number, "\n"))
}
ctx.Send(msg)
}

pice := 0
for _, info := range articles {
pice += (priceList[info.Name] * discountList[info.Name] / 100) * info.Number * 8 / 10
}

ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("是否接受商店将以", pice, "收购全部垃圾", "?\n回答\"\"\"\"")))
// 等待用户下一步选择
recv, cancel1 := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(是|否)$`), zero.CheckUser(ctx.Event.UserID)).Repeat()
defer cancel1()
buy := false
for {
select {
case <-time.After(time.Second * 60):
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("等待超时,取消钓鱼")))
return
case e := <-recv:
nextcmd := e.Event.Message.String()
if nextcmd == "否" {
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("已取消出售")))
return
}
buy = true
}
if buy {
break
}
}

msg := ""
curse, err := dbdata.getNumberFor(uid, "宝藏诅咒")
if err != nil {
ctx.SendChain(message.Text("[ERROR at store.go.9.3]:", err))
return
}
if curse != 0 {
msg = "\n(你身上绑定了" + strconv.Itoa(curse) + "层诅咒)"
pice = pice * (100 - 10*curse) / 100
}

for _, info := range articles {
info.Number = 0
err = dbdata.updateUserThingInfo(uid, info)
if err != nil {
ctx.SendChain(message.Text("[ERROR at store.go.6]:", err))
return
}
}
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("出售成功,你赚到了", pice, msg)))
})
engine.OnRegex(`^购买(`+strings.Join(thingList, "|")+`)\s*(\d*)$`, getdb, refreshFish).SetBlock(true).Limit(limitSet).Handle(func(ctx *zero.Ctx) {
uid := ctx.Event.UserID
numberOfPole, err := dbdata.getNumberFor(uid, "竿")
Expand Down
Loading

0 comments on commit 62894dd

Please sign in to comment.