Skip to content

Commit

Permalink
Merge pull request #76 from the-programmers-hangout/develop
Browse files Browse the repository at this point in the history
release: merge develop with master for 1.8.1
  • Loading branch information
ddivad195 authored May 31, 2021
2 parents 5c399ce + 67fcfb9 commit a5a5dd2
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/main/kotlin/me/ddivad/judgebot/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ suspend fun main(args: Array<String>) {
field {
name = "Build Info"
value = "```" +
"Version: 1.8.0\n" +
"Version: 1.8.1\n" +
"DiscordKt: ${versions.library}\n" +
"Kotlin: $kotlinVersion" +
"```"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
40 changes: 20 additions & 20 deletions src/main/kotlin/me/ddivad/judgebot/embeds/InfractionEmbeds.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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__"
Expand All @@ -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) ?: ""
Expand All @@ -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 {
Expand All @@ -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}"
Expand All @@ -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) ?: ""
Expand Down
9 changes: 5 additions & 4 deletions src/main/kotlin/me/ddivad/judgebot/embeds/UserEmbeds.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 " +
Expand Down Expand Up @@ -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}")
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand Down Expand Up @@ -158,7 +168,6 @@ class MuteService(val configuration: Configuration,
} catch (ex: RequestException) {
println("No permssions to add overwrite to ${it.id.value} - ${it.name}")
}

}
}
}
Expand Down

0 comments on commit a5a5dd2

Please sign in to comment.