From 9b1c9b1aceccf34112c1cdac9e598ab9f1b320d9 Mon Sep 17 00:00:00 2001 From: 3944Realms Date: Fri, 15 Aug 2025 09:51:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=8C=E6=88=90=E5=AF=B9=E5=90=84?= =?UTF-8?q?=E4=B8=AA=E7=B1=BB=E5=9E=8B=E5=93=8D=E5=BA=94Event=E7=9A=84?= =?UTF-8?q?=E6=8A=BD=E8=B1=A1=E5=AE=9A=E4=B9=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.MD | 1 + .../ltdmanager/napcat/events/NapCatEvent.kt | 28 +++++++++ .../napcat/events/file/AbstractFileEvent.kt | 59 ++++++++++++++++++ .../napcat/events/group/AbstractGroupEvent.kt | 60 +++++++++++++++++++ .../events/message/AbstractMessageEvent.kt | 60 +++++++++++++++++++ .../napcat/events/other/AbstractOtherEvent.kt | 59 ++++++++++++++++++ .../events/passkey/AbstractPassKeyEvent.kt | 58 ++++++++++++++++++ .../events/personal/AbstractPersonalEvent.kt | 60 +++++++++++++++++++ .../events/system/AbstractSystemEvent.kt | 29 +++++++++ 9 files changed, 414 insertions(+) create mode 100644 src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/file/AbstractFileEvent.kt create mode 100644 src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/group/AbstractGroupEvent.kt create mode 100644 src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/message/AbstractMessageEvent.kt create mode 100644 src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/other/AbstractOtherEvent.kt create mode 100644 src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/passkey/AbstractPassKeyEvent.kt create mode 100644 src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/personal/AbstractPersonalEvent.kt create mode 100644 src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/system/AbstractSystemEvent.kt diff --git a/README.MD b/README.MD index e69de29..0dcd141 100644 --- a/README.MD +++ b/README.MD @@ -0,0 +1 @@ +# 基于NapCat Websocket Server 框架开发 diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/NapCatEvent.kt b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/NapCatEvent.kt index 93120ee..b284c74 100644 --- a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/NapCatEvent.kt +++ b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/NapCatEvent.kt @@ -3,6 +3,13 @@ package top.r3944realms.ltdmanager.napcat.events import kotlinx.serialization.* import kotlinx.serialization.json.Json import top.r3944realms.ltdmanager.napcat.events.account.AbstractAccountEvent +import top.r3944realms.ltdmanager.napcat.events.file.AbstractFileEvent +import top.r3944realms.ltdmanager.napcat.events.group.AbstractGroupEvent +import top.r3944realms.ltdmanager.napcat.events.message.AbstractMessageEvent +import top.r3944realms.ltdmanager.napcat.events.other.AbstractOtherEvent +import top.r3944realms.ltdmanager.napcat.events.passkey.AbstractPassKeyEvent +import top.r3944realms.ltdmanager.napcat.events.personal.AbstractPersonalEvent +import top.r3944realms.ltdmanager.napcat.events.system.AbstractSystemEvent /** @@ -23,6 +30,13 @@ abstract class NapCatEvent( private val eventTypeMap by lazy { mutableMapOf>().apply { putAll(AbstractAccountEvent.eventTypeMap) + putAll(AbstractFileEvent.eventTypeMap) + putAll(AbstractOtherEvent.eventTypeMap) + putAll(AbstractPersonalEvent.eventTypeMap) + putAll(AbstractPassKeyEvent.eventTypeMap) + putAll(AbstractGroupEvent.eventTypeMap) + putAll(AbstractSystemEvent.eventTypeMap) + putAll(AbstractMessageEvent.eventTypeMap) } } @@ -32,6 +46,20 @@ abstract class NapCatEvent( // 如果是Account相关事件,使用AccountEvent的json配置 if (type.startsWith("account/")) { AbstractAccountEvent.json.decodeFromString(serializer, jsonString) + } else if (type.startsWith("file/")) { + AbstractFileEvent.json.decodeFromString(serializer, jsonString) + } else if (type.startsWith("group/")) { + AbstractGroupEvent.json.decodeFromString(serializer, jsonString) + } else if (type.startsWith("message/")) { + AbstractMessageEvent.json.decodeFromString(serializer, jsonString) + } else if (type.startsWith("passkey/")) { + AbstractPassKeyEvent.json.decodeFromString(serializer, jsonString) + } else if (type.startsWith("personal/")) { + AbstractPersonalEvent.json.decodeFromString(serializer, jsonString) + } else if (type.startsWith("system/")) { + AbstractSystemEvent.json.decodeFromString(serializer, jsonString) + } else if (type.startsWith("other/")) { + AbstractOtherEvent.json.decodeFromString(serializer, jsonString) } else { // 其他类型的事件可以使用默认的Json配置 val json = Json { diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/file/AbstractFileEvent.kt b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/file/AbstractFileEvent.kt new file mode 100644 index 0000000..623cec6 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/file/AbstractFileEvent.kt @@ -0,0 +1,59 @@ +package top.r3944realms.ltdmanager.napcat.events.file + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json +import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.modules.polymorphic +import top.r3944realms.ltdmanager.napcat.events.NapCatEvent + +/** + * QQ 文件相关响应抽象 + * @property status 状态字符串 + * @property retcode 返回代码 + * @property message 消息 + * @property wording 文字描述 + * @property echo 回显字段 (可空) + */ +@Serializable +abstract class AbstractFileEvent( + /** + * 状态字符串 + */ + open val status: Status, + /** + * 返回代码 + */ + open val retcode: Double, + /** + * 消息 + */ + open val message: String, + /** + * 文字描述 + */ + open val wording: String, + /** + * 回显字段 + */ + open val echo: String? = null +) : NapCatEvent() { + override fun type(): String = "file/" + subtype() + companion object { + val eventTypeMap by lazy { + mutableMapOf>().apply { + + } + } + internal val json: Json by lazy { + Json { + ignoreUnknownKeys = true + serializersModule = SerializersModule { + polymorphic(NapCatEvent::class) { + + } + } + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/group/AbstractGroupEvent.kt b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/group/AbstractGroupEvent.kt new file mode 100644 index 0000000..9c8bc53 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/group/AbstractGroupEvent.kt @@ -0,0 +1,60 @@ +package top.r3944realms.ltdmanager.napcat.events.group + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json +import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.modules.polymorphic +import top.r3944realms.ltdmanager.napcat.events.NapCatEvent + +/** + * QQ 群聊相关响应抽象 + * @property status 状态字符串 + * @property retcode 返回代码 + * @property message 消息 + * @property wording 文字描述 + * @property echo 回显字段 (可空) + */ +@Serializable +abstract class AbstractGroupEvent ( +/** + * 状态字符串 + */ +open val status: Status, +/** + * 返回代码 + */ +open val retcode: Double, +/** + * 消息 + */ +open val message: String, +/** + * 文字描述 + */ +open val wording: String, +/** + * 回显字段 + */ +open val echo: String? = null +) : NapCatEvent() { + override fun type(): String = "group/" + subtype() + + companion object { + val eventTypeMap by lazy { + mutableMapOf>().apply { + + } + } + internal val json: Json by lazy { + Json { + ignoreUnknownKeys = true + serializersModule = SerializersModule { + polymorphic(NapCatEvent::class) { + + } + } + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/message/AbstractMessageEvent.kt b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/message/AbstractMessageEvent.kt new file mode 100644 index 0000000..38220b5 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/message/AbstractMessageEvent.kt @@ -0,0 +1,60 @@ +package top.r3944realms.ltdmanager.napcat.events.message + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json +import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.modules.polymorphic +import top.r3944realms.ltdmanager.napcat.events.NapCatEvent + +/** + * QQ 消息相关响应抽象 + * @property status 状态字符串 + * @property retcode 返回代码 + * @property message 消息 + * @property wording 文字描述 + * @property echo 回显字段 (可空) + */ +@Serializable +abstract class AbstractMessageEvent ( + /** + * 状态字符串 + */ + open val status: Status, + /** + * 返回代码 + */ + open val retcode: Double, + /** + * 消息 + */ + open val message: String, + /** + * 文字描述 + */ + open val wording: String, + /** + * 回显字段 + */ + open val echo: String? = null +) : NapCatEvent() { + override fun type(): String = "message/" + subtype() + + companion object { + val eventTypeMap by lazy { + mutableMapOf>().apply { + + } + } + internal val json: Json by lazy { + Json { + ignoreUnknownKeys = true + serializersModule = SerializersModule { + polymorphic(NapCatEvent::class) { + + } + } + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/other/AbstractOtherEvent.kt b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/other/AbstractOtherEvent.kt new file mode 100644 index 0000000..de7796f --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/other/AbstractOtherEvent.kt @@ -0,0 +1,59 @@ +package top.r3944realms.ltdmanager.napcat.events.other + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json +import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.modules.polymorphic +import top.r3944realms.ltdmanager.napcat.events.NapCatEvent +/** + * QQ 其它相关响应抽象 + * @property status 状态字符串 + * @property retcode 返回代码 + * @property message 消息 + * @property wording 文字描述 + * @property echo 回显字段 (可空) + */ +@Serializable +abstract class AbstractOtherEvent ( + /** + * 状态字符串 + */ + open val status: Status, + /** + * 返回代码 + */ + open val retcode: Double, + /** + * 消息 + */ + open val message: String, + /** + * 文字描述 + */ + open val wording: String, + /** + * 回显字段 + */ + open val echo: String? = null +) : NapCatEvent() { + override fun type(): String = "other/" + subtype() + + companion object { + val eventTypeMap by lazy { + mutableMapOf>().apply { + + } + } + internal val json: Json by lazy { + Json { + ignoreUnknownKeys = true + serializersModule = SerializersModule { + polymorphic(NapCatEvent::class) { + + } + } + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/passkey/AbstractPassKeyEvent.kt b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/passkey/AbstractPassKeyEvent.kt new file mode 100644 index 0000000..6a6783a --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/passkey/AbstractPassKeyEvent.kt @@ -0,0 +1,58 @@ +package top.r3944realms.ltdmanager.napcat.events.passkey + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.json.Json +import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.modules.polymorphic +import top.r3944realms.ltdmanager.napcat.events.NapCatEvent + +/** + * QQ 密钥相关响应抽象 + * @property status 状态字符串 + * @property retcode 返回代码 + * @property message 消息 + * @property wording 文字描述 + * @property echo 回显字段 (可空) +*/ +abstract class AbstractPassKeyEvent ( + /** + * 状态字符串 + */ + open val status: Status, + /** + * 返回代码 + */ + open val retcode: Double, + /** + * 消息 + */ + open val message: String, + /** + * 文字描述 + */ + open val wording: String, + /** + * 回显字段 + */ + open val echo: String? = null +) : NapCatEvent() { + override fun type(): String = "passkey/" + subtype() + + companion object { + val eventTypeMap by lazy { + mutableMapOf>().apply { + + } + } + internal val json: Json by lazy { + Json { + ignoreUnknownKeys = true + serializersModule = SerializersModule { + polymorphic(NapCatEvent::class) { + + } + } + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/personal/AbstractPersonalEvent.kt b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/personal/AbstractPersonalEvent.kt new file mode 100644 index 0000000..82a4aaa --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/personal/AbstractPersonalEvent.kt @@ -0,0 +1,60 @@ +package top.r3944realms.ltdmanager.napcat.events.personal + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.Serializable +import kotlinx.serialization.json.Json +import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.modules.polymorphic +import top.r3944realms.ltdmanager.napcat.events.NapCatEvent + +/** + * QQ 个人相关响应抽象 + * @property status 状态字符串 + * @property retcode 返回代码 + * @property message 消息 + * @property wording 文字描述 + * @property echo 回显字段 (可空) + */ +@Serializable +abstract class AbstractPersonalEvent ( + /** + * 状态字符串 + */ + open val status: Status, + /** + * 返回代码 + */ + open val retcode: Double, + /** + * 消息 + */ + open val message: String, + /** + * 文字描述 + */ + open val wording: String, + /** + * 回显字段 + */ + open val echo: String? = null +) : NapCatEvent() { + override fun type(): String = "personal/" + subtype() + + companion object { + val eventTypeMap by lazy { + mutableMapOf>().apply { + + } + } + internal val json: Json by lazy { + Json { + ignoreUnknownKeys = true + serializersModule = SerializersModule { + polymorphic(NapCatEvent::class) { + + } + } + } + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/system/AbstractSystemEvent.kt b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/system/AbstractSystemEvent.kt new file mode 100644 index 0000000..cd9f730 --- /dev/null +++ b/src/main/kotlin/top/r3944realms/ltdmanager/napcat/events/system/AbstractSystemEvent.kt @@ -0,0 +1,29 @@ +package top.r3944realms.ltdmanager.napcat.events.system + +import kotlinx.serialization.KSerializer +import kotlinx.serialization.json.Json +import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.modules.polymorphic +import top.r3944realms.ltdmanager.napcat.events.NapCatEvent + +abstract class AbstractSystemEvent + : NapCatEvent() { + override fun type(): String = "system/" + subtype() + companion object { + val eventTypeMap by lazy { + mutableMapOf>().apply { + + } + } + internal val json: Json by lazy { + Json { + ignoreUnknownKeys = true + serializersModule = SerializersModule { + polymorphic(NapCatEvent::class) { + + } + } + } + } + } +} \ No newline at end of file