37 lines
1.1 KiB
Kotlin
37 lines
1.1 KiB
Kotlin
package nl.voidcorp.watchtower
|
|
|
|
import org.jetbrains.exposed.dao.IntEntity
|
|
import org.jetbrains.exposed.dao.IntEntityClass
|
|
import org.jetbrains.exposed.dao.id.EntityID
|
|
import org.jetbrains.exposed.sql.transactions.transaction
|
|
|
|
class Message(id: EntityID<Int>) : IntEntity(id) {
|
|
companion object : IntEntityClass<Message>(Messages)
|
|
|
|
var user by Messages.user
|
|
var channel by Messages.channel
|
|
var guild by Messages.guild
|
|
var message by Messages.message
|
|
val history by MessageHistory referrersOn MessageHistories.original
|
|
|
|
|
|
fun update(new: String) {
|
|
transaction {
|
|
MessageHistory.new {
|
|
content = new
|
|
original = this@Message
|
|
}
|
|
}
|
|
}
|
|
|
|
val lastVersion
|
|
get() = history.maxBy { it.updated }!!
|
|
}
|
|
|
|
class MessageHistory(id: EntityID<Int>) : IntEntity(id) {
|
|
companion object : IntEntityClass<MessageHistory>(MessageHistories)
|
|
|
|
var content by MessageHistories.content
|
|
var updated by MessageHistories.updated
|
|
var original by Message referencedOn MessageHistories.original
|
|
} |