diff --git a/src/main/kotlin/me/ddivad/judgebot/Main.kt b/src/main/kotlin/me/ddivad/judgebot/Main.kt index 1485070..ed4acf0 100644 --- a/src/main/kotlin/me/ddivad/judgebot/Main.kt +++ b/src/main/kotlin/me/ddivad/judgebot/Main.kt @@ -58,7 +58,7 @@ suspend fun main(args: Array) { field { name = "Build Info" value = "```" + - "Version: 1.8.0\n" + + "Version: 1.8.1\n" + "DiscordKt: ${versions.library}\n" + "Kotlin: $kotlinVersion" + "```" diff --git a/src/main/kotlin/me/ddivad/judgebot/commands/MuteCommands.kt b/src/main/kotlin/me/ddivad/judgebot/commands/MuteCommands.kt index ed741bf..6a45dd9 100644 --- a/src/main/kotlin/me/ddivad/judgebot/commands/MuteCommands.kt +++ b/src/main/kotlin/me/ddivad/judgebot/commands/MuteCommands.kt @@ -28,7 +28,7 @@ fun createMuteCommands(muteService: MuteService) = commands("Mute") { this.message.addReaction(Emojis.x) respond("${targetMember.mention} has DMs disabled and won't receive message.") } - muteService.applyMute(targetMember, length.roundToLong() * 1000, reason) + muteService.applyMuteAndSendReason(targetMember, length.roundToLong() * 1000, reason) respond("User ${targetMember.mention} has been muted") } } diff --git a/src/main/kotlin/me/ddivad/judgebot/embeds/InfractionEmbeds.kt b/src/main/kotlin/me/ddivad/judgebot/embeds/InfractionEmbeds.kt index 6ae111e..8cd4990 100644 --- a/src/main/kotlin/me/ddivad/judgebot/embeds/InfractionEmbeds.kt +++ b/src/main/kotlin/me/ddivad/judgebot/embeds/InfractionEmbeds.kt @@ -18,10 +18,13 @@ fun EmbedBuilder.createInfractionEmbed(guild: Guild, configuration: GuildConfigu fun EmbedBuilder.createWarnEmbed(guild: Guild, configuration: GuildConfiguration, user: User, guildMember: GuildMember, infraction: Infraction, rule: Rule?) { title = "Warn" - description = """ - | ${user.mention}, you have received a **warning** from **${guild.name}**. A warning is a way for staff to inform you that your behaviour needs to change or further infractions will follow. - | If you think this to be unjustified, please **do not** post about it in a public channel but take it up with **Modmail**. - """.trimMargin() + description = "${user.mention}, you have received a **warning** from **${guild.name}**." + + field { + name = "__Reason__" + value = infraction.reason + inline = true + } if (infraction.ruleNumber != null) { field { @@ -30,12 +33,6 @@ fun EmbedBuilder.createWarnEmbed(guild: Guild, configuration: GuildConfiguration } } - field { - name = "__Reason__" - value = infraction.reason - inline = true - } - if (configuration.infractionConfiguration.warnPoints > 0) { field { name = "__Points__" @@ -50,6 +47,8 @@ fun EmbedBuilder.createWarnEmbed(guild: Guild, configuration: GuildConfiguration } } + addField("", "A warning is a way for staff to inform you that your behaviour needs to change or further infractions will follow. \nIf you think this to be unjustified, please **do not** post about it in a public channel but take it up with **Modmail**.") + color = Color.RED thumbnail { url = guild.getIconUrl(Image.Format.PNG) ?: "" @@ -62,10 +61,13 @@ fun EmbedBuilder.createWarnEmbed(guild: Guild, configuration: GuildConfiguration fun EmbedBuilder.createStrikeEmbed(guild: Guild, configuration: GuildConfiguration, user: User, guildMember: GuildMember, infraction: Infraction, rule: Rule?) { title = "Strike" - description = """ - | ${user.mention}, you have received a **strike** from **${guild.name}**. A strike is a formal warning for breaking the rules. - | If you think this is unjustified, please **do not** post about it in a public channel but take it up with **Modmail**. - """.trimMargin() + description = "${user.mention}, you have received a **strike** from **${guild.name}**." + + field { + name = "__Reason__" + value = infraction.reason + inline = false + } if (infraction.ruleNumber != null) { field { @@ -74,12 +76,6 @@ fun EmbedBuilder.createStrikeEmbed(guild: Guild, configuration: GuildConfigurati } } - field { - name = "__Reason__" - value = infraction.reason - inline = false - } - field { name = "__Strike Points__" value = "${infraction.points}" @@ -97,6 +93,10 @@ fun EmbedBuilder.createStrikeEmbed(guild: Guild, configuration: GuildConfigurati value = "${infraction.punishment?.punishment.toString()} ${if (infraction.punishment?.duration != null) "for " + timeToString(infraction.punishment?.duration!!) else "indefinitely"}" inline = true } + + addField("", " A strike is a formal warning for breaking the rules.\nIf you think this to be unjustified, please **do not** post about it in a public channel but take it up with **Modmail**.") + + color = Color.RED thumbnail { url = guild.getIconUrl(Image.Format.PNG) ?: "" diff --git a/src/main/kotlin/me/ddivad/judgebot/embeds/UserEmbeds.kt b/src/main/kotlin/me/ddivad/judgebot/embeds/UserEmbeds.kt index 938cff4..4eb1d1f 100644 --- a/src/main/kotlin/me/ddivad/judgebot/embeds/UserEmbeds.kt +++ b/src/main/kotlin/me/ddivad/judgebot/embeds/UserEmbeds.kt @@ -76,7 +76,8 @@ private suspend fun MenuBuilder.buildOverviewPage( getStatus(guild, target, databaseService)?.let { addField("Status", it) } if (userRecord.infractions.size > 0) { - val lastInfraction = userRecord.infractions[userRecord.infractions.size - 1] + val lastInfraction = userRecord.infractions.maxByOrNull { it.dateTime }!! + addField( "**__Most Recent Infraction__**", "Type: **${lastInfraction.type} (${lastInfraction.points})**\n " + @@ -106,8 +107,8 @@ private suspend fun MenuBuilder.buildInfractionPage( thumbnail { url = target.asUser().avatar.url } - val warnings = userRecord.infractions.filter { it.type == InfractionType.Warn } - val strikes = userRecord.infractions.filter { it.type == InfractionType.Strike } + val warnings = userRecord.infractions.filter { it.type == InfractionType.Warn }.sortedBy { it.dateTime } + val strikes = userRecord.infractions.filter { it.type == InfractionType.Strike }.sortedBy { it.dateTime } val bans = userRecord.infractions.filter { it.punishment?.punishment == PunishmentType.BAN } addInlineField("Warns", "${warnings.size}") @@ -154,7 +155,7 @@ private suspend fun MenuBuilder.buildNotesPages( embedColor: Color, totalPages: Int ) { - val paginatedNotes = userRecord.notes.chunked(4) + val paginatedNotes = userRecord.notes.sortedBy { it.dateTime }.chunked(4) if (userRecord.notes.isEmpty()) { page { color = embedColor diff --git a/src/main/kotlin/me/ddivad/judgebot/services/infractions/BadPfpService.kt b/src/main/kotlin/me/ddivad/judgebot/services/infractions/BadPfpService.kt index 8ee5e31..4b14820 100644 --- a/src/main/kotlin/me/ddivad/judgebot/services/infractions/BadPfpService.kt +++ b/src/main/kotlin/me/ddivad/judgebot/services/infractions/BadPfpService.kt @@ -30,7 +30,7 @@ class BadPfpService(private val muteService: MuteService, } catch (ex: RequestException) { loggingService.dmDisabled(guild, target.asUser()) } - muteService.applyMute(target, timeLimit, "Bad Pfp Mute") + muteService.applyMuteAndSendReason(target, timeLimit, "Mute for BadPfp.") loggingService.badBfpApplied(guild, target) badPfpTracker[toKey((target))] = GlobalScope.launch { delay(timeLimit) diff --git a/src/main/kotlin/me/ddivad/judgebot/services/infractions/InfractionService.kt b/src/main/kotlin/me/ddivad/judgebot/services/infractions/InfractionService.kt index da3d99a..6216665 100644 --- a/src/main/kotlin/me/ddivad/judgebot/services/infractions/InfractionService.kt +++ b/src/main/kotlin/me/ddivad/judgebot/services/infractions/InfractionService.kt @@ -44,7 +44,7 @@ class InfractionService(private val configuration: Configuration, private suspend fun applyPunishment(guild: Guild, target: Member, infraction: Infraction) { when (infraction.punishment?.punishment) { PunishmentType.NONE -> return - PunishmentType.MUTE -> muteService.applyMute(target, infraction.punishment?.duration!!, infraction.reason) + PunishmentType.MUTE -> muteService.applyInfractionMute(target, infraction.punishment?.duration!!, "Infraction mute. Please check corresponding infraction embed above.") PunishmentType.BAN -> { val clearTime = infraction.punishment!!.duration?.let { DateTime().millis.plus(it) } val punishment = Punishment(target.id.value, InfractionType.Ban, infraction.reason, infraction.moderator, clearTime) diff --git a/src/main/kotlin/me/ddivad/judgebot/services/infractions/MuteService.kt b/src/main/kotlin/me/ddivad/judgebot/services/infractions/MuteService.kt index adc15e5..6dc5cf1 100644 --- a/src/main/kotlin/me/ddivad/judgebot/services/infractions/MuteService.kt +++ b/src/main/kotlin/me/ddivad/judgebot/services/infractions/MuteService.kt @@ -51,7 +51,24 @@ class MuteService(val configuration: Configuration, } } - suspend fun applyMute(member: Member, time: Long, reason: String) { + suspend fun applyInfractionMute(member: Member, time: Long, reason: String) { + applyMute(member, time, reason) + } + + suspend fun applyMuteAndSendReason(member: Member, time: Long, reason: String) { + val guild = member.guild.asGuild() + val user = member.asUser() + applyMute(member, time, reason) + try { + member.sendPrivateMessage { + createMuteEmbed(guild, member, reason, time) + } + } catch (ex: RequestException) { + loggingService.dmDisabled(guild, user) + } + } + + private suspend fun applyMute(member: Member, time: Long, reason: String) { val guild = member.guild.asGuild() val user = member.asUser() val clearTime = DateTime.now().plus(time).millis @@ -69,19 +86,12 @@ class MuteService(val configuration: Configuration, removeMute(guild, user) }.also { loggingService.roleApplied(guild, member.asUser(), muteRole) - try { - member.sendPrivateMessage { - createMuteEmbed(guild, member, reason, time) - } - } catch (ex: RequestException) { - loggingService.dmDisabled(guild, user) - } } } suspend fun gag(guild: Guild, target: Member, moderator: User) { loggingService.gagApplied(guild, target, moderator) - this.applyMute(target, 1000L * 60 * 5, "You've been muted temporarily by staff.") + this.applyMuteAndSendReason(target, 1000L * 60 * 5, "You've been muted temporarily by staff.") } fun removeMute(guild: Guild, user: User) { @@ -158,7 +168,6 @@ class MuteService(val configuration: Configuration, } catch (ex: RequestException) { println("No permssions to add overwrite to ${it.id.value} - ${it.name}") } - } } }