Skip to content

Commit

Permalink
CQCode: implement sending LightApp RichMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
PeratX committed Aug 13, 2020
1 parent 3a62fba commit ea6d0bb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
6 changes: 4 additions & 2 deletions Docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@
- 发送抖一抖 `[CQ:shake]`
- 发送各类戳一戳 `[CQ:poke,id=xxx,type=xxx]`,ID和Type见 `mirai``HummerMessage.kt`,必须在该文件中定义的id和type才能发送
- 接收`VipFace` `[CQ:vipface,id=xxx,name=xxx,count=xxx]`
- 发送 `Xml` 消息 `[CQ:xml,data=xxxx]`
- 发送 `Json` 消息 `[CQ:json,data=xxxx]`
- 发送 `XML` 消息 `[CQ:xml,data=xxxx]`
- 发送 `JSON` 消息 `[CQ:json,data=xxxx]`,少部分 JSON 消息为此类型
- 发送 `LightApp` 消息 `[CQ:app,data=xxxx]`,大部分 JSON 消息为此类型
- 接收未知类型 `Rich` 消息 `[CQ:rich,data=xxxx,id=xx]`

## 酷Q API

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ object ChainCodeConverter {
private fun String.toMap() = HashMap<String, String>().apply {
this@toMap.split(",").forEach {
val parts = it.split(delimiters = *arrayOf("="), limit = 2)
this[parts[0]] = parts[1].unescape(true)
this[parts[0].trim()] = parts[1].unescape(true).trim()
}
}

Expand Down Expand Up @@ -157,6 +157,12 @@ object ChainCodeConverter {
"json" -> {
return JsonMessage(args["data"]!!)
}
"app" -> {
return LightApp(args["data"]!!)
}
"rich" -> {
return ServiceMessage(args["id"]!!.toInt(), args["data"]!!)
}
else -> {
MiraiNative.logger.debug("不支持的 CQ码:${parts[0]}")
}
Expand All @@ -175,7 +181,18 @@ object ChainCodeConverter {
is Face -> "[CQ:face,id=${it.id}]"
is VipFace -> "[CQ:vipface,id=${it.kind.id},name=${it.kind.name},count=${it.count}]"
is Image -> "[CQ:image,file=${it.imageId}.mnimg]" // Real file not supported
is RichMessage -> "[CQ:rich,data=${it.content.escape(true)}]"
is RichMessage -> {
val content = it.content.escape(true)
return@joinToString when (it) {
is LightApp -> "[CQ:app,data=$content]"
is ServiceMessage -> when (it.serviceId) {
60 -> "[CQ:xml,data=$content]"
1 -> "[CQ:json,data=$content]"
else -> "[CQ:rich,data=${content},id=${it.serviceId}]"
}
else -> "[CQ:rich,data=$content]" // Which is impossible
}
}
is Voice -> "[CQ:voice,url=${it.url},md5=${it.md5},file=${it.fileName}]"
is PokeMessage -> "[CQ:poke,id=${it.id},type=${it.type},name=${it.name}]"
is FlashImage -> "[CQ:image,file=${it.image.imageId}.mning,type=flash]"
Expand Down

0 comments on commit ea6d0bb

Please sign in to comment.