Skip to content

Commit

Permalink
Merge pull request #111 from the-programmers-hangout/develop
Browse files Browse the repository at this point in the history
release: merge develop with master for 2.4.0 release
  • Loading branch information
ddivad195 authored Aug 4, 2021
2 parents f81cbd2 + 6a2d8e5 commit f2ba5ac
Show file tree
Hide file tree
Showing 20 changed files with 188 additions and 164 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v1
with:
java-version: 11
- name: Cache local Maven repository
uses: actions/cache@v2
with:
path: ~/.m2/repository
key: maven-${{ hashFiles('build.gradle') }}
restore-keys: maven-
- name: Build
run: ./gradlew build
32 changes: 32 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Docker

on:
push:
branches: [ master ]

jobs:
docker:
runs-on: ubuntu-latest
steps:
-
name: Checkout code
uses: actions/checkout@v2
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v1

-
name: Login to DockerHub
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}

-
name: Build and push
uses: docker/build-push-action@v2
with:
context: .
pull: true
push: true
tags: theprogrammershangout/judgebot:latest
20 changes: 10 additions & 10 deletions src/main/kotlin/me/ddivad/judgebot/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import dev.kord.gateway.Intent
import dev.kord.gateway.Intents
import dev.kord.gateway.PrivilegedIntent
import me.ddivad.judgebot.dataclasses.Configuration
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
Expand All @@ -31,6 +32,14 @@ suspend fun main(args: Array<String>) {
commandReaction = null
theme = Color.MAGENTA
entitySupplyStrategy = EntitySupplyStrategy.cacheWithCachingRestFallback
permissions(Permissions.NONE)
intents = Intents(
Intent.GuildMembers,
Intent.DirectMessages,
Intent.GuildBans,
Intent.Guilds,
Intent.GuildMessageReactions
)
}

mentionEmbed {
Expand Down Expand Up @@ -58,7 +67,7 @@ suspend fun main(args: Array<String>) {
field {
name = "Build Info"
value = "```" +
"Version: 2.3.0\n" +
"Version: 2.4.0\n" +
"DiscordKt: ${versions.library}\n" +
"Kotlin: $kotlinVersion" +
"```"
Expand All @@ -73,15 +82,6 @@ suspend fun main(args: Array<String>) {
}
}

permissions {
val permissionsService = discord.getInjectionObjects(PermissionsService::class)
val permission = command.requiredPermissionLevel
if (guild != null)
permissionsService.hasClearance(guild!!, user, permission)
else
return@permissions command.requiredPermissionLevel == PermissionLevel.Everyone
}

onStart {
val (muteService, banService, cacheService) = this.getInjectionObjects(
MuteService::class,
Expand Down
10 changes: 3 additions & 7 deletions src/main/kotlin/me/ddivad/judgebot/arguments/LowerMemberArg.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.ddivad.judgebot.arguments

import dev.kord.core.entity.Member
import me.ddivad.judgebot.services.PermissionsService
import me.jakejmattson.discordkt.api.arguments.*
import me.jakejmattson.discordkt.api.dsl.CommandEvent
import me.jakejmattson.discordkt.api.extensions.toSnowflakeOrNull
Expand All @@ -14,20 +13,17 @@ open class LowerMemberArg(override val name: String = "LowerMemberArg") : Argume
override suspend fun generateExamples(event: CommandEvent<*>) = mutableListOf("@User", "197780697866305536", "302134543639511050")

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

val member = arg.toSnowflakeOrNull()?.let { guild.getMemberOrNull(it) } ?: return Error("Not found")
val author = event.author.asMember(event.guild!!.id)

return when {
event.author.asMember(event.guild!!.id).isHigherRankedThan(permissionsService, member) ->
event.discord.permissions.isHigherLevel(event.discord, member, author) ->
Error("You don't have the permission to use this command on the target user.")
else -> Success(member)
}
}

override fun formatData(data: Member) = "@${data.tag}"
}

suspend fun Member.isHigherRankedThan(permissions: PermissionsService, targetMember: Member) =
permissions.getPermissionRank(this) < permissions.getPermissionRank(targetMember)
}
7 changes: 3 additions & 4 deletions src/main/kotlin/me/ddivad/judgebot/arguments/LowerUserArg.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.ddivad.judgebot.arguments

import dev.kord.core.entity.User
import me.ddivad.judgebot.services.PermissionsService
import me.jakejmattson.discordkt.api.arguments.*
import me.jakejmattson.discordkt.api.dsl.CommandEvent
import me.jakejmattson.discordkt.api.extensions.toSnowflakeOrNull
Expand All @@ -14,15 +13,15 @@ open class LowerUserArg(override val name: String = "LowerUserArg") : ArgumentTy
override suspend 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)
val author = event.author.asMember(event.guild!!.id)

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")
event.discord.permissions.isHigherLevel(event.discord, member, author) ->
Error("You don't have the permission to use this command on the target user.")
else -> Success(member.asUser())
}
}
Expand Down
9 changes: 4 additions & 5 deletions src/main/kotlin/me/ddivad/judgebot/commands/GuildCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,18 @@ import me.ddivad.judgebot.arguments.GuildConfigArg
import me.ddivad.judgebot.conversations.guild.GuildSetupConversation
import me.ddivad.judgebot.conversations.guild.EditConfigConversation
import me.ddivad.judgebot.dataclasses.Configuration
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.ddivad.judgebot.services.PermissionLevel
import me.ddivad.judgebot.services.requiredPermissionLevel
import me.jakejmattson.discordkt.api.dsl.commands

fun guildConfigCommands(configuration: Configuration,
databaseService: DatabaseService,
muteService: MuteService) = commands("Guild") {
guildCommand("setup") {
description = "Configure a guild to use Judgebot."
requiredPermissionLevel = PermissionLevel.Administrator
requiredPermission = Permissions.ADMINISTRATOR
execute {
if (configuration.hasGuildConfig(guild.id.value)) {
respond("Guild configuration exists. To modify it use the commands to set values.")
Expand All @@ -32,7 +31,7 @@ fun guildConfigCommands(configuration: Configuration,

guildCommand("configuration") {
description = "Update configuration parameters for this guild (conversation)."
requiredPermissionLevel = PermissionLevel.Staff
requiredPermission = Permissions.STAFF
execute(GuildConfigArg.optional("options")) {
if (!configuration.hasGuildConfig(guild.id.value)) {
respond("Please run the **setup** command to set this initially.")
Expand All @@ -46,7 +45,7 @@ fun guildConfigCommands(configuration: Configuration,

guildCommand("activePunishments") {
description = "View active punishments for a guild."
requiredPermissionLevel = PermissionLevel.Staff
requiredPermission = Permissions.STAFF
execute {
val punishments = databaseService.guilds.getActivePunishments(guild)
if (punishments.isEmpty()) {
Expand Down
10 changes: 3 additions & 7 deletions src/main/kotlin/me/ddivad/judgebot/commands/InfoCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,20 @@ import dev.kord.x.emoji.Emojis
import dev.kord.x.emoji.addReaction
import me.ddivad.judgebot.arguments.LowerMemberArg
import me.ddivad.judgebot.dataclasses.Info
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.ddivad.judgebot.services.HelpService
import me.ddivad.judgebot.services.PermissionLevel
import me.ddivad.judgebot.services.requiredPermissionLevel
import me.jakejmattson.discordkt.api.arguments.CommandArg
import me.jakejmattson.discordkt.api.arguments.EveryArg
import me.jakejmattson.discordkt.api.arguments.IntegerArg
import me.jakejmattson.discordkt.api.arguments.UnicodeEmojiArg
import me.jakejmattson.discordkt.api.dsl.commands
import me.jakejmattson.discordkt.api.extensions.sendPrivateMessage

@Suppress("unused")
fun createInformationCommands(databaseService: DatabaseService) = commands("Information") {
guildCommand("info") {
description = "Send an information message to a guild member"
requiredPermissionLevel = PermissionLevel.Moderator
requiredPermission = Permissions.MODERATOR
execute(LowerMemberArg, EveryArg("Info Content")) {
val (target, content) = args
try {
Expand All @@ -45,7 +41,7 @@ fun createInformationCommands(databaseService: DatabaseService) = commands("Info

guildCommand("removeInfo") {
description = "Remove an information message from a member record."
requiredPermissionLevel = PermissionLevel.Staff
requiredPermission = Permissions.STAFF
execute(LowerMemberArg, IntegerArg("Info ID")) {
val (target, id) = args
val user = databaseService.users.getOrCreateUser(target, guild)
Expand Down
25 changes: 15 additions & 10 deletions src/main/kotlin/me/ddivad/judgebot/commands/InfractionCommands.kt
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package me.ddivad.judgebot.commands

import dev.kord.common.entity.Permission
import me.ddivad.judgebot.arguments.LowerUserArg
import dev.kord.common.exception.RequestException
import dev.kord.core.behavior.reply
import dev.kord.x.emoji.Emojis
import dev.kord.x.emoji.addReaction
import me.ddivad.judgebot.arguments.LowerMemberArg
import me.ddivad.judgebot.conversations.InfractionConversation
import me.ddivad.judgebot.dataclasses.Configuration
import me.ddivad.judgebot.dataclasses.Infraction
import me.ddivad.judgebot.dataclasses.InfractionType
import me.ddivad.judgebot.dataclasses.Permissions
import me.ddivad.judgebot.extensions.testDmStatus
import me.ddivad.judgebot.services.*
import me.ddivad.judgebot.extensions.*
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.arguments.UserArg
import me.jakejmattson.discordkt.api.conversations.ConversationResult
import me.jakejmattson.discordkt.api.dsl.commands

@Suppress("unused")
Expand All @@ -30,7 +30,7 @@ fun createInfractionCommands(databaseService: DatabaseService,
badnameService: BadnameService) = commands("Infraction") {
guildCommand("strike", "s", "S") {
description = "Strike a user."
requiredPermissionLevel = PermissionLevel.Staff
requiredPermission = Permissions.STAFF
execute(LowerMemberArg, IntegerArg("Weight").optional(1), EveryArg("Reason")) {
val (targetMember, weight, reason) = args
val guildConfiguration = config[guild.id.value] ?: return@execute
Expand All @@ -46,15 +46,20 @@ fun createInfractionCommands(databaseService: DatabaseService,
this.message.addReaction(Emojis.x)
respond("${targetMember.mention} has DMs disabled. No messages will be sent.")
}
InfractionConversation(databaseService, config, infractionService)
val conversationResult = InfractionConversation(databaseService, config, infractionService)
.createInfractionConversation(guild, targetMember, weight, reason, InfractionType.Strike)
.startPublicly(discord, author, channel)
if (conversationResult == ConversationResult.HAS_CONVERSATION) {
message.reply { content = "You already have an active Strike conversation. Make sure you selected a rule." }
} else if (conversationResult == ConversationResult.EXITED) {
message.reply { content = "Infraction cancelled." }
}
}
}

guildCommand("warn", "w", "W") {
description = "Warn a user."
requiredPermissionLevel = PermissionLevel.Moderator
requiredPermission = Permissions.MODERATOR
execute(LowerMemberArg, EveryArg("Reason")) {
val (targetMember, reason) = args
try {
Expand All @@ -72,7 +77,7 @@ fun createInfractionCommands(databaseService: DatabaseService,

guildCommand("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."
requiredPermissionLevel = PermissionLevel.Staff
requiredPermission = Permissions.STAFF
execute(BooleanArg("cancel", "apply", "cancel").optional(true), LowerMemberArg) {
val (cancel, targetMember) = args
try {
Expand Down Expand Up @@ -103,7 +108,7 @@ fun createInfractionCommands(databaseService: DatabaseService,

guildCommand("badname") {
description = "Rename a guild member that has a bad name."
requiredPermissionLevel = PermissionLevel.Moderator
requiredPermission = Permissions.MODERATOR
execute(LowerMemberArg) {
badnameService.chooseRandomNickname(args.first)
respond("User renamed to ${args.first.mention}")
Expand All @@ -112,7 +117,7 @@ fun createInfractionCommands(databaseService: DatabaseService,

guildCommand("cleanseInfractions") {
description = "Use this to delete (permanently) as user's infractions."
requiredPermissionLevel = PermissionLevel.Administrator
requiredPermission = Permissions.ADMINISTRATOR
execute(LowerUserArg) {
val user = databaseService.users.getOrCreateUser(args.first, guild)
if (user.getGuildInfo(guild.id.asString).infractions.isEmpty()) {
Expand All @@ -126,7 +131,7 @@ fun createInfractionCommands(databaseService: DatabaseService,

guildCommand("removeInfraction") {
description = "Use this to delete (permanently) an infraction from a user."
requiredPermissionLevel = PermissionLevel.Administrator
requiredPermission = Permissions.ADMINISTRATOR
execute(LowerUserArg, IntegerArg("Infraction ID")) {
val user = databaseService.users.getOrCreateUser(args.first, guild)
if (user.getGuildInfo(guild.id.asString).infractions.isEmpty()) {
Expand Down
8 changes: 4 additions & 4 deletions src/main/kotlin/me/ddivad/judgebot/commands/MuteCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import dev.kord.common.exception.RequestException
import dev.kord.x.emoji.Emojis
import dev.kord.x.emoji.addReaction
import me.ddivad.judgebot.arguments.LowerMemberArg
import me.ddivad.judgebot.dataclasses.Permissions
import me.ddivad.judgebot.extensions.testDmStatus
import me.ddivad.judgebot.services.*
import me.ddivad.judgebot.services.infractions.MuteService
import me.ddivad.judgebot.services.infractions.RoleState
import me.ddivad.judgebot.util.timeToString
Expand All @@ -18,7 +18,7 @@ import kotlin.math.roundToLong
fun createMuteCommands(muteService: MuteService) = commands("Mute") {
guildCommand("mute") {
description = "Mute a user for a specified time."
requiredPermissionLevel = PermissionLevel.Moderator
requiredPermission = Permissions.MODERATOR
execute(LowerMemberArg, TimeArg("Time"), EveryArg("Reason")) {
val (targetMember, length, reason) = args
try {
Expand All @@ -35,7 +35,7 @@ fun createMuteCommands(muteService: MuteService) = commands("Mute") {

guildCommand("unmute") {
description = "Unmute a user."
requiredPermissionLevel = PermissionLevel.Moderator
requiredPermission = Permissions.MODERATOR
execute(LowerMemberArg) {
val targetMember = args.first
if (muteService.checkRoleState(guild, targetMember) == RoleState.None) {
Expand All @@ -50,7 +50,7 @@ fun createMuteCommands(muteService: MuteService) = commands("Mute") {

guildCommand("gag") {
description = "Mute a user for 5 minutes while you deal with something"
requiredPermissionLevel = PermissionLevel.Moderator
requiredPermission = Permissions.MODERATOR
execute(LowerMemberArg) {
val targetMember = args.first
if (muteService.checkRoleState(guild, targetMember) == RoleState.Tracked) {
Expand Down
Loading

0 comments on commit f2ba5ac

Please sign in to comment.