-
Notifications
You must be signed in to change notification settings - Fork 2k
✨ 添加两个api接口 #886
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
✨ 添加两个api接口 #886
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
// Package lolimi 来源于 https://api.lolimi.cn/ 的接口 | ||
package lolimi | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"strconv" | ||
"strings" | ||
|
||
"github.com/FloatTech/floatbox/binary" | ||
"github.com/FloatTech/floatbox/web" | ||
ctrl "github.com/FloatTech/zbpctrl" | ||
"github.com/FloatTech/zbputils/control" | ||
"github.com/FloatTech/zbputils/ctxext" | ||
"github.com/tidwall/gjson" | ||
zero "github.com/wdvxdr1123/ZeroBot" | ||
"github.com/wdvxdr1123/ZeroBot/message" | ||
) | ||
|
||
const ( | ||
lolimiURL = "https://api.lolimi.cn" | ||
jiaranURL = lolimiURL + "/API/yyhc/jr.php?msg=%v&type=2" | ||
tafeiURL = lolimiURL + "/API/yyhc/taf.php?msg=%v&type=2" | ||
dxlURL = lolimiURL + "/API/yyhc/dxl.php?msg=%v&type=2" | ||
raoURL = lolimiURL + "/API/rao/api.php" | ||
yanURL = lolimiURL + "/API/yan/?url=%v" | ||
xjjURL = lolimiURL + "/API/tup/xjj.php" | ||
qingURL = lolimiURL + "/API/qing/api.php" | ||
fabingURL = lolimiURL + "/API/fabing/fb.php?name=%v" | ||
) | ||
|
||
var ( | ||
engine = control.AutoRegister(&ctrl.Options[*zero.Ctx]{ | ||
DisableOnDefault: false, | ||
Brief: "桑帛云 API", | ||
Help: "- 让[塔菲|嘉然|东雪莲]说我测尼玛\n- 随机绕口令\n- 颜值鉴定[图片]\n" + | ||
"- 随机妹子\n- 随机情话\n- 发病 嘉然\n\n说明: 颜值鉴定只能鉴定三次元图片", | ||
}) | ||
) | ||
|
||
func init() { | ||
engine.OnFullMatch("随机妹子").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { | ||
ctx.SendChain(message.Image(xjjURL)) | ||
}) | ||
engine.OnFullMatch("随机绕口令").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { | ||
data, err := web.GetData(raoURL) | ||
if err != nil { | ||
ctx.SendChain(message.Text("ERROR: ", err)) | ||
return | ||
} | ||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(gjson.Get(binary.BytesToString(data), "data.Msg").String())) | ||
}) | ||
engine.OnFullMatch("随机情话").SetBlock(true).Limit(ctxext.LimitByUser).Handle(func(ctx *zero.Ctx) { | ||
data, err := web.GetData(qingURL) | ||
if err != nil { | ||
ctx.SendChain(message.Text("ERROR: ", err)) | ||
return | ||
} | ||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(binary.BytesToString(data))) | ||
}) | ||
engine.OnPrefix(`发病`).SetBlock(true).Handle(func(ctx *zero.Ctx) { | ||
name := ctx.NickName() | ||
data, err := web.GetData(fmt.Sprintf(fabingURL, url.QueryEscape(name))) | ||
if err != nil { | ||
ctx.SendChain(message.Text("ERROR: ", err)) | ||
return | ||
} | ||
ctx.SendChain(message.Reply(ctx.Event.MessageID), message.Text(gjson.Get(binary.BytesToString(data), "data").String())) | ||
}) | ||
engine.OnKeywordGroup([]string{"颜值鉴定"}, zero.MustProvidePicture).SetBlock(true). | ||
Handle(func(ctx *zero.Ctx) { | ||
list := ctx.State["image_url"].([]string) | ||
if len(list) > 0 { | ||
ctx.SendChain(message.Text("少女祈祷中...")) | ||
data, err := web.GetData(fmt.Sprintf(yanURL, url.QueryEscape(list[0]))) | ||
if err != nil { | ||
ctx.SendChain(message.Text("ERROR: ", err)) | ||
return | ||
} | ||
assessment := gjson.Get(binary.BytesToString(data), "data.text").String() | ||
if assessment == "" { | ||
ctx.SendChain(message.Text("ERROR: 请输入正确的图片")) | ||
return | ||
} | ||
var text strings.Builder // 创建一个strings.Builder实例 | ||
text.WriteString("评价: ") | ||
text.WriteString(assessment) // 添加评估信息 | ||
|
||
for i := 0; i <= 2; i++ { | ||
key := gjson.Get(binary.BytesToString(data), "data.grade.key"+strconv.Itoa(i)).String() | ||
score := gjson.Get(binary.BytesToString(data), "data.grade.score"+strconv.Itoa(i)).String() | ||
if key != "" { | ||
text.WriteString("\n") | ||
text.WriteString(key) | ||
text.WriteString(": ") | ||
text.WriteString(score) | ||
} | ||
} | ||
|
||
ctx.SendChain(message.Text(text.String())) // 发送构建好的字符串 | ||
} | ||
}) | ||
engine.OnRegex("^让(塔菲|嘉然|东雪莲)说([\\s\u4e00-\u9fa5\u3040-\u309F\u30A0-\u30FF\\w\\p{P}\u3000-\u303F\uFF00-\uFFEF]+)$").Limit(ctxext.LimitByGroup).Handle(func(ctx *zero.Ctx) { | ||
name := ctx.State["regex_matched"].([]string)[1] | ||
msg := ctx.State["regex_matched"].([]string)[2] | ||
recordURL := "" | ||
switch name { | ||
case "塔菲", "东雪莲": | ||
ttsURL := "" | ||
if name == "塔菲" { | ||
ttsURL = tafeiURL | ||
} else { | ||
ttsURL = dxlURL | ||
} | ||
data, err := web.GetData(fmt.Sprintf(ttsURL, url.QueryEscape(msg))) | ||
if err != nil { | ||
ctx.SendChain(message.Text("ERROR: ", err)) | ||
return | ||
} | ||
recordURL = gjson.Get(binary.BytesToString(data), "music").String() | ||
case "嘉然": | ||
recordURL = fmt.Sprintf(jiaranURL, url.QueryEscape(msg)) | ||
default: | ||
recordURL = fmt.Sprintf(jiaranURL, url.QueryEscape(msg)) | ||
} | ||
if recordURL == "" { | ||
ctx.SendChain(message.Text("ERROR: 语音生成失败")) | ||
return | ||
} | ||
ctx.SendChain(message.Record(recordURL)) | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.