自定义调用API插件
-
为了解决众多 网络API 调用 问题
为了减少调用一个API去写代码的操作
于是 我随便写了个 可以通过修改配置的就去调用不同API的插件
自定义 调用 API 插件
表达式
启动后生成配置文件
{ //权限类型 有 console all 当为 console 时只能从命令调用 all 则所有都可以 "permType": "console", //输入 参数分隔符 "splitChar": " ", //网页管理的端口 "port": 20042, //全局代理ip "proxyIp": null, //全局代理port "proxyPort": 0, //网页管理的密码 "passwd": "123456", //api 调用模板 "templates": [ ] }
templates 如何配置
示例涩图配置
{ "permType": "all", "splitChar": " ", "templates": [ { "err": "调用失败", "out": "<Pic:$1>", "outArgs": [ "pic[0]" ], "proxyIp": "", "proxyPort": 0, "sw": true, "touch": "随机图片", "url": "http://api.iw233.cn/api.php?sort=cat&type=json" } ] }
- $1 $2 即参数1 参数2 outArgs 指定返回的 数据为 参数N
- $qid 表示发送者id
- $gid 表示所处群id
转换后内部通过转换成message
见 详情表达式
配置后 在群聊/好友 发送 随机图片 即可触发
复杂的返回参数
<details>
<summary>
以下是 https://api.vvhan.com/api/weather?city=徐州&type=week 该 API 返回的数据
</summary>{ "data": { "yesterday": { "date": "30日星期三", "high": "高温 4℃", "fx": "西南风", "low": "低温 -1℃", "fl": "", "type": "雨夹雪" }, "city": "西安", "forecast": [ { "date": "31日星期四", "high": "高温 7℃", "fengli": "", "low": "低温 -6℃", "fengxiang": "西南风", "type": "小雪" }, { "date": "1日星期五", "high": "高温 7℃", "fengli": "", "low": "低温 -4℃", "fengxiang": "东北风", "type": "多云" }, { "date": "2日星期六", "high": "高温 7℃", "fengli": "", "low": "低温 -3℃", "fengxiang": "西南风", "type": "多云" }, { "date": "3日星期天", "high": "高温 10℃", "fengli": "", "low": "低温 -1℃", "fengxiang": "南风", "type": "多云" }, { "date": "4日星期一", "high": "高温 8℃", "fengli": "", "low": "低温 -3℃", "fengxiang": "东北风", "type": "多云" } ], "ganmao": "昼夜温差很大,易发生感冒,请注意适当增减衣服,加强自我防护避免感冒。", "wendu": "2" }, "status": 1000, "desc": "OK" }
</details>
- 配置后 在群聊/好友 发送 未来天气 <城市名> 即可触发
<details>
<summary>配置文件</summary>{ "permType": "all", "splitChar": " ", "templates": [ { "out": "$1:$2\n$3:$4\n$5:$6\n", "outArgs": [ "data.forecast[0].date", "data.forecast[0].type", "data.forecast[1].date", "data.forecast[1].type", "data.forecast[2].date", "data.forecast[2].type" ], "touch": "未来天气", "url": "https://api.vvhan.com/api/weather?city=$1&type=week", "err": "天气查询失败" } ] }
</details>
最后送上实用配置
<details>
<summary>配置文件</summary>{ "passwd": "123456", "permType": "all", "port": 20042, "proxyIp": null, "proxyPort": 0, "splitChar": " ", "templates": [ { "err": "天气查询失败", "out": "<At:$qid>\n$1:$2\n$3:$4\n$5:$6\n", "outArgs": [ "data.forecast[0].date", "data.forecast[0].type", "data.forecast[1].date", "data.forecast[1].type", "data.forecast[2].date", "data.forecast[2].type" ], "proxyIp": "", "proxyPort": 0, "sw": true, "touch": "未来天气", "url": "https://api.vvhan.com/api/weather?city=$1&type=week" }, { "err": "调用失败", "out": "<Pic:$1>", "outArgs": [ "pic[0]" ], "proxyIp": "", "proxyPort": 0, "sw": true, "touch": "随机图片", "url": "http://api.iw233.cn/api.php?sort=cat&type=json" }, { "err": "调用失败", "out": "<Pic:$1>", "outArgs": [ "$url" ], "proxyIp": "", "proxyPort": 0, "sw": true, "touch": "需要ta吗", "url": "https://ovooa.com/API/face_need/?QQ=$number" }, { "err": "调用失败", "out": "<Pic:$1>", "outArgs": [ "[]" ], "proxyIp": "", "proxyPort": 0, "sw": true, "touch": "快手图集", "url": "http://kloping.top/api/search/parseImgs?url=$1&type=ks" }, { "err": "调用失败", "out": "<Pic:$1>", "outArgs": [ "data.[]" ], "proxyIp": "", "proxyPort": 0, "sw": true, "touch": "堆糖搜图", "url": "http://kloping.top/api/search/pic?keyword=$1&num=3&type=duit" }, { "err": "调用失败", "out": "<Music:KugouMusic,$1,$2,https://www.kugou.com/,$3,$4>", "outArgs": [ "data[0].media_name", "data[0].author_name", "data[0].imgUrl", "data[0].songUrl" ], "proxyIp": "", "proxyPort": 0, "sw": true, "touch": "酷狗点歌", "url": "http://kloping.top/api/search/song?keyword=$1&type=kugou&n=2" }, { "err": null, "out": "<At:$qid>\n$1", "outArgs": [ "$all" ], "proxyIp": "", "proxyPort": 0, "sw": true, "touch": "/ping", "url": "https://xian.txma.cn/API/sping.php?url=$1" }, { "err": null, "out": "id:$1\n来自群$2\n的$3\n时间:$call(http://kloping.top/stamp2time?stamp=$4&time=)\n昵称:$5\n信息:$6\n剩余捡起次数:$7", "outArgs": [ "id", "gid", "sid", "time", "name", "message", "state" ], "proxyIp": "", "proxyPort": 0, "sw": true, "touch": "/捡瓶子", "url": "http://kloping.top/api/pickUpBottle" } ] }
</details>
更多 帮助请查看 releases
由于部分API不提供服务 造成的报错请手动访问API后确定是否为该插件的问题
-
大佬,怎么实现获取调用者的qq号?
-
-
@Kloping 感谢大大
-
大佬我又有新问题了,api获取到的时间是纯数字的秒数,有没有办法转为2022.05.07 09:00这样的
-
@q981612327 莫办法,
-
造轮子的轮子...nb
-
大佬,又来麻烦你了,能增加一个获取群昵称的参数嘛,看到个好玩的api
-
大佬 为什么我能获取到音频的链接 $1 然后Audio:$1 机器人 发出的语音都是红感叹号
-
大佬大佬,有没有办法写API开关呀?
-
建议添加代理功能,使用loliconapi时需要把pixiv.cat替换为pixiv.re
-
W/stderr: javax.net.ssl.SSLHandshakeException: PKIX path validation failed: java.security.cert.CertPathValidatorException: validity check failed
W/stderr: java.net.ConnectException: Connection timed out: connect
大佬能关闭ssl验证吗,还有代理问题。
-
能增加一个功能吗?我觉得很实用,比如你使用了指令但查错了他会直接返回$1 $2类似这样
所以能增加查询失败反馈失败吗?
我说的可能不是很清楚,大概意思是参考插件内的模板
未来天气 城市
如果填对了城市直接返回结果如果不填城市也返回结果但全是$1 $2如下,并且填错城市他查不出来也返回如下
所以能增加一个模块比如查询失败反馈自定义失败回复
或者不自定义也行,单纯回复查询失败,指令错误,或者查询对象有误
如果只使用未来天气 不填城市也会回复$1 $1 能添加模块回复无查询对象,请填写对象?
可能添加此类功能比较麻烦但还是希望添加一下,我觉得对于目前版本是一个很不错的想法 -
并且我在使用时会时不时报错
如下
2022-05-30 18:47:10 W/stderr: java.net.ConnectException: Connection refused (Connection refused)
2022-05-30 18:47:10 W/stderr: at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
2022-05-30 18:47:10 W/stderr: at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/java.net.Socket.connect(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/sun.net.NetworkClient.doConnect(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source)
2022-05-30 18:47:10 W/stderr: at MiraiCallApiPlugin-v1.3.jar//org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:859)
2022-05-30 18:47:10 W/stderr: at MiraiCallApiPlugin-v1.3.jar//org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:829)
2022-05-30 18:47:10 W/stderr: at MiraiCallApiPlugin-v1.3.jar//org.jsoup.helper.HttpConnection.execute(HttpConnection.java:366)
2022-05-30 18:47:10 W/stderr: at MiraiCallApiPlugin-v1.3.jar//org.jsoup.helper.HttpConnection.get(HttpConnection.java:353)
2022-05-30 18:47:10 W/stderr: at MiraiCallApiPlugin-v1.3.jar//io.github.Kloping.mirai.p1.Worker.doc(Worker.java:157)
2022-05-30 18:47:10 W/stderr: at MiraiCallApiPlugin-v1.3.jar//io.github.Kloping.mirai.p1.Worker.call(Worker.java:83)
2022-05-30 18:47:10 W/stderr: at MiraiCallApiPlugin-v1.3.jar//io.github.Kloping.mirai.p1.CallApiPlugin$1.onMessage0(CallApiPlugin.java:61)
2022-05-30 18:47:10 W/stderr: at MiraiCallApiPlugin-v1.3.jar//io.github.Kloping.mirai.p1.CallApiPlugin$1.onMessage(CallApiPlugin.java:51)
2022-05-30 18:47:10 W/stderr: at jdk.internal.reflect.GeneratedMethodAccessor41.invoke(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2022-05-30 18:47:10 W/stderr: at java.base/java.lang.reflect.Method.invoke(Unknown Source)
2022-05-30 18:47:10 W/stderr: at net.mamoe.mirai.internal.event.JvmMethodListenersInternalKt.registerEventHandler$callMethod$invokeWithErrorReport(JvmMethodListenersInternal.kt:140)
2022-05-30 18:47:10 W/stderr: at net.mamoe.mirai.internal.event.JvmMethodListenersInternalKt.access$registerEventHandler$callMethod$invokeWithErrorReport(JvmMethodListenersInternal.kt:1)
2022-05-30 18:47:10 W/stderr: at net.mamoe.mirai.internal.event.JvmMethodListenersInternalKt$registerEventHandler$callMethod$2.invokeSuspend(JvmMethodListenersInternal.kt:154)
2022-05-30 18:47:10 W/stderr: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2022-05-30 18:47:10 W/stderr: at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
2022-05-30 18:47:10 W/stderr: at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
2022-05-30 18:47:10 W/stderr: at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
2022-05-30 18:47:10 W/stderr: at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
2022-05-30 18:47:10 W/stderr: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
2022-05-30 18:47:10 W/stderr: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
2022-05-30 18:47:10 W/stderr: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)能看看是怎么回事吗?
如果触发次报错就不会在群内返回结果
等个几分钟又好了
再使用几次又报错用不了
如此循环 -
-
-
-
@Kloping 懂了,感谢
-
大佬 ,这语音功能,我用不了为啥
-
使用时报错
2022-06-04 12:40:37 W/stderr: java.net.ConnectException: Connection refused (Connection refused)
2022-06-04 12:40:37 W/stderr: at java.base/java.net.PlainSocketImpl.socketConnect(Native Method)
2022-06-04 12:40:37 W/stderr: at java.base/java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/java.net.AbstractPlainSocketImpl.connect(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/java.net.SocksSocketImpl.connect(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/java.net.Socket.connect(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/sun.security.ssl.SSLSocketImpl.connect(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/sun.net.NetworkClient.doConnect(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/sun.net.www.http.HttpClient.openServer(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/sun.net.www.protocol.https.HttpsClient.<init>(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/sun.net.www.protocol.https.HttpsClient.New(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(Unknown Source)
2022-06-04 12:40:37 W/stderr: at MiraiCallApiPlugin-v1.4.jar//org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:859)
2022-06-04 12:40:37 W/stderr: at MiraiCallApiPlugin-v1.4.jar//org.jsoup.helper.HttpConnection$Response.execute(HttpConnection.java:829)
2022-06-04 12:40:37 W/stderr: at MiraiCallApiPlugin-v1.4.jar//org.jsoup.helper.HttpConnection.execute(HttpConnection.java:366)
2022-06-04 12:40:37 W/stderr: at MiraiCallApiPlugin-v1.4.jar//org.jsoup.helper.HttpConnection.get(HttpConnection.java:353)
2022-06-04 12:40:37 W/stderr: at MiraiCallApiPlugin-v1.4.jar//io.github.Kloping.mirai.p1.Worker.doc(Worker.java:170)
2022-06-04 12:40:37 W/stderr: at MiraiCallApiPlugin-v1.4.jar//io.github.Kloping.mirai.p1.Worker.call(Worker.java:92)
2022-06-04 12:40:37 W/stderr: at MiraiCallApiPlugin-v1.4.jar//io.github.Kloping.mirai.p1.CallApiPlugin$1.onMessage0(CallApiPlugin.java:61)
2022-06-04 12:40:37 W/stderr: at MiraiCallApiPlugin-v1.4.jar//io.github.Kloping.mirai.p1.CallApiPlugin$1.onMessage(CallApiPlugin.java:71)
2022-06-04 12:40:37 W/stderr: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
2022-06-04 12:40:37 W/stderr: at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
2022-06-04 12:40:37 W/stderr: at java.base/java.lang.reflect.Method.invoke(Unknown Source)
2022-06-04 12:40:37 W/stderr: at net.mamoe.mirai.internal.event.JvmMethodListenersInternalKt.registerEventHandler$callMethod$invokeWithErrorReport(JvmMethodListenersInternal.kt:140)
2022-06-04 12:40:37 W/stderr: at net.mamoe.mirai.internal.event.JvmMethodListenersInternalKt.access$registerEventHandler$callMethod$invokeWithErrorReport(JvmMethodListenersInternal.kt:1)
2022-06-04 12:40:37 W/stderr: at net.mamoe.mirai.internal.event.JvmMethodListenersInternalKt$registerEventHandler$callMethod$2.invokeSuspend(JvmMethodListenersInternal.kt:154)
2022-06-04 12:40:37 W/stderr: at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
2022-06-04 12:40:37 W/stderr: at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
2022-06-04 12:40:37 W/stderr: at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
2022-06-04 12:40:37 W/stderr: at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
2022-06-04 12:40:37 W/stderr: at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
2022-06-04 12:40:37 W/stderr: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:749)
2022-06-04 12:40:37 W/stderr: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
2022-06-04 12:40:37 W/stderr: at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
能看看是出什么问题了吗?
api用的是api.antisniper.net/findnick
一直会报错,看样子是用了cloudflare
难不成是这个问题吗?
如果是的话插件添加一个代理功能会好点(?)