diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/Addons.kt b/src/main/kotlin/net/thauvin/erik/mobibot/Addons.kt index 4e95ad0..8ae52a9 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/Addons.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/Addons.kt @@ -48,9 +48,7 @@ class Addons(private val props: Properties) { val commands: MutableList = mutableListOf() val modules: MutableList = mutableListOf() - val modulesNames: MutableList = mutableListOf() - val names: MutableList = mutableListOf() - val ops: MutableList = mutableListOf() + val names = Names /** * Add a module with properties. @@ -66,8 +64,8 @@ class Addons(private val props: Properties) { if (isEnabled) { modules.add(this) - modulesNames.add(name) - names.addAll(commands) + names.modules.add(name) + names.commands.addAll(commands) } } } @@ -88,9 +86,9 @@ class Addons(private val props: Properties) { commands.add(this) if (isVisible) { if (isOpOnly) { - ops.add(name) + names.ops.add(name) } else { - names.add(name) + names.commands.add(name) } } } @@ -150,11 +148,17 @@ class Addons(private val props: Properties) { } /** - * Sort commands and modules names. + * Holds commands and modules names. */ - fun sort() { - names.sort() - ops.sort() - modulesNames.sort() + object Names { + val modules: MutableList = mutableListOf() + val commands: MutableList = mutableListOf() + val ops: MutableList = mutableListOf() + + fun sort() { + modules.sort() + commands.sort() + ops.sort() + } } } diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/Mobibot.kt b/src/main/kotlin/net/thauvin/erik/mobibot/Mobibot.kt index ee6ad12..d8ff578 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/Mobibot.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/Mobibot.kt @@ -143,10 +143,10 @@ class Mobibot(nickname: String, val channel: String, logsDirPath: String, p: Pro ), ) event.sendMessage("The commands are:") - event.sendList(addons.names, 8, isBold = true, isIndent = true) + event.sendList(addons.names.commands, 8, isBold = true, isIndent = true) if (isChannelOp(channel, event)) { event.sendMessage("The op commands are:") - event.sendList(addons.ops, 8, isBold = true, isIndent = true) + event.sendList(addons.names.ops, 8, isBold = true, isIndent = true) } } @@ -401,7 +401,7 @@ class Mobibot(nickname: String, val channel: String, logsDirPath: String, p: Pro addons.add(Ignore()) addons.add(LinksMgr()) addons.add(Me()) - addons.add(Modules(addons)) + addons.add(Modules(addons.names.modules)) addons.add(Msg()) addons.add(Nick()) addons.add(Posting()) @@ -435,7 +435,7 @@ class Mobibot(nickname: String, val channel: String, logsDirPath: String, p: Pro addons.add(War()) // Sort the addons - addons.sort() + addons.names.sort() } } diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/commands/Modules.kt b/src/main/kotlin/net/thauvin/erik/mobibot/commands/Modules.kt index 1ded9ba..82a0b06 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/commands/Modules.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/commands/Modules.kt @@ -32,13 +32,12 @@ package net.thauvin.erik.mobibot.commands -import net.thauvin.erik.mobibot.Addons import net.thauvin.erik.mobibot.Utils.helpFormat import net.thauvin.erik.mobibot.Utils.isChannelOp import net.thauvin.erik.mobibot.Utils.sendList import org.pircbotx.hooks.types.GenericMessageEvent -class Modules(private val addons: Addons) : AbstractCommand() { +class Modules(private val modules: List) : AbstractCommand() { override val name = "modules" override val help = listOf("To view a list of enabled modules:", helpFormat("%c $name")) override val isOpOnly = true @@ -47,11 +46,11 @@ class Modules(private val addons: Addons) : AbstractCommand() { override fun commandResponse(channel: String, args: String, event: GenericMessageEvent) { if (isChannelOp(channel, event)) { - if (addons.modulesNames.isEmpty()) { + if (modules.isEmpty()) { event.respondPrivateMessage("There are no enabled modules.") } else { event.respondPrivateMessage("The enabled modules are: ") - event.sendList(addons.modulesNames, 7, isIndent = true) + event.sendList(modules, 7, isIndent = true) } } else { helpResponse(channel, args, event) diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/AddonsTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/AddonsTest.kt index 54346a9..f03a2c2 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/AddonsTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/AddonsTest.kt @@ -67,7 +67,7 @@ class AddonsTest { addons.add(Dice()) addons.add(Lookup()) assertThat(addons.modules.size, "modules = 2").isEqualTo(2) - assertThat(addons.modulesNames, "module names").containsExactly("Joke", "RockPaperScissors") + assertThat(addons.names.modules, "module names").containsExactly("Joke", "RockPaperScissors") // Commands addons.add(View()) @@ -79,9 +79,9 @@ class AddonsTest { addons.add(Ignore()) assertThat(addons.commands.size, "commands = 3").isEqualTo(3) - assertThat(addons.ops, "ops").containsExactly("cycle") + assertThat(addons.names.ops, "ops names").containsExactly("cycle") - assertThat(addons.names, "names").containsExactly( + assertThat(addons.names.commands, "command names").containsExactly( "joke", "rock", "paper", diff --git a/version.properties b/version.properties index 4aea8d8..e5629eb 100644 --- a/version.properties +++ b/version.properties @@ -1,9 +1,9 @@ #Generated by the Semver Plugin for Gradle -#Sat Jan 08 23:07:31 PST 2022 -version.buildmeta=2440 +#Tue Jan 18 10:02:08 PST 2022 +version.buildmeta=2450 version.major=0 version.minor=8 version.patch=0 version.prerelease=beta version.project=mobibot -version.semver=0.8.0-beta+2440 +version.semver=0.8.0-beta+2450