Skip to content

Commit

Permalink
Merge pull request #124 from the-programmers-hangout/develop
Browse files Browse the repository at this point in the history
release: merge develop for 2.6.0
  • Loading branch information
ddivad195 authored Aug 29, 2021
2 parents 54ceac1 + e9f05ac commit da0e4e6
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 19 deletions.
7 changes: 4 additions & 3 deletions commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@
| whatpfp | User | Perform a reverse image search of a User's profile picture |

## Utility
| Commands | Arguments | Description |
| -------- | --------- | ------------------------- |
| help | [Command] | Display help information. |
| Commands | Arguments | Description |
| -------- | --------- | ---------------------------------------- |
| help | [Command] | Display help information. |
| report | Message | Flag a message for moderators to review. |

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 @@ -70,7 +70,7 @@ suspend fun main() {
field {
name = "Build Info"
value = "```" +
"Version: 2.5.1\n" +
"Version: 2.6.0\n" +
"DiscordKt: ${versions.library}\n" +
"Kord: ${versions.kord}\n" +
"Kotlin: $kotlinVersion" +
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/me/ddivad/judgebot/commands/UserCommands.kt
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ fun createUserCommands(
requiredPermission = Permissions.STAFF
execute(LowerUserArg, IntegerArg("Delete message days").optional(0), EveryArg) {
val (target, deleteDays, reason) = args
if (deleteDays > 7) {
respond("Delete days cannot be more than **7**. You tried with **${deleteDays}**")
return@execute
}
val ban = Punishment(target.id.asString, InfractionType.Ban, reason, author.id.asString)
banService.banUser(target, guild, ban, deleteDays).also {
loggingService.userBanned(guild, target, ban)
Expand Down
25 changes: 24 additions & 1 deletion src/main/kotlin/me/ddivad/judgebot/commands/UtilityCommands.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
package me.ddivad.judgebot.commands

import dev.kord.core.behavior.getChannelOf
import dev.kord.core.entity.channel.TextChannel
import dev.kord.x.emoji.Emojis
import dev.kord.x.emoji.addReaction
import me.ddivad.judgebot.dataclasses.Configuration
import me.ddivad.judgebot.dataclasses.Permissions
import me.ddivad.judgebot.services.HelpService
import me.ddivad.judgebot.util.createFlagMessage
import me.jakejmattson.discordkt.api.arguments.AnyArg
import me.jakejmattson.discordkt.api.arguments.MessageArg
import me.jakejmattson.discordkt.api.commands.commands
import me.jakejmattson.discordkt.api.extensions.toSnowflake

@Suppress("unused")
fun createInformationCommands(helpService: HelpService) = commands("Utility") {
fun createInformationCommands(helpService: HelpService, configuration: Configuration) = commands("Utility") {
command("help") {
description = "Display help information."
requiredPermission = Permissions.NONE
Expand All @@ -22,4 +30,19 @@ fun createInformationCommands(helpService: HelpService) = commands("Utility") {
}
}
}

slash("report", "Report Message") {
description = "Flag a message for moderators to review."
requiredPermission = Permissions.NONE
execute(MessageArg) {
val guild = guild ?: return@execute
val guildConfiguration = configuration[guild.asGuild().id.value] ?: return@execute

guild.getChannelOf<TextChannel>(guildConfiguration.loggingConfiguration.alertChannel.toSnowflake())
.createMessage(createFlagMessage(author, args.first, channel))
.addReaction(Emojis.question)

respond("Message flagged successfully, thanks!")
}
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package me.ddivad.judgebot.listeners

import dev.kord.common.entity.ChannelType
import dev.kord.core.behavior.getChannelOf
import dev.kord.core.entity.channel.TextChannel
import dev.kord.core.entity.channel.thread.ThreadChannel
import dev.kord.core.event.message.ReactionAddEvent
import dev.kord.x.emoji.Emojis
import dev.kord.x.emoji.addReaction
import me.ddivad.judgebot.dataclasses.Configuration
import me.ddivad.judgebot.util.createFlagMessage
import me.jakejmattson.discordkt.api.dsl.listeners
import me.jakejmattson.discordkt.api.extensions.jumpLink
import me.jakejmattson.discordkt.api.extensions.toSnowflake

@Suppress("unused")
Expand All @@ -23,20 +21,10 @@ fun onMemberReactionAdd(configuration: Configuration) = listeners {
guildConfiguration.reactions.flagMessageReaction -> {
message.deleteReaction(this.emoji)
val channel = message.getChannel()
val isThread = channel.type in setOf(ChannelType.PublicGuildThread, ChannelType.PrivateThread)
guild.asGuild()
.getChannelOf<TextChannel>(guildConfiguration.loggingConfiguration.alertChannel.toSnowflake())
.asChannel()
.createMessage(
"**Message Flagged**" +
"\n**User**: ${user.mention}" +
(if (isThread)
"\n**Thread**: ${channel.mention} (${(channel as? ThreadChannel)?.parent?.mention})"
else
"\n**Channel**: ${channel.mention}") +
"\n**Author:** ${message.asMessage().author?.mention}" +
"\n**Message:** ${message.asMessage().jumpLink()}"
)
.createMessage(createFlagMessage(user.asUser(), message.asMessage(), channel))
.addReaction(Emojis.question)
}
}
Expand Down
21 changes: 21 additions & 0 deletions src/main/kotlin/me/ddivad/judgebot/util/MessageUtils.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package me.ddivad.judgebot.util

import dev.kord.common.entity.ChannelType
import dev.kord.core.entity.Message
import dev.kord.core.entity.User
import dev.kord.core.entity.channel.MessageChannel
import dev.kord.core.entity.channel.thread.ThreadChannel
import me.jakejmattson.discordkt.api.extensions.jumpLink

suspend fun createFlagMessage(user: User, message: Message, channel: MessageChannel): String {
val isThread = channel.type in setOf(ChannelType.PublicGuildThread, ChannelType.PrivateThread)

return "**Message Flagged**" +
"\n**User**: ${user.mention}" +
(if (isThread)
"\n**Thread**: ${channel.mention} (${(channel as? ThreadChannel)?.parent?.mention})"
else
"\n**Channel**: ${channel.mention}") +
"\n**Author:** ${message.author?.mention}" +
"\n**Message:** ${message.jumpLink()}"
}

0 comments on commit da0e4e6

Please sign in to comment.