Skip to content

Commit

Permalink
Merge pull request #130 from the-programmers-hangout/develop
Browse files Browse the repository at this point in the history
release: merge develop with master for v2.7.0
  • Loading branch information
ddivad195 authored Jan 6, 2022
2 parents af278e0 + b6ad47a commit e1bb224
Show file tree
Hide file tree
Showing 50 changed files with 303 additions and 272 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ version = Versions.BOT
description = "judgebot"

plugins {
kotlin("jvm") version "1.5.10"
kotlin("jvm") version "1.6.0"
kotlin("plugin.serialization") version "1.6.0"
id("com.github.johnrengelman.shadow") version "7.0.0"
}

Expand Down
17 changes: 8 additions & 9 deletions src/main/kotlin/me/ddivad/judgebot/Main.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.ddivad.judgebot

import dev.kord.common.annotation.KordPreview
import dev.kord.common.kColor
import dev.kord.core.supplier.EntitySupplyStrategy
import dev.kord.gateway.Intent
import dev.kord.gateway.Intents
Expand All @@ -11,8 +10,9 @@ import me.ddivad.judgebot.dataclasses.Permissions
import me.ddivad.judgebot.services.*
import me.ddivad.judgebot.services.infractions.BanService
import me.ddivad.judgebot.services.infractions.MuteService
import me.jakejmattson.discordkt.api.dsl.bot
import me.jakejmattson.discordkt.api.extensions.addInlineField
import me.jakejmattson.discordkt.dsl.bot
import me.jakejmattson.discordkt.extensions.addInlineField
import me.jakejmattson.discordkt.extensions.pfpUrl
import java.awt.Color

@KordPreview
Expand All @@ -24,8 +24,9 @@ suspend fun main() {
require(token != null) { "Expected the bot token as an environment variable" }

bot(token) {
val configuration = data("config/config.json") { Configuration() }

prefix {
val configuration = discord.getInjectionObjects(Configuration::class)
guild?.let { configuration[guild!!.id.value]?.prefix } ?: defaultPrefix
}

Expand All @@ -49,11 +50,9 @@ suspend fun main() {
val botStats = it.discord.getInjectionObjects(BotStatsService::class)
val channel = it.channel
val self = channel.kord.getSelf()

color = it.discord.configuration.theme?.kColor

color = it.discord.configuration.theme
thumbnail {
url = self.avatar.url
url = self.pfpUrl
}

field {
Expand All @@ -70,7 +69,7 @@ suspend fun main() {
field {
name = "Build Info"
value = "```" +
"Version: 2.6.0\n" +
"Version: 2.7.0\n" +
"DiscordKt: ${versions.library}\n" +
"Kord: ${versions.kord}\n" +
"Kotlin: $kotlinVersion" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package me.ddivad.judgebot.arguments

import me.jakejmattson.discordkt.api.arguments.*
import me.jakejmattson.discordkt.api.commands.CommandEvent
import me.jakejmattson.discordkt.arguments.*
import me.jakejmattson.discordkt.commands.CommandEvent

val validConfigParameters = mutableListOf(
"setPrefix",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package me.ddivad.judgebot.arguments

import dev.kord.core.entity.Member
import me.jakejmattson.discordkt.api.arguments.*
import me.jakejmattson.discordkt.api.commands.CommandEvent
import me.jakejmattson.discordkt.api.extensions.isSelf
import me.jakejmattson.discordkt.api.extensions.toSnowflakeOrNull
import me.jakejmattson.discordkt.arguments.*
import me.jakejmattson.discordkt.commands.CommandEvent
import me.jakejmattson.discordkt.extensions.isSelf
import me.jakejmattson.discordkt.extensions.toSnowflakeOrNull

open class LowerMemberArg(override val name: String = "LowerMemberArg") : Argument<Member> {
companion object : LowerMemberArg()
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/me/ddivad/judgebot/arguments/LowerUserArg.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package me.ddivad.judgebot.arguments

import dev.kord.core.entity.User
import me.jakejmattson.discordkt.api.arguments.*
import me.jakejmattson.discordkt.api.commands.CommandEvent
import me.jakejmattson.discordkt.api.extensions.isSelf
import me.jakejmattson.discordkt.api.extensions.toSnowflakeOrNull
import me.jakejmattson.discordkt.arguments.*
import me.jakejmattson.discordkt.commands.CommandEvent
import me.jakejmattson.discordkt.extensions.isSelf
import me.jakejmattson.discordkt.extensions.toSnowflakeOrNull

open class LowerUserArg(override val name: String = "LowerUserArg") : Argument<User> {
companion object : LowerUserArg()
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/me/ddivad/judgebot/arguments/RuleArg.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package me.ddivad.judgebot.arguments
import dev.kord.core.entity.Guild
import me.ddivad.judgebot.dataclasses.Rule
import me.ddivad.judgebot.services.DatabaseService
import me.jakejmattson.discordkt.api.arguments.*
import me.jakejmattson.discordkt.api.commands.CommandEvent
import me.jakejmattson.discordkt.arguments.*
import me.jakejmattson.discordkt.commands.CommandEvent

open class RuleArg(override val name: String = "Rule") : Argument<Rule> {
override val description = "A rule number"
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/me/ddivad/judgebot/commands/GuildCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import me.ddivad.judgebot.dataclasses.Permissions
import me.ddivad.judgebot.embeds.createActivePunishmentsEmbed
import me.ddivad.judgebot.services.DatabaseService
import me.ddivad.judgebot.services.infractions.MuteService
import me.jakejmattson.discordkt.api.commands.commands
import me.jakejmattson.discordkt.commands.commands

@Suppress("unused")
fun guildConfigCommands(configuration: Configuration,
databaseService: DatabaseService,
muteService: MuteService) = commands("Guild") {
guildCommand("setup") {
command("setup") {
description = "Configure a guild to use Judgebot."
requiredPermission = Permissions.ADMINISTRATOR
execute {
Expand All @@ -30,7 +30,7 @@ fun guildConfigCommands(configuration: Configuration,
}
}

guildCommand("configuration") {
command("configuration") {
description = "Update configuration parameters for this guild (conversation)."
requiredPermission = Permissions.STAFF
execute(GuildConfigArg.optional("options")) {
Expand All @@ -44,7 +44,7 @@ fun guildConfigCommands(configuration: Configuration,
}
}

guildCommand("activePunishments") {
command("activePunishments") {
description = "View active punishments for a guild."
requiredPermission = Permissions.STAFF
execute {
Expand Down
16 changes: 8 additions & 8 deletions src/main/kotlin/me/ddivad/judgebot/commands/InfoCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import me.ddivad.judgebot.dataclasses.Permissions
import me.ddivad.judgebot.embeds.createInformationEmbed
import me.ddivad.judgebot.extensions.testDmStatus
import me.ddivad.judgebot.services.DatabaseService
import me.jakejmattson.discordkt.api.arguments.EveryArg
import me.jakejmattson.discordkt.api.arguments.IntegerArg
import me.jakejmattson.discordkt.api.commands.commands
import me.jakejmattson.discordkt.api.extensions.sendPrivateMessage
import me.jakejmattson.discordkt.arguments.EveryArg
import me.jakejmattson.discordkt.arguments.IntegerArg
import me.jakejmattson.discordkt.commands.commands
import me.jakejmattson.discordkt.extensions.sendPrivateMessage

@Suppress("unused")
fun createInformationCommands(databaseService: DatabaseService) = commands("Information") {
guildCommand("info") {
command("info") {
description = "Send an information message to a guild member"
requiredPermission = Permissions.MODERATOR
execute(LowerMemberArg, EveryArg("Info Content")) {
Expand All @@ -30,7 +30,7 @@ fun createInformationCommands(databaseService: DatabaseService) = commands("Info
return@execute
}
val user = databaseService.users.getOrCreateUser(target, guild)
val information = Info(content, author.id.asString)
val information = Info(content, author.id.toString())
databaseService.users.addInfo(guild, user, information)
target.sendPrivateMessage {
createInformationEmbed(guild, target, information)
Expand All @@ -39,13 +39,13 @@ fun createInformationCommands(databaseService: DatabaseService) = commands("Info
}
}

guildCommand("removeInfo") {
command("removeInfo") {
description = "Remove an information message from a member record."
requiredPermission = Permissions.STAFF
execute(LowerMemberArg, IntegerArg("Info ID")) {
val (target, id) = args
val user = databaseService.users.getOrCreateUser(target, guild)
if (user.getGuildInfo(guild.id.asString).info.isEmpty()) {
if (user.getGuildInfo(guild.id.toString()).info.isEmpty()) {
respond("${target.mention} has no information records.")
return@execute
}
Expand Down
28 changes: 14 additions & 14 deletions src/main/kotlin/me/ddivad/judgebot/commands/InfractionCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ import me.ddivad.judgebot.services.*
import me.ddivad.judgebot.services.infractions.BadPfpService
import me.ddivad.judgebot.services.infractions.BadnameService
import me.ddivad.judgebot.services.infractions.InfractionService
import me.jakejmattson.discordkt.api.arguments.BooleanArg
import me.jakejmattson.discordkt.api.arguments.EveryArg
import me.jakejmattson.discordkt.api.arguments.IntegerArg
import me.jakejmattson.discordkt.api.commands.commands
import me.jakejmattson.discordkt.api.conversations.ConversationResult
import me.jakejmattson.discordkt.arguments.BooleanArg
import me.jakejmattson.discordkt.arguments.EveryArg
import me.jakejmattson.discordkt.arguments.IntegerArg
import me.jakejmattson.discordkt.commands.commands
import me.jakejmattson.discordkt.conversations.ConversationResult

@KordPreview
@Suppress("unused")
Expand All @@ -30,7 +30,7 @@ fun createInfractionCommands(databaseService: DatabaseService,
infractionService: InfractionService,
badPfpService: BadPfpService,
badnameService: BadnameService) = commands("Infraction") {
guildCommand("strike", "s", "S") {
command("strike", "s", "S") {
description = "Strike a user."
requiredPermission = Permissions.STAFF
execute(LowerMemberArg, IntegerArg("Weight").optional(1), EveryArg("Reason")) {
Expand Down Expand Up @@ -59,7 +59,7 @@ fun createInfractionCommands(databaseService: DatabaseService,
}
}

guildCommand("warn", "w", "W") {
command("warn", "w", "W") {
description = "Warn a user."
requiredPermission = Permissions.MODERATOR
execute(LowerMemberArg, EveryArg("Reason")) {
Expand All @@ -77,7 +77,7 @@ fun createInfractionCommands(databaseService: DatabaseService,
}
}

guildCommand("badpfp") {
command("badpfp") {
description = "Notifies the user that they should change their profile pic and applies a 30 minute mute. Bans the user if they don't change picture."
requiredPermission = Permissions.STAFF
execute(BooleanArg("cancel", "apply", "cancel").optional(true), LowerMemberArg) {
Expand All @@ -102,13 +102,13 @@ fun createInfractionCommands(databaseService: DatabaseService,
return@execute
}

val badPfp = Infraction(author.id.asString, "BadPfp", InfractionType.BadPfp)
val badPfp = Infraction(author.id.toString(), "BadPfp", InfractionType.BadPfp)
badPfpService.applyBadPfp(targetMember, guild, timeLimit)
respond("${targetMember.mention} has been muted and a badpfp has been triggered with a time limit of $minutesUntilBan minutes.")
}
}

guildCommand("badname") {
command("badname") {
description = "Rename a guild member that has a bad name."
requiredPermission = Permissions.MODERATOR
execute(LowerMemberArg) {
Expand All @@ -117,12 +117,12 @@ fun createInfractionCommands(databaseService: DatabaseService,
}
}

guildCommand("cleanseInfractions") {
command("cleanseInfractions") {
description = "Use this to delete (permanently) as user's infractions."
requiredPermission = Permissions.ADMINISTRATOR
execute(LowerUserArg) {
val user = databaseService.users.getOrCreateUser(args.first, guild)
if (user.getGuildInfo(guild.id.asString).infractions.isEmpty()) {
if (user.getGuildInfo(guild.id.toString()).infractions.isEmpty()) {
respond("User has no infractions.")
return@execute
}
Expand All @@ -131,12 +131,12 @@ fun createInfractionCommands(databaseService: DatabaseService,
}
}

guildCommand("removeInfraction") {
command("removeInfraction") {
description = "Use this to delete (permanently) an infraction from a user."
requiredPermission = Permissions.ADMINISTRATOR
execute(LowerUserArg, IntegerArg("Infraction ID")) {
val user = databaseService.users.getOrCreateUser(args.first, guild)
if (user.getGuildInfo(guild.id.asString).infractions.isEmpty()) {
if (user.getGuildInfo(guild.id.toString()).infractions.isEmpty()) {
respond("User has no infractions.")
return@execute
}
Expand Down
14 changes: 7 additions & 7 deletions src/main/kotlin/me/ddivad/judgebot/commands/MuteCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import me.ddivad.judgebot.extensions.testDmStatus
import me.ddivad.judgebot.services.infractions.MuteService
import me.ddivad.judgebot.services.infractions.RoleState
import me.ddivad.judgebot.util.timeToString
import me.jakejmattson.discordkt.api.arguments.EveryArg
import me.jakejmattson.discordkt.api.arguments.TimeArg
import me.jakejmattson.discordkt.api.arguments.UserArg
import me.jakejmattson.discordkt.api.commands.commands
import me.jakejmattson.discordkt.arguments.EveryArg
import me.jakejmattson.discordkt.arguments.TimeArg
import me.jakejmattson.discordkt.arguments.UserArg
import me.jakejmattson.discordkt.commands.commands
import kotlin.math.roundToLong

@Suppress("unused")
fun createMuteCommands(muteService: MuteService) = commands("Mute") {
guildCommand("mute") {
command("mute") {
description = "Mute a user for a specified time."
requiredPermission = Permissions.MODERATOR
execute(LowerMemberArg, TimeArg("Time"), EveryArg("Reason")) {
Expand All @@ -34,7 +34,7 @@ fun createMuteCommands(muteService: MuteService) = commands("Mute") {
}
}

guildCommand("unmute") {
command("unmute") {
description = "Unmute a user."
requiredPermission = Permissions.MODERATOR
execute(LowerMemberArg) {
Expand All @@ -49,7 +49,7 @@ fun createMuteCommands(muteService: MuteService) = commands("Mute") {
}
}

guildCommand("gag") {
command("gag") {
description = "Mute a user for 5 minutes while you deal with something"
requiredPermission = Permissions.MODERATOR
execute(LowerMemberArg) {
Expand Down
26 changes: 13 additions & 13 deletions src/main/kotlin/me/ddivad/judgebot/commands/NoteCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,46 @@ package me.ddivad.judgebot.commands
import me.ddivad.judgebot.arguments.LowerMemberArg
import me.ddivad.judgebot.dataclasses.Permissions
import me.ddivad.judgebot.services.DatabaseService
import me.jakejmattson.discordkt.api.arguments.EveryArg
import me.jakejmattson.discordkt.api.arguments.IntegerArg
import me.jakejmattson.discordkt.api.arguments.UserArg
import me.jakejmattson.discordkt.api.commands.commands
import me.jakejmattson.discordkt.arguments.EveryArg
import me.jakejmattson.discordkt.arguments.IntegerArg
import me.jakejmattson.discordkt.arguments.UserArg
import me.jakejmattson.discordkt.commands.commands

@Suppress("unused")
fun noteCommands(databaseService: DatabaseService) = commands("Note") {
guildCommand("note") {
command("note") {
description = "Use this to add a note to a user."
requiredPermission = Permissions.MODERATOR
execute(UserArg, EveryArg("Note Content")) {
val (target, note) = args
val user = databaseService.users.getOrCreateUser(target, guild)
databaseService.users.addNote(guild, user, note, author.id.asString)
databaseService.users.addNote(guild, user, note, author.id.toString())
respond("Note added to ${target.mention}.")
}
}

guildCommand("editNote") {
command("editNote") {
description = "Use this to edit a note."
requiredPermission = Permissions.MODERATOR
execute(UserArg, IntegerArg("Note to edit"), EveryArg("Note Content")) {
val (target, noteId, note) = args
val user = databaseService.users.getOrCreateUser(target, guild)
if (user.getGuildInfo(guild.id.asString).notes.none{ it.id == noteId }) {
if (user.getGuildInfo(guild.id.toString()).notes.none{ it.id == noteId }) {
respond("User has no note with ID $noteId.")
return@execute
}
databaseService.users.editNote(guild, user, noteId, note, author.id.asString)
databaseService.users.editNote(guild, user, noteId, note, author.id.toString())
respond("Note edited.")
}
}

guildCommand("deleteNote") {
command("deleteNote") {
description = "Use this to add a delete a note from a user."
requiredPermission = Permissions.STAFF
execute(LowerMemberArg, IntegerArg("Note ID")) {
val (target, noteId) = args
val user = databaseService.users.getOrCreateUser(target, guild)
if (user.getGuildInfo(guild.id.asString).notes.isEmpty()) {
if (user.getGuildInfo(guild.id.toString()).notes.isEmpty()) {
respond("User has no notes.")
return@execute
}
Expand All @@ -51,13 +51,13 @@ fun noteCommands(databaseService: DatabaseService) = commands("Note") {
}
}

guildCommand("cleanseNotes") {
command("cleanseNotes") {
description = "Use this to delete (permanently) as user's notes."
requiredPermission = Permissions.ADMINISTRATOR
execute(LowerMemberArg) {
val target = args.first
val user = databaseService.users.getOrCreateUser(target, guild)
if (user.getGuildInfo(guild.id.asString).notes.isEmpty()) {
if (user.getGuildInfo(guild.id.toString()).notes.isEmpty()) {
respond("User has no notes.")
return@execute
}
Expand Down
Loading

0 comments on commit e1bb224

Please sign in to comment.