mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-02-09 08:30:26 +00:00
Compare commits
64 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73b879a6f4 | ||
|
|
a5d2e3dfc3 | ||
|
|
0ea804fc86 | ||
|
|
17bfa2a35c | ||
|
|
ff3d1d1de3 | ||
|
|
3a31802735 | ||
|
|
a514bde4e6 | ||
|
|
7f90ba278a | ||
|
|
2e77703571 | ||
|
|
192eef2bbb | ||
|
|
73ecc47e4c | ||
|
|
714df78ea2 | ||
|
|
f4f50acb1d | ||
|
|
8c24194772 | ||
|
|
844b727859 | ||
|
|
148f271586 | ||
|
|
b062198fae | ||
|
|
1c57a64002 | ||
|
|
13bb760f9f | ||
|
|
6c1257184b | ||
|
|
b0463b3cb4 | ||
|
|
1bb8e8b058 | ||
|
|
209b2e8a1f | ||
|
|
0c55c743f7 | ||
|
|
ba7c6cb0a0 | ||
|
|
d3e587f935 | ||
|
|
36190a4f6a | ||
|
|
54d9486c06 | ||
|
|
fe6130872b | ||
|
|
5e41c15d88 | ||
|
|
e776d02d98 | ||
|
|
cc39d0fdb4 | ||
|
|
1456bed668 | ||
|
|
8d2da4199d | ||
|
|
50e75b2257 | ||
|
|
a6e82d578a | ||
|
|
5b6ab7e20d | ||
|
|
23fea2dae9 | ||
|
|
97c1985479 | ||
|
|
035ed3bd13 | ||
|
|
3e04445cac | ||
|
|
f0078bb23f | ||
|
|
1a8ebe02fb | ||
|
|
de986d8be8 | ||
|
|
ab7daa6bdc | ||
|
|
0bf3253cbb | ||
|
|
21269ee835 | ||
|
|
df927d0b7f | ||
|
|
6a3456f4b0 | ||
|
|
db1d583a37 | ||
|
|
146ea6812e | ||
|
|
99b14e183a | ||
|
|
cb52bf6af7 | ||
|
|
a534c9efbd | ||
|
|
7ac397373d | ||
|
|
73c6f4795e | ||
|
|
598efe182c | ||
|
|
a9bb078079 | ||
|
|
673c715d2f | ||
|
|
dbda1b466d | ||
|
|
b7e21fc111 | ||
|
|
6bff62b91b | ||
|
|
5485cc3be9 | ||
|
|
ba0ef37b74 |
20
.github/workflows/pull.yml
vendored
20
.github/workflows/pull.yml
vendored
@@ -1,6 +1,24 @@
|
||||
name: PullLint
|
||||
on: [ pull_request ]
|
||||
on:
|
||||
pull_request_target:
|
||||
types: [assigned, opened, synchronize, reopened]
|
||||
jobs:
|
||||
# This workflow closes invalid PR
|
||||
close-pr:
|
||||
name: closepr
|
||||
# The type of runner that the job will run on
|
||||
runs-on: ubuntu-latest
|
||||
permissions: write-all
|
||||
|
||||
# Steps represent a sequence of tasks that will be executed as part of the job
|
||||
steps:
|
||||
- name: Close PR if commit message contains ".go"
|
||||
if: contains(github.event.pull_request.title, '.go')
|
||||
uses: superbrothers/close-pull-request@v3
|
||||
with:
|
||||
# Optional. Post a issue comment just before closing a pull request.
|
||||
comment: "非法PR. 请`fork`后修改自己的仓库, 而不是向主仓库提交更改. 如果您确信您的PR是为了给主仓库新增功能或修复bug, 请更改默认PR标题."
|
||||
|
||||
golangci:
|
||||
name: lint
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
4
.github/workflows/push.yml
vendored
4
.github/workflows/push.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
||||
- name: Check out code into the Go module directory
|
||||
uses: actions/checkout@master
|
||||
|
||||
- name: golangci-lint
|
||||
- name: Run Lint
|
||||
uses: golangci/golangci-lint-action@master
|
||||
with:
|
||||
version: latest
|
||||
@@ -25,7 +25,7 @@ jobs:
|
||||
git config --local user.name 'github-actions[bot]'
|
||||
git config --local user.email '41898282+github-actions[bot]@users.noreply.github.com'
|
||||
git add --all
|
||||
git commit -m "🎨 改进代码样式"
|
||||
git commit -m "chore(lint): 改进代码样式"
|
||||
|
||||
- name: Create Pull Request
|
||||
if: ${{ !github.head_ref }}
|
||||
|
||||
27
README.md
27
README.md
@@ -15,11 +15,17 @@
|
||||
[](https://github.com/takayama-lily/oicq)
|
||||
[](https://github.com/mamoe/mirai)
|
||||
|
||||
|
||||
|
||||
[](https://goreportcard.com/badge/github.com/FloatTech/ZeroBot-Plugin)
|
||||
[](https://t.me/zerobotplugin)
|
||||
[](https://github.com/wdvxdr1123/ZeroBot)
|
||||
|
||||
|
||||
|
||||
[](https://raw.githubusercontent.com/FloatTech/ZeroBot-Plugin/master/LICENSE)
|
||||
[](https://jq.qq.com/?_wv=1027&k=QMb7x1mM)
|
||||
[](https://jq.qq.com/?_wv=1027&k=QMb7x1mM)
|
||||
[](https://pd.qq.com/s/fjkx81mnr)
|
||||
[](https://t.me/zerobotplugin)
|
||||
|
||||
本项目符合 [OneBot](https://github.com/howmanybots/onebot) 标准,可基于以下项目与机器人框架/平台进行交互
|
||||
@@ -33,6 +39,8 @@
|
||||
|
||||
</div>
|
||||
|
||||
> 专为[后 go-cqhttp 时代](https://github.com/Mrs4s/go-cqhttp/issues/2471)开发迁移的`类zbp`新机器人现已出炉,基于官方api,稳定不风控: [NanoBot-Plugin](https://github.com/FloatTech/NanoBot-Plugin)
|
||||
|
||||
> 如果您不知道什么是 [OneBot](https://github.com/howmanybots/onebot) 或不希望运行多个程序,还可以直接前往 [gocqzbp](https://github.com/FloatTech/gocqzbp) 的 [Release](https://github.com/FloatTech/gocqzbp/releases) 页面下载单一可执行文件或前往 [Packages](https://github.com/FloatTech/gocqzbp/pkgs/container/gocqzbp) 页面使用`docker`,运行后按提示登录即可。
|
||||
|
||||
> 如果您对开发插件感兴趣,欢迎加入[ZeroBot-Plugin-Playground](https://github.com/FloatTech/ZeroBot-Plugin-Playground)
|
||||
@@ -959,6 +967,23 @@ print("run[CQ:image,file="+j["img"]+"]")
|
||||
|
||||
- [x] 吟唱提示[xxxx]
|
||||
|
||||
</details>
|
||||
<details>
|
||||
<summary>钓鱼模拟器</summary>
|
||||
|
||||
`import _ "github.com/FloatTech/ZeroBot-Plugin/plugin/mcfish"`
|
||||
|
||||
- [x] 钓鱼商店
|
||||
- [x] 购买xxx [数量]
|
||||
- [x] 出售xxx [数量]
|
||||
- [x] 钓鱼背包
|
||||
- [x] 装备[xx竿|三叉戟|美西螈]
|
||||
- [x] 附魔[诱钓|海之眷顾]
|
||||
- [x] 修复鱼竿
|
||||
- [x] 合成[xx竿|三叉戟]
|
||||
- [x] 进行钓鱼
|
||||
- [x] 进行n次钓鱼
|
||||
|
||||
</details>
|
||||
<details>
|
||||
<summary>简易midi音乐制作</summary>
|
||||
|
||||
2
data
2
data
Submodule data updated: d5ec04118f...9b983625ca
18
go.mod
18
go.mod
@@ -4,15 +4,15 @@ go 1.20
|
||||
|
||||
require (
|
||||
github.com/Baidu-AIP/golang-sdk v1.1.1
|
||||
github.com/FloatTech/AnimeAPI v1.6.1-0.20230827161910-7e6a3d93a0ba
|
||||
github.com/FloatTech/floatbox v0.0.0-20230827160415-f0865337a824
|
||||
github.com/FloatTech/AnimeAPI v1.7.1-0.20231017135344-aefd1d56e900
|
||||
github.com/FloatTech/floatbox v0.0.0-20231107124407-e38535efa2a2
|
||||
github.com/FloatTech/gg v1.1.3-0.20230226151425-6ea91286ba08
|
||||
github.com/FloatTech/imgfactory v0.2.2-0.20230413152719-e101cc3606ef
|
||||
github.com/FloatTech/rendercard v0.0.10-0.20230223064326-45d29fa4ede9
|
||||
github.com/FloatTech/sqlite v1.6.2
|
||||
github.com/FloatTech/sqlite v1.6.3
|
||||
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b
|
||||
github.com/FloatTech/zbpctrl v1.5.3-0.20230514154630-b74e6fcca380
|
||||
github.com/FloatTech/zbputils v1.6.2-0.20230728081122-94d4d957f3bf
|
||||
github.com/FloatTech/zbpctrl v1.6.0
|
||||
github.com/FloatTech/zbputils v1.7.1-0.20231107124514-083e678fbfe6
|
||||
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e
|
||||
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5
|
||||
github.com/antchfx/htmlquery v1.2.5
|
||||
@@ -29,15 +29,17 @@ require (
|
||||
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
|
||||
github.com/jinzhu/gorm v1.9.16
|
||||
github.com/jozsefsallai/gophersauce v1.0.1
|
||||
github.com/kanrichan/resvg-go v0.0.2-0.20231001163256-63db194ca9f5
|
||||
github.com/lithammer/fuzzysearch v1.1.5
|
||||
github.com/mroth/weightedrand v1.0.0
|
||||
github.com/notnil/chess v1.9.0
|
||||
github.com/pkg/errors v0.9.1
|
||||
github.com/quic-go/quic-go v0.38.1
|
||||
github.com/shirou/gopsutil/v3 v3.23.1
|
||||
github.com/sirupsen/logrus v1.9.0
|
||||
github.com/sirupsen/logrus v1.9.3
|
||||
github.com/tidwall/gjson v1.14.4
|
||||
github.com/wcharczuk/go-chart/v2 v2.1.0
|
||||
github.com/wdvxdr1123/ZeroBot v1.7.4
|
||||
github.com/wdvxdr1123/ZeroBot v1.7.5-0.20231009162356-57f71b9f5258
|
||||
gitlab.com/gomidi/midi/v2 v2.0.25
|
||||
golang.org/x/image v0.3.0
|
||||
golang.org/x/sys v0.8.0
|
||||
@@ -46,6 +48,7 @@ require (
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/ajstarks/svgo v0.0.0-20200320125537-f189e35d30ca // indirect
|
||||
github.com/antchfx/xpath v1.2.1 // indirect
|
||||
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 // indirect
|
||||
github.com/faiface/beep v1.1.0 // indirect
|
||||
@@ -74,6 +77,7 @@ require (
|
||||
github.com/quic-go/qpack v0.4.0 // indirect
|
||||
github.com/quic-go/qtls-go1-20 v0.3.3 // indirect
|
||||
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0 // indirect
|
||||
github.com/tetratelabs/wazero v1.5.0 // indirect
|
||||
github.com/tidwall/match v1.1.1 // indirect
|
||||
github.com/tidwall/pretty v1.2.0 // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.11 // indirect
|
||||
|
||||
36
go.sum
36
go.sum
@@ -2,29 +2,31 @@ github.com/Baidu-AIP/golang-sdk v1.1.1 h1:RQsAmgDSAkiq22I6n7XJ2t3afgzFeqjY46FGhv
|
||||
github.com/Baidu-AIP/golang-sdk v1.1.1/go.mod h1:bXnGw7xPeKt8aF7UCELKrV6UZ/46spItONK1RQBQj1Y=
|
||||
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
|
||||
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
|
||||
github.com/FloatTech/AnimeAPI v1.6.1-0.20230827161910-7e6a3d93a0ba h1:0tqYkIc6RK8P3/cGEMSoBBwhiEHKPJC+1F7xlVkikgY=
|
||||
github.com/FloatTech/AnimeAPI v1.6.1-0.20230827161910-7e6a3d93a0ba/go.mod h1:6vYu7bW5gPQsBnXB+I6yk+eJQaaAwusoQ/I/wQMwOAI=
|
||||
github.com/FloatTech/floatbox v0.0.0-20230827160415-f0865337a824 h1:w72fzQg1Y9+VLSRl7iKzaZ6fG3myyMJfpOSajcjaMDM=
|
||||
github.com/FloatTech/floatbox v0.0.0-20230827160415-f0865337a824/go.mod h1:FwQm6wk+b4wuW54KCKn3zccMX47Q5apnHD/Yakzv0fI=
|
||||
github.com/FloatTech/AnimeAPI v1.7.1-0.20231017135344-aefd1d56e900 h1:UPXoj+lMHFBulp/m+F7uHju0MXslFKQqEplDDz/nOiU=
|
||||
github.com/FloatTech/AnimeAPI v1.7.1-0.20231017135344-aefd1d56e900/go.mod h1:7Olb5U9q1oeayRZQTNBhXQNMf8QT4T9hccsn38IEt/U=
|
||||
github.com/FloatTech/floatbox v0.0.0-20231107124407-e38535efa2a2 h1:O4kptIzgYzNwZlBARZFv8EkA40yB6M5LGxxIF7NKLR8=
|
||||
github.com/FloatTech/floatbox v0.0.0-20231107124407-e38535efa2a2/go.mod h1:TeTlp+hTxpJti4JSdmUqzxGEr4wUBOVct9YWBepilpc=
|
||||
github.com/FloatTech/gg v1.1.3-0.20230226151425-6ea91286ba08 h1:dPLeoiTVSBlgls+66EB/UJ2e38BaASmBN5nANaycSBU=
|
||||
github.com/FloatTech/gg v1.1.3-0.20230226151425-6ea91286ba08/go.mod h1:uzPzAeT35egARdRuu+1oyjU3CmTwCceoq3Vvje7LpcI=
|
||||
github.com/FloatTech/imgfactory v0.2.2-0.20230413152719-e101cc3606ef h1:CJbK/2FRwPuZpeb6M4sWK2d7oXDnBEGhpkQuQrgc91A=
|
||||
github.com/FloatTech/imgfactory v0.2.2-0.20230413152719-e101cc3606ef/go.mod h1:el5hGpj1C1bDRxcTXYRwEivDCr40zZeJpcrLrB1fajs=
|
||||
github.com/FloatTech/rendercard v0.0.10-0.20230223064326-45d29fa4ede9 h1:hffajvmQFfP68U6wUwHemPuuwCUoss+SEFfoLYwbGwE=
|
||||
github.com/FloatTech/rendercard v0.0.10-0.20230223064326-45d29fa4ede9/go.mod h1:NBFPhWae4hqVMeG8ELBBnUQkKce3nDjkljVn6PdiUNs=
|
||||
github.com/FloatTech/sqlite v1.6.2 h1:FytbExjpvYalZxxITtmSenHiPGLPUvlz47LY/P0SCCw=
|
||||
github.com/FloatTech/sqlite v1.6.2/go.mod h1:zFbHzRfB+CJ+VidfjuVbrcin3DAz283F7hF1hIeHzpY=
|
||||
github.com/FloatTech/sqlite v1.6.3 h1:MQkqBNlkPuCoKQQgoNLuTL/2Ci3tBTFAnVYBdD0Wy4M=
|
||||
github.com/FloatTech/sqlite v1.6.3/go.mod h1:zFbHzRfB+CJ+VidfjuVbrcin3DAz283F7hF1hIeHzpY=
|
||||
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b h1:tvciXWq2nuvTbFeJGLDNIdRX3BI546D3O7k7vrVueZw=
|
||||
github.com/FloatTech/ttl v0.0.0-20220715042055-15612be72f5b/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
|
||||
github.com/FloatTech/zbpctrl v1.5.3-0.20230514154630-b74e6fcca380 h1:qmwoT8xVaND01aCdwy+5/j6z490nehQWZAVyTBN8ahU=
|
||||
github.com/FloatTech/zbpctrl v1.5.3-0.20230514154630-b74e6fcca380/go.mod h1:gkGC1C1eEUd/Ld/ja68zas5j2ZktIZCdnj2FMaM+Au0=
|
||||
github.com/FloatTech/zbputils v1.6.2-0.20230728081122-94d4d957f3bf h1:PwH9aMnmN+m204cVIqUrI3e7nsdQi/IGW012Fjzb1bs=
|
||||
github.com/FloatTech/zbputils v1.6.2-0.20230728081122-94d4d957f3bf/go.mod h1:JRnGR7EGeEQgxOs+c0rZAhrS9Es2BTcGHdIDHXIPRzQ=
|
||||
github.com/FloatTech/zbpctrl v1.6.0 h1:BWg9aRR4bUCmNNKj6GPH0TmzFRWYImIi6rQcQTTYRs4=
|
||||
github.com/FloatTech/zbpctrl v1.6.0/go.mod h1:i3GGM5K4HiDsXzvmXQSYoH1QT3tsSaAHjRzHwKGsHG0=
|
||||
github.com/FloatTech/zbputils v1.7.1-0.20231107124514-083e678fbfe6 h1:EMdvLnt6i5dSFloLD1klOM8bdoFZqTtILcMCciOpcMo=
|
||||
github.com/FloatTech/zbputils v1.7.1-0.20231107124514-083e678fbfe6/go.mod h1:4oXgjQ6bGosAF4GbuL/keAhTrGWOV369X5X0ISFebmw=
|
||||
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
||||
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e h1:wR3MXQ3VbUlPKOOUwLOYgh/QaJThBTYtsl673O3lqSA=
|
||||
github.com/RomiChan/syncx v0.0.0-20221202055724-5f842c53020e/go.mod h1:vD7Ra3Q9onRtojoY5sMCLQ7JBgjUsrXDnDKyFxqpf9w=
|
||||
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5 h1:bBmmB7he0iVN4m5mcehfheeRUEer/Avo4ujnxI3uCqs=
|
||||
github.com/RomiChan/websocket v1.4.3-0.20220227141055-9b2c6168c9c5/go.mod h1:0UcFaCkhp6vZw6l5Dpq0Dp673CoF9GdvA8lTfst0GiU=
|
||||
github.com/ajstarks/svgo v0.0.0-20200320125537-f189e35d30ca h1:kWzLcty5V2rzOqJM7Tp/MfSX0RMSI1x4IOLApEefYxA=
|
||||
github.com/ajstarks/svgo v0.0.0-20200320125537-f189e35d30ca/go.mod h1:K08gAheRH3/J6wwsYMMT4xOr94bZjxIelGM0+d/wbFw=
|
||||
github.com/andybalholm/cascadia v1.1.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
|
||||
github.com/antchfx/htmlquery v1.2.5 h1:1lXnx46/1wtv1E/kzmH8vrfMuUKYgkdDBA9pIdMJnk4=
|
||||
github.com/antchfx/htmlquery v1.2.5/go.mod h1:2MCVBzYVafPBmKbrmwB9F5xdd+IEgRY61ci2oOsOQVw=
|
||||
@@ -127,6 +129,8 @@ github.com/jinzhu/now v1.0.1 h1:HjfetcXq097iXP0uoPCdnM4Efp5/9MsM0/M+XOTeR3M=
|
||||
github.com/jinzhu/now v1.0.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
|
||||
github.com/jozsefsallai/gophersauce v1.0.1 h1:BA3ovtQRrAb1qYU9JoRLbDHpxnDunlNcEkEfhCvDDCM=
|
||||
github.com/jozsefsallai/gophersauce v1.0.1/go.mod h1:YVEI7djliMTmZ1Vh01YPF8bUHi+oKhe3yXgKf1T49vg=
|
||||
github.com/kanrichan/resvg-go v0.0.2-0.20231001163256-63db194ca9f5 h1:BXnB1Gz4y/zwQh+ZFNy7rgd+ZfMOrwRr4uZSHEI+ieY=
|
||||
github.com/kanrichan/resvg-go v0.0.2-0.20231001163256-63db194ca9f5/go.mod h1:c9+VS9GaommgIOzNWb5ze4lYwfT8BZ2UDyGiuQTT7yc=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||
@@ -152,6 +156,8 @@ github.com/mroth/weightedrand v1.0.0 h1:V8JeHChvl2MP1sAoXq4brElOcza+jxLkRuwvtQu8
|
||||
github.com/mroth/weightedrand v1.0.0/go.mod h1:3p2SIcC8al1YMzGhAIoXD+r9olo/g/cdJgAD905gyNE=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 h1:zYyBkD/k9seD2A7fsi6Oo2LfFZAehjjQMERAvZLEDnQ=
|
||||
github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646/go.mod h1:jpp1/29i3P1S/RLdc7JQKbRpFeM1dOBd8T9ki5s+AY8=
|
||||
github.com/notnil/chess v1.9.0 h1:YMxR5kUVjtwcuFptGU0/3q7eG3MSHQNbg0VUekvRKV0=
|
||||
github.com/notnil/chess v1.9.0/go.mod h1:cRuJUIBFq9Xki05TWHJxHYkC+fFpq45IWwk94DdlCrA=
|
||||
github.com/onsi/ginkgo/v2 v2.9.5 h1:+6Hr4uxzP4XIUyAkg61dWBw8lb/gc4/X5luuxN/EC+Q=
|
||||
github.com/onsi/ginkgo/v2 v2.9.5/go.mod h1:tvAoo1QUJwNEU2ITftXTpR7R1RbCzoZUOs3RonqW57k=
|
||||
github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE=
|
||||
@@ -177,8 +183,8 @@ github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZV
|
||||
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
|
||||
github.com/shirou/gopsutil/v3 v3.23.1 h1:a9KKO+kGLKEvcPIs4W62v0nu3sciVDOOOPUD0Hz7z/4=
|
||||
github.com/shirou/gopsutil/v3 v3.23.1/go.mod h1:NN6mnm5/0k8jw4cBfCnJtr5L7ErOTg18tMNpgFkn0hA=
|
||||
github.com/sirupsen/logrus v1.9.0 h1:trlNQbNUG3OdDrDil03MCb1H2o9nJ1x4/5LYw7byDE0=
|
||||
github.com/sirupsen/logrus v1.9.0/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
|
||||
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||
@@ -188,6 +194,8 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||
github.com/stretchr/testify v1.8.1 h1:w7B6lhMri9wdJUVmEZPGGhZzrYTPvgJArz7wNPgYKsk=
|
||||
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||
github.com/tetratelabs/wazero v1.5.0 h1:Yz3fZHivfDiZFUXnWMPUoiW7s8tC1sjdBtlJn08qYa0=
|
||||
github.com/tetratelabs/wazero v1.5.0/go.mod h1:0U0G41+ochRKoPKCJlh0jMg1CHkyfK8kDqiirMmKY8A=
|
||||
github.com/tidwall/gjson v1.14.4 h1:uo0p8EbA09J7RQaflQ1aBRffTR7xedD2bcIVSYxLnkM=
|
||||
github.com/tidwall/gjson v1.14.4/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
@@ -200,8 +208,8 @@ github.com/tklauser/numcpus v0.6.0 h1:kebhY2Qt+3U6RNK7UqpYNA+tJ23IBEGKkB7JQBfDYm
|
||||
github.com/tklauser/numcpus v0.6.0/go.mod h1:FEZLMke0lhOUG6w2JadTzp0a+Nl8PF/GFkQ5UVIcaL4=
|
||||
github.com/wcharczuk/go-chart/v2 v2.1.0 h1:tY2slqVQ6bN+yHSnDYwZebLQFkphK4WNrVwnt7CJZ2I=
|
||||
github.com/wcharczuk/go-chart/v2 v2.1.0/go.mod h1:yx7MvAVNcP/kN9lKXM/NTce4au4DFN99j6i1OwDclNA=
|
||||
github.com/wdvxdr1123/ZeroBot v1.7.4 h1:+148rELpf/FCDW2EuvKqpb9bNKcwKRtoh16s2sIb5SE=
|
||||
github.com/wdvxdr1123/ZeroBot v1.7.4/go.mod h1:y29UIOy0RD3P+0meDNIWRhcJF3jtWPN9xP9hgt/AJAU=
|
||||
github.com/wdvxdr1123/ZeroBot v1.7.5-0.20231009162356-57f71b9f5258 h1:Q0dKoj9SHrR8WjjlcX+eyYBjQKqBn/x1pdJJO1IIOxQ=
|
||||
github.com/wdvxdr1123/ZeroBot v1.7.5-0.20231009162356-57f71b9f5258/go.mod h1:y29UIOy0RD3P+0meDNIWRhcJF3jtWPN9xP9hgt/AJAU=
|
||||
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
|
||||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
|
||||
github.com/yusufpapurcu/wmi v1.2.2 h1:KBNDSne4vP5mbSWnJbO+51IMOXJB67QiYCSBrubbPRg=
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
package banner
|
||||
|
||||
// Version ...
|
||||
var Version = "v1.7.3"
|
||||
var Version = "v1.7.6"
|
||||
|
||||
// Copyright ...
|
||||
var Copyright = "© 2020 - 2023 FloatTech"
|
||||
|
||||
// Banner ...
|
||||
var Banner = "* OneBot + ZeroBot + Golang\n" +
|
||||
"* Version " + Version + " - 2023-08-28 16:14:08 +0800 CST\n" +
|
||||
"* Version " + Version + " - 2023-11-08 14:13:37 +0900 JST\n" +
|
||||
"* Copyright " + Copyright + ". All Rights Reserved.\n" +
|
||||
"* Project: https://github.com/FloatTech/ZeroBot-Plugin"
|
||||
|
||||
@@ -27,7 +27,7 @@ var Banner = "* OneBot + ZeroBot + Golang\n" +
|
||||
"* Project: https://github.com/FloatTech/ZeroBot-Plugin"
|
||||
`
|
||||
|
||||
const timeformat = `2006-01-02 15:04:05 +0800 CST`
|
||||
const timeformat = `2006-01-02 15:04:05 +0900 JST`
|
||||
|
||||
func main() {
|
||||
f, err := os.Create("banner/banner.go")
|
||||
|
||||
24
main.go
24
main.go
@@ -34,7 +34,7 @@ import (
|
||||
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/chat" // 基础词库
|
||||
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/sleep_manage" // 统计睡眠时间
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/sleepmanage" // 统计睡眠时间
|
||||
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/atri" // ATRI词库
|
||||
|
||||
@@ -61,19 +61,20 @@ import (
|
||||
// vvvv //
|
||||
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ahsai" // ahsai tts
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ai_false" // 服务器监控
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/aifalse" // 服务器监控
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/aipaint" // ai绘图
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/aiwife" // 随机老婆
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/alipayvoice" // 支付宝到账语音
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/autowithdraw" // 触发者撤回时也自动撤回
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/b14" // base16384加解密
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/baidu" // 百度一下
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/baiduaudit" // 百度内容审核
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/base16384" // base16384加解密
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/base64gua" // base64卦加解密
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/baseamasiro" // base天城文加解密
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/bilibili" // b站相关
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/book_review" // 哀伤雪刃吧推书记录
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/bookreview" // 哀伤雪刃吧推书记录
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/cangtoushi" // 藏头诗
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/chess" // 国际象棋
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/choose" // 选择困难症帮手
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/chouxianghua" // 说抽象话
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/chrev" // 英文字符翻转
|
||||
@@ -85,7 +86,7 @@ import (
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/dish" // 程序员做饭指南
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/drawlots" // 多功能抽签
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/dress" // 女装
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/drift_bottle" // 漂流瓶
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/driftbottle" // 漂流瓶
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/emojimix" // 合成emoji
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/event" // 好友申请群聊邀请事件处理
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/font" // 渲染任意文字到图片
|
||||
@@ -99,7 +100,7 @@ import (
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hitokoto" // 一言
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hs" // 炉石
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/hyaku" // 百人一首
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/image_finder" // 关键字搜图
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/imgfinder" // 关键字搜图
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/inject" // 注入指令
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/jandan" // 煎蛋网无聊图
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/jiami" // 兽语加密
|
||||
@@ -108,17 +109,18 @@ import (
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/kfccrazythursday" // 疯狂星期四
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/lolicon" // lolicon 随机图片
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/magicprompt" // magicprompt吟唱提示
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/mcfish" // 钓鱼模拟器
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/midicreate" // 简易midi音乐制作
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/moegoe" // 日韩 VITS 模型拟声
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/moyu" // 摸鱼
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/moyu_calendar" // 摸鱼人日历
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/moyucalendar" // 摸鱼人日历
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/music" // 点歌
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nativesetu" // 本地涩图
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nativewife" // 本地老婆
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nbnhhsh" // 拼音首字母缩写释义工具
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/nihongo" // 日语语法学习
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/novel" // 铅笔小说网搜索
|
||||
_ "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/qqwife" // 一群一天一夫一妻制群老婆
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/quan" // QQ权重查询
|
||||
@@ -138,16 +140,16 @@ import (
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/tracemoe" // 搜番
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/translation" // 翻译
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/vitsnyaru" // vits猫雷
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/vtb_quotation" // vtb语录
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/vtbmusic" // vtb点歌
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/vtbquotation" // vtb语录
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wallet" // 钱包
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wangyiyun" // 网易云音乐热评
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wantquotes" // 据意查句
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/warframeapi" // warframeAPI插件
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wenben" // 文本指令大全
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wenxinAI" // 百度文心AI画图
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wenxinvilg" // 百度文心AI画图
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wife" // 抽老婆
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/word_count" // 聊天热词
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wordcount" // 聊天热词
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/wordle" // 猜单词
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ygo" // 游戏王相关插件
|
||||
_ "github.com/FloatTech/ZeroBot-Plugin/plugin/ymgal" // 月幕galgame
|
||||
|
||||
@@ -27,7 +27,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("ahsai", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "フリーテキスト音声合成",
|
||||
Help: "- 使[伊織弓鶴|紲星あかり|結月ゆかり|京町セイカ|東北きりたん|東北イタコ|ついなちゃん標準語|ついなちゃん関西弁|音街ウナ|琴葉茜|吉田くん|民安ともえ|桜乃そら|月読アイ|琴葉葵|東北ずん子|月読ショウタ|水奈瀬コウ]说(日语)",
|
||||
|
||||
@@ -5,6 +5,7 @@ import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"image"
|
||||
"image/color"
|
||||
"math"
|
||||
"runtime"
|
||||
"strconv"
|
||||
@@ -45,13 +46,16 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
boottime = time.Now()
|
||||
bgdata *[]byte
|
||||
bgcount uintptr
|
||||
boottime = time.Now()
|
||||
bgdata *[]byte
|
||||
bgcount uintptr
|
||||
isday bool
|
||||
lightcolor = [3][4]uint8{{255, 70, 0, 255}, {255, 165, 0, 255}, {145, 240, 145, 255}}
|
||||
darkcolor = [3][4]uint8{{215, 50, 0, 255}, {205, 135, 0, 255}, {115, 200, 115, 255}}
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("aifalse", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "自检, 全局限速",
|
||||
Help: "- 查询计算机当前活跃度: [检查身体 | 自检 | 启动自检 | 系统状态]\n" +
|
||||
@@ -70,7 +74,26 @@ func init() { // 插件主体
|
||||
}
|
||||
engine.OnFullMatchGroup([]string{"检查身体", "自检", "启动自检", "系统状态"}, zero.AdminPermission).SetBlock(true).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
img, err := drawstatus(ctx.State["manager"].(*ctrl.Control[*zero.Ctx]), ctx.Event.SelfID, zero.BotConfig.NickName[0])
|
||||
now := time.Now().Hour()
|
||||
isday = now > 7 && now < 19
|
||||
|
||||
botrunstatus := ctx.CallAction("get_status", zero.Params{}).Data
|
||||
botverisoninfo := ctx.GetVersionInfo()
|
||||
sb := &strings.Builder{}
|
||||
sb.WriteString("在线(")
|
||||
sb.WriteString(botverisoninfo.Get("app_name").String())
|
||||
sb.WriteString("-")
|
||||
sb.WriteString(botverisoninfo.Get("app_version").String())
|
||||
sb.WriteString(") | 收")
|
||||
sb.WriteString(botrunstatus.Get("stat").Get("message_received").String())
|
||||
sb.WriteString(" | 发")
|
||||
sb.WriteString(botrunstatus.Get("stat").Get("message_sent").String())
|
||||
sb.WriteString(" | 群")
|
||||
sb.WriteString(strconv.Itoa(len(ctx.GetGroupList().Array())))
|
||||
sb.WriteString(" | 好友")
|
||||
sb.WriteString(strconv.Itoa(len(ctx.GetFriendList().Array())))
|
||||
|
||||
img, err := drawstatus(ctx.State["manager"].(*ctrl.Control[*zero.Ctx]), ctx.Event.SelfID, zero.BotConfig.NickName[0], sb.String())
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
@@ -122,7 +145,7 @@ func init() { // 插件主体
|
||||
})
|
||||
}
|
||||
|
||||
func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg image.Image, err error) {
|
||||
func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string, botrunstatus string) (sendimg image.Image, err error) {
|
||||
diskstate, err := diskstate()
|
||||
if err != nil {
|
||||
return
|
||||
@@ -194,6 +217,13 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
defer bwg.Done()
|
||||
blurback = imaging.Blur(canvas.Image(), 8)
|
||||
}()
|
||||
|
||||
if !isday {
|
||||
canvas.SetRGBA255(0, 0, 0, 50)
|
||||
canvas.DrawRectangle(0, 0, cw, ch)
|
||||
canvas.Fill()
|
||||
}
|
||||
|
||||
wg := &sync.WaitGroup{}
|
||||
wg.Add(5)
|
||||
|
||||
@@ -211,9 +241,9 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
|
||||
titlecard.DrawRoundedRectangle(1, 1, float64(titlecard.W()-1*2), float64(titlecardh-1*2), 16)
|
||||
titlecard.SetLineWidth(3)
|
||||
titlecard.SetRGBA255(255, 255, 255, 100)
|
||||
titlecard.SetColor(colorswitch(100))
|
||||
titlecard.StrokePreserve()
|
||||
titlecard.SetRGBA255(255, 255, 255, 140)
|
||||
titlecard.SetColor(colorswitch(140))
|
||||
titlecard.Fill()
|
||||
|
||||
titlecard.DrawImage(avatarf.Circle(0).Image(), (titlecardh-avatarf.H())/2, (titlecardh-avatarf.H())/2)
|
||||
@@ -224,7 +254,7 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
}
|
||||
fw, _ := titlecard.MeasureString(botname)
|
||||
|
||||
titlecard.SetRGBA255(30, 30, 30, 255)
|
||||
titlecard.SetColor(fontcolorswitch())
|
||||
|
||||
titlecard.DrawStringAnchored(botname, float64(titlecardh)+fw/2, float64(titlecardh)*0.5/2, 0.5, 0.5)
|
||||
|
||||
@@ -232,20 +262,24 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
titlecard.SetRGBA255(30, 30, 30, 180)
|
||||
titlecard.SetColor(fontcolorswitch())
|
||||
|
||||
titlecard.NewSubPath()
|
||||
titlecard.MoveTo(float64(titlecardh), float64(titlecardh)/2)
|
||||
titlecard.LineTo(float64(titlecard.W()-titlecardh), float64(titlecardh)/2)
|
||||
titlecard.Stroke()
|
||||
|
||||
fw, _ = titlecard.MeasureString(botrunstatus)
|
||||
|
||||
titlecard.DrawStringAnchored(botrunstatus, float64(titlecardh)+fw/2, float64(titlecardh)*(0.5+0.25/2), 0.5, 0.5)
|
||||
|
||||
brt, err := botruntime()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fw, _ = titlecard.MeasureString(brt)
|
||||
|
||||
titlecard.DrawStringAnchored(brt, float64(titlecardh)+fw/2, float64(titlecardh)*(0.5+0.25/2), 0.5, 0.5)
|
||||
titlecard.DrawStringAnchored(brt, float64(titlecardh)+fw/2, float64(titlecardh)*(0.5+0.5/2), 0.5, 0.5)
|
||||
|
||||
bs, err := botstatus()
|
||||
if err != nil {
|
||||
@@ -253,7 +287,7 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
}
|
||||
fw, _ = titlecard.MeasureString(bs)
|
||||
|
||||
titlecard.DrawStringAnchored(bs, float64(titlecardh)+fw/2, float64(titlecardh)*(0.5+0.5/2), 0.5, 0.5)
|
||||
titlecard.DrawStringAnchored(bs, float64(titlecardh)+fw/2, float64(titlecardh)*(0.5+0.75/2), 0.5, 0.5)
|
||||
titleimg = rendercard.Fillet(titlecard.Image(), 16)
|
||||
}()
|
||||
go func() {
|
||||
@@ -264,26 +298,34 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
|
||||
basiccard.DrawRoundedRectangle(1, 1, float64(basiccard.W()-1*2), float64(basiccardh-1*2), 16)
|
||||
basiccard.SetLineWidth(3)
|
||||
basiccard.SetRGBA255(255, 255, 255, 100)
|
||||
basiccard.SetColor(colorswitch(100))
|
||||
basiccard.StrokePreserve()
|
||||
basiccard.SetRGBA255(255, 255, 255, 140)
|
||||
basiccard.SetColor(colorswitch(140))
|
||||
basiccard.Fill()
|
||||
|
||||
bslen := len(basicstate)
|
||||
for i, v := range basicstate {
|
||||
offset := float64(i) * ((float64(basiccard.W())-200*float64(bslen))/float64(bslen+1) + 200)
|
||||
|
||||
basiccard.SetRGBA255(235, 235, 235, 255)
|
||||
basiccard.SetRGBA255(57, 57, 57, 255)
|
||||
if isday {
|
||||
basiccard.SetRGBA255(235, 235, 235, 255)
|
||||
}
|
||||
basiccard.DrawCircle((float64(basiccard.W())-200*float64(bslen))/float64(bslen+1)+200/2+offset, 20+200/2, 100)
|
||||
basiccard.Fill()
|
||||
|
||||
colors := darkcolor
|
||||
if isday {
|
||||
colors = lightcolor
|
||||
}
|
||||
|
||||
switch {
|
||||
case v.precent > 90:
|
||||
basiccard.SetRGBA255(255, 70, 0, 255)
|
||||
basiccard.SetColor(slice2color(colors[0]))
|
||||
case v.precent > 70:
|
||||
basiccard.SetRGBA255(255, 165, 0, 255)
|
||||
basiccard.SetColor(slice2color(colors[1]))
|
||||
default:
|
||||
basiccard.SetRGBA255(145, 240, 145, 255)
|
||||
basiccard.SetColor(slice2color(colors[2]))
|
||||
}
|
||||
|
||||
basiccard.NewSubPath()
|
||||
@@ -291,7 +333,7 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
basiccard.DrawEllipticalArc((float64(basiccard.W())-200*float64(bslen))/float64(bslen+1)+200/2+offset, 20+200/2, 100, 100, -0.5*math.Pi, -0.5*math.Pi+2*v.precent*0.01*math.Pi)
|
||||
basiccard.Fill()
|
||||
|
||||
basiccard.SetRGBA255(255, 255, 255, 255)
|
||||
basiccard.SetColor(colorswitch(255))
|
||||
basiccard.DrawCircle((float64(basiccard.W())-200*float64(bslen))/float64(bslen+1)+200/2+offset, 20+200/2, 80)
|
||||
basiccard.Fill()
|
||||
|
||||
@@ -303,7 +345,8 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
basiccard.SetRGBA255(213, 213, 213, 255)
|
||||
basiccard.DrawStringAnchored(strconv.FormatFloat(v.precent, 'f', 0, 64)+"%", (float64(basiccard.W())-200*float64(bslen))/float64(bslen+1)+200/2+offset, 20+200/2, 0.5, 0.5)
|
||||
|
||||
basiccard.SetRGBA255(30, 30, 30, 255)
|
||||
basiccard.SetColor(fontcolorswitch())
|
||||
|
||||
_, fw := basiccard.MeasureString(v.name)
|
||||
basiccard.DrawStringAnchored(v.name, (float64(basiccard.W())-200*float64(bslen))/float64(bslen+1)+200/2+offset, 20+200+15+basiccard.FontHeight()/2, 0.5, 0.5)
|
||||
|
||||
@@ -311,7 +354,7 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
basiccard.SetRGBA255(30, 30, 30, 180)
|
||||
basiccard.SetColor(fontcolorswitch())
|
||||
|
||||
textoffsety := basiccard.FontHeight() + 10
|
||||
for k, s := range v.text {
|
||||
@@ -328,9 +371,9 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
|
||||
diskcard.DrawRoundedRectangle(1, 1, float64(diskcard.W()-1*2), float64(diskcardh-1*2), 16)
|
||||
diskcard.SetLineWidth(3)
|
||||
diskcard.SetRGBA255(255, 255, 255, 100)
|
||||
diskcard.SetColor(colorswitch(100))
|
||||
diskcard.StrokePreserve()
|
||||
diskcard.SetRGBA255(255, 255, 255, 140)
|
||||
diskcard.SetColor(colorswitch(140))
|
||||
diskcard.Fill()
|
||||
|
||||
err = diskcard.ParseFontFace(fontbyte, 32)
|
||||
@@ -340,24 +383,33 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
|
||||
dslen := len(diskstate)
|
||||
if dslen == 1 {
|
||||
diskcard.SetRGBA255(192, 192, 192, 255)
|
||||
diskcard.SetRGBA255(57, 57, 57, 255)
|
||||
if isday {
|
||||
diskcard.SetRGBA255(192, 192, 192, 255)
|
||||
}
|
||||
diskcard.DrawRoundedRectangle(40, 40, float64(diskcard.W())-40-100, 50, 12)
|
||||
diskcard.ClipPreserve()
|
||||
diskcard.Fill()
|
||||
|
||||
colors := darkcolor
|
||||
if isday {
|
||||
colors = lightcolor
|
||||
}
|
||||
|
||||
switch {
|
||||
case diskstate[0].precent > 90:
|
||||
diskcard.SetRGBA255(255, 70, 0, 255)
|
||||
diskcard.SetColor(slice2color(colors[0]))
|
||||
case diskstate[0].precent > 70:
|
||||
diskcard.SetRGBA255(255, 165, 0, 255)
|
||||
diskcard.SetColor(slice2color(colors[1]))
|
||||
default:
|
||||
diskcard.SetRGBA255(145, 240, 145, 255)
|
||||
diskcard.SetColor(slice2color(colors[2]))
|
||||
}
|
||||
|
||||
diskcard.DrawRoundedRectangle(40, 40, (float64(diskcard.W())-40-100)*diskstate[0].precent*0.01, 50, 12)
|
||||
diskcard.Fill()
|
||||
diskcard.ResetClip()
|
||||
diskcard.SetRGBA255(30, 30, 30, 255)
|
||||
|
||||
diskcard.SetColor(fontcolorswitch())
|
||||
|
||||
fw, _ := diskcard.MeasureString(diskstate[0].name)
|
||||
fw1, _ := diskcard.MeasureString(diskstate[0].text[0])
|
||||
@@ -369,23 +421,32 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
for i, v := range diskstate {
|
||||
offset := float64(i)*(50+20) - 20
|
||||
|
||||
diskcard.SetRGBA255(192, 192, 192, 255)
|
||||
diskcard.SetRGBA255(57, 57, 57, 255)
|
||||
if isday {
|
||||
diskcard.SetRGBA255(192, 192, 192, 255)
|
||||
}
|
||||
|
||||
diskcard.DrawRoundedRectangle(40, 40+(float64(diskcardh-40*2)-50*float64(dslen))/float64(dslen-1)+offset, float64(diskcard.W())-40-100, 50, 12)
|
||||
diskcard.Fill()
|
||||
|
||||
colors := darkcolor
|
||||
if isday {
|
||||
colors = lightcolor
|
||||
}
|
||||
|
||||
switch {
|
||||
case v.precent > 90:
|
||||
diskcard.SetRGBA255(255, 70, 0, 255)
|
||||
diskcard.SetColor(slice2color(colors[0]))
|
||||
case v.precent > 70:
|
||||
diskcard.SetRGBA255(255, 165, 0, 255)
|
||||
diskcard.SetColor(slice2color(colors[1]))
|
||||
default:
|
||||
diskcard.SetRGBA255(145, 240, 145, 255)
|
||||
diskcard.SetColor(slice2color(colors[2]))
|
||||
}
|
||||
|
||||
diskcard.DrawRoundedRectangle(40, 40+(float64(diskcardh-40*2)-50*float64(dslen))/float64(dslen-1)+offset, (float64(diskcard.W())-40-100)*v.precent*0.01, 50, 12)
|
||||
diskcard.Fill()
|
||||
|
||||
diskcard.SetRGBA255(30, 30, 30, 255)
|
||||
diskcard.SetColor(fontcolorswitch())
|
||||
|
||||
fw, _ := diskcard.MeasureString(v.name)
|
||||
fw1, _ := diskcard.MeasureString(v.text[0])
|
||||
@@ -405,9 +466,9 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
|
||||
moreinfocard.DrawRoundedRectangle(1, 1, float64(moreinfocard.W()-1*2), float64(moreinfocard.H()-1*2), 16)
|
||||
moreinfocard.SetLineWidth(3)
|
||||
moreinfocard.SetRGBA255(255, 255, 255, 100)
|
||||
moreinfocard.SetColor(colorswitch(100))
|
||||
moreinfocard.StrokePreserve()
|
||||
moreinfocard.SetRGBA255(255, 255, 255, 140)
|
||||
moreinfocard.SetColor(colorswitch(140))
|
||||
moreinfocard.Fill()
|
||||
|
||||
err = moreinfocard.ParseFontFace(fontbyte, 32)
|
||||
@@ -419,7 +480,7 @@ func drawstatus(m *ctrl.Control[*zero.Ctx], uid int64, botname string) (sendimg
|
||||
for i, v := range moreinfo {
|
||||
offset := float64(i)*(20+moreinfocard.FontHeight()) - 20
|
||||
|
||||
moreinfocard.SetRGBA255(30, 30, 30, 255)
|
||||
moreinfocard.SetColor(fontcolorswitch())
|
||||
|
||||
fw, _ := moreinfocard.MeasureString(v.name)
|
||||
fw1, _ := moreinfocard.MeasureString(v.text[0])
|
||||
@@ -497,6 +558,8 @@ func botstatus() (string, error) {
|
||||
t.WriteString(runtime.Version())
|
||||
t.WriteString(" | ")
|
||||
t.WriteString(cases.Title(language.English).String(hostinfo.OS))
|
||||
t.WriteString(" ")
|
||||
t.WriteString(runtime.GOARCH)
|
||||
return t.String(), nil
|
||||
}
|
||||
|
||||
@@ -507,7 +570,7 @@ type status struct {
|
||||
}
|
||||
|
||||
func basicstate() (stateinfo [3]*status, err error) {
|
||||
percent, err := cpu.Percent(time.Second, false)
|
||||
percent, err := cpu.Percent(time.Second, true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -515,7 +578,15 @@ func basicstate() (stateinfo [3]*status, err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cores := strconv.Itoa(int(cpuinfo[0].Cores)) + " Core"
|
||||
cpucore, err := cpu.Counts(false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cputhread, err := cpu.Counts(true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cores := strconv.Itoa(cpucore) + "C" + strconv.Itoa(cputhread) + "T"
|
||||
times := "最大 " + strconv.FormatFloat(cpuinfo[0].Mhz/1000, 'f', 1, 64) + "Ghz"
|
||||
|
||||
stateinfo[0] = &status{
|
||||
@@ -595,6 +666,10 @@ func diskstate() (stateinfo []*status, err error) {
|
||||
}
|
||||
|
||||
func moreinfo(m *ctrl.Control[*zero.Ctx]) (stateinfo []*status, err error) {
|
||||
var mems runtime.MemStats
|
||||
runtime.ReadMemStats(&mems)
|
||||
fmtmem := storagefmt(float64(mems.Sys))
|
||||
|
||||
hostinfo, err := host.Info()
|
||||
if err != nil {
|
||||
return
|
||||
@@ -603,12 +678,32 @@ func moreinfo(m *ctrl.Control[*zero.Ctx]) (stateinfo []*status, err error) {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
count := len(m.Manager.M)
|
||||
stateinfo = []*status{
|
||||
{name: "OS", text: []string{hostinfo.Platform}},
|
||||
{name: "CPU", text: []string{cpuinfo[0].ModelName}},
|
||||
{name: "CPU", text: []string{strings.TrimSpace(cpuinfo[0].ModelName)}},
|
||||
{name: "Version", text: []string{hostinfo.PlatformVersion}},
|
||||
{name: "Plugin", text: []string{"共 " + strconv.Itoa(count) + " 个"}},
|
||||
{name: "Memory", text: []string{"已用 " + fmtmem}},
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func colorswitch(a uint8) color.Color {
|
||||
if isday {
|
||||
return color.NRGBA{255, 255, 255, a}
|
||||
}
|
||||
return color.NRGBA{0, 0, 0, a}
|
||||
}
|
||||
|
||||
func fontcolorswitch() color.Color {
|
||||
if isday {
|
||||
return color.NRGBA{30, 30, 30, 255}
|
||||
}
|
||||
return color.NRGBA{235, 235, 235, 255}
|
||||
}
|
||||
|
||||
func slice2color(c [4]uint8) color.Color {
|
||||
return color.NRGBA{c[0], c[1], c[2], c[3]}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ func (r *result) String() string {
|
||||
}
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("aipaint", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "ai绘图",
|
||||
Help: "- [ ai绘图 | 生成色图 | 生成涩图 | ai画图 ] xxx\n" +
|
||||
|
||||
@@ -17,7 +17,7 @@ const (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
control.Register("aiwife", &ctrl.Options[*zero.Ctx]{
|
||||
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "ai随机生成老婆",
|
||||
Help: "- waifu | 随机waifu",
|
||||
|
||||
@@ -16,7 +16,7 @@ const (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("alipayvoice", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "支付宝到账语音",
|
||||
Help: "- 支付宝到账 1",
|
||||
|
||||
@@ -38,7 +38,7 @@ func onDel(uid int64, _ struct{}) {
|
||||
}
|
||||
|
||||
func init() {
|
||||
engine := control.Register("antiabuse", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "违禁词检测",
|
||||
Help: "- /[添加|删除|查看]违禁词",
|
||||
|
||||
@@ -48,7 +48,7 @@ func isAtriSleeping(*zero.Ctx) bool {
|
||||
}
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("atri", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "atri人格文本回复",
|
||||
Help: "本插件基于 ATRI ,为 Golang 移植版\n" +
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
control.Register("autowithdraw", &ctrl.Options[*zero.Ctx]{
|
||||
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "触发者撤回时也自动撤回",
|
||||
Help: "- 撤回一条消息\n",
|
||||
|
||||
@@ -27,7 +27,7 @@ type result struct {
|
||||
}
|
||||
|
||||
func init() { // 主函数
|
||||
en := control.Register("baidu", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Help: "百科\n" +
|
||||
"- 百度/百科/维基/wiki[关键字]",
|
||||
|
||||
@@ -34,7 +34,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("baiduaudit", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "百度内容审核",
|
||||
Help: "##该功能来自百度内容审核, 需购买相关服务, 并创建app##\n" +
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
en := control.Register("base16384", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "base16384加解密",
|
||||
Help: "- 加密xxx\n- 解密xxx\n- 用yyy加密xxx\n- 用yyy解密xxx",
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
en := control.Register("base64gua", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "六十四卦加解密",
|
||||
Help: "- 六十四卦加密xxx\n- 六十四卦解密xxx\n- 六十四卦用yyy加密xxx\n- 六十四卦用yyy解密xxx",
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
en := control.Register("baseamasiro", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "天城文加解密",
|
||||
Help: "- 天城文加密xxx\n- 天城文解密xxx\n- 天城文用yyy加密xxx\n- 天城文用yyy解密xxx",
|
||||
|
||||
@@ -48,7 +48,7 @@ var (
|
||||
|
||||
// 查成分的
|
||||
func init() {
|
||||
engine := control.Register("bilibili", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "b站查成分查弹幕",
|
||||
Help: "- >vup info [xxx]\n" +
|
||||
|
||||
@@ -76,11 +76,17 @@ func handleVideo(ctx *zero.Ctx) {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
summaryMsg, err := getVideoSummary(card)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
msg = append(msg, summaryMsg...)
|
||||
ctx.SendChain(msg...)
|
||||
}
|
||||
|
||||
func handleDynamic(ctx *zero.Ctx) {
|
||||
msg, err := dynamicDetail(ctx.State["regex_matched"].([]string)[2])
|
||||
msg, err := dynamicDetail(cfg, ctx.State["regex_matched"].([]string)[2])
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
|
||||
@@ -3,16 +3,10 @@ package bilibili
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/md5"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
bz "github.com/FloatTech/AnimeAPI/bilibili"
|
||||
@@ -21,38 +15,25 @@ import (
|
||||
ctrl "github.com/FloatTech/zbpctrl"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/img/text"
|
||||
"github.com/RomiChan/syncx"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/tidwall/gjson"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
"github.com/wdvxdr1123/ZeroBot/utils/helper"
|
||||
)
|
||||
|
||||
const (
|
||||
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36"
|
||||
referer = "https://space.bilibili.com/%v"
|
||||
infoURL = "https://api.bilibili.com/x/space/wbi/acc/info?mid=%v&token=&platform=web&web_location=1550101"
|
||||
navURL = "https://api.bilibili.com/x/web-interface/nav"
|
||||
)
|
||||
|
||||
// bdb bilibili推送数据库
|
||||
var bdb *bilibilipushdb
|
||||
|
||||
var (
|
||||
lastTime = map[int64]int64{}
|
||||
liveStatus = map[int64]int{}
|
||||
upMap = map[int64]string{}
|
||||
mixinKeyEncTab = [...]int{
|
||||
46, 47, 18, 2, 53, 8, 23, 32, 15, 50, 10, 31, 58, 3, 45, 35, 27, 43, 5, 49,
|
||||
33, 9, 42, 19, 29, 28, 14, 39, 12, 38, 41, 13, 37, 48, 7, 16, 24, 55, 40,
|
||||
61, 26, 17, 0, 1, 60, 51, 30, 4, 22, 25, 54, 21, 56, 59, 6, 63, 57, 62, 11,
|
||||
36, 20, 34, 44, 52,
|
||||
}
|
||||
cache syncx.Map[string, string]
|
||||
lastUpdateTime time.Time
|
||||
|
||||
replacements = [...]string{"!", "'", "(", ")", "*"}
|
||||
lastTime = map[int64]int64{}
|
||||
liveStatus = map[int64]int{}
|
||||
upMap = map[int64]string{}
|
||||
)
|
||||
|
||||
func init() {
|
||||
@@ -64,6 +45,7 @@ func init() {
|
||||
"- 取消b站动态订阅[uid|name]\n" +
|
||||
"- 取消b站直播订阅[uid|name]\n" +
|
||||
"- b站推送列表\n" +
|
||||
"- [开启|关闭]艾特全体\n" +
|
||||
"Tips: 需要配合job一起使用, 全局只需要设置一个, 无视响应状态推送, 下为例子\n" +
|
||||
"记录在\"@every 5m\"触发的指令)\n" +
|
||||
"拉取b站推送",
|
||||
@@ -74,6 +56,23 @@ func init() {
|
||||
dbpath := en.DataFolder()
|
||||
dbfile := dbpath + "push.db"
|
||||
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) {
|
||||
buid, _ := strconv.ParseInt(ctx.State["uid"].(string), 10, 64)
|
||||
@@ -92,6 +91,7 @@ func init() {
|
||||
}
|
||||
ctx.SendChain(message.Text("已添加" + name + "的订阅"))
|
||||
})
|
||||
|
||||
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)
|
||||
name, err := getName(buid)
|
||||
@@ -143,6 +143,7 @@ func init() {
|
||||
}
|
||||
ctx.SendChain(message.Text("已取消" + name + "的直播订阅"))
|
||||
})
|
||||
|
||||
en.OnRegex(`^[B|b]站推送列表$`, zero.UserOrGrpAdmin).SetBlock(true).Handle(func(ctx *zero.Ctx) {
|
||||
gid := ctx.Event.GroupID
|
||||
if gid == 0 {
|
||||
@@ -189,11 +190,19 @@ func init() {
|
||||
})
|
||||
}
|
||||
|
||||
func changeAtAll(gid int64, b int) (err error) {
|
||||
bpMap := map[string]any{
|
||||
"group_id": gid,
|
||||
"at_all": b,
|
||||
}
|
||||
return bdb.updateAtAll(bpMap)
|
||||
}
|
||||
|
||||
// 取得uid的名字
|
||||
func getName(buid int64) (name string, err error) {
|
||||
var ok bool
|
||||
if name, ok = upMap[buid]; !ok {
|
||||
data, err := web.RequestDataWithHeaders(web.NewDefaultClient(), signURL(fmt.Sprintf(infoURL, buid)), "GET", func(r *http.Request) error {
|
||||
data, err := web.RequestDataWithHeaders(web.NewDefaultClient(), bz.SignURL(fmt.Sprintf(infoURL, buid)), "GET", func(r *http.Request) error {
|
||||
r.Header.Set("User-Agent", ua)
|
||||
return nil
|
||||
}, nil)
|
||||
@@ -212,103 +221,6 @@ func getName(buid int64) (name string, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
func getMixinKey(orig string) string {
|
||||
var str strings.Builder
|
||||
t := 0
|
||||
for _, v := range mixinKeyEncTab {
|
||||
if v < len(orig) {
|
||||
str.WriteByte(orig[v])
|
||||
t++
|
||||
}
|
||||
if t > 31 {
|
||||
break
|
||||
}
|
||||
}
|
||||
return str.String()
|
||||
}
|
||||
|
||||
func wbiSign(params map[string]string, imgKey string, subKey string) map[string]string {
|
||||
mixinKey := getMixinKey(imgKey + subKey)
|
||||
currTime := strconv.FormatInt(time.Now().Unix(), 10)
|
||||
params["wts"] = currTime
|
||||
// Sort keys
|
||||
keys := make([]string, 0, len(params))
|
||||
for k, v := range params {
|
||||
keys = append(keys, k)
|
||||
for _, old := range replacements {
|
||||
v = strings.ReplaceAll(v, old, "")
|
||||
}
|
||||
params[k] = v
|
||||
}
|
||||
sort.Strings(keys)
|
||||
h := md5.New()
|
||||
for k, v := range keys {
|
||||
h.Write([]byte(v))
|
||||
h.Write([]byte{'='})
|
||||
h.Write([]byte(params[v]))
|
||||
if k < len(keys)-1 {
|
||||
h.Write([]byte{'&'})
|
||||
}
|
||||
}
|
||||
h.Write([]byte(mixinKey))
|
||||
params["w_rid"] = hex.EncodeToString(h.Sum(make([]byte, 0, md5.Size)))
|
||||
return params
|
||||
}
|
||||
|
||||
func getWbiKeysCached() (string, string) {
|
||||
if time.Since(lastUpdateTime).Minutes() > 10 {
|
||||
imgKey, subKey := getWbiKeys()
|
||||
cache.Store("imgKey", imgKey)
|
||||
cache.Store("subKey", subKey)
|
||||
lastUpdateTime = time.Now()
|
||||
return imgKey, subKey
|
||||
}
|
||||
imgKeyI, _ := cache.Load("imgKey")
|
||||
subKeyI, _ := cache.Load("subKey")
|
||||
return imgKeyI, subKeyI
|
||||
}
|
||||
|
||||
func getWbiKeys() (string, string) {
|
||||
data, _ := web.RequestDataWithHeaders(web.NewDefaultClient(), navURL, "GET", func(r *http.Request) error {
|
||||
if cfg != nil {
|
||||
cookie, err := cfg.Load()
|
||||
if err == nil {
|
||||
r.Header.Set("cookie", cookie)
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
return errors.New("未配置-cookie")
|
||||
}, nil)
|
||||
json := helper.BytesToString(data)
|
||||
imgURL := gjson.Get(json, "data.wbi_img.img_url").String()
|
||||
subURL := gjson.Get(json, "data.wbi_img.sub_url").String()
|
||||
imgKey := imgURL[strings.LastIndex(imgURL, "/")+1:]
|
||||
imgKey = strings.TrimSuffix(imgKey, filepath.Ext(imgKey))
|
||||
subKey := subURL[strings.LastIndex(subURL, "/")+1:]
|
||||
subKey = strings.TrimSuffix(subKey, filepath.Ext(subKey))
|
||||
return imgKey, subKey
|
||||
}
|
||||
|
||||
func signURL(urlStr string) string {
|
||||
urlObj, _ := url.Parse(urlStr)
|
||||
imgKey, subKey := getWbiKeysCached()
|
||||
query := urlObj.Query()
|
||||
params := map[string]string{}
|
||||
for k, v := range query {
|
||||
if len(v) > 0 {
|
||||
params[k] = v[0]
|
||||
}
|
||||
}
|
||||
newParams := wbiSign(params, imgKey, subKey)
|
||||
for k, v := range newParams {
|
||||
query.Set(k, v)
|
||||
}
|
||||
urlObj.RawQuery = query.Encode()
|
||||
newURL := urlObj.String()
|
||||
return newURL
|
||||
}
|
||||
|
||||
// subscribe 订阅
|
||||
func subscribe(buid, groupid int64) (err error) {
|
||||
bpMap := map[string]any{
|
||||
@@ -466,6 +378,9 @@ func sendLive(ctx *zero.Ctx) error {
|
||||
time.Sleep(time.Millisecond * 100)
|
||||
switch {
|
||||
case gid > 0:
|
||||
if res := bdb.getAtAll(gid); res == 1 {
|
||||
msg = append([]message.MessageSegment{message.AtAll()}, msg...)
|
||||
}
|
||||
ctx.SendGroupMessage(gid, msg)
|
||||
case gid < 0:
|
||||
ctx.SendPrivateMessage(-gid, msg)
|
||||
|
||||
@@ -33,6 +33,15 @@ func (bilibiliup) TableName() string {
|
||||
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数据库
|
||||
func initializePush(dbpath string) *bilibilipushdb {
|
||||
var err error
|
||||
@@ -48,7 +57,7 @@ func initializePush(dbpath string) *bilibilipushdb {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
gdb.AutoMigrate(&bilibilipush{}).AutoMigrate(&bilibiliup{})
|
||||
gdb.AutoMigrate(&bilibilipush{}).AutoMigrate(&bilibiliup{}).AutoMigrate(&bilibiliAt{})
|
||||
return (*bilibilipushdb)(gdb)
|
||||
}
|
||||
|
||||
@@ -130,6 +139,35 @@ func (bdb *bilibilipushdb) getAllPushByGroup(groupID int64) (bpl []bilibilipush)
|
||||
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) {
|
||||
db := (*gorm.DB)(bdb)
|
||||
bu := bilibiliup{
|
||||
|
||||
@@ -2,10 +2,12 @@ package bilibili
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
bz "github.com/FloatTech/AnimeAPI/bilibili"
|
||||
"github.com/FloatTech/floatbox/binary"
|
||||
"github.com/FloatTech/floatbox/web"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
@@ -253,8 +255,8 @@ func card2msg(dynamicCard *bz.DynamicCard, card *bz.Card, cType int) (msg []mess
|
||||
}
|
||||
|
||||
// dynamicDetail 用动态id查动态信息
|
||||
func dynamicDetail(dynamicIDStr string) (msg []message.MessageSegment, err error) {
|
||||
dyc, err := bz.GetDynamicDetail(dynamicIDStr)
|
||||
func dynamicDetail(cookiecfg *bz.CookieConfig, dynamicIDStr string) (msg []message.MessageSegment, err error) {
|
||||
dyc, err := bz.GetDynamicDetail(cookiecfg, dynamicIDStr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
@@ -321,6 +323,30 @@ func videoCard2msg(card bz.Card) (msg []message.MessageSegment, err error) {
|
||||
msg = append(msg, message.Image(card.Pic))
|
||||
msg = append(msg, message.Text("\n点赞: ", bz.HumanNum(card.Stat.Like), " 投币: ", bz.HumanNum(card.Stat.Coin), "\n",
|
||||
"收藏: ", bz.HumanNum(card.Stat.Favorite), " 分享: ", bz.HumanNum(card.Stat.Share), "\n",
|
||||
bz.VURL, card.BvID))
|
||||
bz.VURL, card.BvID, "\n\n"))
|
||||
return
|
||||
}
|
||||
|
||||
// getVideoSummary AI视频总结
|
||||
func getVideoSummary(card bz.Card) (msg []message.MessageSegment, err error) {
|
||||
var (
|
||||
data []byte
|
||||
videoSummary bz.VideoSummary
|
||||
)
|
||||
data, err = web.GetData(bz.SignURL(fmt.Sprintf(bz.VideoSummaryURL, card.BvID, card.CID)))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
err = json.Unmarshal(data, &videoSummary)
|
||||
msg = make([]message.MessageSegment, 0, 16)
|
||||
msg = append(msg, message.Text("已为你生成视频总结\n\n"))
|
||||
msg = append(msg, message.Text(videoSummary.Data.ModelResult.Summary, "\n\n"))
|
||||
for _, v := range videoSummary.Data.ModelResult.Outline {
|
||||
msg = append(msg, message.Text("● ", v.Title, "\n"))
|
||||
for _, p := range v.PartOutline {
|
||||
msg = append(msg, message.Text(fmt.Sprintf("%d:%d %s\n", p.Timestamp/60, p.Timestamp%60, p.Content)))
|
||||
}
|
||||
msg = append(msg, message.Text("\n"))
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
@@ -15,35 +15,6 @@ func TestArticleInfo(t *testing.T) {
|
||||
|
||||
}
|
||||
|
||||
func TestDynamicDetail(t *testing.T) {
|
||||
t.Log("cType = 1")
|
||||
t.Log(dynamicDetail("642279068898689029"))
|
||||
|
||||
t.Log("cType = 2")
|
||||
t.Log(dynamicDetail("642470680290394121"))
|
||||
|
||||
t.Log("cType = 2048")
|
||||
t.Log(dynamicDetail("642277677329285174"))
|
||||
|
||||
t.Log("cType = 4")
|
||||
t.Log(dynamicDetail("642154347357011968"))
|
||||
|
||||
t.Log("cType = 8")
|
||||
t.Log(dynamicDetail("675892999274627104"))
|
||||
|
||||
t.Log("cType = 4308")
|
||||
t.Log(dynamicDetail("668598718656675844"))
|
||||
|
||||
t.Log("cType = 64")
|
||||
t.Log(dynamicDetail("675966082178088963"))
|
||||
|
||||
t.Log("cType = 256")
|
||||
t.Log(dynamicDetail("599253048535707632"))
|
||||
|
||||
t.Log("cType = 4,投票类型")
|
||||
t.Log(dynamicDetail("677231070435868704"))
|
||||
}
|
||||
|
||||
func TestMemberCard(t *testing.T) {
|
||||
card, err := bz.GetMemberCard(2)
|
||||
if err != nil {
|
||||
@@ -75,6 +46,14 @@ func TestVideoInfo(t *testing.T) {
|
||||
t.Log(videoCard2msg(card))
|
||||
}
|
||||
|
||||
func TestGetVideoSummary(t *testing.T) {
|
||||
card, err := bz.GetVideoInfo("BV1mF411j7iU")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(getVideoSummary(card))
|
||||
}
|
||||
|
||||
func TestLiveRoomInfo(t *testing.T) {
|
||||
card, err := bz.GetLiveRoomInfo("83171")
|
||||
if err != nil {
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("bookreview", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "哀伤雪刃推书书评",
|
||||
Help: "- 书评[xxx]\n- 随机书评",
|
||||
@@ -16,7 +16,7 @@ const throttle = 3 // 不可超过 9
|
||||
var sm syncx.Map[int64, string]
|
||||
|
||||
func init() {
|
||||
engine := control.Register("breakrepeat", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "打断复读",
|
||||
Help: "- 打断" + strconv.Itoa(throttle) + "次以上复读\n",
|
||||
|
||||
@@ -30,7 +30,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("cangtoushi", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "藏头诗, 藏尾诗",
|
||||
Help: "- 藏头诗[xxx]\n- 藏尾诗[xxx]",
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
var (
|
||||
poke = rate.NewManager[int64](time.Minute*5, 8) // 戳一戳
|
||||
engine = control.Register("chat", &ctrl.Options[*zero.Ctx]{
|
||||
engine = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "基础反应, 群空调",
|
||||
Help: "chat\n- [BOT名字]\n- [戳一戳BOT]\n- 空调开\n- 空调关\n- 群温度\n- 设置温度[正整数]",
|
||||
|
||||
183
plugin/chess/chess.go
Normal file
183
plugin/chess/chess.go
Normal file
@@ -0,0 +1,183 @@
|
||||
// Package chess 国际象棋
|
||||
package chess
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
ctrl "github.com/FloatTech/zbpctrl"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension/single"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
const helpString = `- 参与/创建一盘游戏:「下棋」(chess)
|
||||
- 参与/创建一盘盲棋:「盲棋」(blind)
|
||||
- 投降认输:「认输」 (resign)
|
||||
- 请求、接受和棋:「和棋」 (draw)
|
||||
- 走棋:!Nxf3 中英文感叹号均可,格式请参考“代数记谱法”(Algebraic notation)
|
||||
- 中断对局:「中断」 (abort)(仅群主/管理员有效)
|
||||
- 查看等级分排行榜:「排行榜」(ranking)
|
||||
- 查看自己的等级分:「等级分」(rate)
|
||||
- 清空等级分:「清空等级分 QQ号」(.clean.rate) (仅超管有效)`
|
||||
|
||||
var (
|
||||
limit = ctxext.NewLimiterManager(time.Microsecond*2500, 1)
|
||||
tempFileDir string
|
||||
engine = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "国际象棋",
|
||||
Help: helpString,
|
||||
PrivateDataFolder: "chess",
|
||||
}).ApplySingle(single.New(
|
||||
single.WithKeyFn(func(ctx *zero.Ctx) int64 { return ctx.Event.GroupID }),
|
||||
single.WithPostFn[int64](func(ctx *zero.Ctx) {
|
||||
ctx.Send(
|
||||
message.ReplyWithMessage(ctx.Event.MessageID,
|
||||
message.Text("有操作正在执行, 请稍后再试..."),
|
||||
),
|
||||
)
|
||||
}),
|
||||
))
|
||||
)
|
||||
|
||||
func init() {
|
||||
// 初始化临时文件夹
|
||||
tempFileDir = path.Join(engine.DataFolder(), "temp")
|
||||
err := os.MkdirAll(tempFileDir, 0750)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
// 初始化数据库
|
||||
dbFilePath := engine.DataFolder() + "chess.db"
|
||||
initDatabase(dbFilePath)
|
||||
// 注册指令
|
||||
engine.OnFullMatchGroup([]string{"下棋", "chess"}, zero.OnlyGroup).SetBlock(true).Limit(limit.LimitByGroup).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if ctx.Event.Sender == nil {
|
||||
return
|
||||
}
|
||||
userUin := ctx.Event.UserID
|
||||
userName := ctx.Event.Sender.NickName
|
||||
groupCode := ctx.Event.GroupID
|
||||
replyMessage, err := game(groupCode, userUin, userName)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.Send(replyMessage)
|
||||
})
|
||||
|
||||
engine.OnFullMatchGroup([]string{"认输", "resign"}, zero.OnlyGroup).SetBlock(true).Limit(limit.LimitByGroup).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
userUin := ctx.Event.UserID
|
||||
groupCode := ctx.Event.GroupID
|
||||
replyMessage, err := resign(groupCode, userUin)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.Send(replyMessage)
|
||||
})
|
||||
|
||||
engine.OnFullMatchGroup([]string{"和棋", "draw"}, zero.OnlyGroup).SetBlock(true).Limit(limit.LimitByGroup).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
userUin := ctx.Event.UserID
|
||||
groupCode := ctx.Event.GroupID
|
||||
replyMessage, err := draw(groupCode, userUin)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.Send(replyMessage)
|
||||
})
|
||||
|
||||
engine.OnFullMatchGroup([]string{"中断", "abort"}, zero.OnlyGroup, zero.AdminPermission).SetBlock(true).Limit(limit.LimitByGroup).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
groupCode := ctx.Event.GroupID
|
||||
replyMessage, err := abort(groupCode)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.Send(replyMessage)
|
||||
})
|
||||
|
||||
engine.OnFullMatchGroup([]string{"盲棋", "blind"}, zero.OnlyGroup).SetBlock(true).Limit(limit.LimitByGroup).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if ctx.Event.Sender == nil {
|
||||
return
|
||||
}
|
||||
userUin := ctx.Event.UserID
|
||||
userName := ctx.Event.Sender.NickName
|
||||
groupCode := ctx.Event.GroupID
|
||||
replyMessage, err := blindfold(groupCode, userUin, userName)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.Send(replyMessage)
|
||||
})
|
||||
|
||||
engine.OnRegex("^[!|!]([0-8]|[R|N|B|Q|K|O|a-h|x]|[-|=|+])+$", zero.OnlyGroup).SetBlock(true).Limit(limit.LimitByGroup).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
userUin := ctx.Event.UserID
|
||||
groupCode := ctx.Event.GroupID
|
||||
userMsgStr := ctx.State["regex_matched"].([]string)[0]
|
||||
moveStr := strings.TrimPrefix(strings.TrimPrefix(userMsgStr, "!"), "!")
|
||||
replyMessage, err := play(groupCode, userUin, moveStr)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.Send(replyMessage)
|
||||
})
|
||||
|
||||
engine.OnFullMatchGroup([]string{"排行榜", "ranking"}).SetBlock(true).Limit(limit.LimitByUser).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
replyMessage, err := getRanking()
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.Send(replyMessage)
|
||||
})
|
||||
|
||||
engine.OnFullMatchGroup([]string{"等级分", "rate"}).SetBlock(true).Limit(limit.LimitByUser).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
if ctx.Event.Sender == nil {
|
||||
return
|
||||
}
|
||||
userUin := ctx.Event.UserID
|
||||
userName := ctx.Event.Sender.NickName
|
||||
replyMessage, err := rate(userUin, userName)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.Send(replyMessage)
|
||||
})
|
||||
|
||||
engine.OnPrefixGroup([]string{"清空等级分", ".clean.rate"}, zero.SuperUserPermission).SetBlock(true).
|
||||
Limit(limit.LimitByUser).
|
||||
Handle(func(ctx *zero.Ctx) {
|
||||
args := ctx.State["args"].(string)
|
||||
playerUin, err := strconv.ParseInt(strings.TrimSpace(args), 10, 64)
|
||||
if err != nil || playerUin <= 0 {
|
||||
ctx.Send(fmt.Sprintf("解析失败「%s」不是正确的 QQ 号。", args))
|
||||
return
|
||||
}
|
||||
replyMessage, err := cleanUserRate(playerUin)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("ERROR: ", err))
|
||||
return
|
||||
}
|
||||
ctx.Send(replyMessage)
|
||||
})
|
||||
}
|
||||
637
plugin/chess/core.go
Normal file
637
plugin/chess/core.go
Normal file
@@ -0,0 +1,637 @@
|
||||
package chess
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"image/color"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/floatbox/binary"
|
||||
"github.com/FloatTech/floatbox/file"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/img/text"
|
||||
|
||||
"github.com/RomiChan/syncx"
|
||||
"github.com/jinzhu/gorm"
|
||||
resvg "github.com/kanrichan/resvg-go"
|
||||
"github.com/notnil/chess"
|
||||
cimage "github.com/notnil/chess/image"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
const eloDefault = 500
|
||||
|
||||
var (
|
||||
chessRoomMap syncx.Map[int64, *chessRoom]
|
||||
errNotExist = errors.New("对局不存在, 发送「下棋」或「chess」可创建对局。")
|
||||
)
|
||||
|
||||
type chessRoom struct {
|
||||
chessGame *chess.Game
|
||||
whitePlayer int64
|
||||
whiteName string
|
||||
blackPlayer int64
|
||||
blackName string
|
||||
drawPlayer int64
|
||||
lastMoveTime int64
|
||||
isBlindfold bool
|
||||
whiteErr bool // 违例记录(盲棋用)
|
||||
blackErr bool
|
||||
}
|
||||
|
||||
// game 下棋
|
||||
func game(groupCode, senderUin int64, senderName string) (message.Message, error) {
|
||||
return createGame(false, groupCode, senderUin, senderName)
|
||||
}
|
||||
|
||||
// blindfold 盲棋
|
||||
func blindfold(groupCode, senderUin int64, senderName string) (message.Message, error) {
|
||||
return createGame(true, groupCode, senderUin, senderName)
|
||||
}
|
||||
|
||||
// abort 中断对局
|
||||
func abort(groupCode int64) (message.Message, error) {
|
||||
if room, ok := chessRoomMap.Load(groupCode); ok {
|
||||
return abortGame(*room, groupCode, "对局已被管理员中断, 游戏结束。")
|
||||
}
|
||||
return nil, errNotExist
|
||||
}
|
||||
|
||||
// draw 和棋
|
||||
func draw(groupCode, senderUin int64) (msg message.Message, err error) {
|
||||
msg = message.Message{message.At(senderUin)}
|
||||
// 检查对局是否存在
|
||||
room, ok := chessRoomMap.Load(groupCode)
|
||||
if !ok {
|
||||
return nil, errNotExist
|
||||
}
|
||||
// 检查消息发送者是否为对局中的玩家
|
||||
if senderUin != room.whitePlayer && senderUin != room.blackPlayer {
|
||||
return
|
||||
}
|
||||
// 处理和棋逻辑
|
||||
room.lastMoveTime = time.Now().Unix()
|
||||
if room.drawPlayer == 0 {
|
||||
room.drawPlayer = senderUin
|
||||
chessRoomMap.Store(groupCode, room)
|
||||
msg = append(msg, message.Text("请求和棋, 发送「和棋」或「draw」接受和棋。走棋视为拒绝和棋。"))
|
||||
return
|
||||
}
|
||||
if room.drawPlayer == senderUin {
|
||||
return
|
||||
}
|
||||
err = room.chessGame.Draw(chess.DrawOffer)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
chessString := getChessString(*room)
|
||||
eloString := ""
|
||||
if len(room.chessGame.Moves()) > 4 {
|
||||
// 若走子次数超过 4 认为是有效对局, 存入数据库
|
||||
dbService := newDBService()
|
||||
if err = dbService.createPGN(chessString, room.whitePlayer, room.blackPlayer, room.whiteName, room.blackName); err != nil {
|
||||
return
|
||||
}
|
||||
whiteScore, blackScore := 0.5, 0.5
|
||||
eloString, err = getELOString(*room, whiteScore, blackScore)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
msg = append(msg, message.Text("接受和棋, 游戏结束。\n", eloString, chessString))
|
||||
chessRoomMap.Delete(groupCode)
|
||||
return
|
||||
}
|
||||
|
||||
// resign 认输
|
||||
func resign(groupCode, senderUin int64) (msg message.Message, err error) {
|
||||
msg = message.Message{message.At(senderUin)}
|
||||
// 检查对局是否存在
|
||||
room, ok := chessRoomMap.Load(groupCode)
|
||||
if !ok {
|
||||
return nil, errNotExist
|
||||
}
|
||||
// 检查是否是当前游戏玩家
|
||||
if senderUin != room.whitePlayer && senderUin != room.blackPlayer {
|
||||
return
|
||||
}
|
||||
// 如果对局未建立, 中断对局
|
||||
if room.whitePlayer == 0 || room.blackPlayer == 0 {
|
||||
chessRoomMap.Delete(groupCode)
|
||||
msg = append(msg, message.Text("对局结束"))
|
||||
return
|
||||
}
|
||||
// 计算认输方
|
||||
var resignColor chess.Color
|
||||
if senderUin == room.whitePlayer {
|
||||
resignColor = chess.White
|
||||
} else {
|
||||
resignColor = chess.Black
|
||||
}
|
||||
if isAprilFoolsDay() {
|
||||
if resignColor == chess.White {
|
||||
resignColor = chess.Black
|
||||
} else {
|
||||
resignColor = chess.White
|
||||
}
|
||||
}
|
||||
room.chessGame.Resign(resignColor)
|
||||
chessString := getChessString(*room)
|
||||
eloString := ""
|
||||
if len(room.chessGame.Moves()) > 4 {
|
||||
// 若走子次数超过 4 认为是有效对局, 存入数据库
|
||||
dbService := newDBService()
|
||||
if err = dbService.createPGN(chessString, room.whitePlayer, room.blackPlayer, room.whiteName, room.blackName); err != nil {
|
||||
return
|
||||
}
|
||||
whiteScore, blackScore := 1.0, 1.0
|
||||
if resignColor == chess.White {
|
||||
whiteScore = 0.0
|
||||
} else {
|
||||
blackScore = 0.0
|
||||
}
|
||||
eloString, err = getELOString(*room, whiteScore, blackScore)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
msg = append(msg, message.Text("认输, 游戏结束。\n", eloString, chessString))
|
||||
if isAprilFoolsDay() {
|
||||
msg = append(msg, message.Text("对手认输, 游戏结束, 你胜利了。\n", eloString, chessString))
|
||||
}
|
||||
chessRoomMap.Delete(groupCode)
|
||||
return
|
||||
}
|
||||
|
||||
// play 走棋
|
||||
func play(senderUin int64, groupCode int64, moveStr string) (msg message.Message, err error) {
|
||||
msg = message.Message{message.At(senderUin)}
|
||||
// 检查对局是否存在
|
||||
room, ok := chessRoomMap.Load(groupCode)
|
||||
if !ok {
|
||||
return nil, errNotExist
|
||||
}
|
||||
// 不是对局中的玩家, 忽略消息
|
||||
if (senderUin != room.whitePlayer) && (senderUin != room.blackPlayer) && !isAprilFoolsDay() {
|
||||
return
|
||||
}
|
||||
// 对局未建立
|
||||
if (room.whitePlayer == 0) || (room.blackPlayer == 0) {
|
||||
msg = append(msg, message.Text("请等候其他玩家加入游戏。"))
|
||||
return
|
||||
}
|
||||
// 需要对手走棋
|
||||
if ((senderUin == room.whitePlayer) && (room.chessGame.Position().Turn() != chess.White)) || ((senderUin == room.blackPlayer) && (room.chessGame.Position().Turn() != chess.Black)) {
|
||||
msg = append(msg, message.Text("请等待对手走棋。"))
|
||||
return
|
||||
}
|
||||
room.lastMoveTime = time.Now().Unix()
|
||||
// 走棋
|
||||
if err = room.chessGame.MoveStr(moveStr); err != nil {
|
||||
// 指令错误时检查
|
||||
if !room.isBlindfold {
|
||||
// 未开启盲棋, 提示指令错误
|
||||
msg = append(msg, message.Text("移动「", moveStr, "」违规, 请检查, 格式请参考「代数记谱法」(Algebraic notation)。"))
|
||||
return
|
||||
}
|
||||
// 开启盲棋, 判断违例情况
|
||||
var currentPlayerColor chess.Color
|
||||
if senderUin == room.whitePlayer {
|
||||
currentPlayerColor = chess.White
|
||||
} else {
|
||||
currentPlayerColor = chess.Black
|
||||
}
|
||||
// 第一次违例, 提示
|
||||
_flag := false
|
||||
if (currentPlayerColor == chess.White) && !room.whiteErr {
|
||||
room.whiteErr = true
|
||||
chessRoomMap.Store(groupCode, room)
|
||||
_flag = true
|
||||
}
|
||||
if (currentPlayerColor == chess.Black) && !room.blackErr {
|
||||
room.blackErr = true
|
||||
chessRoomMap.Store(groupCode, room)
|
||||
_flag = true
|
||||
}
|
||||
if _flag {
|
||||
msg = append(msg, message.Text("移动「", moveStr, "」违规, 再次违规会立即判负。"))
|
||||
return
|
||||
}
|
||||
// 出现多次违例, 判负
|
||||
room.chessGame.Resign(currentPlayerColor)
|
||||
chessString := getChessString(*room)
|
||||
msg = append(msg, message.Text("违规两次,游戏结束。\n", chessString))
|
||||
|
||||
chessRoomMap.Delete(groupCode)
|
||||
return
|
||||
}
|
||||
// 走子之后, 视为拒绝和棋
|
||||
if room.drawPlayer != 0 {
|
||||
room.drawPlayer = 0
|
||||
chessRoomMap.Store(groupCode, room)
|
||||
}
|
||||
// 生成棋盘图片
|
||||
var boardImgEle message.MessageSegment
|
||||
if !room.isBlindfold {
|
||||
boardImgEle, err = getBoardElement(groupCode)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
// 检查游戏是否结束
|
||||
if room.chessGame.Method() != chess.NoMethod {
|
||||
whiteScore, blackScore := 0.5, 0.5
|
||||
var msgBuilder strings.Builder
|
||||
msgBuilder.WriteString("游戏结束, ")
|
||||
switch room.chessGame.Method() {
|
||||
case chess.FivefoldRepetition:
|
||||
msgBuilder.WriteString("和棋, 因为五次重复走子。\n")
|
||||
case chess.SeventyFiveMoveRule:
|
||||
msgBuilder.WriteString("和棋, 因为七十五步规则。\n")
|
||||
case chess.InsufficientMaterial:
|
||||
msgBuilder.WriteString("和棋, 因为不可能将死。\n")
|
||||
case chess.Stalemate:
|
||||
msgBuilder.WriteString("和棋, 因为逼和(无子可动和棋)。\n")
|
||||
case chess.Checkmate:
|
||||
var winner string
|
||||
if room.chessGame.Position().Turn() == chess.White {
|
||||
whiteScore = 0.0
|
||||
blackScore = 1.0
|
||||
winner = "黑方"
|
||||
} else {
|
||||
whiteScore = 1.0
|
||||
blackScore = 0.0
|
||||
winner = "白方"
|
||||
}
|
||||
msgBuilder.WriteString(winner)
|
||||
msgBuilder.WriteString("胜利, 因为将杀。\n")
|
||||
case chess.NoMethod:
|
||||
case chess.Resignation:
|
||||
case chess.DrawOffer:
|
||||
case chess.ThreefoldRepetition:
|
||||
case chess.FiftyMoveRule:
|
||||
default:
|
||||
}
|
||||
chessString := getChessString(*room)
|
||||
eloString := ""
|
||||
if len(room.chessGame.Moves()) > 4 {
|
||||
// 若走子次数超过 4 认为是有效对局, 存入数据库
|
||||
dbService := newDBService()
|
||||
if err = dbService.createPGN(chessString, room.whitePlayer, room.blackPlayer, room.whiteName, room.blackName); err != nil {
|
||||
return
|
||||
}
|
||||
// 仅有效对局才会计算等级分
|
||||
eloString, err = getELOString(*room, whiteScore, blackScore)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
msgBuilder.WriteString(eloString)
|
||||
msgBuilder.WriteString(chessString)
|
||||
msg = append(msg, message.Text(msgBuilder.String()))
|
||||
if !room.isBlindfold {
|
||||
msg = append(msg, boardImgEle)
|
||||
}
|
||||
|
||||
chessRoomMap.Delete(groupCode)
|
||||
return
|
||||
}
|
||||
// 提示玩家继续游戏
|
||||
var currentPlayer int64
|
||||
if room.chessGame.Position().Turn() == chess.White {
|
||||
currentPlayer = room.whitePlayer
|
||||
} else {
|
||||
currentPlayer = room.blackPlayer
|
||||
}
|
||||
msg = message.Message{message.At(currentPlayer), message.Text("对手已走子, 游戏继续。"), boardImgEle}
|
||||
return
|
||||
}
|
||||
|
||||
// rate 获取等级分
|
||||
func rate(senderUin int64, senderName string) (msg message.Message, err error) {
|
||||
rate := 0
|
||||
dbService := newDBService()
|
||||
rate, err = dbService.getELORateByUin(senderUin)
|
||||
if err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
err = errors.New("无法获取等级分信息。")
|
||||
return
|
||||
}
|
||||
err = errors.New("没有查找到等级分信息, 请至少进行一局对局。")
|
||||
}
|
||||
msg = append(msg, message.Text("玩家「", senderName, "」目前的等级分: ", rate))
|
||||
return
|
||||
}
|
||||
|
||||
// cleanUserRate 清空用户等级分
|
||||
func cleanUserRate(senderUin int64) (msg message.Message, err error) {
|
||||
dbService := newDBService()
|
||||
err = dbService.cleanELOByUin(senderUin)
|
||||
if err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
err = errors.New("无法清空等级分。")
|
||||
return
|
||||
}
|
||||
err = errors.New("没有查找到等级分信息, 请检查用户 uid 是否正确。")
|
||||
}
|
||||
msg = append(msg, message.Text("已清空用户「", senderUin, "」的等级分。"))
|
||||
return
|
||||
}
|
||||
|
||||
// createGame 创建游戏
|
||||
func createGame(isBlindfold bool, groupCode int64, senderUin int64, senderName string) (msg message.Message, err error) {
|
||||
room, ok := chessRoomMap.Load(groupCode)
|
||||
if !ok {
|
||||
chessRoomMap.Store(groupCode, &chessRoom{
|
||||
chessGame: chess.NewGame(),
|
||||
whitePlayer: senderUin,
|
||||
whiteName: senderName,
|
||||
blackPlayer: 0,
|
||||
blackName: "",
|
||||
drawPlayer: 0,
|
||||
lastMoveTime: time.Now().Unix(),
|
||||
isBlindfold: isBlindfold,
|
||||
whiteErr: false,
|
||||
blackErr: false,
|
||||
})
|
||||
text := "已创建新的对局, 发送「下棋」或「chess」可加入对局。"
|
||||
if isBlindfold {
|
||||
text = "已创建新的盲棋对局, 发送「盲棋」或「blind」可加入对局。"
|
||||
}
|
||||
msg = append(msg, message.Text(text))
|
||||
return
|
||||
}
|
||||
msg = message.Message{message.At(senderUin)}
|
||||
if room.blackPlayer != 0 {
|
||||
// 检测对局是否已存在超过 6 小时
|
||||
if (time.Now().Unix() - room.lastMoveTime) > 21600 {
|
||||
msg, err = abortGame(*room, groupCode, "对局已存在超过 6 小时, 游戏结束。")
|
||||
msg = append(msg, message.Text("\n\n已有对局已被中断, 如需创建新对局请重新发送指令。"))
|
||||
msg = append(msg, message.At(senderUin))
|
||||
return
|
||||
}
|
||||
// 对局在进行
|
||||
msg = append(msg, message.Text("对局已在进行中, 无法创建或加入对局, 当前对局玩家为: "))
|
||||
if room.whitePlayer != 0 {
|
||||
msg = append(msg, message.At(room.whitePlayer))
|
||||
}
|
||||
if room.blackPlayer != 0 {
|
||||
msg = append(msg, message.At(room.blackPlayer))
|
||||
}
|
||||
msg = append(msg, message.Text(", 群主或管理员发送「中断」或「abort」可中断对局(自动判和)。"))
|
||||
return
|
||||
}
|
||||
if senderUin == room.whitePlayer {
|
||||
msg = append(msg, message.Text("请等候其他玩家加入游戏。"))
|
||||
return
|
||||
}
|
||||
if room.isBlindfold && !isBlindfold {
|
||||
msg = append(msg, message.Text("已创建盲棋对局, 请加入或等待盲棋对局结束之后创建普通对局。"))
|
||||
return
|
||||
}
|
||||
if !room.isBlindfold && isBlindfold {
|
||||
msg = append(msg, message.Text("已创建普通对局, 请加入或等待普通对局结束之后创建盲棋对局。"))
|
||||
return
|
||||
}
|
||||
room.blackPlayer = senderUin
|
||||
room.blackName = senderName
|
||||
chessRoomMap.Store(groupCode, room)
|
||||
var boardImgEle message.MessageSegment
|
||||
if !room.isBlindfold {
|
||||
boardImgEle, err = getBoardElement(groupCode)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
msg = append(msg, message.Text("黑棋已加入对局, 请白方下棋。"), message.At(room.whitePlayer))
|
||||
if !isBlindfold {
|
||||
msg = append(msg, boardImgEle)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// abortGame 中断游戏
|
||||
func abortGame(room chessRoom, groupCode int64, hint string) (message.Message, error) {
|
||||
var msg message.Message
|
||||
err := room.chessGame.Draw(chess.DrawOffer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
chessString := getChessString(room)
|
||||
if len(room.chessGame.Moves()) > 4 {
|
||||
dbService := newDBService()
|
||||
if err := dbService.createPGN(chessString, room.whitePlayer, room.blackPlayer, room.whiteName, room.blackName); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
chessRoomMap.Delete(groupCode)
|
||||
msg = append(msg, message.Text(hint))
|
||||
if room.whitePlayer != 0 {
|
||||
msg = append(msg, message.At(room.whitePlayer))
|
||||
}
|
||||
if room.blackPlayer != 0 {
|
||||
msg = append(msg, message.At(room.blackPlayer))
|
||||
}
|
||||
msg = append(msg, message.Text("\n\n"+chessString))
|
||||
return msg, nil
|
||||
}
|
||||
|
||||
// getBoardElement 获取棋盘图片的消息内容
|
||||
func getBoardElement(groupCode int64) (imgMsg message.MessageSegment, err error) {
|
||||
fontdata, err := file.GetLazyData(text.GNUUnifontFontFile, control.Md5File, true)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
room, ok := chessRoomMap.Load(groupCode)
|
||||
if !ok {
|
||||
return imgMsg, errNotExist
|
||||
}
|
||||
// 获取高亮方块
|
||||
highlightSquare := make([]chess.Square, 0, 2)
|
||||
moves := room.chessGame.Moves()
|
||||
if len(moves) != 0 {
|
||||
lastMove := moves[len(moves)-1]
|
||||
highlightSquare = append(highlightSquare, lastMove.S1())
|
||||
highlightSquare = append(highlightSquare, lastMove.S2())
|
||||
}
|
||||
// 生成棋盘 svg 文件
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
fenStr := room.chessGame.FEN()
|
||||
gameTurn := room.chessGame.Position().Turn()
|
||||
pos := &chess.Position{}
|
||||
if err = pos.UnmarshalText(binary.StringToBytes(fenStr)); err != nil {
|
||||
return
|
||||
}
|
||||
yellow := color.RGBA{255, 255, 0, 1}
|
||||
mark := cimage.MarkSquares(yellow, highlightSquare...)
|
||||
board := pos.Board()
|
||||
fromBlack := cimage.Perspective(gameTurn)
|
||||
err = cimage.SVG(buf, board, fromBlack, mark)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
worker, err := resvg.NewDefaultWorker(context.Background())
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer worker.Close()
|
||||
|
||||
tree, err := worker.NewTreeFromData(buf.Bytes(), &resvg.Options{
|
||||
Dpi: 96,
|
||||
FontFamily: "Unifont",
|
||||
FontSize: 24.0,
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer tree.Close()
|
||||
|
||||
fontdb, err := worker.NewFontDBDefault()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer fontdb.Close()
|
||||
|
||||
err = fontdb.LoadFontData(fontdata)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = tree.ConvertText(fontdb)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
pixmap, err := worker.NewPixmap(720, 720)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer pixmap.Close()
|
||||
|
||||
err = tree.Render(resvg.TransformFromScale(2, 2), pixmap)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
out, err := pixmap.EncodePNG()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
imgMsg = message.ImageBytes(out)
|
||||
return imgMsg, nil
|
||||
}
|
||||
|
||||
// getELOString 获得玩家等级分的文本内容
|
||||
func getELOString(room chessRoom, whiteScore, blackScore float64) (string, error) {
|
||||
if room.whitePlayer == 0 || room.blackPlayer == 0 {
|
||||
return "", nil
|
||||
}
|
||||
var msgBuilder strings.Builder
|
||||
msgBuilder.WriteString("玩家等级分: \n")
|
||||
dbService := newDBService()
|
||||
if err := updateELORate(room.whitePlayer, room.blackPlayer, room.whiteName, room.blackName, whiteScore, blackScore, dbService); err != nil {
|
||||
return "", err
|
||||
}
|
||||
whiteRate, blackRate, err := getELORate(room.whitePlayer, room.blackPlayer, dbService)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
msgBuilder.WriteString(room.whiteName)
|
||||
msgBuilder.WriteString(": ")
|
||||
msgBuilder.WriteString(strconv.Itoa(whiteRate))
|
||||
msgBuilder.WriteString("\n")
|
||||
msgBuilder.WriteString(room.blackName)
|
||||
msgBuilder.WriteString(": ")
|
||||
msgBuilder.WriteString(strconv.Itoa(blackRate))
|
||||
msgBuilder.WriteString("\n\n")
|
||||
return msgBuilder.String(), nil
|
||||
}
|
||||
|
||||
// getRankingString 获取等级分排行榜的文本内容
|
||||
func getRanking() (message.Message, error) {
|
||||
dbService := newDBService()
|
||||
eloList, err := dbService.getHighestRateList()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var msgBuilder strings.Builder
|
||||
msgBuilder.WriteString("当前等级分排行榜: \n\n")
|
||||
for _, elo := range eloList {
|
||||
msgBuilder.WriteString(elo.Name)
|
||||
msgBuilder.WriteString(": ")
|
||||
msgBuilder.WriteString(strconv.Itoa(elo.Rate))
|
||||
msgBuilder.WriteString("\n")
|
||||
}
|
||||
return message.Message{message.Text(msgBuilder.String())}, nil
|
||||
}
|
||||
|
||||
// updateELORate 更新 elo 等级分
|
||||
// 当数据库中没有玩家的等级分信息时, 自动新建一条记录
|
||||
func updateELORate(whiteUin, blackUin int64, whiteName, blackName string, whiteScore, blackScore float64, dbService *chessDBService) error {
|
||||
whiteRate, err := dbService.getELORateByUin(whiteUin)
|
||||
if err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
return err
|
||||
}
|
||||
// create white elo
|
||||
if err := dbService.createELO(whiteUin, whiteName, eloDefault); err != nil {
|
||||
return err
|
||||
}
|
||||
whiteRate = eloDefault
|
||||
}
|
||||
blackRate, err := dbService.getELORateByUin(blackUin)
|
||||
if err != nil {
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
return err
|
||||
}
|
||||
// create black elo
|
||||
if err := dbService.createELO(blackUin, blackName, eloDefault); err != nil {
|
||||
return err
|
||||
}
|
||||
blackRate = eloDefault
|
||||
}
|
||||
whiteRate, blackRate = calculateNewRate(whiteRate, blackRate, whiteScore, blackScore)
|
||||
// 更新白棋玩家的 ELO 等级分
|
||||
if err := dbService.updateELOByUin(whiteUin, whiteName, whiteRate); err != nil {
|
||||
return err
|
||||
}
|
||||
// 更新黑棋玩家的 ELO 等级分
|
||||
return dbService.updateELOByUin(blackUin, blackName, blackRate)
|
||||
}
|
||||
|
||||
// getChessString 获取 PGN 字符串
|
||||
func getChessString(room chessRoom) string {
|
||||
game := room.chessGame
|
||||
dataString := fmt.Sprintf("[Date \"%s\"]\n", time.Now().Format("2006-01-02"))
|
||||
whiteString := fmt.Sprintf("[White \"%s\"]\n", room.whiteName)
|
||||
blackString := fmt.Sprintf("[Black \"%s\"]\n", room.blackName)
|
||||
chessString := game.String()
|
||||
|
||||
return dataString + whiteString + blackString + chessString
|
||||
}
|
||||
|
||||
// getELORate 获取玩家的 ELO 等级分
|
||||
func getELORate(whiteUin, blackUin int64, dbService *chessDBService) (whiteRate int, blackRate int, err error) {
|
||||
whiteRate, err = dbService.getELORateByUin(whiteUin)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
blackRate, err = dbService.getELORateByUin(blackUin)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// isAprilFoolsDay 判断当前时间是否为愚人节期间
|
||||
func isAprilFoolsDay() bool {
|
||||
now := time.Now()
|
||||
return now.Month() == 4 && now.Day() == 1
|
||||
}
|
||||
100
plugin/chess/db.go
Normal file
100
plugin/chess/db.go
Normal file
@@ -0,0 +1,100 @@
|
||||
package chess
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/jinzhu/gorm"
|
||||
)
|
||||
|
||||
var chessDB *gorm.DB
|
||||
|
||||
// elo user elo info
|
||||
type elo struct {
|
||||
gorm.Model
|
||||
Uin int64 `gorm:"unique_index"`
|
||||
Name string
|
||||
Rate int
|
||||
}
|
||||
|
||||
// pgn chess pgn info
|
||||
type pgn struct {
|
||||
gorm.Model
|
||||
Data string
|
||||
WhiteUin int64
|
||||
BlackUin int64
|
||||
WhiteName string
|
||||
BlackName string
|
||||
}
|
||||
|
||||
// chessDBService 数据库服务
|
||||
type chessDBService struct {
|
||||
db *gorm.DB
|
||||
}
|
||||
|
||||
// newDBService 创建数据库服务
|
||||
func newDBService() *chessDBService {
|
||||
return &chessDBService{
|
||||
db: chessDB,
|
||||
}
|
||||
}
|
||||
|
||||
// initDatabase init database
|
||||
func initDatabase(dbPath string) {
|
||||
var err error
|
||||
if _, err = os.Stat(dbPath); err != nil || os.IsNotExist(err) {
|
||||
f, err := os.Create(dbPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer f.Close()
|
||||
}
|
||||
chessDB, err = gorm.Open("sqlite3", dbPath)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
chessDB.AutoMigrate(&elo{}, &pgn{})
|
||||
}
|
||||
|
||||
// createELO 创建 ELO
|
||||
func (s *chessDBService) createELO(uin int64, name string, rate int) error {
|
||||
return s.db.Create(&elo{
|
||||
Uin: uin,
|
||||
Name: name,
|
||||
Rate: rate,
|
||||
}).Error
|
||||
}
|
||||
|
||||
// getELORateByUin 获取 ELO 等级分
|
||||
func (s *chessDBService) getELORateByUin(uin int64) (int, error) {
|
||||
var elo elo
|
||||
err := s.db.Select("rate").Where("uin = ?", uin).First(&elo).Error
|
||||
return elo.Rate, err
|
||||
}
|
||||
|
||||
// getHighestRateList 获取最高的等级分列表
|
||||
func (s *chessDBService) getHighestRateList() ([]elo, error) {
|
||||
var eloList []elo
|
||||
err := s.db.Order("rate desc").Limit(10).Find(&eloList).Error
|
||||
return eloList, err
|
||||
}
|
||||
|
||||
// updateELOByUin 更新 ELO 等级分
|
||||
func (s *chessDBService) updateELOByUin(uin int64, name string, rate int) error {
|
||||
return s.db.Model(&elo{}).Where("uin = ?", uin).Update("name", name).Update("rate", rate).Error
|
||||
}
|
||||
|
||||
// cleanELOByUin 清空用户 ELO 等级分
|
||||
func (s *chessDBService) cleanELOByUin(uin int64) error {
|
||||
return s.db.Model(&elo{}).Where("uin = ?", uin).Update("rate", 100).Error
|
||||
}
|
||||
|
||||
// createPGN 创建 PGN
|
||||
func (s *chessDBService) createPGN(data string, whiteUin int64, blackUin int64, whiteName string, blackName string) error {
|
||||
return s.db.Create(&pgn{
|
||||
Data: data,
|
||||
WhiteUin: whiteUin,
|
||||
BlackUin: blackUin,
|
||||
WhiteName: whiteName,
|
||||
BlackName: blackName,
|
||||
}).Error
|
||||
}
|
||||
37
plugin/chess/elo.go
Normal file
37
plugin/chess/elo.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package chess
|
||||
|
||||
import (
|
||||
"math"
|
||||
)
|
||||
|
||||
// calculateNewRate calculate new rate of the player
|
||||
func calculateNewRate(whiteRate, blackRate int, whiteScore, blackScore float64) (int, int) {
|
||||
k := getKFactor(whiteRate, blackRate)
|
||||
exceptionWhite := calculateException(whiteRate, blackRate)
|
||||
exceptionBlack := calculateException(blackRate, whiteRate)
|
||||
whiteRate = calculateRate(whiteRate, whiteScore, exceptionWhite, k)
|
||||
blackRate = calculateRate(blackRate, blackScore, exceptionBlack, k)
|
||||
return whiteRate, blackRate
|
||||
}
|
||||
|
||||
func calculateException(rate int, opponentRate int) float64 {
|
||||
return 1.0 / (1.0 + math.Pow(10.0, float64(opponentRate-rate)/400.0))
|
||||
}
|
||||
|
||||
func calculateRate(rate int, score float64, exception float64, k int) int {
|
||||
newRate := int(math.Round(float64(rate) + float64(k)*(score-exception)))
|
||||
if newRate < 1 {
|
||||
newRate = 1
|
||||
}
|
||||
return newRate
|
||||
}
|
||||
|
||||
func getKFactor(rateA, rateB int) int {
|
||||
if rateA > 2400 && rateB > 2400 {
|
||||
return 16
|
||||
}
|
||||
if rateA > 2100 && rateB > 2100 {
|
||||
return 24
|
||||
}
|
||||
return 32
|
||||
}
|
||||
80
plugin/chess/elo_test.go
Normal file
80
plugin/chess/elo_test.go
Normal file
@@ -0,0 +1,80 @@
|
||||
package chess
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCalculateNewRate(t *testing.T) {
|
||||
type args struct {
|
||||
whiteRate int
|
||||
blackRate int
|
||||
whiteScore float64
|
||||
blackScore float64
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want int
|
||||
want1 int
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
args: args{
|
||||
whiteRate: 1613,
|
||||
blackRate: 1573,
|
||||
whiteScore: 0.5,
|
||||
blackScore: 0.5,
|
||||
},
|
||||
want: 1611,
|
||||
want1: 1575,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got, got1 := calculateNewRate(tt.args.whiteRate, tt.args.blackRate, tt.args.whiteScore, tt.args.blackScore)
|
||||
if got != tt.want {
|
||||
t.Errorf("CalculateNewRate() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
if got1 != tt.want1 {
|
||||
t.Errorf("CalculateNewRate() got1 = %v, want %v", got1, tt.want1)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func Test_calculateException(t *testing.T) {
|
||||
type args struct {
|
||||
rate int
|
||||
opponentRate int
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want float64
|
||||
}{
|
||||
{
|
||||
name: "test1",
|
||||
args: args{
|
||||
rate: 1613,
|
||||
opponentRate: 1573,
|
||||
},
|
||||
want: 0.5573116,
|
||||
},
|
||||
{
|
||||
name: "test2",
|
||||
args: args{
|
||||
rate: 1613,
|
||||
opponentRate: 1613,
|
||||
},
|
||||
want: 0.5,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := calculateException(tt.args.rate, tt.args.opponentRate); math.Abs(got-tt.want) > 0.0001 {
|
||||
t.Errorf("calculateException() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("choose", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "选择困难症帮手",
|
||||
Help: "例: 选择可口可乐还是百事可乐\n" +
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
en := control.Register("chouxianghua", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "翻译为抽象话",
|
||||
Help: "- 抽象翻译xxx",
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
func init() {
|
||||
// 初始化engine
|
||||
engine := control.Register("chrev", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "英文字符翻转",
|
||||
Help: "例: 翻转 I love you",
|
||||
|
||||
@@ -53,7 +53,7 @@ func init() {
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
control.Register("coser", &ctrl.Options[*zero.Ctx]{
|
||||
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "三次元coser",
|
||||
Help: "- coser",
|
||||
|
||||
@@ -16,7 +16,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("cpstory", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "cp短打", // 这里也许有更好的名字
|
||||
Help: "- 组cp[@xxx][@xxx]\n- 磕cp大老师 雪乃",
|
||||
|
||||
@@ -21,7 +21,7 @@ const (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("curse", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: true,
|
||||
Brief: "骂人反击",
|
||||
Help: "- 骂我\n- 大力骂我",
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
const api = "http://dwz.2xb.cn/zaob"
|
||||
|
||||
func init() {
|
||||
engine := control.Register("dailynews", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "今日早报",
|
||||
Help: "- 今日早报",
|
||||
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("danbooru", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "二次元图片标签识别",
|
||||
Help: "- 鉴赏图片[图片]",
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"github.com/FloatTech/ZeroBot-Plugin/plugin/diana/data"
|
||||
)
|
||||
|
||||
var engine = control.Register("diana", &ctrl.Options[*zero.Ctx]{
|
||||
var engine = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "嘉然相关", // 也许使用常用功能当Brief更好
|
||||
Help: "- 小作文\n" +
|
||||
|
||||
@@ -30,7 +30,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
en := control.Register("dish", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "程序员做饭指南",
|
||||
Help: "-怎么做[xxx]|烹饪[xxx]|随机菜谱|随便做点菜",
|
||||
|
||||
@@ -40,7 +40,7 @@ var (
|
||||
}
|
||||
return lotsList
|
||||
}()
|
||||
en = control.Register("drawlots", &ctrl.Options[*zero.Ctx]{
|
||||
en = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "多功能抽签",
|
||||
Help: "支持图包文件夹和gif抽签\n" +
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("dress", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "女装",
|
||||
Help: "女装\n" +
|
||||
|
||||
@@ -33,7 +33,7 @@ var seaLocker sync.RWMutex
|
||||
// We need a container to inject what we need :(
|
||||
|
||||
func init() {
|
||||
en := control.Register("driftbottle", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "漂流瓶",
|
||||
Help: "- @bot pick" + "- @bot throw xxx (xxx为投递内容)",
|
||||
@@ -17,7 +17,7 @@ import (
|
||||
const bed = "https://www.gstatic.com/android/keyboard/emojikitchen/%d/u%x/u%x_u%x.png"
|
||||
|
||||
func init() {
|
||||
control.Register("emojimix", &ctrl.Options[*zero.Ctx]{
|
||||
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "合成emoji",
|
||||
Help: "- [emoji][emoji]",
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("event", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "好友申请和群聊邀请事件处理",
|
||||
Help: "- [开启|关闭]自动同意[申请|邀请|主人]\n" +
|
||||
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
control.Register("font", &ctrl.Options[*zero.Ctx]{
|
||||
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "渲染任意文字到图片",
|
||||
Help: "- (用[字体])渲染(抖动)文字xxx\n可选字体: [终末体|终末变体|紫罗兰体|樱酥体|Consolas体|粗苹方体|未来荧黑体|Gugi体|八丸体|Impact体|猫啃体|苹方体]",
|
||||
|
||||
@@ -48,7 +48,7 @@ var (
|
||||
|
||||
func init() {
|
||||
// 插件主体
|
||||
en := control.Register("fortune", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "每日运势",
|
||||
Help: "- 运势 | 抽签\n" +
|
||||
|
||||
@@ -24,7 +24,7 @@ type joke struct {
|
||||
var db = &sql.Sqlite{}
|
||||
|
||||
func init() {
|
||||
en := control.Register("funny", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "讲个笑话",
|
||||
Help: "- 讲个笑话[@xxx|qq号|人名] | 夸夸[@xxx|qq号|人名] ",
|
||||
|
||||
@@ -35,7 +35,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("genshin", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "原神模拟抽卡",
|
||||
Help: "- 原神十连\n- 切换原神卡池",
|
||||
|
||||
@@ -126,7 +126,7 @@ func init() { // 插件主体
|
||||
for k := range cmdMap {
|
||||
cmd = append(cmd, k)
|
||||
}
|
||||
en := control.Register("gif", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "制图",
|
||||
Help: "下为制图命令:\n" +
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
control.Register("github", &ctrl.Options[*zero.Ctx]{
|
||||
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "GitHub仓库搜索",
|
||||
Help: "- >github [xxx]\n" +
|
||||
|
||||
@@ -31,7 +31,7 @@ var (
|
||||
// 用户数据
|
||||
cfg config
|
||||
// 插件主体
|
||||
engine = control.Register("guessmusic", &ctrl.Options[*zero.Ctx]{
|
||||
engine = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "猜歌插件",
|
||||
Help: "------bot主人指令------\n" +
|
||||
|
||||
@@ -66,7 +66,7 @@ func init() { // 插件主体
|
||||
panic(err)
|
||||
}
|
||||
|
||||
engine := control.Register("heisi", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "黑丝",
|
||||
Help: "- 来点黑丝\n- 来点白丝\n- 来点jk\n- 来点巨乳\n- 来点足控\n- 来点网红",
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("hitokoto", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "一言",
|
||||
Help: "- 一言[xxx]\n" +
|
||||
|
||||
@@ -41,7 +41,7 @@ const (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("hs", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "炉石搜卡",
|
||||
Help: "- 搜卡[xxxx]\n" +
|
||||
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
const bed = "https://gitcode.net/u011570312/OguraHyakuninIsshu/-/raw/master/"
|
||||
const bed = "https://gitea.seku.su/fumiama/OguraHyakuninIsshu/raw/branch/master/"
|
||||
|
||||
type line struct {
|
||||
番号, 歌人, 上の句, 下の句, 上の句ひらがな, 下の句ひらがな string
|
||||
@@ -51,7 +51,7 @@ func (l *line) String() string {
|
||||
var lines [100]*line
|
||||
|
||||
func init() {
|
||||
engine := control.Register("hyaku", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "百人一首",
|
||||
Help: "- 百人一首(随机发一首)\n" +
|
||||
|
||||
@@ -62,7 +62,7 @@ type resultjson struct {
|
||||
var hrefre = regexp.MustCompile(`<a href=".*">`)
|
||||
|
||||
func init() {
|
||||
control.Register("imgfinder", &ctrl.Options[*zero.Ctx]{
|
||||
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "关键字搜图",
|
||||
Help: "- 来张 [xxx]",
|
||||
@@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
en := control.Register("inject", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "注入指令",
|
||||
Help: "- run[CQ码]",
|
||||
|
||||
@@ -23,7 +23,7 @@ const (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("jandan", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "煎蛋网无聊图",
|
||||
Help: "- 来份[屌|弔|吊]图\n- 更新[屌|弔|吊]图\n",
|
||||
|
||||
@@ -25,7 +25,7 @@ type nmd struct { // struct解析格式大概是
|
||||
}
|
||||
|
||||
func init() { // 主函数
|
||||
en := control.Register("jiami", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "兽语加解密",
|
||||
Help: "兽语加解密\n" +
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("jptingroom", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "日语听力学习材料",
|
||||
Help: "- 随机日语听力\n" +
|
||||
|
||||
@@ -23,7 +23,7 @@ const (
|
||||
)
|
||||
|
||||
func init() {
|
||||
control.Register("juejuezi", &ctrl.Options[*zero.Ctx]{
|
||||
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "绝绝子生成器",
|
||||
Help: "例: 喝奶茶绝绝子\n绝绝子吃饭",
|
||||
|
||||
@@ -15,7 +15,7 @@ const (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("kfccrazythursday", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "疯狂星期四",
|
||||
Help: "疯狂星期四\n",
|
||||
|
||||
@@ -32,7 +32,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
en := control.Register("lolicon", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "随机图片",
|
||||
Help: "- 随机图片\n" +
|
||||
|
||||
@@ -23,7 +23,7 @@ const (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("magicprompt", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "MagicPrompt-Stable-Diffusion吟唱提示",
|
||||
Help: "- 吟唱提示 xxx",
|
||||
|
||||
@@ -64,7 +64,7 @@ var (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("manager", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "群管插件",
|
||||
Help: hint,
|
||||
|
||||
370
plugin/mcfish/fish.go
Normal file
370
plugin/mcfish/fish.go
Normal file
@@ -0,0 +1,370 @@
|
||||
// Package mcfish 钓鱼模拟器
|
||||
package mcfish
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/wallet"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
"github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine.OnRegex(`^进行(([1-5]\d|[1-9])次)?钓鱼$`, getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
uid := ctx.Event.UserID
|
||||
numberOfPole, err := dbdata.getNumberFor(uid, "竿")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.9.3]:", err))
|
||||
return
|
||||
}
|
||||
if numberOfPole > 30 {
|
||||
ctx.SendChain(message.Text("你有", numberOfPole, "支鱼竿,大于30支的玩家不允许钓鱼"))
|
||||
return
|
||||
}
|
||||
fishNumber := 1
|
||||
info := ctx.State["regex_matched"].([]string)[2]
|
||||
if info != "" {
|
||||
number, err := strconv.Atoi(info)
|
||||
if err != nil || number > FishLimit {
|
||||
ctx.SendChain(message.Text("请输入正确的次数"))
|
||||
return
|
||||
}
|
||||
fishNumber = number
|
||||
}
|
||||
equipInfo, err := dbdata.getUserEquip(uid)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.2]:", err))
|
||||
return
|
||||
}
|
||||
if equipInfo == (equip{}) {
|
||||
ok, err := dbdata.checkEquipFor(uid)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.2.1]:", err))
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
ctx.SendChain(message.At(uid), message.Text("请装备鱼竿后钓鱼", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("你尚未装备鱼竿,是否花费100购买鱼竿?\n回答\"是\"或\"否\""))
|
||||
// 等待用户下一步选择
|
||||
recv, cancel := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(是|否)$`), zero.CheckUser(ctx.Event.UserID)).Repeat()
|
||||
defer cancel()
|
||||
buy := false
|
||||
for {
|
||||
select {
|
||||
case <-time.After(time.Second * 120):
|
||||
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
|
||||
}
|
||||
money := wallet.GetWalletOf(uid)
|
||||
if money < 100 {
|
||||
ctx.SendChain(message.Text("你钱包当前只有", money, "ATRI币,无法完成支付"))
|
||||
return
|
||||
}
|
||||
err = wallet.InsertWalletOf(uid, -100)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.3]:", err))
|
||||
return
|
||||
}
|
||||
equipInfo = equip{
|
||||
ID: uid,
|
||||
Equip: "木竿",
|
||||
Durable: 30,
|
||||
}
|
||||
err = dbdata.updateUserEquip(equipInfo)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.4]:", err))
|
||||
return
|
||||
}
|
||||
err = dbdata.setEquipFor(uid)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.4]:", err))
|
||||
return
|
||||
}
|
||||
buy = true
|
||||
}
|
||||
if buy {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if equipInfo.Durable < fishNumber {
|
||||
fishNumber = equipInfo.Durable
|
||||
}
|
||||
residue, err := dbdata.updateFishInfo(uid, fishNumber)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.1]:", err))
|
||||
return
|
||||
}
|
||||
if residue == 0 {
|
||||
ctx.SendChain(message.Text("今天你已经进行", FishLimit, "次钓鱼了.\n游戏虽好,但请不要沉迷。"))
|
||||
return
|
||||
}
|
||||
fishNumber = residue
|
||||
msg := ""
|
||||
if equipInfo.Equip != "美西螈" {
|
||||
equipInfo.Durable -= fishNumber
|
||||
err = dbdata.updateUserEquip(equipInfo)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.5]:", err))
|
||||
return
|
||||
}
|
||||
if equipInfo.Durable < 10 && equipInfo.Durable > 0 {
|
||||
msg = "(你的鱼竿耐久仅剩" + strconv.Itoa(equipInfo.Durable) + ")"
|
||||
} else if equipInfo.Durable <= 0 {
|
||||
msg = "(你的鱼竿已销毁)"
|
||||
}
|
||||
if equipInfo.Equip == "三叉戟" {
|
||||
fishNumber *= 3
|
||||
}
|
||||
} else {
|
||||
fishNmaes, err := dbdata.pickFishFor(uid, fishNumber)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.5.1]:", err))
|
||||
return
|
||||
}
|
||||
if len(fishNmaes) == 0 {
|
||||
equipInfo.Durable = 0
|
||||
err = dbdata.updateUserEquip(equipInfo)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.5]:", err))
|
||||
}
|
||||
ctx.SendChain(message.Text("美西螈因为没吃到鱼,钓鱼时一直没回来,你失去了美西螈"))
|
||||
return
|
||||
}
|
||||
msg = "(美西螈吃掉了"
|
||||
fishNumber = 0
|
||||
for name, number := range fishNmaes {
|
||||
fishNumber += number
|
||||
msg += strconv.Itoa(number) + name + "、"
|
||||
}
|
||||
msg += ")"
|
||||
fishNumber /= 2
|
||||
}
|
||||
waitTime := 120 / (equipInfo.Induce + 1)
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("你开始去钓鱼了,请耐心等待鱼上钩(预计要", time.Second*time.Duration(waitTime), ")"))
|
||||
timer := time.NewTimer(time.Second * time.Duration(rand.Intn(waitTime)+1))
|
||||
for {
|
||||
<-timer.C
|
||||
timer.Stop()
|
||||
break
|
||||
}
|
||||
// 钓到鱼的范围
|
||||
number, err := dbdata.getNumberFor(uid, "鱼")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.5.1]:", err))
|
||||
return
|
||||
}
|
||||
number2, err := dbdata.getNumberFor(uid, "海豚")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.5.1]:", err))
|
||||
return
|
||||
}
|
||||
if number > 100 || equipInfo.Equip == "美西螈" { // 放大概率
|
||||
probabilities["treasure"] = probabilityLimit{
|
||||
Min: 0,
|
||||
Max: 2,
|
||||
}
|
||||
probabilities["pole"] = probabilityLimit{
|
||||
Min: 2,
|
||||
Max: 10,
|
||||
}
|
||||
probabilities["fish"] = probabilityLimit{
|
||||
Min: 10,
|
||||
Max: 45,
|
||||
}
|
||||
probabilities["waste"] = probabilityLimit{
|
||||
Min: 45,
|
||||
Max: 90,
|
||||
}
|
||||
}
|
||||
if number2 != 0 {
|
||||
info := probabilities["waste"]
|
||||
info.Max = 100
|
||||
probabilities["waste"] = info
|
||||
}
|
||||
for name, info := range probabilities {
|
||||
switch name {
|
||||
case "treasure":
|
||||
info.Max += equipInfo.Favor
|
||||
probabilities[name] = info
|
||||
case "pole":
|
||||
info.Min += equipInfo.Favor
|
||||
info.Max += equipInfo.Favor * 2
|
||||
probabilities[name] = info
|
||||
case "fish":
|
||||
info.Min += equipInfo.Favor * 2
|
||||
info.Max += equipInfo.Favor * 3
|
||||
probabilities[name] = info
|
||||
case "waste":
|
||||
info.Min += equipInfo.Favor * 3
|
||||
probabilities[name] = info
|
||||
}
|
||||
}
|
||||
// 钓鱼结算
|
||||
picName := ""
|
||||
thingNameList := make(map[string]int)
|
||||
for i := fishNumber; i > 0; i-- {
|
||||
thingName := ""
|
||||
typeOfThing := ""
|
||||
number := 1
|
||||
dice := rand.Intn(100)
|
||||
switch {
|
||||
case dice >= probabilities["waste"].Min && dice < probabilities["waste"].Max: // 垃圾
|
||||
typeOfThing = "waste"
|
||||
thingName = wasteList[rand.Intn(len(wasteList))]
|
||||
picName = thingName
|
||||
case dice >= probabilities["treasure"].Min && dice < probabilities["treasure"].Max: // 宝藏
|
||||
dice = rand.Intn(100)
|
||||
switch {
|
||||
case dice >= probabilities["美西螈"].Min && dice < probabilities["美西螈"].Max:
|
||||
typeOfThing = "pole"
|
||||
picName = "美西螈"
|
||||
thingName = "美西螈"
|
||||
case dice >= probabilities["唱片"].Min && dice < probabilities["唱片"].Max:
|
||||
typeOfThing = "article"
|
||||
picName = "唱片"
|
||||
thingName = "唱片"
|
||||
case dice >= probabilities["海之眷顾"].Min && dice < probabilities["海之眷顾"].Max:
|
||||
typeOfThing = "article"
|
||||
picName = "book"
|
||||
thingName = "海之眷顾"
|
||||
case dice >= probabilities["净化书"].Min && dice < probabilities["净化书"].Max:
|
||||
typeOfThing = "article"
|
||||
picName = "book"
|
||||
thingName = "净化书"
|
||||
case dice >= probabilities["宝藏诅咒"].Min && dice < probabilities["宝藏诅咒"].Max:
|
||||
typeOfThing = "article"
|
||||
picName = "book"
|
||||
thingName = "宝藏诅咒"
|
||||
case dice >= probabilities["海豚"].Min && dice < probabilities["海豚"].Max:
|
||||
typeOfThing = "fish"
|
||||
picName = "海豚"
|
||||
thingName = "海豚"
|
||||
default:
|
||||
typeOfThing = "article"
|
||||
picName = "book"
|
||||
thingName = "诱钓"
|
||||
}
|
||||
case dice >= probabilities["pole"].Min && dice < probabilities["pole"].Max: // 宝藏
|
||||
typeOfThing = "pole"
|
||||
dice := rand.Intn(100)
|
||||
switch {
|
||||
case dice >= probabilities["铁竿"].Min && dice < probabilities["铁竿"].Max:
|
||||
thingName = "铁竿"
|
||||
case dice >= probabilities["金竿"].Min && dice < probabilities["金竿"].Max:
|
||||
thingName = "金竿"
|
||||
case dice >= probabilities["钻石竿"].Min && dice < probabilities["钻石竿"].Max:
|
||||
thingName = "钻石竿"
|
||||
case dice >= probabilities["下界合金竿竿竿"].Min && dice < probabilities["下界合金竿竿竿"].Max:
|
||||
thingName = "下界合金竿竿竿"
|
||||
default:
|
||||
thingName = "木竿"
|
||||
}
|
||||
picName = thingName
|
||||
case dice >= probabilities["fish"].Min && dice < probabilities["fish"].Max:
|
||||
typeOfThing = "fish"
|
||||
dice = rand.Intn(100)
|
||||
switch {
|
||||
case dice >= probabilities["墨鱼"].Min && dice < probabilities["墨鱼"].Max:
|
||||
thingName = "墨鱼"
|
||||
case dice >= probabilities["鳕鱼"].Min && dice < probabilities["鳕鱼"].Max:
|
||||
thingName = "鳕鱼"
|
||||
case dice >= probabilities["鲑鱼"].Min && dice < probabilities["鲑鱼"].Max:
|
||||
thingName = "鲑鱼"
|
||||
case dice >= probabilities["热带鱼"].Min && dice < probabilities["热带鱼"].Max:
|
||||
thingName = "热带鱼"
|
||||
case dice >= probabilities["河豚"].Min && dice < probabilities["河豚"].Max:
|
||||
thingName = "河豚"
|
||||
default:
|
||||
thingName = "鹦鹉螺"
|
||||
}
|
||||
picName = thingName
|
||||
default:
|
||||
thingNameList["赛博空气"]++
|
||||
}
|
||||
if thingName != "" {
|
||||
newThing := article{}
|
||||
if strings.Contains(thingName, "竿") {
|
||||
info := strconv.Itoa(rand.Intn(durationList[thingName])+1) +
|
||||
"/" + strconv.Itoa(rand.Intn(10)) + "/" +
|
||||
strconv.Itoa(rand.Intn(3)) + "/" + strconv.Itoa(rand.Intn(2))
|
||||
newThing = article{
|
||||
Duration: time.Now().Unix()*100 + int64(i),
|
||||
Type: typeOfThing,
|
||||
Name: thingName,
|
||||
Number: number,
|
||||
Other: info,
|
||||
}
|
||||
} else {
|
||||
thingInfo, err := dbdata.getUserThingInfo(uid, thingName)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.6]:", err))
|
||||
return
|
||||
}
|
||||
if len(thingInfo) == 0 {
|
||||
newThing = article{
|
||||
Duration: time.Now().Unix()*100 + int64(i),
|
||||
Type: typeOfThing,
|
||||
Name: thingName,
|
||||
}
|
||||
} else {
|
||||
newThing = thingInfo[0]
|
||||
}
|
||||
if equipInfo.Equip == "美西螈" && thingName != "美西螈" {
|
||||
number += 2
|
||||
}
|
||||
newThing.Number += number
|
||||
}
|
||||
err = dbdata.updateUserThingInfo(uid, newThing)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.7]:", err))
|
||||
return
|
||||
}
|
||||
thingNameList[thingName] += number
|
||||
}
|
||||
}
|
||||
err = dbdata.updateCurseFor(uid, "fish", fishNumber)
|
||||
if err != nil {
|
||||
logrus.Warnln(err)
|
||||
}
|
||||
if len(thingNameList) == 1 {
|
||||
thingName := ""
|
||||
numberOfFish := 0
|
||||
for name, number := range thingNameList {
|
||||
thingName = name
|
||||
numberOfFish = number
|
||||
}
|
||||
if picName != "" {
|
||||
pic, err := engine.GetLazyData(picName+".png", false)
|
||||
if err != nil {
|
||||
logrus.Warnln("[mcfish]error:", err)
|
||||
ctx.SendChain(message.At(uid), message.Text("恭喜你钓到了", numberOfFish, thingName, "\n", msg))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.At(uid), message.Text("恭喜你钓到了", numberOfFish, thingName, "\n", msg), message.ImageBytes(pic))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.At(uid), message.Text("恭喜你钓到了", numberOfFish, thingName, "\n", msg))
|
||||
return
|
||||
}
|
||||
msgInfo := make(message.Message, 0, 3+len(thingNameList))
|
||||
msgInfo = append(msgInfo, message.Reply(ctx.Event.MessageID), message.Text("你进行了", fishNumber, "次钓鱼,结果如下:\n"))
|
||||
for name, number := range thingNameList {
|
||||
msgInfo = append(msgInfo, message.Text(name, " : ", number, "\n"))
|
||||
}
|
||||
msgInfo = append(msgInfo, message.Text(msg))
|
||||
ctx.Send(msgInfo)
|
||||
})
|
||||
}
|
||||
776
plugin/mcfish/main.go
Normal file
776
plugin/mcfish/main.go
Normal file
@@ -0,0 +1,776 @@
|
||||
// Package mcfish 钓鱼模拟器
|
||||
package mcfish
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
fcext "github.com/FloatTech/floatbox/ctxext"
|
||||
"github.com/FloatTech/floatbox/math"
|
||||
sql "github.com/FloatTech/sqlite"
|
||||
ctrl "github.com/FloatTech/zbpctrl"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
type fishdb struct {
|
||||
db *sql.Sqlite
|
||||
sync.RWMutex
|
||||
}
|
||||
|
||||
// FishLimit 钓鱼次数上限
|
||||
const FishLimit = 50
|
||||
|
||||
// version 规则版本号
|
||||
const version = "5.4.2"
|
||||
|
||||
// 各物品信息
|
||||
type jsonInfo struct {
|
||||
ZoneInfo []zoneInfo `json:"分类"` // 区域概率
|
||||
ArticleInfo []articleInfo `json:"物品"` // 物品信息
|
||||
}
|
||||
type zoneInfo struct {
|
||||
Name string `json:"类型"` // 类型
|
||||
Probability int `json:"概率[0-100)"` // 概率
|
||||
}
|
||||
type articleInfo struct {
|
||||
Name string `json:"名称"` // 名称
|
||||
Type string `json:"类型"` // 类型
|
||||
Probability int `json:"概率[0-100),omitempty"` // 概率
|
||||
Durable int `json:"耐久上限,omitempty"` // 耐久
|
||||
Price int `json:"价格"` // 价格
|
||||
}
|
||||
|
||||
type probabilityLimit struct {
|
||||
Min int
|
||||
Max int
|
||||
}
|
||||
|
||||
type equip struct {
|
||||
ID int64 // 用户
|
||||
Equip string // 装备名称
|
||||
Durable int // 耐久
|
||||
Maintenance int // 维修次数
|
||||
Induce int // 诱钓等级
|
||||
Favor int // 眷顾等级
|
||||
}
|
||||
|
||||
type article struct {
|
||||
Duration int64
|
||||
Name string
|
||||
Number int
|
||||
Other string // 耐久/维修次数/诱钓/眷顾
|
||||
Type string
|
||||
}
|
||||
|
||||
type store struct {
|
||||
Duration int64
|
||||
Name string
|
||||
Number int
|
||||
Price int
|
||||
Other string // 耐久/维修次数/诱钓/眷顾
|
||||
Type string
|
||||
}
|
||||
|
||||
type fishState struct {
|
||||
ID int64
|
||||
Duration int64
|
||||
Fish int
|
||||
Equip int
|
||||
Curse int // 功德--(x)
|
||||
Bless int // 功德++(x)
|
||||
}
|
||||
|
||||
type storeDiscount struct {
|
||||
Name string
|
||||
Discount int
|
||||
}
|
||||
|
||||
// buff状态记录
|
||||
// buff0: 优惠卷
|
||||
type buffInfo struct {
|
||||
ID int64
|
||||
Duration int64
|
||||
BuyTimes int `db:"Buff0"` // 购买次数
|
||||
Coupon int `db:"Buff1"` // 优惠卷
|
||||
SalesPole int `db:"Buff2"` // 卖鱼竿上限
|
||||
BuyTing int `db:"Buff3"` // 购买上限
|
||||
Buff4 int `db:"Buff4"` // 暂定
|
||||
Buff5 int `db:"Buff5"` // 暂定
|
||||
Buff6 int `db:"Buff6"` // 暂定
|
||||
Buff7 int `db:"Buff7"` // 暂定
|
||||
Buff8 int `db:"Buff8"` // 暂定
|
||||
Buff9 int `db:"Buff9"` // 暂定
|
||||
}
|
||||
|
||||
var (
|
||||
articlesInfo = jsonInfo{} // 物品信息
|
||||
thingList = make([]string, 0, 100) // 竿列表
|
||||
poleList = make([]string, 0, 10) // 竿列表
|
||||
fishList = make([]string, 0, 10) // 鱼列表
|
||||
treasureList = make([]string, 0, 10) // 鱼列表
|
||||
wasteList = make([]string, 0, 10) // 垃圾列表
|
||||
probabilities = make(map[string]probabilityLimit, 50) // 概率分布
|
||||
priceList = make(map[string]int, 50) // 价格分布
|
||||
durationList = make(map[string]int, 50) // 装备耐久分布
|
||||
discountList = make(map[string]int, 50) // 价格波动信息
|
||||
enchantLevel = []string{"0", "Ⅰ", "Ⅱ", "Ⅲ"}
|
||||
dbdata = &fishdb{
|
||||
db: &sql.Sqlite{},
|
||||
}
|
||||
)
|
||||
|
||||
var (
|
||||
engine = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "钓鱼",
|
||||
Help: "一款钓鱼模拟器\n----------指令----------\n" +
|
||||
"- 钓鱼看板/钓鱼商店\n- 购买xxx\n- 购买xxx [数量]\n- 出售xxx\n- 出售xxx [数量]\n" +
|
||||
"- 钓鱼背包\n- 装备[xx竿|三叉戟|美西螈]\n- 附魔[诱钓|海之眷顾]\n- 修复鱼竿\n- 合成[xx竿|三叉戟]\n- 消除[绑定|宝藏]诅咒\n- 消除[绑定|宝藏]诅咒 [数量]\n" +
|
||||
"- 进行钓鱼\n- 进行n次钓鱼\n- 当前装备概率明细\n" +
|
||||
"规则V" + version + ":\n" +
|
||||
"1.每日的商店价格是波动的!!如何最大化收益自己考虑一下喔\n" +
|
||||
"2.装备信息:\n-> 木竿 : 耐久上限:30 均价:100 上钩概率:0.7%\n-> 铁竿 : 耐久上限:50 均价:300 上钩概率:0.2%\n-> 金竿 : 耐久上限:70 均价700 上钩概率:0.06%\n" +
|
||||
"-> 钻石竿 : 耐久上限:100 均价1500 上钩概率:0.03%\n-> 下界合金竿 : 耐久上限:150 均价3100 上钩概率:0.01%\n-> 三叉戟 : 可使1次钓鱼视为3次钓鱼. 耐久上限:300 均价4000 只能合成、修复和交易\n" +
|
||||
"3.附魔书信息:\n-> 诱钓 : 减少上钩时间. 均价:1000, 上钩概率:0.25%\n-> 海之眷顾 : 增加宝藏上钩概率. 均价:2500, 上钩概率:0.10%\n" +
|
||||
"4.稀有物品:\n-> 唱片 : 出售物品时使用该物品使价格翻倍. 均价:3000, 上钩概率:0.01%\n" +
|
||||
"-> 美西螈 : 可装备,获得隐形[钓鱼佬]buff,并让钓到除鱼竿和美西螈外的物品数量变成3,无耐久上限.不可修复/附魔,每次钓鱼消耗两任意鱼类物品. 均价:3000, 上钩概率:0.01%\n" +
|
||||
"-> 海豚 : 使空竿概率变成垃圾概率. 均价:1000, 上钩概率:0.19%\n" +
|
||||
"-> 宝藏诅咒 : 无法交易,每一层就会增加购买时10%价格和减少出售时10%价格(超过10层会变为倒贴钱). 上钩概率:0.25%\n-> 净化书 : 用于消除宝藏诅咒. 均价:5000, 上钩概率:0.19%\n" +
|
||||
"5.鱼类信息:\n-> 鳕鱼 : 均价:10 上钩概率:0.69%\n-> 鲑鱼 : 均价:50 上钩概率:0.2%\n-> 热带鱼 : 均价:100 上钩概率:0.06%\n-> 河豚 : 均价:300 上钩概率:0.03%\n-> 鹦鹉螺 : 均价:500 上钩概率:0.01%\n-> 墨鱼 : 均价:500 上钩概率:0.01%\n" +
|
||||
"6.垃圾:\n-> 均价:10 上钩概率:30%\n" +
|
||||
"7.物品BUFF:\n-> 钓鱼佬 : 当背包名字含有'鱼'的物品数量超过100时激活,钓到物品概率提高至90%\n-> 修复大师 : 当背包鱼竿数量超过10时激活,修复物品时耐久百分百继承\n" +
|
||||
"8.合成:\n-> 铁竿 : 3x木竿\n-> 金竿 : 3x铁竿\n-> 钻石竿 : 3x金竿\n-> 下界合金竿 : 3x钻石竿\n-> 三叉戟 : 3x下界合金竿\n注:合成成功率90%,继承附魔等级合/3的等级\n" +
|
||||
"9.杂项:\n-> 无装备的情况下,每人最多可以购买3次100块钱的鱼竿\n-> 默认状态钓鱼上钩概率为60%(理论值!!!)\n-> 附魔的鱼竿会因附魔变得昂贵,每个附魔最高3级\n-> 三叉戟不算鱼竿,修复时可直接满耐久\n" +
|
||||
"-> 鱼竿数量大于50的不能买东西;\n 鱼竿数量大于30的不能钓鱼;\n 每购/售10次鱼竿获得1层宝藏诅咒;\n 每购买20次物品将获得3次价格减半福利;\n 每钓鱼75次获得1本净化书;\n" +
|
||||
" 每天最多只可出售5个鱼竿和购买15次物品;",
|
||||
PublicDataFolder: "McFish",
|
||||
}).ApplySingle(ctxext.DefaultSingle)
|
||||
getdb = fcext.DoOnceOnSuccess(func(ctx *zero.Ctx) bool {
|
||||
dbdata.db.DBPath = engine.DataFolder() + "fishdata.db"
|
||||
err := dbdata.db.Open(time.Hour * 24)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at main.go.1]:", err))
|
||||
return false
|
||||
}
|
||||
return true
|
||||
})
|
||||
)
|
||||
|
||||
func init() {
|
||||
// go func() {
|
||||
_, err := engine.GetLazyData("articlesInfo.json", false)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
reader, err := os.Open(engine.DataFolder() + "articlesInfo.json")
|
||||
if err == nil {
|
||||
err = json.NewDecoder(reader).Decode(&articlesInfo)
|
||||
}
|
||||
if err == nil {
|
||||
err = reader.Close()
|
||||
}
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
probableList := make([]int, 4)
|
||||
for _, info := range articlesInfo.ZoneInfo {
|
||||
switch info.Name {
|
||||
case "treasure":
|
||||
probableList[0] = info.Probability
|
||||
case "pole":
|
||||
probableList[1] = info.Probability
|
||||
case "fish":
|
||||
probableList[2] = info.Probability
|
||||
case "waste":
|
||||
probableList[3] = info.Probability
|
||||
}
|
||||
}
|
||||
probabilities["treasure"] = probabilityLimit{
|
||||
Min: 0,
|
||||
Max: probableList[0],
|
||||
}
|
||||
probabilities["pole"] = probabilityLimit{
|
||||
Min: probableList[0],
|
||||
Max: probableList[1],
|
||||
}
|
||||
probabilities["fish"] = probabilityLimit{
|
||||
Min: probableList[1],
|
||||
Max: probableList[2],
|
||||
}
|
||||
probabilities["waste"] = probabilityLimit{
|
||||
Min: probableList[2],
|
||||
Max: probableList[3],
|
||||
}
|
||||
min := make(map[string]int, 4)
|
||||
for _, info := range articlesInfo.ArticleInfo {
|
||||
switch {
|
||||
case info.Type == "pole" || info.Name == "美西螈":
|
||||
poleList = append(poleList, info.Name)
|
||||
case info.Type == "fish" || info.Name == "海豚":
|
||||
fishList = append(fishList, info.Name)
|
||||
case info.Type == "waste":
|
||||
wasteList = append(wasteList, info.Name)
|
||||
case info.Type == "treasure":
|
||||
treasureList = append(treasureList, info.Name)
|
||||
}
|
||||
if info.Name != "宝藏诅咒" {
|
||||
thingList = append(thingList, info.Name)
|
||||
priceList[info.Name] = info.Price
|
||||
}
|
||||
if info.Durable != 0 {
|
||||
durationList[info.Name] = info.Durable
|
||||
}
|
||||
probabilities[info.Name] = probabilityLimit{
|
||||
Min: min[info.Type],
|
||||
Max: min[info.Type] + info.Probability,
|
||||
}
|
||||
min[info.Type] += info.Probability
|
||||
}
|
||||
// }()
|
||||
}
|
||||
|
||||
// 更新上限信息
|
||||
func (sql *fishdb) updateFishInfo(uid int64, number int) (residue int, err error) {
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
userInfo := fishState{ID: uid}
|
||||
err = sql.db.Create("fishState", &userInfo)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
_ = sql.db.Find("fishState", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
|
||||
if time.Unix(userInfo.Duration, 0).Day() != time.Now().Day() {
|
||||
userInfo.Fish = 0
|
||||
userInfo.Duration = time.Now().Unix()
|
||||
}
|
||||
if userInfo.Fish >= FishLimit {
|
||||
return 0, nil
|
||||
}
|
||||
residue = number
|
||||
if userInfo.Fish+number > FishLimit {
|
||||
residue = FishLimit - userInfo.Fish
|
||||
number = residue
|
||||
}
|
||||
userInfo.Fish += number
|
||||
err = sql.db.Insert("fishState", &userInfo)
|
||||
return
|
||||
}
|
||||
|
||||
// 更新诅咒
|
||||
func (sql *fishdb) updateCurseFor(uid int64, info string, number int) (err error) {
|
||||
if number < 1 {
|
||||
return
|
||||
}
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
userInfo := fishState{ID: uid}
|
||||
err = sql.db.Create("fishState", &userInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
changeCheck := false
|
||||
add := 0
|
||||
buffName := "宝藏诅咒"
|
||||
_ = sql.db.Find("fishState", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
|
||||
if info == "fish" {
|
||||
userInfo.Bless += number
|
||||
for userInfo.Bless >= 75 {
|
||||
add++
|
||||
changeCheck = true
|
||||
buffName = "净化书"
|
||||
userInfo.Bless -= 75
|
||||
}
|
||||
} else {
|
||||
userInfo.Curse += number
|
||||
for userInfo.Curse >= 10 {
|
||||
add++
|
||||
changeCheck = true
|
||||
userInfo.Curse -= 10
|
||||
}
|
||||
}
|
||||
err = sql.db.Insert("fishState", &userInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if changeCheck {
|
||||
table := strconv.FormatInt(uid, 10) + "Pack"
|
||||
thing := article{
|
||||
Duration: time.Now().Unix(),
|
||||
Name: buffName,
|
||||
Type: "treasure",
|
||||
}
|
||||
_ = sql.db.Find(table, &thing, "where Name = '"+buffName+"'")
|
||||
thing.Number += add
|
||||
return sql.db.Insert(table, &thing)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
/************************装备相关函数***********************/
|
||||
/*********************************************************/
|
||||
|
||||
func (sql *fishdb) checkEquipFor(uid int64) (ok bool, err error) {
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
userInfo := fishState{ID: uid}
|
||||
err = sql.db.Create("fishState", &userInfo)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if !sql.db.CanFind("fishState", "where ID = "+strconv.FormatInt(uid, 10)) {
|
||||
return true, nil
|
||||
}
|
||||
err = sql.db.Find("fishState", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
if userInfo.Equip > 3 {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (sql *fishdb) setEquipFor(uid int64) (err error) {
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
userInfo := fishState{ID: uid}
|
||||
err = sql.db.Create("fishState", &userInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_ = sql.db.Find("fishState", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
userInfo.Equip++
|
||||
return sql.db.Insert("fishState", &userInfo)
|
||||
}
|
||||
|
||||
// 获取装备信息
|
||||
func (sql *fishdb) getUserEquip(uid int64) (userInfo equip, err error) {
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
err = sql.db.Create("equips", &userInfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if !sql.db.CanFind("equips", "where ID = "+strconv.FormatInt(uid, 10)) {
|
||||
return
|
||||
}
|
||||
err = sql.db.Find("equips", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
|
||||
return
|
||||
}
|
||||
|
||||
// 更新装备信息
|
||||
func (sql *fishdb) updateUserEquip(userInfo equip) (err error) {
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
err = sql.db.Create("equips", &userInfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if userInfo.Durable == 0 {
|
||||
return sql.db.Del("equips", "where ID = "+strconv.FormatInt(userInfo.ID, 10))
|
||||
}
|
||||
return sql.db.Insert("equips", &userInfo)
|
||||
}
|
||||
|
||||
func (sql *fishdb) pickFishFor(uid int64, number int) (fishNames map[string]int, err error) {
|
||||
fishNames = make(map[string]int, 6)
|
||||
name := strconv.FormatInt(uid, 10) + "Pack"
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
userInfo := article{}
|
||||
err = sql.db.Create(name, &userInfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count, err := sql.db.Count(name)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if count == 0 {
|
||||
return
|
||||
}
|
||||
if !sql.db.CanFind(name, "where Type is 'fish'") {
|
||||
return
|
||||
}
|
||||
fishInfo := article{}
|
||||
k := 0
|
||||
for i := number * 2; i > 0 && k < len(fishList); {
|
||||
_ = sql.db.Find(name, &fishInfo, "where Name is '"+fishList[k]+"'")
|
||||
if fishInfo.Number <= 0 {
|
||||
k++
|
||||
continue
|
||||
}
|
||||
if fishInfo.Number < i {
|
||||
k++
|
||||
fishInfo.Number = 0
|
||||
i -= fishInfo.Number
|
||||
fishNames[fishInfo.Name] += fishInfo.Number
|
||||
} else {
|
||||
fishNames[fishInfo.Name] += i
|
||||
fishInfo.Number -= i
|
||||
i = 0
|
||||
}
|
||||
if fishInfo.Number <= 0 {
|
||||
err = sql.db.Del(name, "where Duration = "+strconv.FormatInt(fishInfo.Duration, 10))
|
||||
} else {
|
||||
err = sql.db.Insert(name, &fishInfo)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
/************************背包相关函数***********************/
|
||||
/*********************************************************/
|
||||
|
||||
// 获取用户背包信息
|
||||
func (sql *fishdb) getUserPack(uid int64) (thingInfos []article, err error) {
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
userInfo := article{}
|
||||
err = sql.db.Create(strconv.FormatInt(uid, 10)+"Pack", &userInfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count, err := sql.db.Count(strconv.FormatInt(uid, 10) + "Pack")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if count == 0 {
|
||||
return
|
||||
}
|
||||
err = sql.db.FindFor(strconv.FormatInt(uid, 10)+"Pack", &userInfo, "ORDER by Type, Name, Other ASC", func() error {
|
||||
thingInfos = append(thingInfos, userInfo)
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 获取用户物品信息
|
||||
func (sql *fishdb) getUserThingInfo(uid int64, thing 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
|
||||
}
|
||||
count, err := sql.db.Count(name)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if count == 0 {
|
||||
return
|
||||
}
|
||||
if !sql.db.CanFind(name, "where Name = '"+thing+"'") {
|
||||
return
|
||||
}
|
||||
err = sql.db.FindFor(name, &userInfo, "where Name = '"+thing+"'", func() error {
|
||||
thingInfos = append(thingInfos, userInfo)
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 更新用户物品信息
|
||||
func (sql *fishdb) updateUserThingInfo(uid int64, userInfo article) (err error) {
|
||||
name := strconv.FormatInt(uid, 10) + "Pack"
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
err = sql.db.Create(name, &userInfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if userInfo.Number == 0 {
|
||||
return sql.db.Del(name, "where Duration = "+strconv.FormatInt(userInfo.Duration, 10))
|
||||
}
|
||||
return sql.db.Insert(name, &userInfo)
|
||||
}
|
||||
|
||||
// 获取某关键字的数量
|
||||
func (sql *fishdb) getNumberFor(uid int64, thing string) (number int, 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
|
||||
}
|
||||
count, err := sql.db.Count(name)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if count == 0 {
|
||||
return
|
||||
}
|
||||
if !sql.db.CanFind(name, "where Name glob '*"+thing+"*'") {
|
||||
return
|
||||
}
|
||||
info := article{}
|
||||
err = sql.db.FindFor(name, &info, "where Name glob '*"+thing+"*'", func() error {
|
||||
number += info.Number
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
/*********************************************************/
|
||||
/************************商店相关函数***********************/
|
||||
/*********************************************************/
|
||||
|
||||
// 刷新商店信息
|
||||
func (sql *fishdb) refreshStroeInfo() (ok bool, err error) {
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
err = sql.db.Create("stroeDiscount", &storeDiscount{})
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
lastTime := storeDiscount{}
|
||||
_ = sql.db.Find("stroeDiscount", &lastTime, "where Name = 'lastTime'")
|
||||
refresh := false
|
||||
timeNow := time.Now().Day()
|
||||
if timeNow != lastTime.Discount {
|
||||
lastTime = storeDiscount{
|
||||
Name: "lastTime",
|
||||
Discount: timeNow,
|
||||
}
|
||||
err = sql.db.Insert("stroeDiscount", &lastTime)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
refresh = true
|
||||
}
|
||||
for _, name := range thingList {
|
||||
thing := storeDiscount{}
|
||||
switch refresh {
|
||||
case true:
|
||||
thingDiscount := 50 + rand.Intn(150)
|
||||
thing = storeDiscount{
|
||||
Name: name,
|
||||
Discount: thingDiscount,
|
||||
}
|
||||
err = sql.db.Insert("stroeDiscount", &thing)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
default:
|
||||
_ = sql.db.Find("stroeDiscount", &thing, "where Name = '"+name+"'")
|
||||
}
|
||||
if thing.Discount != 0 {
|
||||
discountList[name] = thing.Discount
|
||||
} else {
|
||||
discountList[name] = 100
|
||||
}
|
||||
}
|
||||
thing := store{}
|
||||
oldThing := []store{}
|
||||
_ = sql.db.FindFor("stroeDiscount", &thing, "where type = 'pole'", func() error {
|
||||
if time.Since(time.Unix(thing.Duration, 0)) > 24 {
|
||||
oldThing = append(oldThing, thing)
|
||||
}
|
||||
return nil
|
||||
})
|
||||
for _, info := range oldThing {
|
||||
_ = sql.db.Del("stroeDiscount", "where Duration = "+strconv.FormatInt(info.Duration, 10))
|
||||
}
|
||||
if refresh {
|
||||
err = sql.db.Create("store", &store{})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
// 每天调控1种鱼
|
||||
fish := fishList[rand.Intn(len(fishList))]
|
||||
thingInfo := store{
|
||||
Duration: time.Now().Unix(),
|
||||
Name: fish,
|
||||
Type: "fish",
|
||||
Price: priceList[fish] * discountList[fish] / 100,
|
||||
}
|
||||
_ = sql.db.Find("store", &thingInfo, "where Name = '"+fish+"'")
|
||||
thingInfo.Number += (100 - discountList[fish])
|
||||
if thingInfo.Number < 1 {
|
||||
thingInfo.Number = 100
|
||||
}
|
||||
_ = sql.db.Insert("store", &thingInfo)
|
||||
// 每天上架20本净化书
|
||||
thingInfo = store{
|
||||
Duration: time.Now().Unix(),
|
||||
Name: "净化书",
|
||||
Type: "article",
|
||||
Price: priceList["净化书"] * discountList["净化书"] / 100,
|
||||
}
|
||||
_ = sql.db.Find("store", &thingInfo, "where Name = '净化书'")
|
||||
thingInfo.Number = 20
|
||||
_ = sql.db.Insert("store", &thingInfo)
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// 获取商店信息
|
||||
func (sql *fishdb) getStoreInfo() (thingInfos []store, err error) {
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
thingInfo := store{}
|
||||
err = sql.db.Create("store", &thingInfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count, err := sql.db.Count("store")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if count == 0 {
|
||||
return
|
||||
}
|
||||
err = sql.db.FindFor("store", &thingInfo, "ORDER by Type, Name, Price ASC", func() error {
|
||||
thingInfos = append(thingInfos, thingInfo)
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 获取商店物品信息
|
||||
func (sql *fishdb) getStoreThingInfo(thing string) (thingInfos []store, err error) {
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
thingInfo := store{}
|
||||
err = sql.db.Create("store", &thingInfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count, err := sql.db.Count("store")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if count == 0 {
|
||||
return
|
||||
}
|
||||
if !sql.db.CanFind("store", "where Name = '"+thing+"'") {
|
||||
return
|
||||
}
|
||||
err = sql.db.FindFor("store", &thingInfo, "where Name = '"+thing+"'", func() error {
|
||||
thingInfos = append(thingInfos, thingInfo)
|
||||
return nil
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
// 获取商店物品信息
|
||||
func (sql *fishdb) checkStoreFor(thing store, number int) (ok bool, err error) {
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
err = sql.db.Create("store", &thing)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
count, err := sql.db.Count("store")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if count == 0 {
|
||||
return false, nil
|
||||
}
|
||||
if !sql.db.CanFind("store", "where Duration = "+strconv.FormatInt(thing.Duration, 10)) {
|
||||
return false, nil
|
||||
}
|
||||
err = sql.db.Find("store", &thing, "where Duration = "+strconv.FormatInt(thing.Duration, 10))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if thing.Number < number {
|
||||
return false, nil
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
// 更新商店信息
|
||||
func (sql *fishdb) updateStoreInfo(thingInfo store) (err error) {
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
err = sql.db.Create("store", &thingInfo)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if thingInfo.Number == 0 {
|
||||
return sql.db.Del("store", "where Duration = "+strconv.FormatInt(thingInfo.Duration, 10))
|
||||
}
|
||||
return sql.db.Insert("store", &thingInfo)
|
||||
}
|
||||
|
||||
// 更新购买次数
|
||||
func (sql *fishdb) updateBuyTimeFor(uid int64, add int) (err error) {
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
userInfo := buffInfo{ID: uid}
|
||||
err = sql.db.Create("buff", &userInfo)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_ = sql.db.Find("buff", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
|
||||
userInfo.BuyTimes += add
|
||||
if userInfo.BuyTimes > 20 {
|
||||
userInfo.BuyTimes -= 20
|
||||
userInfo.Coupon = 3
|
||||
}
|
||||
return sql.db.Insert("buff", &userInfo)
|
||||
}
|
||||
|
||||
// 使用优惠卷
|
||||
func (sql *fishdb) useCouponAt(uid int64, times int) (int, error) {
|
||||
useTimes := -1
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
userInfo := buffInfo{ID: uid}
|
||||
err := sql.db.Create("buff", &userInfo)
|
||||
if err != nil {
|
||||
return useTimes, err
|
||||
}
|
||||
_ = sql.db.Find("buff", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
|
||||
if userInfo.Coupon > 0 {
|
||||
useTimes = math.Min(userInfo.Coupon, times)
|
||||
userInfo.Coupon -= useTimes
|
||||
}
|
||||
return useTimes, sql.db.Insert("buff", &userInfo)
|
||||
}
|
||||
|
||||
// 检测上限
|
||||
func (sql *fishdb) checkCanSalesFor(uid int64, sales bool) (int, error) {
|
||||
residue := 0
|
||||
sql.Lock()
|
||||
defer sql.Unlock()
|
||||
userInfo := buffInfo{ID: uid}
|
||||
err := sql.db.Create("buff", &userInfo)
|
||||
if err != nil {
|
||||
return residue, err
|
||||
}
|
||||
_ = sql.db.Find("buff", &userInfo, "where ID = "+strconv.FormatInt(uid, 10))
|
||||
if time.Now().Day() != time.Unix(userInfo.Duration, 0).Day() {
|
||||
userInfo.SalesPole = 0
|
||||
userInfo.BuyTing = 0
|
||||
}
|
||||
if sales && userInfo.SalesPole < 5 {
|
||||
residue = 5 - userInfo.SalesPole
|
||||
userInfo.SalesPole++
|
||||
} else if userInfo.BuyTing < 15 {
|
||||
residue = 15 - userInfo.SalesPole
|
||||
userInfo.SalesPole++
|
||||
}
|
||||
return residue, sql.db.Insert("buff", &userInfo)
|
||||
}
|
||||
517
plugin/mcfish/pack.go
Normal file
517
plugin/mcfish/pack.go
Normal file
@@ -0,0 +1,517 @@
|
||||
// Package mcfish 钓鱼模拟器
|
||||
package mcfish
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"image"
|
||||
"image/color"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/wallet"
|
||||
"github.com/FloatTech/floatbox/file"
|
||||
"github.com/FloatTech/floatbox/math"
|
||||
"github.com/FloatTech/gg"
|
||||
"github.com/FloatTech/imgfactory"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
"github.com/FloatTech/zbputils/img/text"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine.OnFullMatch("钓鱼背包", getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
uid := ctx.Event.UserID
|
||||
equipInfo, err := dbdata.getUserEquip(uid)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pack.go.1]:", err))
|
||||
return
|
||||
}
|
||||
articles, err := dbdata.getUserPack(uid)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pack.go.2]:", err))
|
||||
return
|
||||
}
|
||||
pic, err := drawPackImage(uid, equipInfo, articles)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pack.go.3]:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.ImageBytes(pic))
|
||||
})
|
||||
engine.OnRegex(`^消除绑定诅咒(\d*)$`, getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
uid := ctx.Event.UserID
|
||||
number, _ := strconv.Atoi(ctx.State["regex_matched"].([]string)[1])
|
||||
if number == 0 {
|
||||
number = 1
|
||||
}
|
||||
number1, err := dbdata.getNumberFor(uid, "宝藏诅咒")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.3.1]:", err))
|
||||
return
|
||||
}
|
||||
if number1 == 0 {
|
||||
ctx.SendChain(message.Text("你没有绑定任何诅咒"))
|
||||
return
|
||||
}
|
||||
if number1 < number {
|
||||
number = number1
|
||||
}
|
||||
number2, err := dbdata.getNumberFor(uid, "净化书")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.3.2]:", err))
|
||||
return
|
||||
}
|
||||
if number2 < number {
|
||||
ctx.SendChain(message.Text("你没有足够的解除诅咒的道具"))
|
||||
return
|
||||
}
|
||||
articles, err := dbdata.getUserThingInfo(uid, "净化书")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.3.3]:", err))
|
||||
return
|
||||
}
|
||||
articles[0].Number -= number
|
||||
err = dbdata.updateUserThingInfo(uid, articles[0])
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.3.4]:", err))
|
||||
return
|
||||
}
|
||||
articles, err = dbdata.getUserThingInfo(uid, "宝藏诅咒")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("消除失败,净化书销毁了\n[ERROR at store.go.3.5]:", err))
|
||||
return
|
||||
}
|
||||
articles[0].Number -= number
|
||||
err = dbdata.updateUserThingInfo(uid, articles[0])
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.3.5]:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text("消除成功"))
|
||||
})
|
||||
engine.OnFullMatch("当前装备概率明细", getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
uid := ctx.Event.UserID
|
||||
equipInfo, err := dbdata.getUserEquip(uid)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pack.go.1]:", err))
|
||||
return
|
||||
}
|
||||
number, err := dbdata.getNumberFor(uid, "鱼")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.5.1]:", err))
|
||||
return
|
||||
}
|
||||
msg := make(message.Message, 0, 20+len(thingList))
|
||||
msg = append(msg, message.At(uid), message.Text("\n大类概率:\n"))
|
||||
probableList := make([]int, 4)
|
||||
for _, info := range articlesInfo.ZoneInfo {
|
||||
switch info.Name {
|
||||
case "treasure":
|
||||
probableList[0] = info.Probability
|
||||
case "pole":
|
||||
probableList[1] = info.Probability
|
||||
case "fish":
|
||||
probableList[2] = info.Probability
|
||||
case "waste":
|
||||
probableList[3] = info.Probability
|
||||
}
|
||||
}
|
||||
if number > 100 || equipInfo.Equip == "美西螈" { // 放大概率
|
||||
probableList = []int{2, 8, 35, 45}
|
||||
}
|
||||
if equipInfo.Favor > 0 {
|
||||
probableList[0] += equipInfo.Favor
|
||||
probableList[1] += equipInfo.Favor
|
||||
probableList[2] += equipInfo.Favor
|
||||
probableList[3] -= equipInfo.Favor * 3
|
||||
}
|
||||
probable := probableList[0]
|
||||
msg = append(msg, message.Text("宝藏 : ", probableList[0], "%\n"))
|
||||
probable += probableList[1]
|
||||
msg = append(msg, message.Text("鱼竿 : ", probableList[1], "%\n"))
|
||||
probable += probableList[2]
|
||||
msg = append(msg, message.Text("鱼类 : ", probableList[2], "%\n"))
|
||||
probable += probableList[3]
|
||||
msg = append(msg, message.Text("垃圾 : ", probableList[3], "%\n"))
|
||||
msg = append(msg, message.Text("合计 : ", probable, "%\n"))
|
||||
msg = append(msg, message.Text("-----------\n宝藏概率:\n"))
|
||||
for _, name := range treasureList {
|
||||
msg = append(msg, message.Text(name, " : ",
|
||||
strconv.FormatFloat(float64(probabilities[name].Max-probabilities[name].Min)*float64(probableList[0])/100, 'f', 2, 64),
|
||||
"%\n"))
|
||||
}
|
||||
msg = append(msg, message.Text("-----------\n鱼竿概率:\n"))
|
||||
for _, name := range poleList {
|
||||
if name != "美西螈" {
|
||||
msg = append(msg, message.Text(name, " : ",
|
||||
strconv.FormatFloat(float64(probabilities[name].Max-probabilities[name].Min)*float64(probableList[1])/100, 'f', 2, 64),
|
||||
"%\n"))
|
||||
} else if name == "美西螈" {
|
||||
msg = append(msg, message.Text(name, " : ",
|
||||
strconv.FormatFloat(float64(probabilities[name].Max-probabilities[name].Min)*float64(probableList[0])/100, 'f', 2, 64),
|
||||
"%\n"))
|
||||
}
|
||||
}
|
||||
msg = append(msg, message.Text("-----------\n鱼类概率:\n"))
|
||||
for _, name := range fishList {
|
||||
if name != "海豚" {
|
||||
msg = append(msg, message.Text(name, " : ",
|
||||
strconv.FormatFloat(float64(probabilities[name].Max-probabilities[name].Min)*float64(probableList[2])/100, 'f', 2, 64),
|
||||
"%\n"))
|
||||
} else if name == "海豚" {
|
||||
msg = append(msg, message.Text(name, " : ",
|
||||
strconv.FormatFloat(float64(probabilities[name].Max-probabilities[name].Min)*float64(probableList[0])/100, 'f', 2, 64),
|
||||
"%\n"))
|
||||
}
|
||||
}
|
||||
msg = append(msg, message.Text("-----------"))
|
||||
ctx.Send(msg)
|
||||
})
|
||||
}
|
||||
|
||||
func drawPackImage(uid int64, equipInfo equip, articles []article) (imagePicByte []byte, err error) {
|
||||
fontdata, err := file.GetLazyData(text.BoldFontFile, control.Md5File, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
var (
|
||||
wg sync.WaitGroup
|
||||
equipBlock image.Image // 装备信息
|
||||
packBlock image.Image // 背包信息
|
||||
)
|
||||
wg.Add(1)
|
||||
// 绘制ID
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if equipInfo == (equip{}) {
|
||||
equipBlock, err = drawEquipEmptyBlock(fontdata)
|
||||
} else {
|
||||
equipBlock, err = drawEquipInfoBlock(equipInfo, fontdata)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
wg.Add(1)
|
||||
// 绘制基本信息
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
if len(articles) == 0 {
|
||||
packBlock, err = drawArticleEmptyBlock(fontdata)
|
||||
} else {
|
||||
packBlock, err = drawArticleInfoBlock(uid, articles, fontdata)
|
||||
}
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}()
|
||||
wg.Wait()
|
||||
if equipBlock == nil || packBlock == nil {
|
||||
err = errors.New("生成图片失败,数据缺失")
|
||||
return
|
||||
}
|
||||
// 计算图片高度
|
||||
backDX := 1020
|
||||
backDY := 10 + equipBlock.Bounds().Dy() + 10 + packBlock.Bounds().Dy() + 10
|
||||
canvas := gg.NewContext(backDX, backDY)
|
||||
|
||||
// 画底色
|
||||
canvas.DrawRectangle(0, 0, float64(backDX), float64(backDY))
|
||||
canvas.SetRGBA255(150, 150, 150, 255)
|
||||
canvas.Fill()
|
||||
canvas.DrawRectangle(10, 10, float64(backDX-20), float64(backDY-20))
|
||||
canvas.SetRGBA255(255, 255, 255, 255)
|
||||
canvas.Fill()
|
||||
|
||||
canvas.DrawImage(equipBlock, 10, 10)
|
||||
canvas.DrawImage(packBlock, 10, 10+equipBlock.Bounds().Dy()+10)
|
||||
|
||||
return imgfactory.ToBytes(canvas.Image())
|
||||
}
|
||||
|
||||
// 绘制装备栏区域
|
||||
func drawEquipEmptyBlock(fontdata []byte) (image.Image, error) {
|
||||
canvas := gg.NewContext(1000, 300)
|
||||
// 画底色
|
||||
canvas.DrawRectangle(0, 0, 1000, 300)
|
||||
canvas.SetRGBA255(255, 255, 255, 150)
|
||||
canvas.Fill()
|
||||
// 边框框
|
||||
canvas.DrawRectangle(0, 0, 1000, 300)
|
||||
canvas.SetLineWidth(3)
|
||||
canvas.SetRGBA255(0, 0, 0, 255)
|
||||
canvas.Stroke()
|
||||
|
||||
canvas.SetColor(color.Black)
|
||||
err := canvas.ParseFontFace(fontdata, 100)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
textW, textH := canvas.MeasureString("装备信息")
|
||||
canvas.DrawString("装备信息", 10, 10+textH)
|
||||
canvas.DrawLine(10, textH*1.2, textW, textH*1.2)
|
||||
canvas.SetLineWidth(3)
|
||||
canvas.SetRGBA255(0, 0, 0, 255)
|
||||
canvas.Stroke()
|
||||
if err = canvas.ParseFontFace(fontdata, 50); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
canvas.DrawString("没有装备任何鱼竿", 50, 10+textH*2+50)
|
||||
return canvas.Image(), nil
|
||||
}
|
||||
func drawEquipInfoBlock(equipInfo equip, fontdata []byte) (image.Image, error) {
|
||||
canvas := gg.NewContext(1, 1)
|
||||
err := canvas.ParseFontFace(fontdata, 100)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, titleH := canvas.MeasureString("装备信息")
|
||||
err = canvas.ParseFontFace(fontdata, 50)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, textH := canvas.MeasureString("装备信息")
|
||||
|
||||
backDY := math.Max(int(10+titleH*2+(textH*2)*4+10), 300)
|
||||
|
||||
canvas = gg.NewContext(1000, backDY)
|
||||
// 画底色
|
||||
canvas.DrawRectangle(0, 0, 1000, float64(backDY))
|
||||
canvas.SetRGBA255(255, 255, 255, 150)
|
||||
canvas.Fill()
|
||||
// 边框框
|
||||
canvas.DrawRectangle(0, 0, 1000, float64(backDY))
|
||||
canvas.SetLineWidth(3)
|
||||
canvas.SetRGBA255(0, 0, 0, 255)
|
||||
canvas.Stroke()
|
||||
getAvatar, err := engine.GetLazyData(equipInfo.Equip+".png", false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
equipPic, _, err := image.Decode(bytes.NewReader(getAvatar))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
picDy := float64(backDY) - 10 - titleH*2
|
||||
equipPic = imgfactory.Size(equipPic, int(picDy)-10, int(picDy)-10).Image()
|
||||
canvas.DrawImage(equipPic, 10, 10+int(titleH)*2)
|
||||
|
||||
// 放字
|
||||
canvas.SetColor(color.Black)
|
||||
if err = canvas.ParseFontFace(fontdata, 100); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
titleW, titleH := canvas.MeasureString("装备信息")
|
||||
canvas.DrawString("装备信息", 10, 10+titleH*1.2)
|
||||
canvas.DrawLine(10, titleH*1.6, titleW, titleH*1.6)
|
||||
canvas.SetLineWidth(3)
|
||||
canvas.SetRGBA255(0, 0, 0, 255)
|
||||
canvas.Stroke()
|
||||
|
||||
textDx := picDy + 10
|
||||
textDy := 10 + titleH*2
|
||||
if err = canvas.ParseFontFace(fontdata, 75); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
textW, textH := canvas.MeasureString(equipInfo.Equip)
|
||||
canvas.DrawStringAnchored(equipInfo.Equip, textDx+textW/2, textDy+textH/2, 0.5, 0.5)
|
||||
|
||||
textDy += textH * 1.5
|
||||
if err = canvas.ParseFontFace(fontdata, 50); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
textW, textH = canvas.MeasureString("维修次数")
|
||||
durable := strconv.Itoa(equipInfo.Durable)
|
||||
valueW, _ := canvas.MeasureString("100")
|
||||
barW := 1000 - textDx - textW - 10 - valueW - 10
|
||||
|
||||
canvas.DrawStringAnchored("装备耐久", textDx+textW/2, textDy+textH/2, 0.5, 0.5)
|
||||
canvas.DrawRectangle(textDx+textW+5, textDy, barW, textH*1.2)
|
||||
canvas.SetRGB255(150, 150, 150)
|
||||
canvas.Fill()
|
||||
canvas.SetRGB255(0, 0, 0)
|
||||
durableW := barW * float64(equipInfo.Durable) / float64(durationList[equipInfo.Equip])
|
||||
canvas.DrawRectangle(textDx+textW+5, textDy, durableW, textH*1.2)
|
||||
canvas.SetRGB255(102, 102, 102)
|
||||
canvas.Fill()
|
||||
canvas.SetColor(color.Black)
|
||||
canvas.DrawStringAnchored(durable, textDx+textW+5+barW+5+valueW/2, textDy+textH/2, 0.5, 0.5)
|
||||
|
||||
textDy += textH * 2
|
||||
maintenance := strconv.Itoa(equipInfo.Maintenance)
|
||||
canvas.DrawStringAnchored("维修次数", textDx+textW/2, textDy+textH/2, 0.5, 0.5)
|
||||
canvas.DrawRectangle(textDx+textW+5, textDy, barW, textH*1.2)
|
||||
canvas.SetRGB255(150, 150, 150)
|
||||
canvas.Fill()
|
||||
canvas.SetRGB255(0, 0, 0)
|
||||
canvas.DrawRectangle(textDx+textW+5, textDy, barW*float64(equipInfo.Maintenance)/10, textH*1.2)
|
||||
canvas.SetRGB255(102, 102, 102)
|
||||
canvas.Fill()
|
||||
canvas.SetColor(color.Black)
|
||||
canvas.DrawStringAnchored(maintenance, textDx+textW+5+barW+5+valueW/2, textDy+textH/2, 0.5, 0.5)
|
||||
|
||||
textDy += textH * 3
|
||||
canvas.DrawString(" 附魔: 诱钓"+enchantLevel[equipInfo.Induce]+" 海之眷顾"+enchantLevel[equipInfo.Favor], textDx, textDy)
|
||||
return canvas.Image(), nil
|
||||
}
|
||||
|
||||
// 绘制背包信息区域
|
||||
func drawArticleEmptyBlock(fontdata []byte) (image.Image, error) {
|
||||
canvas := gg.NewContext(1000, 300)
|
||||
// 画底色
|
||||
canvas.DrawRectangle(0, 0, 1000, 300)
|
||||
canvas.SetRGBA255(255, 255, 255, 150)
|
||||
canvas.Fill()
|
||||
// 边框框
|
||||
canvas.DrawRectangle(0, 0, 1000, 300)
|
||||
canvas.SetLineWidth(3)
|
||||
canvas.SetRGBA255(0, 0, 0, 255)
|
||||
canvas.Stroke()
|
||||
|
||||
canvas.SetColor(color.Black)
|
||||
err := canvas.ParseFontFace(fontdata, 100)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
textW, textH := canvas.MeasureString("背包信息")
|
||||
canvas.DrawString("背包信息", 10, 10+textH*1.2)
|
||||
canvas.DrawLine(10, textH*1.6, textW, textH*1.6)
|
||||
canvas.SetLineWidth(3)
|
||||
canvas.SetRGBA255(0, 0, 0, 255)
|
||||
canvas.Stroke()
|
||||
if err = canvas.ParseFontFace(fontdata, 50); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
canvas.DrawStringAnchored("背包没有存放任何东西", 500, 10+textH*2+50, 0.5, 0)
|
||||
return canvas.Image(), nil
|
||||
}
|
||||
func drawArticleInfoBlock(uid int64, articles []article, fontdata []byte) (image.Image, error) {
|
||||
canvas := gg.NewContext(1, 1)
|
||||
err := canvas.ParseFontFace(fontdata, 100)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
titleW, titleH := canvas.MeasureString("背包信息")
|
||||
front := 45.0
|
||||
err = canvas.ParseFontFace(fontdata, front)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, textH := canvas.MeasureString("高度")
|
||||
|
||||
nameWOfFiest := 0.0
|
||||
nameWOfSecond := 0.0
|
||||
for i, info := range articles {
|
||||
textW, _ := canvas.MeasureString(info.Name + "(" + info.Other + ")")
|
||||
if i%2 == 0 && textW > nameWOfFiest {
|
||||
nameWOfFiest = textW
|
||||
} else if textW > nameWOfSecond {
|
||||
nameWOfSecond = textW
|
||||
}
|
||||
}
|
||||
valueW, _ := canvas.MeasureString("10000")
|
||||
|
||||
if (10+nameWOfFiest+10+valueW+10)+(10+nameWOfSecond+10+valueW+10) > 980 {
|
||||
front = 32.0
|
||||
err = canvas.ParseFontFace(fontdata, front)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, textH = canvas.MeasureString("高度")
|
||||
|
||||
nameWOfFiest = 0
|
||||
nameWOfSecond = 0
|
||||
for i, info := range articles {
|
||||
textW, _ := canvas.MeasureString(info.Name + "(" + info.Other + ")")
|
||||
if i%2 == 0 && textW > nameWOfFiest {
|
||||
nameWOfFiest = textW
|
||||
} else if textW > nameWOfSecond {
|
||||
nameWOfSecond = textW
|
||||
}
|
||||
}
|
||||
valueW, _ = canvas.MeasureString("10000")
|
||||
}
|
||||
wallW := (980 - (10 + nameWOfFiest + 10 + valueW + 10) - (10 + nameWOfSecond + 10 + valueW + 10)) / 2
|
||||
backY := math.Max(10+int(titleH*1.6)+10+int(textH*2)*(math.Ceil(len(articles), 2)+1), 500)
|
||||
canvas = gg.NewContext(1000, backY)
|
||||
// 画底色
|
||||
canvas.DrawRectangle(0, 0, 1000, float64(backY))
|
||||
canvas.SetRGBA255(255, 255, 255, 150)
|
||||
canvas.Fill()
|
||||
// 边框框
|
||||
canvas.DrawRectangle(0, 0, 1000, float64(backY))
|
||||
canvas.SetLineWidth(3)
|
||||
canvas.SetRGBA255(0, 0, 0, 255)
|
||||
canvas.Stroke()
|
||||
|
||||
// 放字
|
||||
canvas.SetColor(color.Black)
|
||||
err = canvas.ParseFontFace(fontdata, 100)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
canvas.DrawString("背包信息", 10, 10+titleH*1.2)
|
||||
canvas.DrawLine(10, titleH*1.6, titleW, titleH*1.6)
|
||||
canvas.SetLineWidth(3)
|
||||
canvas.SetRGBA255(0, 0, 0, 255)
|
||||
canvas.Stroke()
|
||||
|
||||
textDy := 10 + titleH*1.7
|
||||
if err = canvas.ParseFontFace(fontdata, front); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
canvas.SetColor(color.Black)
|
||||
numberOfFish := 0
|
||||
numberOfEquip := 0
|
||||
canvas.DrawStringAnchored("名称", wallW+20+nameWOfFiest/2, textDy+textH/2, 0.5, 0.5)
|
||||
canvas.DrawStringAnchored("数量", wallW+20+nameWOfFiest+10+valueW/2, textDy+textH/2, 0.5, 0.5)
|
||||
canvas.DrawStringAnchored("名称", wallW+20+nameWOfFiest+10+valueW+10+10+nameWOfSecond/2, textDy+textH/2, 0.5, 0.5)
|
||||
canvas.DrawStringAnchored("数量", wallW+20+nameWOfFiest+10+valueW+10+10+nameWOfSecond+10+valueW/2, textDy+textH/2, 0.5, 0.5)
|
||||
textDy += textH * 2
|
||||
for i, info := range articles {
|
||||
name := info.Name
|
||||
if info.Other != "" {
|
||||
if strings.Contains(info.Name, "竿") {
|
||||
numberOfEquip++
|
||||
}
|
||||
name += "(" + info.Other + ")"
|
||||
} else if strings.Contains(name, "鱼") {
|
||||
numberOfFish += info.Number
|
||||
}
|
||||
valueStr := strconv.Itoa(info.Number)
|
||||
if i%2 == 0 {
|
||||
if i != 0 {
|
||||
textDy += textH * 2
|
||||
}
|
||||
canvas.DrawStringAnchored(name, wallW+20+nameWOfFiest/2, textDy+textH/2, 0.5, 0.5)
|
||||
canvas.DrawStringAnchored(valueStr, wallW+20+nameWOfFiest+10+valueW/2, textDy+textH/2, 0.5, 0.5)
|
||||
} else {
|
||||
canvas.DrawStringAnchored(name, wallW+20+nameWOfFiest+10+valueW+10+10+nameWOfSecond/2, textDy+textH/2, 0.5, 0.5)
|
||||
canvas.DrawStringAnchored(valueStr, wallW+20+nameWOfFiest+10+valueW+10+10+nameWOfSecond+10+valueW/2, textDy+textH/2, 0.5, 0.5)
|
||||
}
|
||||
}
|
||||
if err = canvas.ParseFontFace(fontdata, 30); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
textDy = 10
|
||||
text := "钱包余额: " + strconv.Itoa(wallet.GetWalletOf(uid))
|
||||
textW, textH := canvas.MeasureString(text)
|
||||
w, _ := canvas.MeasureString("维修大师[已激活]")
|
||||
if w > textW {
|
||||
textW = w
|
||||
}
|
||||
canvas.DrawStringAnchored(text, 980-textW/2, textDy+textH/2, 0.5, 0.5)
|
||||
textDy += textH * 1.5
|
||||
if numberOfFish > 100 {
|
||||
canvas.DrawStringAnchored("钓鱼佬[已激活]", 980-textW/2, textDy+textH/2, 0.5, 0.5)
|
||||
textDy += textH * 1.5
|
||||
}
|
||||
if numberOfEquip > 10 {
|
||||
canvas.DrawStringAnchored("维修大师[已激活]", 980-textW/2, textDy+textH/2, 0.5, 0.5)
|
||||
}
|
||||
return canvas.Image(), nil
|
||||
}
|
||||
485
plugin/mcfish/pole.go
Normal file
485
plugin/mcfish/pole.go
Normal file
@@ -0,0 +1,485 @@
|
||||
// Package mcfish 钓鱼模拟器
|
||||
package mcfish
|
||||
|
||||
import (
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/zbputils/ctxext"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine.OnRegex(`^装备(`+strings.Join(poleList, "|")+`)$`, getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
uid := ctx.Event.UserID
|
||||
equipInfo, err := dbdata.getUserEquip(uid)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.1]:", err))
|
||||
return
|
||||
}
|
||||
thingName := ctx.State["regex_matched"].([]string)[1]
|
||||
articles, err := dbdata.getUserThingInfo(uid, thingName)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.2]:", err))
|
||||
return
|
||||
}
|
||||
if len(articles) == 0 {
|
||||
ctx.SendChain(message.Text("你的背包不存在该物品"))
|
||||
return
|
||||
}
|
||||
poles := make([]equip, 0, len(articles))
|
||||
if thingName != "美西螈" {
|
||||
for _, info := range articles {
|
||||
poleInfo := strings.Split(info.Other, "/")
|
||||
durable, _ := strconv.Atoi(poleInfo[0])
|
||||
maintenance, _ := strconv.Atoi(poleInfo[1])
|
||||
induceLevel, _ := strconv.Atoi(poleInfo[2])
|
||||
favorLevel, _ := strconv.Atoi(poleInfo[3])
|
||||
poles = append(poles, equip{
|
||||
ID: uid,
|
||||
Equip: info.Name,
|
||||
Durable: durable,
|
||||
Maintenance: maintenance,
|
||||
Induce: induceLevel,
|
||||
Favor: favorLevel,
|
||||
})
|
||||
}
|
||||
} else {
|
||||
poles = append(poles, equip{
|
||||
ID: uid,
|
||||
Equip: thingName,
|
||||
Durable: 999,
|
||||
})
|
||||
}
|
||||
check := false
|
||||
index := 0
|
||||
if len(poles) > 1 {
|
||||
msg := make(message.Message, 0, 3+len(articles))
|
||||
msg = append(msg, message.Reply(ctx.Event.MessageID), message.Text("找到以下鱼竿:\n"))
|
||||
for i, info := range poles {
|
||||
msg = append(msg, message.Text("[", i, "] ", info.Equip, " : 耐", info.Durable, "/修", info.Maintenance,
|
||||
"/诱", enchantLevel[info.Induce], "/眷顾", enchantLevel[info.Favor], "\n"))
|
||||
}
|
||||
msg = append(msg, message.Text("————————\n输入对应序号进行装备,或回复“取消”取消"))
|
||||
ctx.Send(msg)
|
||||
// 等待用户下一步选择
|
||||
recv, cancel := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(取消|\d+)$`), zero.CheckUser(ctx.Event.UserID)).Repeat()
|
||||
defer cancel()
|
||||
for {
|
||||
select {
|
||||
case <-time.After(time.Second * 120):
|
||||
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
|
||||
}
|
||||
index, err = strconv.Atoi(nextcmd)
|
||||
if err != nil || index > len(articles)-1 {
|
||||
ctx.SendChain(message.At(ctx.Event.UserID), message.Text("请输入正确的序号"))
|
||||
continue
|
||||
}
|
||||
check = true
|
||||
}
|
||||
if check {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
newEquipInfo := poles[index]
|
||||
packEquip := articles[index]
|
||||
packEquip.Number--
|
||||
err = dbdata.updateUserThingInfo(uid, packEquip)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.3]:", err))
|
||||
return
|
||||
}
|
||||
err = dbdata.updateUserEquip(newEquipInfo)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.3.1]:", err))
|
||||
return
|
||||
}
|
||||
oldthing := article{}
|
||||
if equipInfo != (equip{}) && equipInfo.Equip != "美西螈" {
|
||||
oldthing = article{
|
||||
Duration: time.Now().Unix(),
|
||||
Type: "pole",
|
||||
Name: equipInfo.Equip,
|
||||
Number: 1,
|
||||
Other: strconv.Itoa(equipInfo.Durable) + "/" + strconv.Itoa(equipInfo.Maintenance) + "/" + strconv.Itoa(equipInfo.Induce) + "/" + strconv.Itoa(equipInfo.Favor),
|
||||
}
|
||||
} else if equipInfo.Equip == "美西螈" {
|
||||
articles, err = dbdata.getUserThingInfo(uid, "美西螈")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.3.2]:", err))
|
||||
return
|
||||
}
|
||||
if len(articles) == 0 {
|
||||
oldthing = article{
|
||||
Duration: time.Now().Unix(),
|
||||
Type: "pole",
|
||||
Name: equipInfo.Equip,
|
||||
Number: 1,
|
||||
}
|
||||
} else {
|
||||
oldthing = articles[0]
|
||||
oldthing.Number++
|
||||
}
|
||||
}
|
||||
err = dbdata.updateUserThingInfo(uid, oldthing)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.4]:", err))
|
||||
return
|
||||
}
|
||||
ctx.Send(
|
||||
message.ReplyWithMessage(ctx.Event.MessageID,
|
||||
message.Text("装备成功"),
|
||||
),
|
||||
)
|
||||
})
|
||||
engine.OnFullMatchGroup([]string{"修复鱼竿", "维修鱼竿"}, getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
uid := ctx.Event.UserID
|
||||
equipInfo, err := dbdata.getUserEquip(uid)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.5]:", err))
|
||||
return
|
||||
}
|
||||
if equipInfo.Equip == "" || equipInfo.Equip == "美西螈" {
|
||||
ctx.SendChain(message.Text("仅能修复装备中的鱼竿"))
|
||||
return
|
||||
}
|
||||
if equipInfo.Maintenance >= 10 {
|
||||
ctx.SendChain(message.Text("装备的鱼竿已经达到修复上限"))
|
||||
return
|
||||
}
|
||||
articles, err := dbdata.getUserThingInfo(uid, equipInfo.Equip)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.6]:", err))
|
||||
return
|
||||
}
|
||||
if len(articles) == 0 {
|
||||
ctx.SendChain(message.Text("你的背包不存在相同鱼竿进行修复"))
|
||||
return
|
||||
}
|
||||
poles := make([]equip, 0, len(articles))
|
||||
for _, info := range articles {
|
||||
poleInfo := strings.Split(info.Other, "/")
|
||||
durable, _ := strconv.Atoi(poleInfo[0])
|
||||
maintenance, _ := strconv.Atoi(poleInfo[1])
|
||||
induceLevel, _ := strconv.Atoi(poleInfo[2])
|
||||
favorLevel, _ := strconv.Atoi(poleInfo[3])
|
||||
poles = append(poles, equip{
|
||||
ID: uid,
|
||||
Equip: info.Name,
|
||||
Durable: durable,
|
||||
Maintenance: maintenance,
|
||||
Induce: induceLevel,
|
||||
Favor: favorLevel,
|
||||
})
|
||||
}
|
||||
index := 0
|
||||
check := false
|
||||
if len(articles) > 1 {
|
||||
msg := make(message.Message, 0, 3+len(articles))
|
||||
msg = append(msg, message.Text("找到以下鱼竿:\n"))
|
||||
for i, info := range poles {
|
||||
msg = append(msg, message.Text("[", i, "] ", info.Equip, " : 耐", info.Durable, "/修", info.Maintenance,
|
||||
"/诱", enchantLevel[info.Induce], "/眷顾", enchantLevel[info.Favor], "\n"))
|
||||
}
|
||||
msg = append(msg, message.Text("————————\n输入对应序号进行修复,或回复“取消”取消"))
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, msg...))
|
||||
// 等待用户下一步选择
|
||||
recv, cancel := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(取消|\d+)$`), zero.CheckUser(ctx.Event.UserID)).Repeat()
|
||||
defer cancel()
|
||||
for {
|
||||
select {
|
||||
case <-time.After(time.Second * 120):
|
||||
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
|
||||
}
|
||||
index, err = strconv.Atoi(nextcmd)
|
||||
if err != nil || index > len(articles)-1 {
|
||||
ctx.SendChain(message.At(ctx.Event.UserID), message.Text("请输入正确的序号"))
|
||||
continue
|
||||
}
|
||||
check = true
|
||||
}
|
||||
if check {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
newEquipInfo := poles[index]
|
||||
number, err := dbdata.getNumberFor(uid, "竿")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at fish.go.5.1]:", err))
|
||||
return
|
||||
}
|
||||
if number <= 10 {
|
||||
number = 8
|
||||
} else {
|
||||
number = 10
|
||||
}
|
||||
equipInfo.Durable += newEquipInfo.Durable * number / 10
|
||||
if equipInfo.Durable > durationList[equipInfo.Equip] || equipInfo.Equip == "三叉戟" {
|
||||
equipInfo.Durable = durationList[equipInfo.Equip]
|
||||
}
|
||||
msg := ""
|
||||
if newEquipInfo.Induce != 0 && rand.Intn(100) < 50 {
|
||||
equipInfo.Induce += newEquipInfo.Induce
|
||||
if equipInfo.Induce > 3 {
|
||||
equipInfo.Induce = 3
|
||||
}
|
||||
msg += ",诱钓等级提升至" + enchantLevel[equipInfo.Induce]
|
||||
}
|
||||
if newEquipInfo.Favor != 0 && rand.Intn(100) < 50 {
|
||||
equipInfo.Favor += newEquipInfo.Favor
|
||||
if equipInfo.Favor > 3 {
|
||||
equipInfo.Favor = 3
|
||||
}
|
||||
msg += ",海之眷顾等级提升至" + enchantLevel[equipInfo.Favor]
|
||||
}
|
||||
thingInfo := articles[index]
|
||||
thingInfo.Number = 0
|
||||
err = dbdata.updateUserThingInfo(uid, thingInfo)
|
||||
if err == nil {
|
||||
equipInfo.Maintenance++
|
||||
err = dbdata.updateUserEquip(equipInfo)
|
||||
}
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.7]:", err))
|
||||
return
|
||||
}
|
||||
ctx.Send(
|
||||
message.ReplyWithMessage(ctx.Event.MessageID,
|
||||
message.Text("鱼竿修复成功,耐久提高至", equipInfo.Durable, msg),
|
||||
),
|
||||
)
|
||||
})
|
||||
engine.OnRegex(`^附魔(诱钓|海之眷顾)$`, getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
uid := ctx.Event.UserID
|
||||
equipInfo, err := dbdata.getUserEquip(uid)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.7]:", err))
|
||||
return
|
||||
}
|
||||
if equipInfo.Equip == "" || equipInfo.Equip == "美西螈" {
|
||||
ctx.SendChain(message.Text("仅可对装备中的进行附魔"))
|
||||
return
|
||||
}
|
||||
book := ctx.State["regex_matched"].([]string)[1]
|
||||
books, err := dbdata.getUserThingInfo(uid, book)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.8]:", err))
|
||||
return
|
||||
}
|
||||
if len(books) == 0 {
|
||||
ctx.SendChain(message.Text("你的背包不存在", book, "进行附魔"))
|
||||
return
|
||||
}
|
||||
bookInfo := books[0]
|
||||
bookInfo.Number--
|
||||
err = dbdata.updateUserThingInfo(uid, bookInfo)
|
||||
number := 0
|
||||
if err == nil {
|
||||
if rand.Intn(100) > 50 {
|
||||
ctx.SendChain(message.Text("附魔失败了"))
|
||||
return
|
||||
}
|
||||
switch book {
|
||||
case "诱钓":
|
||||
equipInfo.Induce++
|
||||
if equipInfo.Induce > 3 {
|
||||
equipInfo.Induce = 3
|
||||
}
|
||||
number = equipInfo.Induce
|
||||
case "海之眷顾":
|
||||
equipInfo.Favor++
|
||||
if equipInfo.Favor > 3 {
|
||||
equipInfo.Favor = 3
|
||||
}
|
||||
number = equipInfo.Favor
|
||||
default:
|
||||
ctx.SendChain(message.Text("附魔失败了"))
|
||||
return
|
||||
}
|
||||
err = dbdata.updateUserEquip(equipInfo)
|
||||
}
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.9]:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.Text("附魔成功,", book, "等级提高至", enchantLevel[number]))
|
||||
})
|
||||
engine.OnRegex(`^合成(.+竿|三叉戟)$`, getdb).SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) {
|
||||
uid := ctx.Event.UserID
|
||||
thingList := []string{"木竿", "铁竿", "金竿", "钻石竿", "下界合金竿", "三叉戟"}
|
||||
thingName := ctx.State["regex_matched"].([]string)[1]
|
||||
indexOfMaterial := -1
|
||||
for i, name := range thingList {
|
||||
if thingName == name {
|
||||
indexOfMaterial = (i - 1)
|
||||
break
|
||||
}
|
||||
}
|
||||
if indexOfMaterial < 0 {
|
||||
return
|
||||
}
|
||||
articles, err := dbdata.getUserThingInfo(uid, thingList[indexOfMaterial])
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.10]:", err))
|
||||
return
|
||||
}
|
||||
max := len(articles)
|
||||
if max < 3 {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("你的合成材料不足"))
|
||||
return
|
||||
}
|
||||
poles := make([]equip, 0, max)
|
||||
for _, info := range articles {
|
||||
poleInfo := strings.Split(info.Other, "/")
|
||||
durable, _ := strconv.Atoi(poleInfo[0])
|
||||
maintenance, _ := strconv.Atoi(poleInfo[1])
|
||||
induceLevel, _ := strconv.Atoi(poleInfo[2])
|
||||
favorLevel, _ := strconv.Atoi(poleInfo[3])
|
||||
poles = append(poles, equip{
|
||||
ID: uid,
|
||||
Equip: info.Name,
|
||||
Durable: durable,
|
||||
Maintenance: maintenance,
|
||||
Induce: induceLevel,
|
||||
Favor: favorLevel,
|
||||
})
|
||||
}
|
||||
list := []int{0, 1, 2}
|
||||
check := false
|
||||
if len(articles) > 3 {
|
||||
msg := make(message.Message, 0, 3+len(articles))
|
||||
msg = append(msg, message.Text("找到以下鱼竿:\n"))
|
||||
for i, info := range poles {
|
||||
msg = append(msg, message.Text("[", i, "] ", info.Equip, " : 耐", info.Durable, "/修", info.Maintenance,
|
||||
"/诱", enchantLevel[info.Induce], "/眷顾", enchantLevel[info.Favor], "\n"))
|
||||
}
|
||||
msg = append(msg, message.Text("————————\n输入3个序号进行合成(用空格分割),或回复“取消”取消"))
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, msg...))
|
||||
// 等待用户下一步选择
|
||||
recv, cancel := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(取消|\d+ \d+ \d+)$`), zero.CheckUser(ctx.Event.UserID)).Repeat()
|
||||
defer cancel()
|
||||
for {
|
||||
select {
|
||||
case <-time.After(time.Second * 120):
|
||||
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
|
||||
}
|
||||
chooseList := strings.Split(nextcmd, " ")
|
||||
first, err := strconv.Atoi(chooseList[0])
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.11.1]:", err))
|
||||
return
|
||||
}
|
||||
second, err := strconv.Atoi(chooseList[1])
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.11.2]:", err))
|
||||
return
|
||||
}
|
||||
third, err := strconv.Atoi(chooseList[2])
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.11.3]:", err))
|
||||
return
|
||||
}
|
||||
list = []int{first, second, third}
|
||||
if first == second || first == third || second == third {
|
||||
ctx.SendChain(message.At(ctx.Event.UserID), message.Text("[0]请输入正确的序号\n", list))
|
||||
continue
|
||||
}
|
||||
if first > max || second > max || third > max {
|
||||
ctx.SendChain(message.At(ctx.Event.UserID), message.Text("[", max, "]请输入正确的序号\n", list))
|
||||
continue
|
||||
}
|
||||
check = true
|
||||
}
|
||||
if check {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
favorLevel := 0
|
||||
induceLevel := 0
|
||||
for _, index := range list {
|
||||
thingInfo := articles[index]
|
||||
thingInfo.Number = 0
|
||||
err = dbdata.updateUserThingInfo(uid, thingInfo)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.12]:", err))
|
||||
return
|
||||
}
|
||||
favorLevel += poles[index].Favor
|
||||
induceLevel += poles[index].Induce
|
||||
}
|
||||
if rand.Intn(100) >= 90 {
|
||||
ctx.Send(
|
||||
message.ReplyWithMessage(ctx.Event.MessageID,
|
||||
message.Text("合成失败,材料已销毁"),
|
||||
),
|
||||
)
|
||||
return
|
||||
}
|
||||
attribute := strconv.Itoa(durationList[thingName]) + "/0/" + strconv.Itoa(induceLevel/3) + "/" + strconv.Itoa(favorLevel/3)
|
||||
newthing := article{
|
||||
Duration: time.Now().Unix(),
|
||||
Type: "pole",
|
||||
Name: thingName,
|
||||
Number: 1,
|
||||
Other: attribute,
|
||||
}
|
||||
err = dbdata.updateUserThingInfo(uid, newthing)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at pole.go.12]:", err))
|
||||
return
|
||||
}
|
||||
ctx.Send(
|
||||
message.ReplyWithMessage(ctx.Event.MessageID,
|
||||
message.Text(thingName, "合成成功", list, "\n属性: ", attribute),
|
||||
),
|
||||
)
|
||||
})
|
||||
}
|
||||
702
plugin/mcfish/store.go
Normal file
702
plugin/mcfish/store.go
Normal file
@@ -0,0 +1,702 @@
|
||||
// Package mcfish 钓鱼模拟器
|
||||
package mcfish
|
||||
|
||||
import (
|
||||
"image"
|
||||
"image/color"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/FloatTech/AnimeAPI/wallet"
|
||||
"github.com/FloatTech/floatbox/file"
|
||||
"github.com/FloatTech/floatbox/math"
|
||||
"github.com/FloatTech/gg"
|
||||
"github.com/FloatTech/imgfactory"
|
||||
"github.com/FloatTech/zbputils/control"
|
||||
"github.com/FloatTech/zbputils/img/text"
|
||||
"github.com/sirupsen/logrus"
|
||||
zero "github.com/wdvxdr1123/ZeroBot"
|
||||
"github.com/wdvxdr1123/ZeroBot/extension/rate"
|
||||
"github.com/wdvxdr1123/ZeroBot/message"
|
||||
)
|
||||
|
||||
var (
|
||||
storeLimiter = rate.NewManager[int64](time.Second*3, 1)
|
||||
refresh = false
|
||||
timeNow = 0
|
||||
refreshFish = func(ctx *zero.Ctx) bool {
|
||||
if refresh && timeNow == time.Now().Day() {
|
||||
return true
|
||||
}
|
||||
refresh, err := dbdata.refreshStroeInfo()
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.1]:", err))
|
||||
return refresh
|
||||
}
|
||||
timeNow = time.Now().Day()
|
||||
return refresh
|
||||
}
|
||||
)
|
||||
|
||||
func limitSet(ctx *zero.Ctx) *rate.Limiter {
|
||||
return storeLimiter.Load(ctx.Event.UserID)
|
||||
}
|
||||
|
||||
func init() {
|
||||
engine.OnFullMatchGroup([]string{"钓鱼看板", "钓鱼商店"}, getdb, refreshFish).SetBlock(true).Limit(limitSet).Handle(func(ctx *zero.Ctx) {
|
||||
infos, err := dbdata.getStoreInfo()
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.2]:", err))
|
||||
return
|
||||
}
|
||||
var picImage image.Image
|
||||
if len(infos) == 0 {
|
||||
picImage, err = drawStroeEmptyImage()
|
||||
} else {
|
||||
picImage, err = drawStroeInfoImage(infos)
|
||||
}
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.3]:", err))
|
||||
return
|
||||
}
|
||||
pic, err := imgfactory.ToBytes(picImage)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.4]:", err))
|
||||
return
|
||||
}
|
||||
ctx.SendChain(message.ImageBytes(pic))
|
||||
})
|
||||
engine.OnRegex(`^出售(`+strings.Join(thingList, "|")+`)\s*(\d*)$`, getdb, refreshFish).SetBlock(true).Limit(limitSet).Handle(func(ctx *zero.Ctx) {
|
||||
uid := ctx.Event.UserID
|
||||
thingName := ctx.State["regex_matched"].([]string)[1]
|
||||
if strings.Contains(thingName, "竿") {
|
||||
times, err := dbdata.checkCanSalesFor(uid, true)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.75]:", err))
|
||||
return
|
||||
}
|
||||
if times <= 0 {
|
||||
ctx.SendChain(message.Text("出售次数已达到上限,明天再来售卖吧"))
|
||||
return
|
||||
}
|
||||
}
|
||||
number, _ := strconv.Atoi(ctx.State["regex_matched"].([]string)[2])
|
||||
if number == 0 || strings.Contains(thingName, "竿") {
|
||||
number = 1
|
||||
}
|
||||
articles, err := dbdata.getUserThingInfo(uid, thingName)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.5]:", err))
|
||||
return
|
||||
}
|
||||
if len(articles) == 0 {
|
||||
ctx.SendChain(message.Text("你的背包不存在该物品"))
|
||||
return
|
||||
}
|
||||
index := 0
|
||||
thing := article{}
|
||||
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 {
|
||||
if info.Other != "" && info.Name != "美西螈" {
|
||||
msg = append(msg, message.Text("[", i, "] ", info.Name, "(", info.Other, ")\n"))
|
||||
} else {
|
||||
msg = append(msg, message.Text(
|
||||
"[", i, "]", info.Name, " 数量: ", info.Number, "\n"))
|
||||
}
|
||||
}
|
||||
msg = append(msg, message.Text("————————\n输入对应序号进行装备,或回复“取消”取消"))
|
||||
ctx.Send(msg)
|
||||
// 等待用户下一步选择
|
||||
sell := false
|
||||
recv, cancel := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(取消|\d+)$`), zero.CheckUser(ctx.Event.UserID)).Repeat()
|
||||
defer cancel()
|
||||
for {
|
||||
select {
|
||||
case <-time.After(time.Second * 120):
|
||||
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
|
||||
}
|
||||
index, err = strconv.Atoi(nextcmd)
|
||||
if err != nil || index > len(articles)-1 {
|
||||
ctx.SendChain(message.At(ctx.Event.UserID), message.Text("请输入正确的序号"))
|
||||
continue
|
||||
}
|
||||
sell = true
|
||||
}
|
||||
if sell {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
thing = articles[index]
|
||||
if thing.Number < number {
|
||||
number = thing.Number
|
||||
}
|
||||
|
||||
var pice int
|
||||
if strings.Contains(thingName, "竿") || thingName == "三叉戟" {
|
||||
poleInfo := strings.Split(articles[index].Other, "/")
|
||||
durable, _ := strconv.Atoi(poleInfo[0])
|
||||
maintenance, _ := strconv.Atoi(poleInfo[1])
|
||||
induceLevel, _ := strconv.Atoi(poleInfo[2])
|
||||
favorLevel, _ := strconv.Atoi(poleInfo[3])
|
||||
pice = (priceList[thingName] - (durationList[thingName] - durable) - maintenance*2 + induceLevel*600 + favorLevel*1800) * discountList[thingName] / 100
|
||||
} else {
|
||||
pice = priceList[thingName] * discountList[thingName] / 100
|
||||
}
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("是否接受商店将以", pice*number*8/10, "收购", number, "个", thingName, "?\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
|
||||
}
|
||||
}
|
||||
|
||||
records, err := dbdata.getUserThingInfo(uid, "唱片")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.9.1]:", err))
|
||||
return
|
||||
}
|
||||
if len(records) != 0 {
|
||||
recordInfo := records[0]
|
||||
numberOfRecord := recordInfo.Number
|
||||
if thingName == "唱片" {
|
||||
numberOfRecord -= number
|
||||
}
|
||||
if numberOfRecord > 0 {
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("是否使用唱片让价格翻倍?\n回答\"是\"或\"否\"")))
|
||||
// 等待用户下一步选择
|
||||
recv, cancel2 := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(是|否)$`), zero.CheckUser(ctx.Event.UserID)).Repeat()
|
||||
defer cancel2()
|
||||
use := false
|
||||
checkTime := false
|
||||
for {
|
||||
select {
|
||||
case <-time.After(time.Second * 60):
|
||||
checkTime = true
|
||||
case e := <-recv:
|
||||
nextcmd := e.Event.Message.String()
|
||||
if nextcmd == "是" {
|
||||
use = true
|
||||
}
|
||||
checkTime = true
|
||||
}
|
||||
if checkTime {
|
||||
break
|
||||
}
|
||||
}
|
||||
if use {
|
||||
pice *= 2
|
||||
if thingName == "唱片" {
|
||||
thing.Number--
|
||||
}
|
||||
recordInfo.Number--
|
||||
err = dbdata.updateUserThingInfo(uid, recordInfo)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.9.2]:", err))
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
}
|
||||
thing.Number -= number
|
||||
err = dbdata.updateUserThingInfo(uid, thing)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.6]:", err))
|
||||
return
|
||||
}
|
||||
newCommodity := store{}
|
||||
if strings.Contains(thing.Name, "竿") || thing.Name == "三叉戟" {
|
||||
if pice >= priceList[thing.Name]*2 { // 无附魔的不要
|
||||
newCommodity = store{
|
||||
Duration: time.Now().Unix(),
|
||||
Type: "pole",
|
||||
Name: thing.Name,
|
||||
Number: 1,
|
||||
Price: pice,
|
||||
Other: thing.Other,
|
||||
}
|
||||
polelist, _ := dbdata.getStoreThingInfo(thing.Name)
|
||||
if len(polelist) > 5 { // 超出上限的不要
|
||||
newCommodity.Type = "waste"
|
||||
}
|
||||
}
|
||||
} else {
|
||||
things, err1 := dbdata.getStoreThingInfo(thingName)
|
||||
if err1 != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.8]:", err1))
|
||||
return
|
||||
}
|
||||
if len(things) == 0 {
|
||||
things = append(things, store{
|
||||
Duration: time.Now().Unix(),
|
||||
Name: thing.Name,
|
||||
Price: pice,
|
||||
Type: thing.Type,
|
||||
})
|
||||
}
|
||||
newCommodity = things[0]
|
||||
if newCommodity.Number < 255 {
|
||||
newCommodity.Number += number
|
||||
if newCommodity.Number > 255 {
|
||||
newCommodity.Number = 255
|
||||
}
|
||||
}
|
||||
}
|
||||
if newCommodity != (store{}) && newCommodity.Type != "waste" { // 不收垃圾
|
||||
err = dbdata.updateStoreInfo(newCommodity)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.9]:", err))
|
||||
return
|
||||
}
|
||||
}
|
||||
pice = pice * 8 / 10
|
||||
err = wallet.InsertWalletOf(uid, pice*number)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.10]:", err))
|
||||
return
|
||||
}
|
||||
if strings.Contains(thingName, "竿") {
|
||||
err = dbdata.updateCurseFor(uid, "sell", 1)
|
||||
if err != nil {
|
||||
logrus.Warnln(err)
|
||||
}
|
||||
}
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("出售成功,你赚到了", pice*number, 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, "竿")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.9.3]:", err))
|
||||
return
|
||||
}
|
||||
if numberOfPole > 50 {
|
||||
ctx.SendChain(message.Text("你有", numberOfPole, "支鱼竿,大于50支的玩家不允许购买东西"))
|
||||
return
|
||||
}
|
||||
buytimes, err := dbdata.checkCanSalesFor(uid, false)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.75]:", err))
|
||||
return
|
||||
}
|
||||
if buytimes <= 0 {
|
||||
ctx.SendChain(message.Text("出售次数已达到上限,明天再来购买吧"))
|
||||
return
|
||||
}
|
||||
thingName := ctx.State["regex_matched"].([]string)[1]
|
||||
number, _ := strconv.Atoi(ctx.State["regex_matched"].([]string)[2])
|
||||
if number == 0 {
|
||||
number = 1
|
||||
}
|
||||
thingInfos, err := dbdata.getStoreThingInfo(thingName)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.11]:", err))
|
||||
return
|
||||
}
|
||||
if len(thingInfos) == 0 {
|
||||
ctx.SendChain(message.Text("当前商店并没有上架该物品"))
|
||||
return
|
||||
}
|
||||
if thingName == "净化书" {
|
||||
curse, err := dbdata.getNumberFor(uid, "宝藏诅咒")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.303]:", err))
|
||||
return
|
||||
}
|
||||
if curse == 0 {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("你身上没有诅咒,不能购买该商品"))
|
||||
return
|
||||
}
|
||||
bless, err := dbdata.getNumberFor(uid, "净化书")
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.303]:", err))
|
||||
return
|
||||
}
|
||||
if bless >= curse {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("你身上净化书已足够,不能购买该商品"))
|
||||
return
|
||||
}
|
||||
if curse < number {
|
||||
number = curse
|
||||
}
|
||||
}
|
||||
index := 0
|
||||
pice := make([]int, 0, len(thingInfos))
|
||||
for _, info := range thingInfos {
|
||||
if strings.Contains(thingName, "竿") || thingName == "三叉戟" {
|
||||
poleInfo := strings.Split(info.Other, "/")
|
||||
durable, _ := strconv.Atoi(poleInfo[0])
|
||||
maintenance, _ := strconv.Atoi(poleInfo[1])
|
||||
induceLevel, _ := strconv.Atoi(poleInfo[2])
|
||||
favorLevel, _ := strconv.Atoi(poleInfo[3])
|
||||
thingPice := (priceList[info.Name] - (durationList[info.Name] - durable) - maintenance*2 + induceLevel*600 + favorLevel*1800) * discountList[info.Name] / 100
|
||||
pice = append(pice, thingPice)
|
||||
} else {
|
||||
thingPice := priceList[info.Name] * discountList[info.Name] / 100
|
||||
pice = append(pice, thingPice)
|
||||
}
|
||||
}
|
||||
if len(thingInfos) > 1 {
|
||||
msg := make(message.Message, 0, 3+len(thingInfos))
|
||||
msg = append(msg, message.Text("找到以下物品:\n"))
|
||||
for i, info := range thingInfos {
|
||||
if strings.Contains(thingName, "竿") || thingName == "三叉戟" {
|
||||
msg = append(msg, message.Text(
|
||||
"[", i, "]", info.Name, "(", info.Other, ") 价格:", pice[i], "\n"))
|
||||
} else {
|
||||
msg = append(msg, message.Text(
|
||||
"[", i, "]", info.Name, " 数量:", info.Number, " 价格:", pice[i], "\n"))
|
||||
}
|
||||
}
|
||||
msg = append(msg, message.Text("————————\n输入对应序号进行装备,或回复“取消”取消"))
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, msg...))
|
||||
// 等待用户下一步选择
|
||||
sell := false
|
||||
recv, cancel := zero.NewFutureEvent("message", 999, false, zero.RegexRule(`^(取消|\d+)$`), zero.CheckUser(ctx.Event.UserID)).Repeat()
|
||||
defer cancel()
|
||||
for {
|
||||
select {
|
||||
case <-time.After(time.Second * 120):
|
||||
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
|
||||
}
|
||||
index, err = strconv.Atoi(nextcmd)
|
||||
if err != nil || index > len(thingInfos)-1 {
|
||||
ctx.SendChain(message.At(ctx.Event.UserID), message.Text("请输入正确的序号"))
|
||||
continue
|
||||
}
|
||||
sell = true
|
||||
}
|
||||
if sell {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
thing := thingInfos[index]
|
||||
if thing.Number < number {
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("商店数量不足")))
|
||||
return
|
||||
}
|
||||
price := pice[index] * number
|
||||
|
||||
msg := ""
|
||||
times := math.Min(3, number)
|
||||
coupon, err := dbdata.useCouponAt(uid, times)
|
||||
if err != nil {
|
||||
logrus.Warnln(err)
|
||||
}
|
||||
if coupon != -1 {
|
||||
msg += "\n(半价福利还有" + strconv.Itoa(3-coupon) + "次)"
|
||||
price = pice[index]*(number-coupon) + (pice[index]/2)*coupon
|
||||
} else {
|
||||
err = dbdata.updateBuyTimeFor(uid, 1)
|
||||
if err != nil {
|
||||
logrus.Warnln(err)
|
||||
}
|
||||
}
|
||||
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) + "层诅咒)"
|
||||
price = price * (100 + 10*curse) / 100
|
||||
}
|
||||
|
||||
money := wallet.GetWalletOf(uid)
|
||||
if money < price {
|
||||
ctx.SendChain(message.Text("你身上的钱(", money, ")不够支付", msg))
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("你确定花费", price, "购买", number, "个", thingName, "?", msg, "\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
|
||||
}
|
||||
}
|
||||
|
||||
ok, err := dbdata.checkStoreFor(thing, number)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.11]:", err))
|
||||
return
|
||||
}
|
||||
if !ok {
|
||||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text("你慢了一步,物品被别人买走了"))
|
||||
return
|
||||
}
|
||||
thing.Number -= number
|
||||
err = dbdata.updateStoreInfo(thing)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.12]:", err))
|
||||
return
|
||||
}
|
||||
err = wallet.InsertWalletOf(uid, -price)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.13]:", err))
|
||||
return
|
||||
}
|
||||
newCommodity := article{}
|
||||
if strings.Contains(thingName, "竿") || thingName == "三叉戟" {
|
||||
newCommodity = article{
|
||||
Duration: time.Now().Unix(),
|
||||
Type: thing.Type,
|
||||
Name: thing.Name,
|
||||
Number: 1,
|
||||
Other: thing.Other,
|
||||
}
|
||||
} else {
|
||||
things, err1 := dbdata.getUserThingInfo(uid, thingName)
|
||||
if err1 != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.15]:", err1))
|
||||
return
|
||||
}
|
||||
if len(things) == 0 {
|
||||
things = append(things, article{
|
||||
Duration: time.Now().Unix(),
|
||||
Name: thing.Name,
|
||||
Type: thing.Type,
|
||||
})
|
||||
}
|
||||
newCommodity = things[0]
|
||||
newCommodity.Number += number
|
||||
}
|
||||
err = dbdata.updateUserThingInfo(uid, newCommodity)
|
||||
if err != nil {
|
||||
ctx.SendChain(message.Text("[ERROR at store.go.14]:", err))
|
||||
return
|
||||
}
|
||||
if strings.Contains(thingName, "竿") {
|
||||
err = dbdata.updateCurseFor(uid, "buy", 1)
|
||||
if err != nil {
|
||||
logrus.Warnln(err)
|
||||
}
|
||||
}
|
||||
ctx.Send(message.ReplyWithMessage(ctx.Event.MessageID, message.Text("你用", price, "购买了", number, thingName)))
|
||||
})
|
||||
}
|
||||
|
||||
func drawStroeEmptyImage() (picImage image.Image, err error) {
|
||||
fontdata, err := file.GetLazyData(text.BoldFontFile, control.Md5File, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
canvas := gg.NewContext(1000, 300)
|
||||
// 画底色
|
||||
canvas.DrawRectangle(0, 0, 1000, 300)
|
||||
canvas.SetRGBA255(255, 255, 255, 150)
|
||||
canvas.Fill()
|
||||
// 边框框
|
||||
canvas.DrawRectangle(0, 0, 1000, 300)
|
||||
canvas.SetLineWidth(3)
|
||||
canvas.SetRGBA255(0, 0, 0, 255)
|
||||
canvas.Stroke()
|
||||
|
||||
canvas.SetColor(color.Black)
|
||||
err = canvas.ParseFontFace(fontdata, 100)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
textW, textH := canvas.MeasureString("价格信息")
|
||||
canvas.DrawString("价格信息", 10, 10+textH*1.2)
|
||||
canvas.DrawLine(10, textH*1.6, textW, textH*1.6)
|
||||
canvas.SetLineWidth(3)
|
||||
canvas.SetRGBA255(0, 0, 0, 255)
|
||||
canvas.Stroke()
|
||||
if err = canvas.ParseFontFace(fontdata, 50); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
canvas.DrawStringAnchored("当前商店并没有上架任何物品", 500, 10+textH*2+50, 0.5, 0)
|
||||
return canvas.Image(), nil
|
||||
}
|
||||
|
||||
func drawStroeInfoImage(stroeInfo []store) (picImage image.Image, err error) {
|
||||
fontdata, err := file.GetLazyData(text.BoldFontFile, control.Md5File, true)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
canvas := gg.NewContext(1, 1)
|
||||
err = canvas.ParseFontFace(fontdata, 100)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
titleW, titleH := canvas.MeasureString("价格信息")
|
||||
|
||||
err = canvas.ParseFontFace(fontdata, 50)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
_, textH := canvas.MeasureString("高度")
|
||||
nameW, _ := canvas.MeasureString("下界合金竿(100/100/0/0)")
|
||||
numberW, _ := canvas.MeasureString("10000")
|
||||
priceW, _ := canvas.MeasureString("10000")
|
||||
|
||||
bolckW := int(10 + nameW + 50 + numberW + 50 + priceW + 10)
|
||||
backY := 10 + int(titleH*2+10)*2 + 10 + (len(stroeInfo)+len(discountList)/2+2)*int(textH*2) + 10
|
||||
canvas = gg.NewContext(bolckW, math.Max(backY, 500))
|
||||
// 画底色
|
||||
canvas.DrawRectangle(0, 0, float64(bolckW), float64(backY))
|
||||
canvas.SetRGBA255(150, 150, 150, 255)
|
||||
canvas.Fill()
|
||||
|
||||
// 放字
|
||||
canvas.SetColor(color.Black)
|
||||
err = canvas.ParseFontFace(fontdata, 100)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
canvas.DrawString("今日波动", 10, 10+titleH*1.2)
|
||||
canvas.DrawLine(10, titleH*1.6, titleW, titleH*1.6)
|
||||
canvas.SetLineWidth(3)
|
||||
canvas.SetRGBA255(0, 0, 0, 255)
|
||||
canvas.Stroke()
|
||||
|
||||
textDy := 10 + titleH*1.7
|
||||
if err = canvas.ParseFontFace(fontdata, 35); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
textDx, textDh := canvas.MeasureString("下界合金竿(均价1000)")
|
||||
valueDx, _ := canvas.MeasureString("+100%")
|
||||
i := 0
|
||||
for _, name := range thingList {
|
||||
text := name + "(均价" + strconv.Itoa(priceList[name]) + ") "
|
||||
|
||||
if i == 2 {
|
||||
i = 0
|
||||
textDy += textDh * 2
|
||||
}
|
||||
canvas.SetColor(color.Black)
|
||||
canvas.DrawStringAnchored(text, 20+(textDx+valueDx+10)*float64(i)+10, textDy+textDh/2, 0, 0.5)
|
||||
if discountList[name]-100 > 0 {
|
||||
canvas.SetRGBA255(200, 50, 50, 255)
|
||||
text = "+" + strconv.Itoa(discountList[name]-100) + "%"
|
||||
} else {
|
||||
canvas.SetRGBA255(63, 133, 55, 255)
|
||||
text = strconv.Itoa(discountList[name]-100) + "%"
|
||||
}
|
||||
canvas.DrawStringAnchored(text, 20+(textDx+valueDx+10)*float64(i)+10+textDx+10, textDy+textDh/2, 0, 0.5)
|
||||
i++
|
||||
}
|
||||
canvas.SetColor(color.Black)
|
||||
textDy += textDh * 2
|
||||
canvas.DrawStringAnchored("注:出售商品将会额外扣除20%的税收,附魔鱼竿请按实际价格", 10, textDy+10+textDh/2, 0, 0.5)
|
||||
|
||||
textDy += textH * 2
|
||||
err = canvas.ParseFontFace(fontdata, 100)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
canvas.DrawString("上架内容", 10, textDy+titleH*1.2)
|
||||
canvas.DrawLine(10, textDy+titleH*1.6, titleW, textDy+titleH*1.6)
|
||||
canvas.SetLineWidth(3)
|
||||
canvas.SetRGBA255(0, 0, 0, 255)
|
||||
canvas.Stroke()
|
||||
|
||||
textDy += 10 + titleH*1.7
|
||||
if err = canvas.ParseFontFace(fontdata, 50); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
canvas.DrawStringAnchored("名称", 10+nameW/2, textDy+textH/2, 0.5, 0.5)
|
||||
canvas.DrawStringAnchored("数量", 10+nameW+10+numberW/2, textDy+textH/2, 0.5, 0.5)
|
||||
canvas.DrawStringAnchored("价格", 10+nameW+10+numberW+50+priceW/2, textDy+textH/2, 0.5, 0.5)
|
||||
|
||||
for _, info := range stroeInfo {
|
||||
textDy += textH * 2
|
||||
name := info.Name
|
||||
if info.Other != "" && info.Name != "美西螈" {
|
||||
name += "(" + info.Other + ")"
|
||||
}
|
||||
numberStr := strconv.Itoa(info.Number)
|
||||
pice := 0
|
||||
if strings.Contains(name, "竿") {
|
||||
poleInfo := strings.Split(info.Other, "/")
|
||||
durable, _ := strconv.Atoi(poleInfo[0])
|
||||
maintenance, _ := strconv.Atoi(poleInfo[1])
|
||||
induceLevel, _ := strconv.Atoi(poleInfo[2])
|
||||
favorLevel, _ := strconv.Atoi(poleInfo[3])
|
||||
pice = (priceList[info.Name] - (durationList[info.Name] - durable) - maintenance*2 + induceLevel*600 + favorLevel*1800) * discountList[info.Name] / 100
|
||||
} else {
|
||||
pice = priceList[info.Name] * discountList[info.Name] / 100
|
||||
}
|
||||
|
||||
canvas.DrawStringAnchored(name, 10+nameW/2, textDy+textH/2, 0.5, 0.5)
|
||||
canvas.DrawStringAnchored(numberStr, 10+nameW+10+numberW/2, textDy+textH/2, 0.5, 0.5)
|
||||
canvas.DrawStringAnchored(strconv.Itoa(pice), 10+nameW+10+numberW+50+priceW/2, textDy+textH/2, 0.5, 0.5)
|
||||
}
|
||||
return canvas.Image(), nil
|
||||
}
|
||||
@@ -28,7 +28,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("midicreate", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "midi音乐制作",
|
||||
Help: "- midi制作 CCGGAAGR FFEEDDCR GGFFEEDR GGFFEEDR CCGGAAGR FFEEDDCR\n" +
|
||||
|
||||
@@ -31,7 +31,7 @@ var speakers = map[string]uint{
|
||||
var 原 = newapikeystore("./data/tts/o.txt")
|
||||
|
||||
func init() {
|
||||
en := control.Register("moegoe", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "日韩中 VITS 模型拟声",
|
||||
Help: "- 让[宁宁|爱瑠|芳乃|茉子|丛雨|小春|七海]说(日语)\n" +
|
||||
|
||||
@@ -23,31 +23,31 @@ func TestSetHoliday(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
err = SetHoliday("元旦", 1, 2023, 1, 1)
|
||||
err = SetHoliday("元旦", 1, 2024, 1, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = SetHoliday("春节", 7, 2023, 1, 21)
|
||||
err = SetHoliday("春节", 7, 2024, 2, 10)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = SetHoliday("清明节", 1, 2023, 4, 5)
|
||||
err = SetHoliday("清明节", 1, 2024, 4, 5)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = SetHoliday("劳动节", 1, 2023, 5, 1)
|
||||
err = SetHoliday("劳动节", 1, 2024, 5, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = SetHoliday("端午节", 1, 2023, 6, 22)
|
||||
err = SetHoliday("端午节", 1, 2023, 6, 10)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = SetHoliday("中秋节", 1, 2023, 9, 29)
|
||||
err = SetHoliday("中秋节", 2, 2023, 9, 29)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
err = SetHoliday("国庆节", 7, 2023, 10, 1)
|
||||
err = SetHoliday("国庆节", 6, 2023, 10, 1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ var (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
control.Register("moyu", &ctrl.Options[*zero.Ctx]{
|
||||
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: true,
|
||||
Brief: "摸鱼提醒",
|
||||
Help: "- /启用 moyu\n" +
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
control.Register("moyucalendar", &ctrl.Options[*zero.Ctx]{
|
||||
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: true,
|
||||
Brief: "摸鱼人日历",
|
||||
Help: "- /启用 moyucalendar\n" +
|
||||
@@ -22,7 +22,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
control.Register("music", &ctrl.Options[*zero.Ctx]{
|
||||
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "点歌",
|
||||
Help: "- 点歌[xxx]\n" +
|
||||
|
||||
@@ -23,7 +23,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("nativesetu", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "本地涩图",
|
||||
Help: "- 本地[xxx]\n" +
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
control.Register("nbnhhsh", &ctrl.Options[*zero.Ctx]{
|
||||
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "拼音首字母释义工具",
|
||||
Help: "- ?? [缩写]",
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("nihongo", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "日语学习",
|
||||
Help: "- 日语语法[xxx](使用tag随机)\n" +
|
||||
|
||||
@@ -48,7 +48,7 @@ var (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("novel", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Extra: control.ExtraFromString("novel"),
|
||||
Brief: "铅笔小说网搜索",
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
const hso = "https://gchat.qpic.cn/gchatpic_new//--4234EDEC5F147A4C319A41149D7E0EA9/0"
|
||||
|
||||
func init() {
|
||||
engine := control.Register("nsfw", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "nsfw图片识别",
|
||||
Help: "- nsfw打分[图片]",
|
||||
|
||||
@@ -23,7 +23,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("nwife", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "本地老婆",
|
||||
Help: "- 抽wife[@xxx]\n- 添加wife[名字][图片]\n- 删除wife[名字]\n- [让 | 不让]所有人均可添加wife",
|
||||
@@ -17,10 +17,10 @@ import (
|
||||
"github.com/FloatTech/zbputils/img/text"
|
||||
)
|
||||
|
||||
const bed = "https://gitcode.net/u011570312/senso-ji-omikuji/-/raw/main/"
|
||||
const bed = "https://gitea.seku.su/fumiama/senso-ji-omikuji/raw/branch/main/"
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("omikuji", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "浅草寺求签",
|
||||
Help: "- 求签 | 占卜\n- 解签",
|
||||
|
||||
@@ -56,7 +56,7 @@ var (
|
||||
民政局 = &婚姻登记{
|
||||
db: &sql.Sqlite{},
|
||||
}
|
||||
engine = control.Register("qqwife", &ctrl.Options[*zero.Ctx]{
|
||||
engine = control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "一群一天一夫一妻制群老婆",
|
||||
Help: "- 娶群友\n- 群老婆列表\n- [允许|禁止]自由恋爱\n- [允许|禁止]牛头人\n- 设置CD为xx小时 →(默认12小时)\n- 重置花名册\n- 重置所有花名册(用于清除所有群数据及其设置)\n- 查好感度[对方Q号|@对方QQ]\n- 好感度列表\n- 好感度数据整理 (当好感度列表出现重复名字时使用)\n" +
|
||||
|
||||
@@ -24,7 +24,7 @@ type result struct {
|
||||
}
|
||||
|
||||
func init() { // 主函数
|
||||
en := control.Register("quan", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "QQ权重查询",
|
||||
Help: "权重查询方式\n" +
|
||||
|
||||
@@ -36,7 +36,7 @@ const (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("qzone", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "QQ空间表白墙",
|
||||
Help: "- 登录QQ空间 (Cookie过期很快, 要经常登录)\n" +
|
||||
|
||||
@@ -24,7 +24,7 @@ const (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("realcugan", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "Real-CUGAN清晰术",
|
||||
Help: "- 清晰术(双重吟唱|三重吟唱|四重吟唱)(强力术式|中等术式|弱术式|不变式|原式)[图片]",
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
en := control.Register("reborn", &ctrl.Options[*zero.Ctx]{
|
||||
en := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "投胎模拟器",
|
||||
Help: "- reborn",
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
var ro = runoob.NewRunOOB("066417defb80d038228de76ec581a50a")
|
||||
|
||||
func init() {
|
||||
control.Register("runcode", &ctrl.Options[*zero.Ctx]{
|
||||
control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "在线代码运行",
|
||||
Help: ">runcode [language] [code block]\n" +
|
||||
|
||||
@@ -29,7 +29,7 @@ var (
|
||||
)
|
||||
|
||||
func init() { // 插件主体
|
||||
engine := control.Register("saucenao", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "以图搜图",
|
||||
Help: "- 以图搜图 | 搜索图片 | 以图识图[图片]\n" +
|
||||
|
||||
@@ -31,7 +31,7 @@ import (
|
||||
)
|
||||
|
||||
func init() {
|
||||
engine := control.Register("scale", &ctrl.Options[*zero.Ctx]{
|
||||
engine := control.AutoRegister(&ctrl.Options[*zero.Ctx]{
|
||||
DisableOnDefault: false,
|
||||
Brief: "二次元图片放大",
|
||||
Help: "- 放大图片[图片]",
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user