Skip to content

Commit

Permalink
Merge pull request #117 from the-programmers-hangout/develop
Browse files Browse the repository at this point in the history
release: merge develop with master
  • Loading branch information
ddivad195 authored Aug 16, 2021
2 parents a341785 + c69ea37 commit b996889
Show file tree
Hide file tree
Showing 38 changed files with 152 additions and 119 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/discord-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: Post Release to Discord

on:
release:
types:
- created

jobs:
run_main:
runs-on: ubuntu-18.04
name: Discord Webhook
steps:
- name: Send message
uses: ddivad195/discord-styled-releases@main
with:
project_name: "Judgebot"
embed_colour: "1315909"
webhook_id: ${{ secrets.DISCORD_WEBHOOK_ID }}
webhook_token: ${{ secrets.DISCORD_WEBHOOK_TOKEN }}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ tasks {

object Versions {
const val BOT = "1.0.0"
const val DISCORDKT = "0.22.0-SNAPSHOT"
const val DISCORDKT = "0.23.0-SNAPSHOT"
}
11 changes: 7 additions & 4 deletions src/main/kotlin/me/ddivad/judgebot/Main.kt
Original file line number Diff line number Diff line change
@@ -1,5 +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
Expand All @@ -14,8 +15,9 @@ import me.jakejmattson.discordkt.api.dsl.bot
import me.jakejmattson.discordkt.api.extensions.addInlineField
import java.awt.Color

@KordPreview
@PrivilegedIntent
suspend fun main(args: Array<String>) {
suspend fun main() {
val token = System.getenv("BOT_TOKEN") ?: null
val defaultPrefix = System.getenv("DEFAULT_PREFIX") ?: "j!"

Expand All @@ -31,7 +33,7 @@ suspend fun main(args: Array<String>) {
allowMentionPrefix = true
commandReaction = null
theme = Color.MAGENTA
entitySupplyStrategy = EntitySupplyStrategy.cacheWithCachingRestFallback
entitySupplyStrategy = EntitySupplyStrategy.cacheWithRestFallback
permissions(Permissions.NONE)
intents = Intents(
Intent.GuildMembers,
Expand Down Expand Up @@ -67,10 +69,11 @@ suspend fun main(args: Array<String>) {
field {
name = "Build Info"
value = "```" +
"Version: 2.4.1\n" +
"Version: 2.5.0\n" +
"DiscordKt: ${versions.library}\n" +
"Kord: ${versions.kord}\n" +
"Kotlin: $kotlinVersion" +
"```"
"```"
}
field {
name = "Uptime"
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.dsl.CommandEvent
import me.jakejmattson.discordkt.api.commands.CommandEvent

val validConfigParameters = mutableListOf(
"setPrefix",
Expand All @@ -23,7 +23,7 @@ val validConfigParameters = mutableListOf(
"options"
)

open class GuildConfigArg(override val name: String = "GuildConfig") : ArgumentType<String> {
open class GuildConfigArg(override val name: String = "GuildConfig") : Argument<String> {
override val description = "A Guild configuration"

companion object : GuildConfigArg()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package me.ddivad.judgebot.arguments

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

open class LowerMemberArg(override val name: String = "LowerMemberArg") : ArgumentType<Member> {
open class LowerMemberArg(override val name: String = "LowerMemberArg") : Argument<Member> {
companion object : LowerMemberArg()

override val description = "A Member with a lower rank"
Expand All @@ -19,8 +20,9 @@ open class LowerMemberArg(override val name: String = "LowerMemberArg") : Argume
val author = event.author.asMember(event.guild!!.id)

return when {
event.discord.permissions.isHigherLevel(event.discord, member, author) ->
event.discord.permissions.isHigherLevel(event.discord, member, author) || event.author.isSelf() ->
Error("You don't have the permission to use this command on the target user.")
event.author == member -> Error("You can't use this command on yourself!")
else -> Success(member)
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/main/kotlin/me/ddivad/judgebot/arguments/LowerUserArg.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package me.ddivad.judgebot.arguments

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

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

override val description = "A user with a lower rank"
Expand All @@ -20,9 +21,12 @@ open class LowerUserArg(override val name: String = "LowerUserArg") : ArgumentTy
val author = event.author.asMember(event.guild!!.id)

return when {
event.discord.permissions.isHigherLevel(event.discord, member, author) ->
event.discord.permissions.isHigherLevel(event.discord, member, author) || event.author.isSelf() ->
Error("You don't have the permission to use this command on the target user.")
event.author == member -> Error("You can't use this command on yourself!")
else -> Success(member.asUser())
}
}

override fun formatData(data: User) = "@${data.tag}"
}
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 @@ -4,9 +4,9 @@ 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.dsl.CommandEvent
import me.jakejmattson.discordkt.api.commands.CommandEvent

open class RuleArg(override val name: String = "Rule") : ArgumentType<Rule> {
open class RuleArg(override val name: String = "Rule") : Argument<Rule> {
override val description = "A rule number"

override suspend fun generateExamples(event: CommandEvent<*>): List<String> = mutableListOf("1", "2", "3")
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/me/ddivad/judgebot/commands/GuildCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ 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.dsl.commands
import me.jakejmattson.discordkt.api.commands.commands

@Suppress("unused")
fun guildConfigCommands(configuration: Configuration,
databaseService: DatabaseService,
muteService: MuteService) = commands("Guild") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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.dsl.commands
import me.jakejmattson.discordkt.api.commands.commands
import me.jakejmattson.discordkt.api.extensions.sendPrivateMessage

@Suppress("unused")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.ddivad.judgebot.commands

import dev.kord.common.annotation.KordPreview
import me.ddivad.judgebot.arguments.LowerUserArg
import dev.kord.common.exception.RequestException
import dev.kord.core.behavior.reply
Expand All @@ -19,9 +20,10 @@ 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.api.dsl.commands

@KordPreview
@Suppress("unused")
fun createInfractionCommands(databaseService: DatabaseService,
config: Configuration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ 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.dsl.commands
import me.jakejmattson.discordkt.api.commands.commands
import kotlin.math.roundToLong

@Suppress("unused")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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.dsl.commands
import me.jakejmattson.discordkt.api.commands.commands

@Suppress("unused")
fun noteCommands(databaseService: DatabaseService) = commands("Note") {
Expand Down
9 changes: 4 additions & 5 deletions src/main/kotlin/me/ddivad/judgebot/commands/RuleCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ import me.ddivad.judgebot.embeds.createRulesEmbed
import me.ddivad.judgebot.embeds.createRulesEmbedDetailed
import me.ddivad.judgebot.services.DatabaseService
import me.jakejmattson.discordkt.api.arguments.MessageArg
import me.jakejmattson.discordkt.api.dsl.commands
import me.jakejmattson.discordkt.api.commands.commands
import me.jakejmattson.discordkt.api.extensions.jumpLink

@Suppress("unused")
fun ruleCommands(configuration: Configuration,
databaseService: DatabaseService) = commands("Rule") {
fun ruleCommands(databaseService: DatabaseService) = commands("Rule") {

guildCommand("addRule") {
description = "Add a rule to this guild."
Expand Down Expand Up @@ -55,7 +54,7 @@ fun ruleCommands(configuration: Configuration,
execute(MessageArg.optionalNullable(null)) {
val messageToEdit = args.first
if (messageToEdit != null) {
messageToEdit.edit { this.embed { createRulesEmbed(guild, databaseService.guilds.getRules(guild)) } }
messageToEdit.edit { this.embeds?.first()?.createRulesEmbed(guild, databaseService.guilds.getRules(guild)) }
respond("Existing embed updated: ${messageToEdit.jumpLink()}")
} else {
respond {
Expand All @@ -71,7 +70,7 @@ fun ruleCommands(configuration: Configuration,
execute(MessageArg.optionalNullable(null)) {
val messageToEdit = args.first
if (messageToEdit != null) {
messageToEdit.edit { this.embed { createRulesEmbedDetailed(guild, databaseService.guilds.getRules(guild)) } }
messageToEdit.edit { embeds?.first()?.createRulesEmbedDetailed(guild, databaseService.guilds.getRules(guild))}
respond("Existing embed updated: ${messageToEdit.jumpLink()}")
} else {
respond {
Expand Down
5 changes: 2 additions & 3 deletions src/main/kotlin/me/ddivad/judgebot/commands/UserCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import me.ddivad.judgebot.services.DatabaseService
import me.ddivad.judgebot.services.LoggingService
import me.ddivad.judgebot.services.infractions.BanService
import me.jakejmattson.discordkt.api.arguments.*
import me.jakejmattson.discordkt.api.dsl.commands
import me.jakejmattson.discordkt.api.commands.commands
import me.jakejmattson.discordkt.api.extensions.mutualGuilds
import me.jakejmattson.discordkt.api.extensions.sendPrivateMessage
import java.awt.Color
Expand All @@ -33,7 +33,6 @@ fun createUserCommands(
execute(UserArg) {
val user = databaseService.users.getOrCreateUser(args.first, guild)
databaseService.users.incrementUserHistory(user, guild)
val linkedAccounts = user.getLinkedAccounts(guild)
respondMenu {
createHistoryEmbed(args.first, user, guild, config, databaseService)
}
Expand Down Expand Up @@ -148,7 +147,7 @@ fun createUserCommands(
user.sendPrivateMessage {
createSelfHistoryEmbed(user, guildMember, currentGuild, config)
}
this.message.addReaction(Emojis.whiteCheckMark)
this.message?.addReaction(Emojis.whiteCheckMark)
} else {
guildChoiceConversation(mutualGuilds, config).startPrivately(discord, author)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ package me.ddivad.judgebot.commands
import me.ddivad.judgebot.dataclasses.Permissions
import me.ddivad.judgebot.services.HelpService
import me.jakejmattson.discordkt.api.arguments.AnyArg
import me.jakejmattson.discordkt.api.arguments.CommandArg
import me.jakejmattson.discordkt.api.dsl.commands
import me.jakejmattson.discordkt.api.commands.commands

@Suppress("unused")
fun createInformationCommands(helpService: HelpService) = commands("Utility") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import dev.kord.core.entity.Guild
import me.ddivad.judgebot.dataclasses.Configuration
import me.ddivad.judgebot.embeds.createSelfHistoryEmbed
import me.ddivad.judgebot.services.DatabaseService
import me.jakejmattson.discordkt.api.arguments.IntegerRangeArg
import me.jakejmattson.discordkt.api.conversations.conversation
import java.awt.Color

Expand All @@ -14,21 +13,25 @@ fun guildChoiceConversation(
configuration: Configuration
) = conversation {
val databaseService = discord.getInjectionObjects(DatabaseService::class)
val guildIndex = promptEmbed(IntegerRangeArg(1, guilds.size)) {
title = "Select Server"
description = "Respond with the server you want to view your history for."
thumbnail {
url = discord.kord.getSelf().avatar.url
val guild = promptButton<Guild> {
embed {
color = Color.MAGENTA.kColor
title = "Select Server"
description = "Select the server you to view history for."
thumbnail {
url = discord.kord.getSelf().avatar.url
}
}
color = Color.MAGENTA.kColor
guilds.toList().forEachIndexed { index, guild ->
field {
name = "${index + 1}) ${guild.name}"

guilds.toList().chunked(5).forEach { row ->
buttons {
row.forEach { guild ->
button(guild.name, null, guild)
}
}
}
} - 1
}

val guild = guilds[guildIndex]
val guildMember = databaseService.users.getOrCreateUser(user, guild)

respond {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.ddivad.judgebot.conversations

import dev.kord.common.annotation.KordPreview
import dev.kord.common.entity.ButtonStyle
import dev.kord.core.entity.Guild
import dev.kord.core.entity.Member
Expand All @@ -10,6 +11,7 @@ import me.ddivad.judgebot.services.DatabaseService
import me.ddivad.judgebot.services.infractions.InfractionService
import me.jakejmattson.discordkt.api.conversations.conversation

@KordPreview
class InfractionConversation(
private val databaseService: DatabaseService,
private val configuration: Configuration,
Expand Down
Loading

0 comments on commit b996889

Please sign in to comment.