Added Names holding object to Addons.

This commit is contained in:
Erik C. Thauvin 2022-01-18 10:03:50 -08:00
parent a70f22d402
commit 881bd716b0
5 changed files with 29 additions and 26 deletions

View file

@ -48,9 +48,7 @@ class Addons(private val props: Properties) {
val commands: MutableList<AbstractCommand> = mutableListOf()
val modules: MutableList<AbstractModule> = mutableListOf()
val modulesNames: MutableList<String> = mutableListOf()
val names: MutableList<String> = mutableListOf()
val ops: MutableList<String> = 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.
*/
object Names {
val modules: MutableList<String> = mutableListOf()
val commands: MutableList<String> = mutableListOf()
val ops: MutableList<String> = mutableListOf()
fun sort() {
names.sort()
modules.sort()
commands.sort()
ops.sort()
modulesNames.sort()
}
}
}

View file

@ -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()
}
}

View file

@ -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<String>) : 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)

View file

@ -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",

View file

@ -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