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:",
helpFormat("%c $name $me")
)
private val helpOp = listOf(
"To ignore a link posted to the channel:",
helpFormat("https://www.foo.bar " + bold("%n"), false),
"To add/remove nicks from the ignored list:",
helpFormat("%c $name <nick> [<nick> ...]")
private val helpOp = help.plus(
arrayOf("To add/remove nicks from the ignored list:", helpFormat("%c $name <nick> [<nick> ...]"))
)
override val isOp = false

View file

@ -37,7 +37,7 @@ import net.thauvin.erik.mobibot.Utils.helpFormat
class Nick(bot: Mobibot) : AbstractCommand(bot) {
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 isPublic = true
override val isVisible = true

View file

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

View file

@ -114,7 +114,9 @@ object EntriesMgr {
output.output(rss, fw)
}
} 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 {
commands.add(CRYPTO_CMD)
help.add("To retrieve a cryptocurrency's market price:")
help.add(helpFormat("%c $CRYPTO_CMD <symbol> [<currency>]"))
help.add("For example:")
help.add(helpFormat("%c $CRYPTO_CMD BTC"))
help.add(helpFormat("%c $CRYPTO_CMD ETH EUR"))
help.add(helpFormat("%c $CRYPTO_CMD ETH2 GPB"))
with(help) {
add("To retrieve a cryptocurrency's market price:")
add(helpFormat("%c $CRYPTO_CMD <symbol> [<currency>]"))
add("For example:")
add(helpFormat("%c $CRYPTO_CMD BTC"))
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> {
@Suppress("MagicNumber")
return Pair(Random.nextInt(1, 7), Random.nextInt(1, 7))
return Random.nextInt(1, 7) to Random.nextInt(1, 7)
}
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/).
*/
override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) {
try {
bot.send(cyan(randomJoke().msg))
} catch (e: ModuleException) {
if (bot.logger.isWarnEnabled) bot.logger.warn(e.debugMessage, e)
bot.send(sender, e.message, isPrivate)
with(bot) {
try {
send(cyan(randomJoke().msg))
} catch (e: ModuleException) {
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) {
/**
* 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) {
with(bot) {
@ -163,27 +163,52 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
add(ErrorMessage(INVALID_SYMBOL))
return messages
}
add(
PublicMessage(
"Symbol: " + unescapeXml(quote.getString("01. symbol"))
+ " [" + unescapeXml(symbolInfo.getString("2. name")) + ']'
)
)
add(PublicMessage(" Price: " + unescapeXml(quote.getString("05. price"))))
add(PublicMessage(" Previous: " + unescapeXml(quote.getString("08. previous close"))))
add(NoticeMessage(" Open: " + unescapeXml(quote.getString("02. open"))))
add(NoticeMessage(" High: " + unescapeXml(quote.getString("03. high"))))
add(NoticeMessage(" Low: " + unescapeXml(quote.getString("04. low"))))
add(NoticeMessage(" Volume: " + unescapeXml(quote.getString("06. volume"))))
@Suppress("MagicNumber")
val pad = 10
add(
NoticeMessage(
" Latest: " + unescapeXml(quote.getString("07. latest trading day"))
PublicMessage(
"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(
NoticeMessage(
" Change: " + unescapeXml(quote.getString("09. change")) + " ["
+ unescapeXml(quote.getString("10. change percent")) + ']'
"Change:".padEnd(pad).prependIndent()
+ 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) {
if (args.isNotBlank()) {
try {
val messages = getWeather(args, properties[OWM_API_KEY_PROP])
if (messages[0].isError) {
helpResponse(sender, isPrivate)
} else {
for (msg in messages) {
bot.send(sender, msg)
with(bot) {
try {
val messages = getWeather(args, properties[OWM_API_KEY_PROP])
if (messages[0].isError) {
helpResponse(sender, isPrivate)
} else {
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 {
helpResponse(sender, isPrivate)
@ -174,7 +176,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
}
}
} 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) {
throw ModuleException("getWeather($query)", "Unable to perform weather lookup.", e)
}
@ -195,11 +197,13 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
init {
commands.add(WEATHER_CMD)
help.add("To display weather information:")
help.add(helpFormat("%c $WEATHER_CMD <city> [, <country code>]"))
help.add("For example:")
help.add(helpFormat("%c $WEATHER_CMD paris, fr"))
help.add("The default ISO 3166 country code is ${bold("US")}. Zip codes supported in most countries.")
with(help) {
add("To display weather information:")
add(helpFormat("%c $WEATHER_CMD <city> [, <country code>]"))
add("For example:")
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)
}
}

View file

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