那个,这是玩QQ骰子游戏的,所以发送的骰子只有六面,无法生成更大的(当然,可以发送文本,但是没有意义了)
至于同时骰,应该是可以的,你可以rd history里面进行查看
greenhandzdl 发布的帖子
-
RE: 最小化骰子插件(可能)
-
求助:mirai中文乱码及图片等识别下载问题
先贴个code
globalEventChannel().subscribeAlways<GroupMessageEvent> { file_write_last_line("$dataFolder/groupMessage","${group.id.toString()}.txt","${sender.id.toString()}:${message.contentToString()}") }
其中file_write_last_line实际上就是封装了appendFile,但是效果会出现乱码:
-
RE: # 如何设置工作目录&&如何new一个目录&&接入TBP过程到底有什么问题
json大概跑了,基本上卡在签名那
我目前没太多时间去整,而且我相信用户也没有耐心去调该死的配置(真的,特别麻烦)
所以到最后我可能会尝试接入其他的机器人api -
mirai-plugins-sayBack
仅用于群聊(注意可能与其他插件冲突)
一个致力于让你的机器人回复你的消息的插件(说了跟没说一样)
项目地址:https://github.com/greenhandzdl/mirai-plugins-sayBack/tree/master
编译版本:https://github.com/greenhandzdl/mirai-plugins-sayBack/releases面向对象
- 具有一定能力
- 懒人
功能(0.0.2):
好感度升级类:
- 签到
功能类:
- 复读 + 复读文本
- 好图
- 网易云 歌名
- 精准维基 + 检查文本
- 相关维基 + 检查文本
- 问答 + 文本 [如果有人能帮忙修复就更好了]
游戏类:
- 猜数字
开始|结束 | 所猜数字大小[0,100],10次机会
补充说明:
- 可能写的时候只考虑到自己用,并没有特意去注册什么指令
- 签到之类的点数只是为了防刷屏,敬请谅解
- 更新可能也只能暑假了,毕竟马上要学考什么的
- 暑假目标:重构项目,建立权限系统,把该死几百行的代码拆开
-
RE: 小白求助:Mirai怎么实现发送URL下的图片?
@greenhandzdl 在 小白求助:Mirai怎么实现发送URL下的图片? 中说:
val buffer = ByteArray(1024)
var len = 0
while (inputStream.read(buffer).also { len = it } != -1) {
fos.write(buffer, 0, len)
}
在我的ide里面确实已经下载了该图片,但是发不出去 -
RE: 小白求助:Mirai怎么实现发送URL下的图片?
···kotlin
message.contentToString().startsWith("好图") -> {
val url = "https://一个链接,大抵是图片的/random_img.php"
val file = File("./img/")
if (!file.exists()) {
file.mkdirs()
}
val fileName = "./img/" + System.currentTimeMillis() + ".jpg"
val fileUrl = URL(url)
val conn = fileUrl.openConnection()
conn.connect()
val inputStream = conn.getInputStream()
val fos = FileOutputStream(fileName)
val buffer = ByteArray(1024)
var len = 0
while (inputStream.read(buffer).also { len = it } != -1) {
fos.write(buffer, 0, len)
}
fos.close()
inputStream.close()
group.sendMessage(
messageChainOf(
At(sender) + Image(
fileName
)
)
)
}能帮忙看看哪里错了吗
-
RE: # 如何设置工作目录&&如何new一个目录&&接入TBP过程到底有什么问题
@greenhandzdl
同样的,我试图插入维基api也遇到这种情况message.contentToString().startsWith("维基") -> { val m = message.contentToString().replace("维基", "") val result = wiki(m) group.sendMessage(messageChainOf(PlainText(result))) }
fun wiki(m :String) :String{ val requestBody =FormBody.Builder() .add("title", m) .build() val request = Request.Builder() .url("https://wiki.greenhandzdl.tk/api/rest_v1/page/related/") .post(requestBody) .build() val response = OkHttpClient().newCall(request).execute() val responseBody = response.body?.string() val json = JSONObject(responseBody) //解析每一个page和extract,并将page和extract拼接起来返回 val pages = json.getJSONArray("pages") var result = "" for (i in 0 until pages.length()) { val page = pages.getJSONObject(i) val extract = page.getString("extract") val title = page.getString("title") result += title + ":" + extract + "\n" } return result }
-
RE: # 如何设置工作目录&&如何new一个目录&&接入TBP过程到底有什么问题
谢谢大佬
另外开发中的还有这几个问题并没有解决:
- 接入TBP接口中的error:
022-05-02 22:27:45 E/sayBack: Exception in coroutine Plugin com.greenhandzdl.mirai-plugins-sayBack of sayBack org.json.JSONException: JSONObject["ResponseMessage"] not found. at org.json.JSONObject.get(JSONObject.java:587) at org.json.JSONObject.getString(JSONObject.java:874) at com.greenhandzdl.SayBackKt.tbp(SayBack.kt:261) at com.greenhandzdl.SayBack$onEnable$1.invokeSuspend(SayBack.kt:180) at com.greenhandzdl.SayBack$onEnable$1.invoke(SayBack.kt) at com.greenhandzdl.SayBack$onEnable$1.invoke(SayBack.kt) at net.mamoe.mirai.event.EventChannel$subscribeAlways$1.invokeSuspend(EventChannel.kt:455) at net.mamoe.mirai.event.EventChannel$subscribeAlways$1.invoke(EventChannel.kt) at net.mamoe.mirai.event.EventChannel$subscribeAlways$1.invoke(EventChannel.kt) at net.mamoe.mirai.internal.event.Handler$onEvent$2.invokeSuspend(InternalEventListeners.kt:50) at net.mamoe.mirai.internal.event.Handler$onEvent$2.invoke(InternalEventListeners.kt) at net.mamoe.mirai.internal.event.Handler$onEvent$2.invoke(InternalEventListeners.kt) at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89) at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:166) at kotlinx.coroutines.BuildersKt.withContext(Unknown Source) at net.mamoe.mirai.internal.event.Handler.onEvent(InternalEventListeners.kt:50) at net.mamoe.mirai.internal.event.InternalEventListenersKt.process(InternalEventListeners.kt:166) at net.mamoe.mirai.internal.event.InternalEventListenersKt.callAndRemoveIfRequired(InternalEventListeners.kt:115) at net.mamoe.mirai.event._EventBroadcast.broadcastImpl(Event.kt:174) at net.mamoe.mirai.IMirai.broadcastEvent(IMirai.kt:318) at net.mamoe.mirai.internal.MiraiImpl.broadcastEvent$suspendImpl(MiraiImpl.kt:308) at net.mamoe.mirai.internal.MiraiImpl.broadcastEvent(MiraiImpl.kt) at net.mamoe.mirai.event._EventBroadcast.broadcastPublic$suspendImpl(Event.kt:161) at net.mamoe.mirai.event._EventBroadcast.broadcastPublic(Event.kt) at net.mamoe.mirai.event.EventKt.broadcast(Event.kt:146) at net.mamoe.mirai.internal.network.components.EventDispatcherImpl$broadcast$2.invokeSuspend(EventDispatcher.kt:90) at net.mamoe.mirai.internal.network.components.EventDispatcherImpl$broadcast$2.invoke(EventDispatcher.kt) at net.mamoe.mirai.internal.network.components.EventDispatcherImpl$broadcast$2.invoke(EventDispatcher.kt) at kotlinx.coroutines.intrinsics.UndispatchedKt.startUndispatchedOrReturn(Undispatched.kt:89) at kotlinx.coroutines.BuildersKt__Builders_commonKt.withContext(Builders.common.kt:166) at kotlinx.coroutines.BuildersKt.withContext(Unknown Source) at net.mamoe.mirai.internal.network.components.EventDispatcherImpl.broadcast$suspendImpl(EventDispatcher.kt:89) at net.mamoe.mirai.internal.network.components.EventDispatcherImpl.broadcast(EventDispatcher.kt) at net.mamoe.mirai.internal.network.components.EventDispatcherImpl$broadcastAsync$job$1.invokeSuspend(EventDispatcher.kt:105) at net.mamoe.mirai.internal.network.components.EventDispatcherImpl$broadcastAsync$job$1.invoke(EventDispatcher.kt) at net.mamoe.mirai.internal.network.components.EventDispatcherImpl$broadcastAsync$job$1.invoke(EventDispatcher.kt) at kotlinx.coroutines.intrinsics.UndispatchedKt.startCoroutineUndispatched(Undispatched.kt:55) at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:112) at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126) at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56) at kotlinx.coroutines.BuildersKt.launch(Unknown Source) at net.mamoe.mirai.internal.network.components.EventDispatcherImpl.broadcastAsync-kKe4JaQ(EventDispatcher.kt:102) at net.mamoe.mirai.internal.network.components.EventDispatcher.broadcastAsync-kKe4JaQ$default(EventDispatcher.kt:35) at net.mamoe.mirai.internal.network.components.EventBroadcasterPacketHandler.impl(PacketHandler.kt:87) at net.mamoe.mirai.internal.network.components.EventBroadcasterPacketHandler.handlePacket(PacketHandler.kt:73) at net.mamoe.mirai.internal.network.components.PacketHandlerChain.handlePacket(PacketHandler.kt:42) at net.mamoe.mirai.internal.network.handler.NetworkHandlerSupport$collectReceived$3.invokeSuspend(NetworkHandlerSupport.kt:84) at net.mamoe.mirai.internal.network.handler.NetworkHandlerSupport$collectReceived$3.invoke(NetworkHandlerSupport.kt) at net.mamoe.mirai.internal.network.handler.NetworkHandlerSupport$collectReceived$3.invoke(NetworkHandlerSupport.kt) at kotlinx.coroutines.intrinsics.UndispatchedKt.startCoroutineUndispatched(Undispatched.kt:55) at kotlinx.coroutines.CoroutineStart.invoke(CoroutineStart.kt:112) at kotlinx.coroutines.AbstractCoroutine.start(AbstractCoroutine.kt:126) at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch(Builders.common.kt:56) at kotlinx.coroutines.BuildersKt.launch(Unknown Source) at kotlinx.coroutines.BuildersKt__Builders_commonKt.launch$default(Builders.common.kt:47) at kotlinx.coroutines.BuildersKt.launch$default(Unknown Source) at net.mamoe.mirai.internal.network.handler.NetworkHandlerSupport.collectReceived$mirai_core(NetworkHandlerSupport.kt:82) at net.mamoe.mirai.internal.network.impl.netty.NettyNetworkHandler$PacketDecodePipeline$send$1.invokeSuspend(NettyNetworkHandler.kt:178) at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33) at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106) at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164) at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.base/java.lang.Thread.run(Thread.java:829) 2022-05-02 22:27:45 V/Bot.742431945: [无产Bot,联合起来!(970131925)] greenhandzdl(修炼中)(2029252158) -> 问答 草 >
部分代码
fun tbp(m :String) : String{ val json = JSONObject(File("$configFolder/TBP.json").readText()) //获取数据 val SecretId = json.getString("SecretId") val SecretKey = json.getString("SecretKey") val BotId = json.getString("BotId") val BotEnv = json.getString("BotEnv") val TerminalId = json.getString("TerminalId") val requestBody = FormBody.Builder() .add("SecretId", SecretId) .add("SecretKey", SecretKey) .add("BotId", BotId) .add("BotEnv", BotEnv) .add("TerminalId", TerminalId) .add("InputText", m) .build() val request = Request.Builder() .url("https://tbp.tencentcloudapi.com") .post(requestBody) .build() val response = OkHttpClient().newCall(request).execute() val responseData = response.body?.string() //解析json val jsonObject = JSONObject(responseData) //提取json中的ResponseMessage并转为string var responseMessage = jsonObject.getString("ResponseMessage") if (responseMessage == "") { responseMessage = "由于网络问题,暂时没找到答案!" } return responseMessage } }
message.contentToString().startsWith("问答") -> { val m = message.contentToString().replace("问答", "") val responseMessage = tbp(m) group.sendMessage(messageChainOf(PlainText(responseMessage))) }
-
RE: # 如何设置工作目录&&如何new一个目录&&接入TBP过程到底有什么问题
···
public interface PluginFileExtensions {
/**
* 数据目录路径
* @see PluginData
*/
public val dataFolderPath: Path/** * 数据目录. `dataFolderPath.toFile()` * @see PluginData */ public val dataFolder: File
···
我是这样用的val pluginfiles = File(Plugin.dataFolderPath) ··· 但是dataFolderPath报错
-
RE: # 如何设置工作目录&&如何new一个目录&&接入TBP过程到底有什么问题
val pluginfiles = File(Plugin.dataFolder).listFiles()
ide提示datafile飘红
Unresolved reference: dataFolder -
# 如何设置工作目录&&如何new一个目录&&接入TBP过程到底有什么问题
~ 如何设置工作目录
override fun onEnable() { super.onEnable() logger.info("sayBack onEnable") val workingDir = File("data/com.greenhandzdl/") val cacheDir = File("data/com.greenhandzdl/cache/") init()//初始化配置文件
这样好像不太对
~如何创建目录val file = File("data/插件名") file.mkdirs()
提示special,飘红
~TBP函数相关问题fun TBP(m: String) : String{ val json = JSONObject(File("data/TBP").readText()) //获取数据 val SecretId = json.getString("SecretId") val SecretKey = json.getString("SecretKey") val BotId = json.getString("BotId") val BotEnv = json.getString("BotEnv") val TerminalId = json.getString("TerminalId") val requestBody = FormBody.Builder() .add("SecretId", SecretId) .add("SecretKey", SecretKey) .add("BotId", BotId) .add("BotEnv", BotEnv) .add("TerminalId", TerminalId) .add("InputText", m) .build() val request = Request.Builder() .url("https://tbp.tencentcloudapi.com") .post(requestBody) .build() val response = OkHttpClient().newCall(request).execute() val responseData = response.body?.string() //解析json val jsonObject = JSONObject(responseData) //提取json中的ResponseMessage并转为string var responseMessage = jsonObject.getString("ResponseMessage") if (responseMessage == "") { responseMessage = "由于网络问题,暂时没找到答案!" } return responseMessage }
相关问题项目:https://github.com/greenhandzdl/mirai-plugins-sayBack/blob/master/src/main/kotlin/SayBack.kt