Initial Commit
This commit is contained in:
26
src/main/kotlin/commands/user/UserCommand.kt
Normal file
26
src/main/kotlin/commands/user/UserCommand.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package de.steamwar.commands.user
|
||||
|
||||
import com.github.ajalt.clikt.core.CliktCommand
|
||||
import com.github.ajalt.clikt.core.CliktError
|
||||
import com.github.ajalt.clikt.core.findOrSetObject
|
||||
import com.github.ajalt.clikt.parameters.arguments.argument
|
||||
import de.steamwar.db.schema.SteamwarUser
|
||||
import de.steamwar.db.schema.SteamwarUserTable
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.core.or
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
|
||||
class UserCommand: CliktCommand("user") {
|
||||
val userId by argument()
|
||||
val user by findOrSetObject("user") {
|
||||
transaction {
|
||||
SteamwarUser.find { (SteamwarUserTable.id eq userId.toIntOrNull()) or (SteamwarUserTable.username eq userId) }
|
||||
.firstOrNull()
|
||||
?.let { return@transaction it } ?: throw CliktError("User not found!")
|
||||
}
|
||||
}
|
||||
|
||||
override fun run() {
|
||||
user.id
|
||||
}
|
||||
}
|
||||
50
src/main/kotlin/commands/user/UsesrInfoCommand.kt
Normal file
50
src/main/kotlin/commands/user/UsesrInfoCommand.kt
Normal file
@@ -0,0 +1,50 @@
|
||||
package de.steamwar.commands.user
|
||||
|
||||
import com.github.ajalt.clikt.core.CliktCommand
|
||||
import com.github.ajalt.clikt.core.requireObject
|
||||
import com.github.ajalt.mordant.table.table
|
||||
import de.steamwar.db.schema.Session
|
||||
import de.steamwar.db.schema.SteamwarUser
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.jdbc.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import kotlin.time.DurationUnit
|
||||
import kotlin.time.ExperimentalTime
|
||||
|
||||
class UsesrInfoCommand: CliktCommand("info") {
|
||||
val user by requireObject<SteamwarUser>("user")
|
||||
|
||||
@OptIn(ExperimentalTime::class)
|
||||
override fun run() {
|
||||
transaction {
|
||||
val sessions = Session.selectAll().where { Session.user eq user.id.value }.map { it[Session.start] to it[Session.end] }
|
||||
|
||||
val totalPlayed = sessions.map { it.second - it.first }.sumOf { it.toDouble(DurationUnit.HOURS) }
|
||||
val firstJoin = sessions.minByOrNull { it.first }?.first
|
||||
val lastJoin = sessions.maxByOrNull { it.second }?.second
|
||||
|
||||
echo(
|
||||
table {
|
||||
body {
|
||||
row("Name", user.username)
|
||||
row("UUID", user.uuid)
|
||||
row("Team", user.team.name)
|
||||
row("Leader", user.leader)
|
||||
row("Locale", user.locale)
|
||||
row("Beigetreten am", firstJoin)
|
||||
row("Zuletzt gesehen am", lastJoin)
|
||||
row("Spielzeit", totalPlayed.toString() + "h")
|
||||
row("Punishments", table {
|
||||
header { row("Typ", "Ersteller", "Von", "Bis", "Grund") }
|
||||
body {
|
||||
user.punishments.map {
|
||||
row(it.type, it.punisher.username, it.starttime.toString(), if (it.perma) "Perma" else it.endtime.toString(), it.reason)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user