Skip to content

Commit

Permalink
Merge pull request #62 from the-programmers-hangout/develop
Browse files Browse the repository at this point in the history
release: version 1.5.0 release
  • Loading branch information
ddivad195 authored Nov 25, 2020
2 parents b4eabb1 + eef13b2 commit 232ab26
Show file tree
Hide file tree
Showing 16 changed files with 260 additions and 199 deletions.
19 changes: 9 additions & 10 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@
| rules | (Message) | List the rules of this guild. Pass a message ID to edit existing rules embed. |

## User
| Commands | Arguments | Description |
| ------------ | ------------------------------------------- | ---------------------------------------------------------- |
| ban | LowerMemberArg, (Delete message days), Text | Ban a member from this guild. |
| getBanReason | User | Get a ban reason for a banned user |
| history, h | User | Use this to view a user's record. |
| selfHistory | | View your infraction history (contents will be DM'd) |
| setBanReason | User, Text | Set a ban reason for a banned user |
| status, st | User | Use this to view a user's status card. |
| unban | User | Unban a banned member from this guild. |
| whatpfp | User | Perform a reverse image search of a User's profile picture |
| Commands | Arguments | Description |
| ------------ | ----------------------------------------- | ---------------------------------------------------------- |
| ban | LowerUserArg, (Delete message days), Text | Ban a member from this guild. |
| getBanReason | User | Get a ban reason for a banned user |
| history, h | User | Use this to view a user's record. |
| selfHistory | | View your infraction history (contents will be DM'd) |
| setBanReason | User, Text | Set a ban reason for a banned user |
| unban | User | Unban a banned member from this guild. |
| whatpfp | User | Perform a reverse image search of a User's profile picture |

## Utility
| Commands | Arguments | Description |
Expand Down
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.4.1\n" +
"Version: 1.5.0\n" +
"DiscordKt: ${versions.library}\n" +
"Kotlin: $kotlinVersion" +
"```"
Expand Down
30 changes: 30 additions & 0 deletions src/main/kotlin/me/ddivad/judgebot/arguments/LowerUserArg.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package me.ddivad.judgebot.arguments

import com.gitlab.kordlib.core.entity.User
import me.ddivad.judgebot.services.PermissionsService
import me.jakejmattson.discordkt.api.arguments.ArgumentResult
import me.jakejmattson.discordkt.api.arguments.ArgumentType
import me.jakejmattson.discordkt.api.dsl.CommandEvent
import me.jakejmattson.discordkt.api.arguments.Success
import me.jakejmattson.discordkt.api.arguments.Error
import me.jakejmattson.discordkt.api.extensions.toSnowflakeOrNull

open class LowerUserArg(override val name: String = "LowerUserArg") : ArgumentType<User>() {
companion object : LowerUserArg()

override fun generateExamples(event: CommandEvent<*>) = mutableListOf("@User", "197780697866305536", "302134543639511050")

override suspend fun convert(arg: String, args: List<String>, event: CommandEvent<*>): ArgumentResult<User> {
val permissionsService = event.discord.getInjectionObjects(PermissionsService::class)
val guild = event.guild ?: return Error("No guild found")

val user = arg.toSnowflakeOrNull()?.let { guild.kord.getUser(it) } ?: return Error("User Not Found")
val member = guild.getMemberOrNull(user.id) ?: return Success(user)

return when {
event.author.asMember(event.guild!!.id).isHigherRankedThan(permissionsService, member) ->
Error("You don't have the permission to use this command on the target user")
else -> Success(member.asUser())
}
}
}
12 changes: 12 additions & 0 deletions src/main/kotlin/me/ddivad/judgebot/commands/InfoCommands.kt
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package me.ddivad.judgebot.commands

import com.gitlab.kordlib.common.exception.RequestException
import com.gitlab.kordlib.kordx.emoji.Emojis
import com.gitlab.kordlib.kordx.emoji.addReaction
import me.ddivad.judgebot.arguments.LowerMemberArg
import me.ddivad.judgebot.dataclasses.Info
import me.ddivad.judgebot.embeds.createInformationEmbed
import me.ddivad.judgebot.extensions.testDmStatus
import me.ddivad.judgebot.services.DatabaseService
import me.ddivad.judgebot.services.PermissionLevel
import me.ddivad.judgebot.services.requiredPermissionLevel
Expand All @@ -18,6 +22,14 @@ fun createInformationCommands(databaseService: DatabaseService) = commands("Info
requiredPermissionLevel = PermissionLevel.Moderator
execute(LowerMemberArg, EveryArg("Info Content")) {
val (target, content) = args
try {
target.testDmStatus()
this.message.addReaction(Emojis.whiteCheckMark)
} catch (ex: RequestException) {
this.message.addReaction(Emojis.x)
respond("Target user has DM's disabled. Info will not be sent.")
return@execute
}
val user = databaseService.users.getOrCreateUser(target, guild)
val information = Info(content, author.id.value)
databaseService.users.addInfo(guild, user, information)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.ddivad.judgebot.commands

import com.gitlab.kordlib.common.exception.RequestException
import com.gitlab.kordlib.kordx.emoji.Emojis
import com.gitlab.kordlib.kordx.emoji.addReaction
import me.ddivad.judgebot.arguments.LowerMemberArg
import me.ddivad.judgebot.conversations.InfractionConversation
import me.ddivad.judgebot.dataclasses.Configuration
Expand Down Expand Up @@ -34,7 +36,9 @@ fun createInfractionCommands(databaseService: DatabaseService,
}
try {
targetMember.testDmStatus()
this.message.addReaction(Emojis.whiteCheckMark)
} catch (ex: RequestException) {
this.message.addReaction(Emojis.x)
respond("Target user has DM's disabled. Infraction cancelled.")
return@execute
}
Expand All @@ -51,7 +55,9 @@ fun createInfractionCommands(databaseService: DatabaseService,
val (targetMember, reason) = args
try {
targetMember.testDmStatus()
this.message.addReaction(Emojis.whiteCheckMark)
} catch (ex: RequestException) {
this.message.addReaction(Emojis.x)
respond("Target user has DM's disabled. Infraction cancelled.")
return@execute
}
Expand All @@ -68,7 +74,9 @@ fun createInfractionCommands(databaseService: DatabaseService,
val (cancel, targetMember) = args
try {
targetMember.testDmStatus()
this.message.addReaction(Emojis.whiteCheckMark)
} catch (ex: RequestException) {
this.message.addReaction(Emojis.x)
respond("Target user has DM's disabled. Infraction cancelled.")
return@execute
}
Expand Down
13 changes: 5 additions & 8 deletions src/main/kotlin/me/ddivad/judgebot/commands/MuteCommands.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package me.ddivad.judgebot.commands

import com.gitlab.kordlib.common.exception.RequestException
import com.gitlab.kordlib.kordx.emoji.Emojis
import com.gitlab.kordlib.kordx.emoji.addReaction
import me.ddivad.judgebot.arguments.LowerMemberArg
import me.ddivad.judgebot.extensions.testDmStatus
import me.ddivad.judgebot.services.*
Expand All @@ -21,9 +23,10 @@ fun createMuteCommands(muteService: MuteService) = commands("Mute") {
val (targetMember, length, reason) = args
try {
targetMember.testDmStatus()
this.message.addReaction(Emojis.whiteCheckMark)
} catch (ex: RequestException) {
respond("Unable to contact the target user. Infraction cancelled.")
return@execute
this.message.addReaction(Emojis.x)
respond("User has DM's disabled and won't receive message.")
}
muteService.applyMute(targetMember, length.roundToLong() * 1000, reason)
respond("User ${targetMember.mention} has been muted")
Expand All @@ -50,12 +53,6 @@ fun createMuteCommands(muteService: MuteService) = commands("Mute") {
requiredPermissionLevel = PermissionLevel.Moderator
execute(LowerMemberArg) {
val targetMember = args.first
try {
targetMember.testDmStatus()
} catch (ex: RequestException) {
respond("Unable to contact the target user. Infraction cancelled.")
return@execute
}
if (muteService.checkRoleState(guild, targetMember) == RoleState.Tracked) {
respond("User ${targetMember.mention} is already muted")
return@execute
Expand Down
20 changes: 5 additions & 15 deletions src/main/kotlin/me/ddivad/judgebot/commands/UserCommands.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package me.ddivad.judgebot.commands

import me.ddivad.judgebot.arguments.LowerMemberArg
import me.ddivad.judgebot.arguments.LowerUserArg
import me.ddivad.judgebot.dataclasses.*
import me.ddivad.judgebot.embeds.createHistoryEmbed
import me.ddivad.judgebot.embeds.createSelfHistoryEmbed
import me.ddivad.judgebot.embeds.createStatusEmbed
import me.ddivad.judgebot.services.DatabaseService
import me.ddivad.judgebot.services.LoggingService
import me.ddivad.judgebot.services.PermissionLevel
import me.ddivad.judgebot.services.infractions.BanService
import me.ddivad.judgebot.services.requiredPermissionLevel
import me.jakejmattson.discordkt.api.arguments.EitherArg
import me.jakejmattson.discordkt.api.arguments.EveryArg
import me.jakejmattson.discordkt.api.arguments.IntegerArg
import me.jakejmattson.discordkt.api.arguments.UserArg
Expand All @@ -34,16 +35,6 @@ fun createUserCommands(databaseService: DatabaseService,
}
}

guildCommand("status", "st") {
description = "Use this to view a user's status card."
requiredPermissionLevel = PermissionLevel.Moderator
execute(UserArg) {
val user = databaseService.users.getOrCreateUser(args.first, guild)
databaseService.users.incrementUserHistory(user, guild)
createStatusEmbed(args.first, user, guild, config)
}
}

guildCommand("whatpfp") {
description = "Perform a reverse image search of a User's profile picture"
requiredPermissionLevel = PermissionLevel.Moderator
Expand All @@ -62,11 +53,11 @@ fun createUserCommands(databaseService: DatabaseService,
guildCommand("ban") {
description = "Ban a member from this guild."
requiredPermissionLevel = PermissionLevel.Staff
execute(LowerMemberArg, IntegerArg("Delete message days").makeOptional(1), EveryArg) {
execute(LowerUserArg, IntegerArg("Delete message days").makeOptional(1), EveryArg) {
val (target, deleteDays, reason) = args
val ban = Punishment(target.id.value, InfractionType.Ban , reason, author.id.value)
banService.banUser(target, guild, ban, deleteDays).also {
loggingService.userBanned(guild, target.asUser(), ban)
loggingService.userBanned(guild, target, ban)
respond("User ${target.mention} banned")
}
}
Expand Down Expand Up @@ -110,8 +101,7 @@ fun createUserCommands(databaseService: DatabaseService,
execute(UserArg) {
val user = args.first
guild.getBanOrNull(user.id)?.let {
val reason = databaseService.guilds.getBanOrNull(guild, user.id.value)?.reason
?: guild.getBan(args.first.id).reason
val reason = databaseService.guilds.getBanOrNull(guild, user.id.value)?.reason ?: it.reason
respond(reason ?: "No reason logged")
return@execute
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ data class Configuration(
newConfiguration.punishments.add(PunishmentLevel(10, PunishmentType.MUTE, 1000L * 60 * 60 * 1))
newConfiguration.punishments.add(PunishmentLevel(20, PunishmentType.MUTE, 1000L * 60 * 60 * 12))
newConfiguration.punishments.add(PunishmentLevel(30, PunishmentType.MUTE, 1000L * 60 * 60 * 24))
newConfiguration.punishments.add(PunishmentLevel(40, PunishmentType.BAN, 1000L * 60 * 60 * 24 * 30))
newConfiguration.punishments.add(PunishmentLevel(40, PunishmentType.MUTE, 1000L * 60 * 60 * 24 * 30))
newConfiguration.punishments.add(PunishmentLevel(50, PunishmentType.BAN))

guildConfigurations[guild.id.longValue] = newConfiguration
Expand Down
22 changes: 8 additions & 14 deletions src/main/kotlin/me/ddivad/judgebot/dataclasses/GuildInformation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ data class GuildInformation(
val bans: MutableList<Ban> = mutableListOf(),
val punishments: MutableList<Punishment> = mutableListOf()
) {
fun addRule(rule: Rule): GuildInformation {
this.rules.add(rule).let { this }
return this
fun addRule(rule: Rule): GuildInformation = this.apply {
this.rules.add(rule)
}

fun archiveRule(ruleNumber: Int): GuildInformation {
this.rules.find { it.number == ruleNumber }!!.archived = true
return this
fun archiveRule(ruleNumber: Int): GuildInformation = this.apply {
this.rules.find { it.number == ruleNumber }?.archived = true
}

fun editRule(oldRule: Rule, updatedRule: Rule): Rule {
Expand All @@ -23,17 +21,15 @@ data class GuildInformation(
return updatedRule
}

fun addPunishment(punishment: Punishment): GuildInformation {
fun addPunishment(punishment: Punishment): GuildInformation = this.apply {
val nextId: Int = if (this.punishments.isEmpty()) 1 else this.punishments.maxByOrNull { it.id }!!.id + 1
punishment.id = nextId
this.punishments.add(punishment)
return this
}

fun removePunishment(userId: String, type: InfractionType): GuildInformation {
fun removePunishment(userId: String, type: InfractionType): GuildInformation = this.apply {
val punishment = this.getPunishmentByType(type, userId).first()
this.punishments.remove(punishment)
return this
}

fun getPunishmentByType(type: InfractionType, userId: String): List<Punishment> {
Expand All @@ -48,15 +44,13 @@ data class GuildInformation(
return this.bans.any { it.userId == userId }
}

fun addBan(ban: Ban): GuildInformation {
fun addBan(ban: Ban): GuildInformation = this.apply {
this.bans.add(ban)
return this
}

fun removeBan(userId: String): GuildInformation {
fun removeBan(userId: String): GuildInformation = this.apply {
val ban = this.bans.find { it.userId == userId }
this.bans.remove(ban)
return this
}
}

Expand Down
Loading

0 comments on commit 232ab26

Please sign in to comment.