diff --git a/build.gradle.kts b/build.gradle.kts index 9efda1c..cd659bf 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -14,9 +14,9 @@ application { tasks.withType { manifest { attributes( - mapOf( - "Main-Class" to botMainClass - ) + mapOf( + "Main-Class" to botMainClass + ) ) } } @@ -47,4 +47,4 @@ dependencies { tasks.withType { kotlinOptions.jvmTarget = "1.8" -} \ No newline at end of file +} diff --git a/src/main/kotlin/moe/kageru/kagebot/Globals.kt b/src/main/kotlin/moe/kageru/kagebot/Globals.kt index 89eaa19..fecccf2 100644 --- a/src/main/kotlin/moe/kageru/kagebot/Globals.kt +++ b/src/main/kotlin/moe/kageru/kagebot/Globals.kt @@ -16,4 +16,4 @@ object Globals { lateinit var systemConfig: SystemConfig lateinit var features: Features var commandCounter: AtomicInteger = AtomicInteger(0) -} \ No newline at end of file +} diff --git a/src/main/kotlin/moe/kageru/kagebot/Log.kt b/src/main/kotlin/moe/kageru/kagebot/Log.kt index c8cf4a0..937d4e5 100644 --- a/src/main/kotlin/moe/kageru/kagebot/Log.kt +++ b/src/main/kotlin/moe/kageru/kagebot/Log.kt @@ -2,7 +2,10 @@ package moe.kageru.kagebot import java.time.ZoneId import java.time.format.DateTimeFormatter -import java.util.logging.* +import java.util.logging.FileHandler +import java.util.logging.Formatter +import java.util.logging.LogRecord +import java.util.logging.Logger object Log { val log: Logger by lazy { @@ -17,9 +20,9 @@ object Log { private class LogFormatter : Formatter() { private val timeFormatter: DateTimeFormatter = - DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault()) + DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss").withZone(ZoneId.systemDefault()) override fun format(record: LogRecord): String { return "[${record.level}] ${timeFormatter.format(record.instant)}: ${record.message}\n" } -} \ No newline at end of file +} diff --git a/src/main/kotlin/moe/kageru/kagebot/Util.kt b/src/main/kotlin/moe/kageru/kagebot/Util.kt index 8fdbcd1..8098852 100644 --- a/src/main/kotlin/moe/kageru/kagebot/Util.kt +++ b/src/main/kotlin/moe/kageru/kagebot/Util.kt @@ -10,7 +10,7 @@ import org.javacord.api.entity.permission.Role import org.javacord.api.entity.user.User import org.javacord.api.event.message.MessageCreateEvent import java.awt.Color -import java.util.* +import java.util.Optional import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletionException @@ -23,7 +23,7 @@ object Util { * Mimics the behavior of [Optional.ifPresent], but returns null if the optional is empty, * allowing easier fallback behavior via Kotlin’s ?: operator. */ - inline fun Optional.ifNotEmpty(op: (T) -> R): R? { + private inline fun Optional.ifNotEmpty(op: (T) -> R): R? { if (this.isPresent) { return op(this.get()) } @@ -114,4 +114,4 @@ object Util { Globals.server.getMemberById(id).orElse(null) } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/moe/kageru/kagebot/command/MessageActions.kt b/src/main/kotlin/moe/kageru/kagebot/command/MessageActions.kt index e0caa35..11cc48b 100644 --- a/src/main/kotlin/moe/kageru/kagebot/command/MessageActions.kt +++ b/src/main/kotlin/moe/kageru/kagebot/command/MessageActions.kt @@ -34,4 +34,3 @@ class MessageActions(rawActions: RawMessageActions) { } } } - diff --git a/src/main/kotlin/moe/kageru/kagebot/command/MessageRedirect.kt b/src/main/kotlin/moe/kageru/kagebot/command/MessageRedirect.kt index 012818c..ba059e3 100644 --- a/src/main/kotlin/moe/kageru/kagebot/command/MessageRedirect.kt +++ b/src/main/kotlin/moe/kageru/kagebot/command/MessageRedirect.kt @@ -38,4 +38,4 @@ internal class MessageRedirect(rawRedirect: RawRedirect) { log.warning("Could not redirect message to channel $target") } } -} \ No newline at end of file +} diff --git a/src/main/kotlin/moe/kageru/kagebot/command/RoleAssignment.kt b/src/main/kotlin/moe/kageru/kagebot/command/RoleAssignment.kt index f713e37..3c51203 100644 --- a/src/main/kotlin/moe/kageru/kagebot/command/RoleAssignment.kt +++ b/src/main/kotlin/moe/kageru/kagebot/command/RoleAssignment.kt @@ -14,4 +14,4 @@ internal class RoleAssignment(rawAssignment: RawAssignment) { Util.userFromMessage(message)?.addRole(role, "Requested via command.") ?: log.warning("Could not find user ${message.messageAuthor.name} for role assign") } -} \ No newline at end of file +} diff --git a/src/main/kotlin/moe/kageru/kagebot/config/RawCommands.kt b/src/main/kotlin/moe/kageru/kagebot/config/RawCommands.kt index dbff5ee..062c7d0 100644 --- a/src/main/kotlin/moe/kageru/kagebot/config/RawCommands.kt +++ b/src/main/kotlin/moe/kageru/kagebot/config/RawCommands.kt @@ -7,7 +7,8 @@ class RawCommand( val response: String?, val matchType: String?, val permissions: RawPermissions?, - @SerializedName("action") val actions: RawMessageActions?, + @SerializedName("action") + val actions: RawMessageActions?, val embed: List?, val feature: String? ) @@ -15,4 +16,4 @@ class RawCommand( class RawPermissions(val hasOneOf: List?, val hasNoneOf: List?, val onlyDM: Boolean) class RawMessageActions(val delete: Boolean, val redirect: RawRedirect?, val assign: RawAssignment?) class RawRedirect(val target: String?, val anonymous: Boolean) -class RawAssignment(var role: String?) \ No newline at end of file +class RawAssignment(var role: String?) diff --git a/src/main/kotlin/moe/kageru/kagebot/config/RawConfig.kt b/src/main/kotlin/moe/kageru/kagebot/config/RawConfig.kt index 568f985..a32a9f7 100644 --- a/src/main/kotlin/moe/kageru/kagebot/config/RawConfig.kt +++ b/src/main/kotlin/moe/kageru/kagebot/config/RawConfig.kt @@ -7,13 +7,15 @@ import java.io.File class RawConfig( val system: RawSystemConfig?, val localization: RawLocalization?, - @SerializedName("command") val commands: List?, - @SerializedName("feature") val features: RawFeatures? + @SerializedName("command") + val commands: List?, + @SerializedName("feature") + val features: RawFeatures? ) { companion object { - const val DEFAULT_CONFIG_PATH = "config.toml" + private const val DEFAULT_CONFIG_PATH = "config.toml" - fun readFromString(tomlContent: String) = Toml().read(tomlContent).to(RawConfig::class.java) + fun readFromString(tomlContent: String): RawConfig = Toml().read(tomlContent).to(RawConfig::class.java) fun read(path: String = DEFAULT_CONFIG_PATH): RawConfig { val toml: Toml = Toml().read(run { diff --git a/src/main/kotlin/moe/kageru/kagebot/features/DebugFeature.kt b/src/main/kotlin/moe/kageru/kagebot/features/DebugFeature.kt index ce632aa..a9e900f 100644 --- a/src/main/kotlin/moe/kageru/kagebot/features/DebugFeature.kt +++ b/src/main/kotlin/moe/kageru/kagebot/features/DebugFeature.kt @@ -62,4 +62,4 @@ class DebugFeature : MessageFeature() { private fun getOsInfo() = "Running on ${System.getProperty("os.name")} " + "${System.getProperty("os.version")}-${System.getProperty("os.arch")}.\n" -} \ No newline at end of file +} diff --git a/src/main/kotlin/moe/kageru/kagebot/features/Features.kt b/src/main/kotlin/moe/kageru/kagebot/features/Features.kt index 8949ff0..f0407e3 100644 --- a/src/main/kotlin/moe/kageru/kagebot/features/Features.kt +++ b/src/main/kotlin/moe/kageru/kagebot/features/Features.kt @@ -12,4 +12,4 @@ class Features(val welcome: WelcomeFeature?, debug: DebugFeature, help: HelpFeat private val featureMap = mapOf("help" to help, "debug" to debug, "welcome" to welcome) fun findByString(feature: String) = featureMap[feature] -} \ No newline at end of file +} diff --git a/src/main/kotlin/moe/kageru/kagebot/features/HelpFeature.kt b/src/main/kotlin/moe/kageru/kagebot/features/HelpFeature.kt index 268771c..a2d9e38 100644 --- a/src/main/kotlin/moe/kageru/kagebot/features/HelpFeature.kt +++ b/src/main/kotlin/moe/kageru/kagebot/features/HelpFeature.kt @@ -17,4 +17,4 @@ class HelpFeature : MessageFeature() { private fun listCommands(message: MessageCreateEvent) = Globals.commands .filter { it.matchType == MatchType.PREFIX && it.isAllowed(message) } .map { it.trigger } - .joinToString("\n") \ No newline at end of file + .joinToString("\n") diff --git a/src/main/kotlin/moe/kageru/kagebot/features/MessageFeature.kt b/src/main/kotlin/moe/kageru/kagebot/features/MessageFeature.kt index 83914f5..754bf61 100644 --- a/src/main/kotlin/moe/kageru/kagebot/features/MessageFeature.kt +++ b/src/main/kotlin/moe/kageru/kagebot/features/MessageFeature.kt @@ -8,4 +8,4 @@ abstract class MessageFeature { } internal abstract fun handleInternal(message: MessageCreateEvent) -} \ No newline at end of file +} diff --git a/src/main/kotlin/moe/kageru/kagebot/features/WelcomeFeature.kt b/src/main/kotlin/moe/kageru/kagebot/features/WelcomeFeature.kt index 115d19c..d72847e 100644 --- a/src/main/kotlin/moe/kageru/kagebot/features/WelcomeFeature.kt +++ b/src/main/kotlin/moe/kageru/kagebot/features/WelcomeFeature.kt @@ -22,4 +22,4 @@ class WelcomeFeature(rawWelcome: RawWelcomeFeature) : MessageFeature() { Util.findChannel(it) } val fallbackMessage: String? = rawWelcome.fallbackMessage -} \ No newline at end of file +} diff --git a/src/test/kotlin/moe/kageru/kagebot/ConfigTest.kt b/src/test/kotlin/moe/kageru/kagebot/ConfigTest.kt index a24c06d..097b867 100644 --- a/src/test/kotlin/moe/kageru/kagebot/ConfigTest.kt +++ b/src/test/kotlin/moe/kageru/kagebot/ConfigTest.kt @@ -11,4 +11,4 @@ class ConfigTest : StringSpec({ Globals.systemConfig shouldNotBe null Globals.commands.size shouldBe 2 } -}) \ No newline at end of file +}) diff --git a/src/test/kotlin/moe/kageru/kagebot/TestUtil.kt b/src/test/kotlin/moe/kageru/kagebot/TestUtil.kt index 0f7d64d..ed0fbab 100644 --- a/src/test/kotlin/moe/kageru/kagebot/TestUtil.kt +++ b/src/test/kotlin/moe/kageru/kagebot/TestUtil.kt @@ -15,7 +15,7 @@ import org.javacord.api.entity.message.embed.EmbedBuilder import org.javacord.api.entity.user.User import org.javacord.api.event.message.MessageCreateEvent import org.javacord.core.entity.message.embed.EmbedBuilderDelegateImpl -import java.util.* +import java.util.Optional object TestUtil { fun mockMessage( @@ -119,4 +119,4 @@ object TestUtil { replyString shouldNotContain string } } -} \ No newline at end of file +} diff --git a/src/test/kotlin/moe/kageru/kagebot/command/CommandTest.kt b/src/test/kotlin/moe/kageru/kagebot/command/CommandTest.kt index 73bae6c..40ffa1c 100644 --- a/src/test/kotlin/moe/kageru/kagebot/command/CommandTest.kt +++ b/src/test/kotlin/moe/kageru/kagebot/command/CommandTest.kt @@ -276,4 +276,4 @@ class CommandTest : StringSpec({ roles shouldBe mutableListOf(Util.findRole("testrole")) } } -}) \ No newline at end of file +}) diff --git a/src/test/kotlin/moe/kageru/kagebot/features/DebugFeatureTest.kt b/src/test/kotlin/moe/kageru/kagebot/features/DebugFeatureTest.kt index 4e33c83..0b434a0 100644 --- a/src/test/kotlin/moe/kageru/kagebot/features/DebugFeatureTest.kt +++ b/src/test/kotlin/moe/kageru/kagebot/features/DebugFeatureTest.kt @@ -29,4 +29,4 @@ class DebugFeatureTest : StringSpec({ DebugFeature().handle(message) verify(exactly = 1) { message.channel.sendMessage(any()) } } -}) \ No newline at end of file +})