Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeJMattson committed Aug 6, 2022
1 parent 9ec81c3 commit 3cfe125
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 43 deletions.
20 changes: 10 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<p align="center">
<a href="https://kotlinlang.org/">
<img alt="Kotlin" src="https://img.shields.io/badge/Kotlin-1.7.10-blue.svg?logo=Kotlin">
</a>
<a href="https://github.com/JakeJMattson/DiscordKt">
<img alt="DiscordKt" src="https://img.shields.io/badge/DiscordKt-0.23.2-blue.svg?logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAABmJLR0QA/wD/AP+gvaeTAAAEvElEQVRYw+2Yy2seVRiHn3Ob756kiWlrq7ZqDSJUsSqoK4srQXHjRnShf4ILl/4FrkVcKLgS1FW3FRR05b1IMVXbNG2SJvny5ct3nZkz5+IitpW2giYOFskLA7M4Z+Y57/m9P857YC92F+Lqy/T0M/F2Atvc/EIAyNs9g3uAuw3974lZMFc9jsJwLj+Dj+72ATxSO8KrB1/nHjOHd5q1rM3Hm+/zc/b9f1vFTV3npbuf49k7ThJ9gisM3ulrz5nBj3zSfY+u39hxFe8IUCA4efgRXjv2PA05iXeaiGHyiRa2L+l87SnsNmRaBE53T3F68CnuH2z7jgHvm5rljRPPMTdxz7VMVeemOPTyYSp3JgCMzlt+fWdA71zEO41zmqV0hY823mPBzpcHeKg1wYcvvEJCDe8V1GpMv3iM5qMzN42NEdpfjFn4YETakXinyQt4e/ktLtvz5Rj1s/cfpVWPmEpO88Emh988cUs4ACFg/8k6j707w+wT23NqVc+Tk0+X54ONisBUcnRiqT9/P157vPd/OT7GiFM5B16SJJWcpJJTM6o8m6lVBCaxSBmIaU5sVXGFxXuB1gYpr/48YnNLlmYgInISTDVDFoZ6mYB3tAw6sUjlQVyXbAyRwlqUUiAEaZoSQ7imcCEiSSXHK89krVoeoNEek1i8V3hxc01577F5QSTcIMhtDUrlSYwrD3CyLrcz6BUBzy3LPsuham7gu57BZjUpr0jqFYE2BdoUmIX5bS+5ack3fDKC+2ENnVhMJadqYnkZbA9ztCkIMiCWziJ7bewjTxFmD17nUX8CXB/gv7pAuDTCJBrvFZ1sUB5gp+9Z35LMTjm0CsjxKuarUxQH7iV/+ElivQFCIEYp6odzhF9WiU5jEo2QnvZajc1RiRo0JtIbw3CkmZkKTLX+yGb7POqzRYqDx1AuIi5dIRSCkGikDPQtLK9VGI8jifHlAQ5zi1YFISjWupLeSLN/2lE1AekDanWe4BVBK7xQZCGy1jV0uooQLcoERn5YogZHGd3UMtXQaKmwXnLpimKiEZmddmgp8TIQRaDT1bTbGlsEjLE4qehmlp4dlQfoY6CfFgxTz76mpllVSKkYZprhkqHViOAl3X5CnguEdhgiQ+9pDwNpIfEyLw/w4sYYj0NIxcYwMBgrZiY0iY5EL+mPFdFHoijQJuKjY3Mo2RpFolBECYuD1fJ8sJ85Pp/f4EpvjFKBAsdyz9IeWKJyaO1QxiGVo59nLG9ljIscpR1bdsB36xdJfVZmkXhSF/lmsc++dsrxuxrsq1VIi8jlTqBZUcQg6I8FtpAorcl9wfzGgKWtETEKBkVa4hZ3Uu6cSjg6U6U7Lvjy1x5376vw0KEGiTQMck8MEoREKMFCZ8C59SHOgZSSy70Ri71u+U3T/omEx4+2mKprQJBIwYOHGhyZrkFULG9Zzi6NGeWeGCVjG/hppcul7t+3mF01TVcnHp2t8tiRFonePuNJISAIfIQYBD4IfmuP+Gmlh/NhR13djvviCCy0M1a6OcfvavLAgfr2IUtEBLDSt3y32GeY766B33XjnrvItxcH/LaeMXewipaCC+2M1Z69va4+tsYFX18o9m639gD/d4B7sdv4Hc8YdmfiizvVAAAAAElFTkSuQmCC">
</a>
<br>
<a href="https://discordapp.com/users/254786431656919051/">
<img alt="Discord JakeyWakey#1569" src="https://img.shields.io/badge/Personal-JakeyWakey%231569-%2300BFFF.svg?logo=discord">
</a>
<a href="https://kotlinlang.org/">
<img alt="Kotlin" src="https://img.shields.io/badge/Kotlin-1.7.10-%23A97BFF.svg?logo=Kotlin">
</a>
<a href="https://github.com/discordkt/discordkt/releases/">
<img alt="Version" src="https://img.shields.io/badge/Version-0.23.2-%23E15ABA?label=Version&logo=GitHub">
</a>
<br>
<a href="https://discordapp.com/users/254786431656919051/">
<img alt="Discord JakeyWakey#1569" src="https://img.shields.io/badge/Personal-JakeyWakey%231569-%2300BFFF.svg?logo=discord">
</a>
</p>

# ModMail
Expand Down
2 changes: 0 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ plugins {
}

repositories {
mavenLocal()
mavenCentral()
maven("https://oss.sonatype.org/content/repositories/snapshots/")
}

dependencies {
Expand Down
11 changes: 5 additions & 6 deletions src/main/kotlin/me/jakejmattson/modmail/MainApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package me.jakejmattson.modmail
import dev.kord.common.annotation.KordPreview
import dev.kord.common.entity.Permission
import dev.kord.common.entity.Permissions
import dev.kord.common.kColor
import dev.kord.gateway.Intent
import dev.kord.gateway.PrivilegedIntent
import kotlinx.serialization.Serializable
Expand All @@ -19,8 +20,6 @@ import kotlin.system.exitProcess
@Serializable
private data class Properties(val version: String, val kotlin: String, val repository: String) : Data()

private val propFile = Properties::class.java.getResource("/properties.json").path

private val startup = Instant.now()

@KordPreview
Expand All @@ -35,7 +34,7 @@ suspend fun main(it: Array<String>) {

bot(token) {
val configuration = data(configFile.path) { Configuration() }
val project = data(propFile) { Properties("0.0", "0.0", "0.0") }
val project = data(javaClass.getResource("/properties.json")?.path ?: "") { Properties("0.0", "0.0", "0.0") }

prefix {
guild?.let { configuration[it]?.prefix } ?: " "
Expand All @@ -44,15 +43,15 @@ suspend fun main(it: Array<String>) {
configure {
commandReaction = null
dualRegistry = false
theme = Color(0x00bfff)
intents = Intent.GuildMembers + Intent.Guilds + Intent.DirectMessages + Intent.DirectMessageTyping + Intent.GuildMessageTyping + Intent.GuildBans
recommendCommands = false
intents = Intent.Guilds + Intent.GuildMembers + Intent.GuildBans + Intent.DirectMessages + Intent.DirectMessageTyping + Intent.GuildMessageTyping
defaultPermissions = Permissions(Permission.ManageMessages)
}

mentionEmbed {
title = "ModMail ${project.version}"
description = "A Discord report management bot."

color = Color.white.kColor
thumbnail(it.discord.kord.getSelf().pfpUrl)
addInlineField("Source", "[GitHub](${project.repository})")
addInlineField("Ping", it.discord.kord.gateway.averagePing?.toString() ?: "Unknown")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import me.jakejmattson.discordkt.arguments.AnyArg
import me.jakejmattson.discordkt.arguments.EveryArg
import me.jakejmattson.discordkt.commands.subcommand
import me.jakejmattson.discordkt.extensions.*
import me.jakejmattson.modmail.services.*
import me.jakejmattson.modmail.services.Locale
import me.jakejmattson.modmail.services.MacroService
import me.jakejmattson.modmail.services.findReport
import java.awt.Color

@Suppress("unused")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package me.jakejmattson.modmail.commands

import dev.kord.common.kColor
import dev.kord.core.behavior.channel.createEmbed
import dev.kord.core.behavior.channel.createMessage
import dev.kord.core.behavior.channel.edit
import me.jakejmattson.discordkt.arguments.AnyArg
import me.jakejmattson.discordkt.arguments.EveryArg
import me.jakejmattson.discordkt.commands.commands
import me.jakejmattson.discordkt.extensions.pfpUrl
import me.jakejmattson.discordkt.extensions.author
import me.jakejmattson.modmail.extensions.archiveString
import me.jakejmattson.modmail.listeners.deletionQueue
import me.jakejmattson.modmail.services.*
import java.awt.Color

@Suppress("unused")
fun reportCommands(configuration: Configuration, loggingService: LoggingService) = commands("Report") {
Expand Down Expand Up @@ -82,11 +84,9 @@ fun reportCommands(configuration: Configuration, loggingService: LoggingService)
val messageAuthor = author

channel.createEmbed {
author {
name = messageAuthor.tag
icon = messageAuthor.pfpUrl
}
author(messageAuthor)
description = args.first
color = Color.white.kColor
}

loggingService.command(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import me.jakejmattson.discordkt.arguments.UserArg
import me.jakejmattson.discordkt.commands.CommandEvent
import me.jakejmattson.discordkt.commands.commands
import me.jakejmattson.discordkt.extensions.addField
import me.jakejmattson.discordkt.extensions.thumbnail
import me.jakejmattson.modmail.extensions.archiveString
import me.jakejmattson.modmail.services.*
import java.awt.Color
Expand All @@ -33,9 +34,7 @@ fun reportHelperCommands(configuration: Configuration, reportService: ReportServ
addField("Chatting with ${guild.name}!", Locale.BOT_DESCRIPTION)
}

thumbnail {
url = guild.getIconUrl(Image.Format.JPEG) ?: ""
}
thumbnail(guild.getIconUrl(Image.Format.JPEG) ?: "")
}

val reportChannel = guild.createTextChannel(username) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import me.jakejmattson.discordkt.Discord
import me.jakejmattson.discordkt.conversations.conversation
import me.jakejmattson.discordkt.extensions.mutualGuilds
import me.jakejmattson.discordkt.extensions.pfpUrl
import me.jakejmattson.discordkt.extensions.thumbnail
import me.jakejmattson.modmail.services.Configuration
import me.jakejmattson.modmail.services.ReportService

Expand All @@ -18,9 +19,7 @@ fun guildChoiceConversation(discord: Discord, message: Message) = conversation {
embed {
title = "Select Server"
description = "Select the server you want to contact."
thumbnail {
url = discord.kord.getSelf().pfpUrl
}
thumbnail(discord.kord.getSelf().pfpUrl)
}

guilds.toList().chunked(5).forEach { row ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import dev.kord.core.event.message.MessageUpdateEvent
import me.jakejmattson.discordkt.Discord
import me.jakejmattson.discordkt.dsl.listeners
import me.jakejmattson.modmail.extensions.cleanContent
import me.jakejmattson.modmail.services.*
import me.jakejmattson.modmail.services.LoggingService
import me.jakejmattson.modmail.services.ReportService
import me.jakejmattson.modmail.services.findReport

@Suppress("unused")
fun editListener(discord: Discord, reportService: ReportService, loggingService: LoggingService) = listeners {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ fun reportListener(discord: Discord, config: Configuration, reportService: Repor
val report = channel.findReport() ?: return@on
val member = report.liveMember(kord) ?: return@on addFailReaction()
val prefix = config[getGuild()]?.prefix ?: return@on
val content = fullContent().takeUnless { it.isBlank() || it.startsWith(prefix) || it.startsWith("/") } ?: return@on
val content = fullContent().takeUnless { it.isBlank() || it.startsWith(prefix) || it.startsWith("/") }
?: return@on
val newMessage = member.sendPrivateMessage(content)

report.messages[id] = newMessage.id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package me.jakejmattson.modmail.services

import dev.kord.common.kColor
import dev.kord.core.behavior.channel.createMessage
import dev.kord.core.entity.Guild
import dev.kord.core.entity.User
Expand All @@ -11,6 +12,7 @@ import me.jakejmattson.discordkt.commands.CommandEvent
import me.jakejmattson.discordkt.extensions.addField
import me.jakejmattson.discordkt.extensions.pfpUrl
import me.jakejmattson.discordkt.extensions.thumbnail
import java.awt.Color

@Service
class LoggingService(discord: Discord, private val config: Configuration) {
Expand Down Expand Up @@ -89,10 +91,10 @@ class LoggingService(discord: Discord, private val config: Configuration) {
}
}

addField("Edit Detected!", "The user has performed a message edit in <#${report.channelId}>.")

color = Color.white.kColor
thumbnail(report.liveMember(kord)?.pfpUrl ?: "")
addField("Edit Detected!", "<@!${report.userId}> edited a message.")
createFields("Old Content", old)
createFields("New Content", new)
thumbnail(report.liveMember(kord)?.pfpUrl ?: "")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class MacroService {

private fun MutableList<Macro>.hasMacro(name: String) = this.any { it.name.equals(name, true) }

fun getGuildMacros(guild: Guild) = macroMap.getOrPut(guild.id.toString()) { arrayListOf() }
fun getGuildMacros(guild: Guild) = macroMap.getOrPut(guild.id.toString()) { mutableListOf() }

fun addMacro(name: String, message: String, guild: Guild): Boolean {
val macroList = getGuildMacros(guild)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import dev.kord.common.entity.MessageType
import dev.kord.common.entity.Snowflake
import dev.kord.common.kColor
import dev.kord.core.Kord
import dev.kord.core.behavior.*
import dev.kord.core.behavior.UserBehavior
import dev.kord.core.behavior.channel.MessageChannelBehavior
import dev.kord.core.behavior.channel.createEmbed
import dev.kord.core.behavior.channel.createMessage
import dev.kord.core.behavior.createTextChannel
import dev.kord.core.entity.*
import dev.kord.core.entity.channel.Category
import dev.kord.core.entity.channel.MessageChannel
import dev.kord.core.entity.channel.TextChannel
import dev.kord.rest.Image
import dev.kord.rest.builder.message.EmbedBuilder
import dev.kord.rest.builder.message.create.allowedMentions
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.count
Expand Down Expand Up @@ -164,7 +164,7 @@ private suspend fun sendReportClosedEmbed(report: Report, kord: Kord) {
val guild = kord.getGuild(report.guildId) ?: return
val user = kord.getUser(report.userId) ?: return

val builder: EmbedBuilder.() -> Unit = {
user.sendPrivateMessage {
color = Color.RED.kColor

field {
Expand All @@ -177,8 +177,4 @@ private suspend fun sendReportClosedEmbed(report: Report, kord: Kord) {
icon = guild.getIconUrl(Image.Format.PNG)
}
}

user.sendPrivateMessage {
builder(this)
}
}

0 comments on commit 3cfe125

Please sign in to comment.