Skip to content

Commit

Permalink
add commandHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoyv404 committed Nov 13, 2023
1 parent 4f35f90 commit 5164f0f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 85 deletions.
32 changes: 32 additions & 0 deletions src/main/kotlin/com/xiaoyv404/mirai/app/fsh/CommandHistory.kt
Original file line number Diff line number Diff line change
@@ -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()
}
}
1 change: 1 addition & 0 deletions src/main/kotlin/com/xiaoyv404/mirai/app/fsh/Fsh.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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("未知参数")
Expand Down
73 changes: 0 additions & 73 deletions src/main/kotlin/com/xiaoyv404/mirai/app/history/process.kt

This file was deleted.

21 changes: 9 additions & 12 deletions src/main/kotlin/com/xiaoyv404/mirai/model/HistoryRecord.kt
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
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<HistoryRecord> {
companion object : Entity.Factory<HistoryRecord>()

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
}

object HistoryRecords : Table<HistoryRecord>("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 }
}

0 comments on commit 5164f0f

Please sign in to comment.