Added addons.help()
This commit is contained in:
parent
4b52ab8c28
commit
aaecc8a9b4
5 changed files with 28 additions and 44 deletions
|
@ -121,6 +121,23 @@ class Addons {
|
|||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Commands and Modules help.
|
||||
*/
|
||||
fun help(sender: String, topic: String, isOp: Boolean, isPrivate: Boolean): Boolean {
|
||||
for (command in commands) {
|
||||
if (command.isVisible && command.name.startsWith(topic)) {
|
||||
return command.helpResponse(topic, sender, isOp, isPrivate)
|
||||
}
|
||||
}
|
||||
for (module in modules) {
|
||||
if (module.commands.contains(topic)) {
|
||||
return module.helpResponse(sender, isPrivate)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort commands and modules names.
|
||||
*/
|
||||
|
|
|
@ -34,11 +34,11 @@ package net.thauvin.erik.mobibot
|
|||
import net.thauvin.erik.mobibot.PinboardUtils.addPin
|
||||
import net.thauvin.erik.mobibot.PinboardUtils.deletePin
|
||||
import net.thauvin.erik.mobibot.PinboardUtils.updatePin
|
||||
import net.thauvin.erik.mobibot.Utils.buildCmdSyntax
|
||||
import net.thauvin.erik.mobibot.Utils.colorize
|
||||
import net.thauvin.erik.mobibot.Utils.ensureDir
|
||||
import net.thauvin.erik.mobibot.Utils.getIntProperty
|
||||
import net.thauvin.erik.mobibot.Utils.helpFormat
|
||||
import net.thauvin.erik.mobibot.Utils.buildCmdSyntax
|
||||
import net.thauvin.erik.mobibot.Utils.isoLocalDate
|
||||
import net.thauvin.erik.mobibot.Utils.today
|
||||
import net.thauvin.erik.mobibot.commands.AddLog
|
||||
|
@ -234,18 +234,6 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds with the commands help, if any.
|
||||
*/
|
||||
private fun helpCommands(sender: String, topic: String, isPrivate: Boolean): Boolean {
|
||||
for (command in addons.commands) {
|
||||
if (command.isVisible && command.name.startsWith(topic)) {
|
||||
return command.helpResponse(topic, sender, isOp(sender), isPrivate)
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds with the default help.
|
||||
*/
|
||||
|
@ -265,38 +253,14 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds with the modules help, if any.
|
||||
*/
|
||||
private fun helpModules(sender: String, topic: String, isPrivate: Boolean): Boolean {
|
||||
for (module in addons.modules) {
|
||||
for (cmd in module.commands) {
|
||||
if (topic == cmd) {
|
||||
module.helpResponse(sender, isPrivate)
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Responds with the default, commands or modules help.
|
||||
*/
|
||||
private fun helpResponse(sender: String, topic: String, isPrivate: Boolean) {
|
||||
val isOp = isOp(sender)
|
||||
if (topic.isBlank()) {
|
||||
if (topic.isBlank() || !addons.help(sender, topic.toLowerCase().trim(), isOp, isPrivate)) {
|
||||
helpDefault(sender, isOp, isPrivate)
|
||||
} else {
|
||||
// Command, Modules or Default
|
||||
if (!helpCommands(sender, topic, isPrivate) && !helpModules(
|
||||
sender,
|
||||
topic.toLowerCase().trim(),
|
||||
isPrivate
|
||||
)
|
||||
) {
|
||||
helpDefault(sender, isOp, isPrivate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -74,10 +74,11 @@ abstract class AbstractModule(val bot: Mobibot) {
|
|||
/**
|
||||
* Responds with the module's help.
|
||||
*/
|
||||
open fun helpResponse(sender: String, isPrivate: Boolean) {
|
||||
open fun helpResponse(sender: String, isPrivate: Boolean) : Boolean {
|
||||
for (h in help) {
|
||||
bot.send(sender, Utils.buildCmdSyntax(h, bot.nick, isPrivateMsgEnabled && isPrivate), isPrivate)
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -67,12 +67,12 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
|
|||
* Converts the specified currencies.
|
||||
*/
|
||||
override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) {
|
||||
with(bot) {
|
||||
bot.apply {
|
||||
if (EXCHANGE_RATES.isEmpty()) {
|
||||
try {
|
||||
loadRates()
|
||||
} catch (e: ModuleException) {
|
||||
if (bot.logger.isWarnEnabled) logger.warn(e.debugMessage, e)
|
||||
if (logger.isWarnEnabled) logger.warn(e.debugMessage, e)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -93,8 +93,8 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
|
|||
}
|
||||
}
|
||||
|
||||
override fun helpResponse(sender: String, isPrivate: Boolean) {
|
||||
with(bot) {
|
||||
override fun helpResponse(sender: String, isPrivate: Boolean) : Boolean {
|
||||
bot.apply {
|
||||
if (EXCHANGE_RATES.isEmpty()) {
|
||||
try {
|
||||
loadRates()
|
||||
|
@ -125,6 +125,7 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
|
|||
sendList(sender, ArrayList(EXCHANGE_RATES.keys), 11, isPrivate, isIndent = true)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue