Skip to content

Commit 7807e68

Browse files
committed
✨ add plugin Heisi
1 parent 4cd81cb commit 7807e68

6 files changed

Lines changed: 161 additions & 1 deletion

File tree

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,14 @@ print("run[CQ:image,file="+j["img"]+"]")
707707

708708
- 本地歌曲命名规则为:\n歌名 - 歌手 - 其他(歌曲出处之类)
709709

710+
</details>
711+
<details>
712+
<summary>黑丝</summary>
713+
714+
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/heisi"`
715+
716+
- [x] 来点黑丝/白丝/jk/巨乳/足控/网红
717+
710718
</details>
711719
<details>
712720
<summary>炉石</summary>

main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ import (
8686
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/gif" // 制图
8787
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/github" // 搜索GitHub仓库
8888
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/guessmusic" // 猜歌
89+
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/heisi" // 黑丝
8990
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hs" // 炉石
9091
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hyaku" // 百人一首
9192
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/image_finder" // 关键字搜图

plugin/heisi/heisi.go

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Package heisi 黑丝
2+
package heisi
3+
4+
import (
5+
"math/rand"
6+
"strconv"
7+
"unsafe"
8+
9+
fbctxext "github.com/FloatTech/floatbox/ctxext"
10+
ctrl "github.com/FloatTech/zbpctrl"
11+
"github.com/FloatTech/zbputils/control"
12+
"github.com/FloatTech/zbputils/ctxext"
13+
zero "github.com/wdvxdr1123/ZeroBot"
14+
"github.com/wdvxdr1123/ZeroBot/message"
15+
)
16+
17+
var (
18+
heisiPic []item
19+
baisiPic []item
20+
jkPic []item
21+
jurPic []item
22+
zukPic []item
23+
mcnPic []item
24+
fileList = [...]string{"heisi.bin", "baisi.bin", "jk.bin", "jur.bin", "zuk.bin", "mcn.bin"}
25+
)
26+
27+
func init() { // 插件主体
28+
engine := control.Register("heisi", &ctrl.Options[*zero.Ctx]{
29+
DisableOnDefault: false,
30+
Help: "黑丝\n" +
31+
"- 来点黑丝\n- 来点白丝\n- 来点jk\n- 来点巨乳\n- 来点足控\n- 来点网红",
32+
PublicDataFolder: "Heisi",
33+
})
34+
35+
engine.OnFullMatchGroup([]string{"来点黑丝", "来点白丝", "来点jk", "来点巨乳", "来点足控", "来点网红"}, zero.OnlyGroup, fbctxext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
36+
for i, filePath := range fileList {
37+
data, err := engine.GetLazyData(filePath, true)
38+
if err != nil {
39+
ctx.SendChain(message.Text("ERROR: ", err))
40+
return false
41+
}
42+
if len(data)%10 != 0 {
43+
ctx.SendChain(message.Text("ERROR: invalid data " + strconv.Itoa(i)))
44+
return false
45+
}
46+
s := (*slice)(unsafe.Pointer(&data))
47+
s.len /= 10
48+
s.cap /= 10
49+
switch i {
50+
case 0:
51+
heisiPic = *(*[]item)(unsafe.Pointer(s))
52+
case 1:
53+
baisiPic = *(*[]item)(unsafe.Pointer(s))
54+
case 2:
55+
jkPic = *(*[]item)(unsafe.Pointer(s))
56+
case 3:
57+
jurPic = *(*[]item)(unsafe.Pointer(s))
58+
case 4:
59+
zukPic = *(*[]item)(unsafe.Pointer(s))
60+
case 5:
61+
mcnPic = *(*[]item)(unsafe.Pointer(s))
62+
}
63+
}
64+
return true
65+
})).SetBlock(true).
66+
Handle(func(ctx *zero.Ctx) {
67+
matched := ctx.State["matched"].(string)
68+
var pic item
69+
switch matched {
70+
case "来点黑丝":
71+
pic = heisiPic[rand.Intn(len(heisiPic))]
72+
case "来点白丝":
73+
pic = baisiPic[rand.Intn(len(baisiPic))]
74+
case "来点jk":
75+
pic = jkPic[rand.Intn(len(jkPic))]
76+
case "来点巨乳":
77+
pic = jurPic[rand.Intn(len(jurPic))]
78+
case "来点足控":
79+
pic = zukPic[rand.Intn(len(zukPic))]
80+
case "来点网红":
81+
pic = mcnPic[rand.Intn(len(mcnPic))]
82+
}
83+
m := message.Message{ctxext.FakeSenderForwardNode(ctx, message.Image(pic.String()))}
84+
if id := ctx.Send(m).ID(); id == 0 {
85+
ctx.SendChain(message.Text("ERROR: 可能被风控或下载图片用时过长,请耐心等待"))
86+
}
87+
})
88+
}

plugin/heisi/packer.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package heisi
2+
3+
import (
4+
"encoding/binary"
5+
"encoding/hex"
6+
"fmt"
7+
"math/bits"
8+
)
9+
10+
const (
11+
template2021 = "http://hs.heisiwu.com/wp-content/uploads/%4d/%02d/%4d%02d16%06d-611a3%8s.jpg"
12+
templategeneral = "http://hs.heisiwu.com/wp-content/uploads/%4d/%02d/%015x"
13+
)
14+
15+
type item [10]byte
16+
17+
// String item to url
18+
func (it item) String() string {
19+
year, month := int((it[0]>>4)&0x0f), int(it[0]&0x0f)
20+
year += 2021
21+
if year == 2021 {
22+
num := binary.BigEndian.Uint32(it[1:5])
23+
dstr := hex.EncodeToString(it[5:9])
24+
return fmt.Sprintf(template2021, year, month, year, month, num, dstr)
25+
}
26+
d := binary.BigEndian.Uint64(it[1:9])
27+
isscaled := it[9]&0x80 > 0
28+
num := int(it[9] & 0x7f)
29+
trestore := fmt.Sprintf(templategeneral, year, month, d&0x0fffffff_ffffffff)
30+
if num > 0 {
31+
trestore += fmt.Sprintf("-%d", num)
32+
}
33+
if isscaled {
34+
trestore += "-scaled"
35+
}
36+
d = bits.RotateLeft64(d, 4) & 0x0f
37+
switch d {
38+
case 0:
39+
trestore += ".jpg"
40+
case 1:
41+
trestore += ".png"
42+
case 2:
43+
trestore += ".webp"
44+
default:
45+
return "invalid ext"
46+
}
47+
return trestore
48+
}

plugin/heisi/slice.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package heisi
2+
3+
import "unsafe"
4+
5+
// slice is the runtime representation of a slice.
6+
// It cannot be used safely or portably and its representation may
7+
// change in a later release.
8+
//
9+
// Unlike reflect.SliceHeader, its Data field is sufficient to guarantee the
10+
// data it references will not be garbage collected.
11+
type slice struct {
12+
data unsafe.Pointer
13+
len int
14+
cap int
15+
}

0 commit comments

Comments
 (0)