Skip to content

Commit 67fcfb9

Browse files
authored
Merge pull request #75 from the-programmers-hangout/fix/history-embed-order
feat: miscellaneous updates and fixes
2 parents 1b359ff + 743cc96 commit 67fcfb9

File tree

7 files changed

+48
-38
lines changed

7 files changed

+48
-38
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: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,13 @@ fun EmbedBuilder.createInfractionEmbed(guild: Guild, configuration: GuildConfigu
1818

1919
fun EmbedBuilder.createWarnEmbed(guild: Guild, configuration: GuildConfiguration, user: User, guildMember: GuildMember, infraction: Infraction, rule: Rule?) {
2020
title = "Warn"
21-
description = """
22-
| ${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.
23-
| If you think this to be unjustified, please **do not** post about it in a public channel but take it up with **Modmail**.
24-
""".trimMargin()
21+
description = "${user.mention}, you have received a **warning** from **${guild.name}**."
22+
23+
field {
24+
name = "__Reason__"
25+
value = infraction.reason
26+
inline = true
27+
}
2528

2629
if (infraction.ruleNumber != null) {
2730
field {
@@ -30,12 +33,6 @@ fun EmbedBuilder.createWarnEmbed(guild: Guild, configuration: GuildConfiguration
3033
}
3134
}
3235

33-
field {
34-
name = "__Reason__"
35-
value = infraction.reason
36-
inline = true
37-
}
38-
3936
if (configuration.infractionConfiguration.warnPoints > 0) {
4037
field {
4138
name = "__Points__"
@@ -50,6 +47,8 @@ fun EmbedBuilder.createWarnEmbed(guild: Guild, configuration: GuildConfiguration
5047
}
5148
}
5249

50+
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**.")
51+
5352
color = Color.RED
5453
thumbnail {
5554
url = guild.getIconUrl(Image.Format.PNG) ?: ""
@@ -62,10 +61,13 @@ fun EmbedBuilder.createWarnEmbed(guild: Guild, configuration: GuildConfiguration
6261

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

7072
if (infraction.ruleNumber != null) {
7173
field {
@@ -74,12 +76,6 @@ fun EmbedBuilder.createStrikeEmbed(guild: Guild, configuration: GuildConfigurati
7476
}
7577
}
7678

77-
field {
78-
name = "__Reason__"
79-
value = infraction.reason
80-
inline = false
81-
}
82-
8379
field {
8480
name = "__Strike Points__"
8581
value = "${infraction.points}"
@@ -97,6 +93,10 @@ fun EmbedBuilder.createStrikeEmbed(guild: Guild, configuration: GuildConfigurati
9793
value = "${infraction.punishment?.punishment.toString()} ${if (infraction.punishment?.duration != null) "for " + timeToString(infraction.punishment?.duration!!) else "indefinitely"}"
9894
inline = true
9995
}
96+
97+
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**.")
98+
99+
100100
color = Color.RED
101101
thumbnail {
102102
url = guild.getIconUrl(Image.Format.PNG) ?: ""

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ 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[userRecord.infractions.size - 1]
79+
val lastInfraction = userRecord.infractions.maxByOrNull { it.dateTime }!!
80+
8081
addField(
8182
"**__Most Recent Infraction__**",
8283
"Type: **${lastInfraction.type} (${lastInfraction.points})**\n " +
@@ -106,8 +107,8 @@ private suspend fun MenuBuilder.buildInfractionPage(
106107
thumbnail {
107108
url = target.asUser().avatar.url
108109
}
109-
val warnings = userRecord.infractions.filter { it.type == InfractionType.Warn }
110-
val strikes = userRecord.infractions.filter { it.type == InfractionType.Strike }
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 }
111112
val bans = userRecord.infractions.filter { it.punishment?.punishment == PunishmentType.BAN }
112113

113114
addInlineField("Warns", "${warnings.size}")
@@ -154,7 +155,7 @@ private suspend fun MenuBuilder.buildNotesPages(
154155
embedColor: Color,
155156
totalPages: Int
156157
) {
157-
val paginatedNotes = userRecord.notes.chunked(4)
158+
val paginatedNotes = userRecord.notes.sortedBy { it.dateTime }.chunked(4)
158159
if (userRecord.notes.isEmpty()) {
159160
page {
160161
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)