diff --git a/src/main/kotlin/com/xiaoyv404/mirai/app/fsh/CommandHistory.kt b/src/main/kotlin/com/xiaoyv404/mirai/app/fsh/CommandHistory.kt new file mode 100644 index 00000000..0586b89a --- /dev/null +++ b/src/main/kotlin/com/xiaoyv404/mirai/app/fsh/CommandHistory.kt @@ -0,0 +1,32 @@ +package com.xiaoyv404.mirai.app.fsh + +import com.xiaoyv404.mirai.core.App +import com.xiaoyv404.mirai.core.gid +import com.xiaoyv404.mirai.core.uid +import com.xiaoyv404.mirai.dao.save +import com.xiaoyv404.mirai.model.HistoryRecord +import net.mamoe.mirai.event.events.MessageEvent +import net.mamoe.mirai.message.data.ids +import java.time.Instant +import java.time.LocalDateTime +import java.time.ZoneId +import java.time.ZoneOffset + +@App +object CommandHistory { + fun add(command: String, msg: MessageEvent) { + HistoryRecord { + this.sendTime = LocalDateTime.ofInstant( + Instant.ofEpochSecond(msg.time.toLong() + 10800), ZoneId.ofOffset( + "UTC", + ZoneOffset.of("+18") + ) + ) + this.command = command + this.gid = msg.gid() + this.uid = msg.uid() + this.msgId = msg.message.ids[0].toLong() + this.content = msg.message.contentToString() + }.save() + } +} \ No newline at end of file diff --git a/src/main/kotlin/com/xiaoyv404/mirai/app/fsh/Fsh.kt b/src/main/kotlin/com/xiaoyv404/mirai/app/fsh/Fsh.kt index c82b1633..61e4b4cb 100644 --- a/src/main/kotlin/com/xiaoyv404/mirai/app/fsh/Fsh.kt +++ b/src/main/kotlin/com/xiaoyv404/mirai/app/fsh/Fsh.kt @@ -47,6 +47,7 @@ class Fsh : NfAppMessageHandler() { if (fshApp.executeRsh(argsList.toTypedArray(), msg)) { // 调用成功进行限制计次 fshApp.submitCallLimiter(uid, gid) + CommandHistory.add(argsList[0], msg) } } catch (_: UnrecognizedOptionException) { msg.reply("未知参数") diff --git a/src/main/kotlin/com/xiaoyv404/mirai/app/history/process.kt b/src/main/kotlin/com/xiaoyv404/mirai/app/history/process.kt deleted file mode 100644 index bf3a9ba9..00000000 --- a/src/main/kotlin/com/xiaoyv404/mirai/app/history/process.kt +++ /dev/null @@ -1,73 +0,0 @@ -package com.xiaoyv404.mirai.app.history - -import com.xiaoyv404.mirai.* -import com.xiaoyv404.mirai.core.* -import com.xiaoyv404.mirai.dao.* -import com.xiaoyv404.mirai.model.* -import com.xiaoyv404.mirai.tool.* -import kotlinx.serialization.* -import net.mamoe.mirai.contact.Group -import net.mamoe.mirai.event.events.* -import net.mamoe.mirai.message.data.* -import net.mamoe.mirai.message.data.MessageChain.Companion.serializeToJsonString -import java.time.* - -@App -class History : NfAppMessageHandler() { - override fun getAppName() = "History" - override fun getVersion() = "1.0.0" - override fun getAppDescription() = "消息记录器" - override suspend fun handleMessage(msg: MessageEvent) { - val message = msg.message - val group = msg.subject - if (group !is Group) - return - when (message[1]) { - is PlainText -> { - message.content - } - is Image -> { - message.content - } - is At -> { - message.content - } - is AtAll -> { - message.content - } - is Face -> { - message.content - } - is MarketFace -> { - message.content - } - else -> { - return - } - }.let { - FileUtils.saveFileFromString( - it + "\n", - PluginMain.resolveDataFile("history/${msg.gid()}.txt") - ) - } - try { - HistoryRecord { - sendTime = LocalDateTime.ofInstant( - Instant.ofEpochSecond(message.time.toLong() + 10800), ZoneId.ofOffset( - "UTC", - ZoneOffset.of("+18") - ) - ) - eventType = "msg" - groupId = msg.gid() - groupName = group.name - senderId = msg.uid() - senderName = msg.senderName - msgId = message.ids[0].toLong() - content = message.serializeToJsonString() - }.save() - } catch (_: SerializationException) { - // 不必理会 - } - } -} \ No newline at end of file diff --git a/src/main/kotlin/com/xiaoyv404/mirai/model/HistoryRecord.kt b/src/main/kotlin/com/xiaoyv404/mirai/model/HistoryRecord.kt index 46de3f6f..8cc5155c 100644 --- a/src/main/kotlin/com/xiaoyv404/mirai/model/HistoryRecord.kt +++ b/src/main/kotlin/com/xiaoyv404/mirai/model/HistoryRecord.kt @@ -1,18 +1,17 @@ package com.xiaoyv404.mirai.model -import org.ktorm.entity.* +import org.ktorm.entity.Entity import org.ktorm.schema.* -import java.time.* +import java.time.LocalDateTime interface HistoryRecord : Entity { companion object : Entity.Factory() + val id: Long var sendTime: LocalDateTime - var eventType: String - var groupId: Long - var groupName: String - var senderId: Long - var senderName: String + var command: String + var gid: Long + var uid: Long var msgId: Long var content: String } @@ -20,11 +19,9 @@ interface HistoryRecord : Entity { object HistoryRecords : Table("History_Record") { val id = long("id").primaryKey().bindTo { it.id } val sendTime = datetime("send_time").bindTo { it.sendTime } - val eventType = varchar("event_type").bindTo { it.eventType } - val groupId = long("group_id").bindTo { it.groupId } - val groupName = varchar("group_name").bindTo { it.groupName } - val senderId = long("sender_id").bindTo { it.senderId } - val senderName = varchar("sender_name").bindTo { it.senderName } + val eventType = varchar("command").bindTo { it.command } + val groupId = long("group_id").bindTo { it.gid } + val senderId = long("sender_id").bindTo { it.uid } val msgId = long("msg_id").bindTo { it.msgId } val content = text("content").bindTo { it.content } } \ No newline at end of file