Skip to content

Commit

Permalink
chore: Did some TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
phinner committed Nov 2, 2023
1 parent be8dfa0 commit a093cbd
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ class PunishmentListener(instances: InstanceManager) : ImperiumApplication.Liste

override fun onImperiumInit() {
messenger.subscribe<PunishmentMessage> { message ->
// TODO Implement pardon notification ?
if (message.type != PunishmentMessage.Type.CREATE) {
return@subscribe
}
val (author, _, id, extra) = message
val punishment = punishments.findById(id)!!
var user = punishment.target.uuid?.let { users.findByUuid(it) }
Expand All @@ -55,17 +51,30 @@ class PunishmentListener(instances: InstanceManager) : ImperiumApplication.Liste
}

val embed =
EmbedBuilder()
.setTimestampToNow()
.setColor(Color.RED)
.setTitle("Punishment `$id`")
.addField("Target", user?.lastName ?: "`<UNKNOWN>`", true)
.addField("Type", punishment.type.toString(), true)
.addField("Duration", punishment.duration?.toString() ?: "`PERMANENT`", true)
.addField("Reason", punishment.reason, false)
if (extra is PunishmentMessage.Extra.Nsfw) {
embed.addField("NSFW Entry ID", extra.entry.toHexString(), false)
}
EmbedBuilder().setTimestampToNow().apply {
when (message.type) {
PunishmentMessage.Type.CREATE -> {
setColor(Color.RED)
setTitle("Punishment `$id`")
addField("Target", user?.lastName ?: "`<UNKNOWN>`", true)
addField("Type", punishment.type.toString(), true)
addField(
"Duration", punishment.duration?.toString() ?: "`PERMANENT`", true)
addField("Reason", punishment.reason, false)
if (extra is PunishmentMessage.Extra.Nsfw) {
addField("NSFW Entry ID", extra.entry.toHexString(), false)
}
}
PunishmentMessage.Type.PARDON -> {
setColor(Color.GREEN)
setTitle("Pardoned `$id`")
addField("Target", user?.lastName ?: "`<UNKNOWN>`", true)
addField("Type", punishment.type.toString(), true)
addField("Reason", punishment.pardon?.reason ?: "`<UNKNOWN>`", false)
}
}
}

when (author) {
is Identity.Discord -> embed.setAuthor(discord.api.getUserById(author.id).await())
is Identity.Mindustry -> embed.setAuthor(author.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ import mindustry.Vars
import mindustry.net.Administration.PlayerInfo
import mindustry.server.ServerControl

// TODO Add permission support
class MindustryCommandRegistry(
plugin: MindustryPlugin,
private val config: ImperiumConfig,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import com.xpdustry.imperium.common.inject.InstanceManager
import com.xpdustry.imperium.common.inject.get
import com.xpdustry.imperium.common.message.Messenger
import com.xpdustry.imperium.common.misc.capitalize
import com.xpdustry.imperium.common.misc.logger
import com.xpdustry.imperium.common.misc.toInetAddress
import com.xpdustry.imperium.common.security.ReportMessage
import com.xpdustry.imperium.common.security.SmoothRateLimiter
Expand All @@ -48,13 +47,10 @@ import kotlin.time.Duration.Companion.seconds
import kotlinx.coroutines.launch
import mindustry.gen.Player

private val logger = logger<ReportCommand>()
private val limiter = SmoothRateLimiter<InetAddress>(1, 60.seconds)

// TODO
// - Implement tile reporting ?
// - Add rate limit warning BEFORE running the command
class ReportCommand(instances: InstanceManager) : ImperiumApplication.Listener {
private val limiter = SmoothRateLimiter<InetAddress>(1, 60.seconds)
private val reportInterface =
createReportInterface(
instances.get<MindustryPlugin>(),
Expand All @@ -65,6 +61,11 @@ class ReportCommand(instances: InstanceManager) : ImperiumApplication.Listener {
@Command(["report"])
@ClientSide
private fun onPlayerReport(sender: CommandSender) {
if (!limiter.incrementAndCheck(sender.player.ip().toInetAddress())) {
sender.player.showInfoMessage(
"[red]You are limited to one report per minute. Please try again later.")
return
}
reportInterface.open(sender.player)
}
}
Expand All @@ -85,11 +86,6 @@ fun createReportInterface(
"Are you sure you want to report [accent]${view.state[REPORT_PLAYER]!!.plainName()}[] for [accent]${view.state[REPORT_REASON]!!.name.lowercase().capitalize()}[]?"
pane.options.addRow(
MenuOption("[green]Yes") { _ ->
if (!limiter.incrementAndCheck(view.viewer.ip().toInetAddress())) {
view.viewer.showInfoMessage(
"[red]You are limited to one report per minute. Please try again later.")
return@MenuOption
}
view.closeAll()
ImperiumScope.MAIN.launch {
val sent =
Expand Down

0 comments on commit a093cbd

Please sign in to comment.