Add SteamWar CLI module

- add Clikt-based `sw` entrypoint and subcommands
- include database, user, dev, and profiler commands
- wire CLI build and CI install/release steps
This commit is contained in:
2026-05-09 16:46:59 +02:00
parent 8ade5180cb
commit 1451750bcb
15 changed files with 581 additions and 0 deletions
+9
View File
@@ -0,0 +1,9 @@
package de.steamwar.commands.user
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.Context
class UserCommand: CliktCommand("user") {
override fun run() = Unit
override fun help(context: Context): String = "User related commands"
}
+65
View File
@@ -0,0 +1,65 @@
package de.steamwar.commands.user
import com.github.ajalt.clikt.core.CliktCommand
import com.github.ajalt.clikt.core.CliktError
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.useDb
import de.steamwar.sql.Punishment
import de.steamwar.sql.SessionTable
import de.steamwar.sql.SteamwarUser
import de.steamwar.sql.Team
import org.jetbrains.exposed.v1.core.eq
import org.jetbrains.exposed.v1.jdbc.selectAll
import java.time.Duration
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") }
override val printHelpOnEmptyArgs = true
override fun run() = useDb {
val sessions =
SessionTable.selectAll().where { SessionTable.userId eq user.id.value }
.map { it[SessionTable.startTime] to it[SessionTable.endTime] }
val totalPlayed = sessions.sumOf { Duration.between(it.first, it.second).toMinutes() } / 60.0
val firstJoin = sessions.minByOrNull { it.first }?.first
val lastJoin = sessions.maxByOrNull { it.second }?.second
val punishments = Punishment.getAllPunishmentsOfPlayer(user.id.value)
echo(
table {
body {
row("Name", user.userName)
row("UUID", user.uuid)
row("Team", Team.byId(user.team).teamName)
row("Leader", user.leader)
row("Locale", user.locale)
row("Beigetreten am", firstJoin)
row("Zuletzt gesehen am", lastJoin)
row("Spielzeit", totalPlayed.toString() + "h")
row("Punishments", if (punishments.isEmpty()) "Keine" else table {
header { row("Typ", "Ersteller", "Von", "Bis", "Grund") }
body {
punishments.map {
row(
it.type,
SteamwarUser.byId(it.punisher)?.userName ?: it.punisher,
it.startTime.toString(),
if (it.perma) "Perma" else it.endTime.toString(),
it.reason
)
}
}
})
}
}
)
}
}
@@ -0,0 +1,42 @@
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.useDb
import de.steamwar.sql.SteamwarUser
import de.steamwar.sql.SteamwarUserTable
import de.steamwar.sql.Team
import org.jetbrains.exposed.v1.core.eq
import org.jetbrains.exposed.v1.core.like
class UserSearchCommand : CliktCommand("search") {
val query by argument().help("Name, Id, UUID or DiscordId")
override val printHelpOnEmptyArgs = true
override fun help(context: Context): String = "Search for users"
override fun run() = useDb {
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.team) { teamId -> Team.byId(teamId) }.teamName, it.discordId) }
}
})
}
}