This commit is contained in:
Erik C. Thauvin 2021-07-30 01:26:12 -07:00
parent 1535290290
commit af9546e3d1
10 changed files with 94 additions and 58 deletions

View file

@ -54,11 +54,8 @@ class Ignore(bot: Mobibot) : AbstractCommand(bot) {
"To toggle your ignore status:", "To toggle your ignore status:",
helpFormat("%c $name $me") helpFormat("%c $name $me")
) )
private val helpOp = listOf( private val helpOp = help.plus(
"To ignore a link posted to the channel:", arrayOf("To add/remove nicks from the ignored list:", helpFormat("%c $name <nick> [<nick> ...]"))
helpFormat("https://www.foo.bar " + bold("%n"), false),
"To add/remove nicks from the ignored list:",
helpFormat("%c $name <nick> [<nick> ...]")
) )
override val isOp = false override val isOp = false

View file

@ -37,7 +37,7 @@ import net.thauvin.erik.mobibot.Utils.helpFormat
class Nick(bot: Mobibot) : AbstractCommand(bot) { class Nick(bot: Mobibot) : AbstractCommand(bot) {
override val name = "nick" override val name = "nick"
override val help = listOf("To change the bot's nickname:", helpFormat("%c $name <nick>")) override val help = listOf("To change the bot's nickname:", helpFormat("%c $name <new_nick>"))
override val isOp = true override val isOp = true
override val isPublic = true override val isPublic = true
override val isVisible = true override val isVisible = true

View file

@ -51,15 +51,17 @@ class Users(bot: Mobibot) : AbstractCommand(bot) {
isPrivate: Boolean isPrivate: Boolean
) { ) {
val nicks = mutableListOf<String>() val nicks = mutableListOf<String>()
bot.getUsers(bot.channel).forEach { user -> with(bot) {
if (bot.isOp(user.nick)) { getUsers(channel).forEach { user ->
nicks.add("@${user.nick}") if (isOp(user.nick)) {
} else { nicks.add("@${user.nick}")
nicks.add(user.nick) } else {
nicks.add(user.nick)
}
} }
}
@Suppress("MagicNumber") @Suppress("MagicNumber")
bot.sendList(sender, nicks.sorted(), 8, isPrivate, isIndent = true) sendList(sender, nicks.sorted(), 8, isPrivate, isIndent = true)
}
} }
} }

View file

@ -114,7 +114,9 @@ object EntriesMgr {
output.output(rss, fw) output.output(rss, fw)
} }
} else { } else {
bot.logger.warn("Unable to generate the backlogs feed. No property configured.") if (bot.logger.isErrorEnabled) {
bot.logger.warn("Unable to generate the backlogs feed. No property configured.")
}
} }
} }

View file

@ -87,11 +87,13 @@ class CryptoPrices(bot: Mobibot) : ThreadedModule(bot) {
init { init {
commands.add(CRYPTO_CMD) commands.add(CRYPTO_CMD)
help.add("To retrieve a cryptocurrency's market price:") with(help) {
help.add(helpFormat("%c $CRYPTO_CMD <symbol> [<currency>]")) add("To retrieve a cryptocurrency's market price:")
help.add("For example:") add(helpFormat("%c $CRYPTO_CMD <symbol> [<currency>]"))
help.add(helpFormat("%c $CRYPTO_CMD BTC")) add("For example:")
help.add(helpFormat("%c $CRYPTO_CMD ETH EUR")) add(helpFormat("%c $CRYPTO_CMD BTC"))
help.add(helpFormat("%c $CRYPTO_CMD ETH2 GPB")) add(helpFormat("%c $CRYPTO_CMD ETH EUR"))
add(helpFormat("%c $CRYPTO_CMD ETH2 GPB"))
}
} }
} }

View file

@ -75,7 +75,7 @@ class Dice(bot: Mobibot) : AbstractModule(bot) {
private fun roll(): Pair<Int, Int> { private fun roll(): Pair<Int, Int> {
@Suppress("MagicNumber") @Suppress("MagicNumber")
return Pair(Random.nextInt(1, 7), Random.nextInt(1, 7)) return Random.nextInt(1, 7) to Random.nextInt(1, 7)
} }
companion object { companion object {

View file

@ -59,11 +59,13 @@ class Joke(bot: Mobibot) : ThreadedModule(bot) {
* Returns a random joke from [The Internet Chuck Norris Database](http://www.icndb.com/). * Returns a random joke from [The Internet Chuck Norris Database](http://www.icndb.com/).
*/ */
override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) { override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) {
try { with(bot) {
bot.send(cyan(randomJoke().msg)) try {
} catch (e: ModuleException) { send(cyan(randomJoke().msg))
if (bot.logger.isWarnEnabled) bot.logger.warn(e.debugMessage, e) } catch (e: ModuleException) {
bot.send(sender, e.message, isPrivate) if (logger.isWarnEnabled) logger.warn(e.debugMessage, e)
send(sender, e.message, isPrivate)
}
} }
} }

View file

@ -51,7 +51,7 @@ import java.net.URL
*/ */
class StockQuote(bot: Mobibot) : ThreadedModule(bot) { class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
/** /**
* Returns the specified stock quote from Alpha Avantage. * Returns the specified stock quote from Alpha Vantage.
*/ */
override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) { override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) {
with(bot) { with(bot) {
@ -163,27 +163,52 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
add(ErrorMessage(INVALID_SYMBOL)) add(ErrorMessage(INVALID_SYMBOL))
return messages return messages
} }
add( add(
PublicMessage( PublicMessage(
"Symbol: " + unescapeXml(quote.getString("01. symbol")) "Symbol: " + unescapeXml(quote.getString("01. symbol"))
+ " [" + unescapeXml(symbolInfo.getString("2. name")) + ']' + " [" + unescapeXml(symbolInfo.getString("2. name")) + ']'
) )
) )
add(PublicMessage(" Price: " + unescapeXml(quote.getString("05. price"))))
add(PublicMessage(" Previous: " + unescapeXml(quote.getString("08. previous close")))) @Suppress("MagicNumber")
add(NoticeMessage(" Open: " + unescapeXml(quote.getString("02. open")))) val pad = 10
add(NoticeMessage(" High: " + unescapeXml(quote.getString("03. high"))))
add(NoticeMessage(" Low: " + unescapeXml(quote.getString("04. low"))))
add(NoticeMessage(" Volume: " + unescapeXml(quote.getString("06. volume"))))
add( add(
NoticeMessage( PublicMessage(
" Latest: " + unescapeXml(quote.getString("07. latest trading day")) "Price:".padEnd(pad).prependIndent()
+ unescapeXml(quote.getString("05. price"))
) )
) )
add(
PublicMessage(
"Previous:".padEnd(pad).prependIndent()
+ unescapeXml(quote.getString("08. previous close"))
)
)
val data = arrayOf(
"Open" to "02. open",
"High" to "03. high",
"Low" to "04. low",
"Volume" to "06. volume",
"Latest" to "07. latest trading day"
)
data.forEach {
add(
NoticeMessage(
"${it.first}:".padEnd(pad).prependIndent(),
unescapeXml(quote.getString(it.second))
)
)
}
add( add(
NoticeMessage( NoticeMessage(
" Change: " + unescapeXml(quote.getString("09. change")) + " [" "Change:".padEnd(pad).prependIndent()
+ unescapeXml(quote.getString("10. change percent")) + ']' + unescapeXml(quote.getString("09. change"))
+ " [" + unescapeXml(quote.getString("10. change percent")) + ']'
) )
) )
} }

View file

@ -56,18 +56,20 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
*/ */
override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) { override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) {
if (args.isNotBlank()) { if (args.isNotBlank()) {
try { with(bot) {
val messages = getWeather(args, properties[OWM_API_KEY_PROP]) try {
if (messages[0].isError) { val messages = getWeather(args, properties[OWM_API_KEY_PROP])
helpResponse(sender, isPrivate) if (messages[0].isError) {
} else { helpResponse(sender, isPrivate)
for (msg in messages) { } else {
bot.send(sender, msg) for (msg in messages) {
send(sender, msg)
}
} }
} catch (e: ModuleException) {
if (logger.isDebugEnabled) logger.debug(e.debugMessage, e)
send(e.message)
} }
} catch (e: ModuleException) {
if (bot.logger.isDebugEnabled) bot.logger.debug(e.debugMessage, e)
bot.send(e.message)
} }
} else { } else {
helpResponse(sender, isPrivate) helpResponse(sender, isPrivate)
@ -174,7 +176,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
} }
} }
} catch (e: APIException) { } catch (e: APIException) {
throw ModuleException("getWeather($query)", "Unable to perform weather lookup.", e) throw ModuleException("getWeather($query)", "A weather API error has occurred.", e)
} catch (e: NullPointerException) { } catch (e: NullPointerException) {
throw ModuleException("getWeather($query)", "Unable to perform weather lookup.", e) throw ModuleException("getWeather($query)", "Unable to perform weather lookup.", e)
} }
@ -195,11 +197,13 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
init { init {
commands.add(WEATHER_CMD) commands.add(WEATHER_CMD)
help.add("To display weather information:") with(help) {
help.add(helpFormat("%c $WEATHER_CMD <city> [, <country code>]")) add("To display weather information:")
help.add("For example:") add(helpFormat("%c $WEATHER_CMD <city> [, <country code>]"))
help.add(helpFormat("%c $WEATHER_CMD paris, fr")) add("For example:")
help.add("The default ISO 3166 country code is ${bold("US")}. Zip codes supported in most countries.") add(helpFormat("%c $WEATHER_CMD paris, fr"))
add("The default ISO 3166 country code is ${bold("US")}. Zip codes supported in most countries.")
}
initProperties(OWM_API_KEY_PROP) initProperties(OWM_API_KEY_PROP)
} }
} }

View file

@ -211,10 +211,12 @@ class WorldTime(bot: Mobibot) : AbstractModule(bot) {
override val isPrivateMsgEnabled = true override val isPrivateMsgEnabled = true
init { init {
help.add("To display a country's current date/time:") with(help) {
help.add(helpFormat("%c $TIME_CMD [<country code>]")) add("To display a country's current date/time:")
help.add("For a listing of the supported countries:") add(helpFormat("%c $TIME_CMD [<country code>]"))
help.add(helpFormat("%c $TIME_CMD")) add("For a listing of the supported countries:")
add(helpFormat("%c $TIME_CMD"))
}
commands.add(TIME_CMD) commands.add(TIME_CMD)
} }
} }