Skip to content

Commit ba0af6a

Browse files
committed
feat: update embeds and infraction flow
Changes: - Updated infraction flow to only send mute embeds if mute isn't part of an infraction. - Updated infraction embeds to make them clearer, by putting the reason first. - Updated history embeds to sort infractions by date, instead of infraction id.
1 parent 9e4f41c commit ba0af6a

File tree

7 files changed

+81
-29
lines changed

7 files changed

+81
-29
lines changed

src/main/kotlin/me/ddivad/judgebot/Main.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ suspend fun main(args: Array<String>) {
5858
field {
5959
name = "Build Info"
6060
value = "```" +
61-
"Version: 1.8.0\n" +
61+
"Version: 1.8.1\n" +
6262
"DiscordKt: ${versions.library}\n" +
6363
"Kotlin: $kotlinVersion" +
6464
"```"

src/main/kotlin/me/ddivad/judgebot/commands/MuteCommands.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ fun createMuteCommands(muteService: MuteService) = commands("Mute") {
2828
this.message.addReaction(Emojis.x)
2929
respond("${targetMember.mention} has DMs disabled and won't receive message.")
3030
}
31-
muteService.applyMute(targetMember, length.roundToLong() * 1000, reason)
31+
muteService.applyMuteAndSendReason(targetMember, length.roundToLong() * 1000, reason)
3232
respond("User ${targetMember.mention} has been muted")
3333
}
3434
}

src/main/kotlin/me/ddivad/judgebot/embeds/InfractionEmbeds.kt

Lines changed: 54 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ fun EmbedBuilder.createInfractionEmbed(guild: Guild, configuration: GuildConfigu
1616
else if (infraction.type == InfractionType.Strike) createStrikeEmbed(guild, configuration, user, guildMember, infraction, rule)
1717
}
1818

19-
fun EmbedBuilder.createWarnEmbed(guild: Guild, configuration: GuildConfiguration, user: User, guildMember: GuildMember, infraction: Infraction, rule: Rule?) {
19+
fun EmbedBuilder.createWarnEmbed1(guild: Guild, configuration: GuildConfiguration, user: User, guildMember: GuildMember, infraction: Infraction, rule: Rule?) {
2020
title = "Warn"
2121
description = "${user.mention}, you have received a **warning** from **${guild.name}**."
2222

2323
field {
2424
name = "__Reason__"
2525
value = infraction.reason
26-
inline = false
2726
}
2827

2928
if (infraction.ruleNumber != null) {
@@ -50,9 +49,9 @@ fun EmbedBuilder.createWarnEmbed(guild: Guild, configuration: GuildConfiguration
5049
field {
5150
name = ""
5251
value = """
53-
A warning is a way for staff to inform you that your behaviour needs to change or further infractions will follow.
54-
If you think this to be unjustified, please **do not** post about it in a public channel but DM **Modmail**.
55-
""".trimIndent()
52+
| A warning is a way for staff to inform you that your behaviour needs to change or further infractions will follow.
53+
| If you think this to be unjustified, please **do not** post about it in a public channel but take it up with **Modmail**.
54+
""".trimMargin()
5655
}
5756

5857
color = Color.RED
@@ -65,12 +64,15 @@ fun EmbedBuilder.createWarnEmbed(guild: Guild, configuration: GuildConfiguration
6564
}
6665
}
6766

68-
fun EmbedBuilder.createStrikeEmbed(guild: Guild, configuration: GuildConfiguration, user: User, guildMember: GuildMember, infraction: Infraction, rule: Rule?) {
69-
title = "Strike"
70-
description = """
71-
| ${user.mention}, you have received a **strike** from **${guild.name}**. A strike is a formal warning for breaking the rules.
72-
| If you think this is unjustified, please **do not** post about it in a public channel but take it up with **Modmail**.
73-
""".trimMargin()
67+
fun EmbedBuilder.createWarnEmbed(guild: Guild, configuration: GuildConfiguration, user: User, guildMember: GuildMember, infraction: Infraction, rule: Rule?) {
68+
title = "Warn"
69+
description = "${user.mention}, you have received a **warning** from **${guild.name}**."
70+
71+
field {
72+
name = "__Reason__"
73+
value = infraction.reason
74+
inline = true
75+
}
7476

7577
if (infraction.ruleNumber != null) {
7678
field {
@@ -79,12 +81,49 @@ fun EmbedBuilder.createStrikeEmbed(guild: Guild, configuration: GuildConfigurati
7981
}
8082
}
8183

84+
if (configuration.infractionConfiguration.warnPoints > 0) {
85+
field {
86+
name = "__Points__"
87+
value = "${infraction.points}"
88+
inline = true
89+
}
90+
91+
field {
92+
name = "__Points Count__"
93+
value = "${guildMember.getPoints(guild)} / ${configuration.infractionConfiguration.pointCeiling}"
94+
inline = true
95+
}
96+
}
97+
98+
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**.")
99+
100+
color = Color.RED
101+
thumbnail {
102+
url = guild.getIconUrl(Image.Format.PNG) ?: ""
103+
}
104+
footer {
105+
icon = guild.getIconUrl(Image.Format.PNG) ?: ""
106+
text = guild.name
107+
}
108+
}
109+
110+
fun EmbedBuilder.createStrikeEmbed(guild: Guild, configuration: GuildConfiguration, user: User, guildMember: GuildMember, infraction: Infraction, rule: Rule?) {
111+
title = "Strike"
112+
description = "${user.mention}, you have received a **strike** from **${guild.name}**."
113+
82114
field {
83115
name = "__Reason__"
84116
value = infraction.reason
85117
inline = false
86118
}
87119

120+
if (infraction.ruleNumber != null) {
121+
field {
122+
name = "__Rule Broken__"
123+
value = "**[${rule?.title}](${rule?.link})** \n${rule?.description}"
124+
}
125+
}
126+
88127
field {
89128
name = "__Strike Points__"
90129
value = "${infraction.points}"
@@ -102,6 +141,10 @@ fun EmbedBuilder.createStrikeEmbed(guild: Guild, configuration: GuildConfigurati
102141
value = "${infraction.punishment?.punishment.toString()} ${if (infraction.punishment?.duration != null) "for " + timeToString(infraction.punishment?.duration!!) else "indefinitely"}"
103142
inline = true
104143
}
144+
145+
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**.")
146+
147+
105148
color = Color.RED
106149
thumbnail {
107150
url = guild.getIconUrl(Image.Format.PNG) ?: ""

src/main/kotlin/me/ddivad/judgebot/embeds/UserEmbeds.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ private suspend fun MenuBuilder.buildOverviewPage(
7676
getStatus(guild, target, databaseService)?.let { addField("Status", it) }
7777

7878
if (userRecord.infractions.size > 0) {
79-
val lastInfraction = userRecord.infractions.sortedByDescending { it.dateTime }[0]
79+
val lastInfraction = userRecord.infractions.maxByOrNull { it.dateTime }!!
8080

8181
addField(
8282
"**__Most Recent Infraction__**",
@@ -107,8 +107,8 @@ private suspend fun MenuBuilder.buildInfractionPage(
107107
thumbnail {
108108
url = target.asUser().avatar.url
109109
}
110-
val warnings = userRecord.infractions.filter { it.type == InfractionType.Warn }.sortedByDescending { it.dateTime }
111-
val strikes = userRecord.infractions.filter { it.type == InfractionType.Strike }.sortedByDescending { it.dateTime }
110+
val warnings = userRecord.infractions.filter { it.type == InfractionType.Warn }.sortedBy { it.dateTime }
111+
val strikes = userRecord.infractions.filter { it.type == InfractionType.Strike }.sortedBy { it.dateTime }
112112
val bans = userRecord.infractions.filter { it.punishment?.punishment == PunishmentType.BAN }
113113

114114
addInlineField("Warns", "${warnings.size}")
@@ -155,7 +155,7 @@ private suspend fun MenuBuilder.buildNotesPages(
155155
embedColor: Color,
156156
totalPages: Int
157157
) {
158-
val paginatedNotes = userRecord.notes.sortedByDescending { it.dateTime }.chunked(4)
158+
val paginatedNotes = userRecord.notes.sortedBy { it.dateTime }.chunked(4)
159159
if (userRecord.notes.isEmpty()) {
160160
page {
161161
color = embedColor

src/main/kotlin/me/ddivad/judgebot/services/infractions/BadPfpService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class BadPfpService(private val muteService: MuteService,
3030
} catch (ex: RequestException) {
3131
loggingService.dmDisabled(guild, target.asUser())
3232
}
33-
muteService.applyMute(target, timeLimit, "Bad Pfp Mute")
33+
muteService.applyMuteAndSendReason(target, timeLimit, "Mute for BadPfp.")
3434
loggingService.badBfpApplied(guild, target)
3535
badPfpTracker[toKey((target))] = GlobalScope.launch {
3636
delay(timeLimit)

src/main/kotlin/me/ddivad/judgebot/services/infractions/InfractionService.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class InfractionService(private val configuration: Configuration,
4444
private suspend fun applyPunishment(guild: Guild, target: Member, infraction: Infraction) {
4545
when (infraction.punishment?.punishment) {
4646
PunishmentType.NONE -> return
47-
PunishmentType.MUTE -> muteService.applyMute(target, infraction.punishment?.duration!!, infraction.reason)
47+
PunishmentType.MUTE -> muteService.applyInfractionMute(target, infraction.punishment?.duration!!, "Infraction mute. Please check corresponding infraction embed above.")
4848
PunishmentType.BAN -> {
4949
val clearTime = infraction.punishment!!.duration?.let { DateTime().millis.plus(it) }
5050
val punishment = Punishment(target.id.value, InfractionType.Ban, infraction.reason, infraction.moderator, clearTime)

src/main/kotlin/me/ddivad/judgebot/services/infractions/MuteService.kt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,24 @@ class MuteService(val configuration: Configuration,
5151
}
5252
}
5353

54-
suspend fun applyMute(member: Member, time: Long, reason: String) {
54+
suspend fun applyInfractionMute(member: Member, time: Long, reason: String) {
55+
applyMute(member, time, reason)
56+
}
57+
58+
suspend fun applyMuteAndSendReason(member: Member, time: Long, reason: String) {
59+
val guild = member.guild.asGuild()
60+
val user = member.asUser()
61+
applyMute(member, time, reason)
62+
try {
63+
member.sendPrivateMessage {
64+
createMuteEmbed(guild, member, reason, time)
65+
}
66+
} catch (ex: RequestException) {
67+
loggingService.dmDisabled(guild, user)
68+
}
69+
}
70+
71+
private suspend fun applyMute(member: Member, time: Long, reason: String) {
5572
val guild = member.guild.asGuild()
5673
val user = member.asUser()
5774
val clearTime = DateTime.now().plus(time).millis
@@ -69,19 +86,12 @@ class MuteService(val configuration: Configuration,
6986
removeMute(guild, user)
7087
}.also {
7188
loggingService.roleApplied(guild, member.asUser(), muteRole)
72-
try {
73-
member.sendPrivateMessage {
74-
createMuteEmbed(guild, member, reason, time)
75-
}
76-
} catch (ex: RequestException) {
77-
loggingService.dmDisabled(guild, user)
78-
}
7989
}
8090
}
8191

8292
suspend fun gag(guild: Guild, target: Member, moderator: User) {
8393
loggingService.gagApplied(guild, target, moderator)
84-
this.applyMute(target, 1000L * 60 * 5, "You've been muted temporarily by staff.")
94+
this.applyMuteAndSendReason(target, 1000L * 60 * 5, "You've been muted temporarily by staff.")
8595
}
8696

8797
fun removeMute(guild: Guild, user: User) {
@@ -158,7 +168,6 @@ class MuteService(val configuration: Configuration,
158168
} catch (ex: RequestException) {
159169
println("No permssions to add overwrite to ${it.id.value} - ${it.name}")
160170
}
161-
162171
}
163172
}
164173
}

0 commit comments

Comments
 (0)