@@ -1,26 +1,7 @@
|
||||
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
|
||||
}
|
||||
override fun run() = Unit
|
||||
}
|
||||
@@ -1,28 +1,38 @@
|
||||
package de.steamwar.commands.user
|
||||
|
||||
import com.github.ajalt.clikt.core.CliktCommand
|
||||
import com.github.ajalt.clikt.core.requireObject
|
||||
import com.github.ajalt.clikt.core.CliktError
|
||||
import com.github.ajalt.clikt.core.findOrSetObject
|
||||
import com.github.ajalt.clikt.parameters.arguments.argument
|
||||
import com.github.ajalt.clikt.parameters.arguments.help
|
||||
import com.github.ajalt.mordant.table.table
|
||||
import de.steamwar.db.findUser
|
||||
import de.steamwar.db.schema.Session
|
||||
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.selectAll
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
import kotlin.time.DurationUnit
|
||||
import kotlin.time.ExperimentalTime
|
||||
|
||||
class UserInfoCommand: CliktCommand("info") {
|
||||
val user by requireObject<SteamwarUser>("user")
|
||||
class UserInfoCommand : CliktCommand("info") {
|
||||
val userId by argument().help("Id, Name, UUID or DiscordId")
|
||||
val user by lazy { findUser(userId) ?: throw CliktError("User not found") }
|
||||
|
||||
@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 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
|
||||
|
||||
val punishments = user.punishments
|
||||
|
||||
echo(
|
||||
table {
|
||||
body {
|
||||
@@ -34,11 +44,17 @@ class UserInfoCommand: CliktCommand("info") {
|
||||
row("Beigetreten am", firstJoin)
|
||||
row("Zuletzt gesehen am", lastJoin)
|
||||
row("Spielzeit", totalPlayed.toString() + "h")
|
||||
row("Punishments", table {
|
||||
row("Punishments", if (punishments.empty()) "Keine" else 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)
|
||||
punishments.map {
|
||||
row(
|
||||
it.type,
|
||||
it.punisher.username,
|
||||
it.starttime.toString(),
|
||||
if (it.perma) "Perma" else it.endtime.toString(),
|
||||
it.reason
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
40
src/main/kotlin/commands/user/UserSearchCommand.kt
Normal file
40
src/main/kotlin/commands/user/UserSearchCommand.kt
Normal file
@@ -0,0 +1,40 @@
|
||||
package de.steamwar.commands.user
|
||||
|
||||
import com.github.ajalt.clikt.core.CliktCommand
|
||||
import com.github.ajalt.clikt.core.Context
|
||||
import com.github.ajalt.clikt.parameters.arguments.argument
|
||||
import com.github.ajalt.clikt.parameters.arguments.help
|
||||
import com.github.ajalt.mordant.table.table
|
||||
import de.steamwar.db.joinedOr
|
||||
import de.steamwar.db.schema.SteamwarUser
|
||||
import de.steamwar.db.schema.SteamwarUserTable
|
||||
import de.steamwar.db.schema.Team
|
||||
import org.jetbrains.exposed.v1.core.eq
|
||||
import org.jetbrains.exposed.v1.core.like
|
||||
import org.jetbrains.exposed.v1.jdbc.transactions.transaction
|
||||
|
||||
class UserSearchCommand : CliktCommand("search") {
|
||||
val query by argument().help("Name, Id, UUID or DiscordId")
|
||||
|
||||
override fun help(context: Context): String = "Search for users"
|
||||
|
||||
override fun run() = transaction {
|
||||
val users = SteamwarUser.find {
|
||||
joinedOr(
|
||||
SteamwarUserTable.username like "%$query%",
|
||||
SteamwarUserTable.uuid like "%$query%",
|
||||
query.toLongOrNull()?.let { SteamwarUserTable.discordId eq it },
|
||||
query.toIntOrNull()?.let { SteamwarUserTable.id eq it }
|
||||
)
|
||||
}
|
||||
|
||||
val teams = mutableMapOf<Int, Team>()
|
||||
|
||||
echo(table {
|
||||
header { row("Id", "Username", "UUID", "Team", "DiscordId") }
|
||||
body {
|
||||
users.map { row(it.id.value, it.username, it.uuid, teams.computeIfAbsent(it.teamId) { _ -> it.team }.name, it.discordId) }
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user