Added Names holding object to Addons.
This commit is contained in:
parent
a70f22d402
commit
881bd716b0
5 changed files with 29 additions and 26 deletions
|
@ -48,9 +48,7 @@ class Addons(private val props: Properties) {
|
||||||
|
|
||||||
val commands: MutableList<AbstractCommand> = mutableListOf()
|
val commands: MutableList<AbstractCommand> = mutableListOf()
|
||||||
val modules: MutableList<AbstractModule> = mutableListOf()
|
val modules: MutableList<AbstractModule> = mutableListOf()
|
||||||
val modulesNames: MutableList<String> = mutableListOf()
|
val names = Names
|
||||||
val names: MutableList<String> = mutableListOf()
|
|
||||||
val ops: MutableList<String> = mutableListOf()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a module with properties.
|
* Add a module with properties.
|
||||||
|
@ -66,8 +64,8 @@ class Addons(private val props: Properties) {
|
||||||
|
|
||||||
if (isEnabled) {
|
if (isEnabled) {
|
||||||
modules.add(this)
|
modules.add(this)
|
||||||
modulesNames.add(name)
|
names.modules.add(name)
|
||||||
names.addAll(commands)
|
names.commands.addAll(commands)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -88,9 +86,9 @@ class Addons(private val props: Properties) {
|
||||||
commands.add(this)
|
commands.add(this)
|
||||||
if (isVisible) {
|
if (isVisible) {
|
||||||
if (isOpOnly) {
|
if (isOpOnly) {
|
||||||
ops.add(name)
|
names.ops.add(name)
|
||||||
} else {
|
} 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() {
|
fun sort() {
|
||||||
names.sort()
|
modules.sort()
|
||||||
|
commands.sort()
|
||||||
ops.sort()
|
ops.sort()
|
||||||
modulesNames.sort()
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,10 +143,10 @@ class Mobibot(nickname: String, val channel: String, logsDirPath: String, p: Pro
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
event.sendMessage("The commands are:")
|
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)) {
|
if (isChannelOp(channel, event)) {
|
||||||
event.sendMessage("The op commands are:")
|
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(Ignore())
|
||||||
addons.add(LinksMgr())
|
addons.add(LinksMgr())
|
||||||
addons.add(Me())
|
addons.add(Me())
|
||||||
addons.add(Modules(addons))
|
addons.add(Modules(addons.names.modules))
|
||||||
addons.add(Msg())
|
addons.add(Msg())
|
||||||
addons.add(Nick())
|
addons.add(Nick())
|
||||||
addons.add(Posting())
|
addons.add(Posting())
|
||||||
|
@ -435,7 +435,7 @@ class Mobibot(nickname: String, val channel: String, logsDirPath: String, p: Pro
|
||||||
addons.add(War())
|
addons.add(War())
|
||||||
|
|
||||||
// Sort the addons
|
// Sort the addons
|
||||||
addons.sort()
|
addons.names.sort()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,13 +32,12 @@
|
||||||
|
|
||||||
package net.thauvin.erik.mobibot.commands
|
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.helpFormat
|
||||||
import net.thauvin.erik.mobibot.Utils.isChannelOp
|
import net.thauvin.erik.mobibot.Utils.isChannelOp
|
||||||
import net.thauvin.erik.mobibot.Utils.sendList
|
import net.thauvin.erik.mobibot.Utils.sendList
|
||||||
import org.pircbotx.hooks.types.GenericMessageEvent
|
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 name = "modules"
|
||||||
override val help = listOf("To view a list of enabled modules:", helpFormat("%c $name"))
|
override val help = listOf("To view a list of enabled modules:", helpFormat("%c $name"))
|
||||||
override val isOpOnly = true
|
override val isOpOnly = true
|
||||||
|
@ -47,11 +46,11 @@ class Modules(private val addons: Addons) : AbstractCommand() {
|
||||||
|
|
||||||
override fun commandResponse(channel: String, args: String, event: GenericMessageEvent) {
|
override fun commandResponse(channel: String, args: String, event: GenericMessageEvent) {
|
||||||
if (isChannelOp(channel, event)) {
|
if (isChannelOp(channel, event)) {
|
||||||
if (addons.modulesNames.isEmpty()) {
|
if (modules.isEmpty()) {
|
||||||
event.respondPrivateMessage("There are no enabled modules.")
|
event.respondPrivateMessage("There are no enabled modules.")
|
||||||
} else {
|
} else {
|
||||||
event.respondPrivateMessage("The enabled modules are: ")
|
event.respondPrivateMessage("The enabled modules are: ")
|
||||||
event.sendList(addons.modulesNames, 7, isIndent = true)
|
event.sendList(modules, 7, isIndent = true)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
helpResponse(channel, args, event)
|
helpResponse(channel, args, event)
|
||||||
|
|
|
@ -67,7 +67,7 @@ class AddonsTest {
|
||||||
addons.add(Dice())
|
addons.add(Dice())
|
||||||
addons.add(Lookup())
|
addons.add(Lookup())
|
||||||
assertThat(addons.modules.size, "modules = 2").isEqualTo(2)
|
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
|
// Commands
|
||||||
addons.add(View())
|
addons.add(View())
|
||||||
|
@ -79,9 +79,9 @@ class AddonsTest {
|
||||||
addons.add(Ignore())
|
addons.add(Ignore())
|
||||||
assertThat(addons.commands.size, "commands = 3").isEqualTo(3)
|
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",
|
"joke",
|
||||||
"rock",
|
"rock",
|
||||||
"paper",
|
"paper",
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#Generated by the Semver Plugin for Gradle
|
#Generated by the Semver Plugin for Gradle
|
||||||
#Sat Jan 08 23:07:31 PST 2022
|
#Tue Jan 18 10:02:08 PST 2022
|
||||||
version.buildmeta=2440
|
version.buildmeta=2450
|
||||||
version.major=0
|
version.major=0
|
||||||
version.minor=8
|
version.minor=8
|
||||||
version.patch=0
|
version.patch=0
|
||||||
version.prerelease=beta
|
version.prerelease=beta
|
||||||
version.project=mobibot
|
version.project=mobibot
|
||||||
version.semver=0.8.0-beta+2440
|
version.semver=0.8.0-beta+2450
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue