Cleanup.
This commit is contained in:
parent
9f3dc273f0
commit
d6df365e4b
22 changed files with 102 additions and 98 deletions
|
@ -97,8 +97,9 @@ class Addons {
|
|||
return true
|
||||
}
|
||||
}
|
||||
for (module in modules) {
|
||||
if (((isPrivate && module.isPrivateMsgEnabled) || !isPrivate) && module.commands.contains(cmd)) {
|
||||
val mods = if (isPrivate) modules.filter { it.isPrivateMsgEnabled } else modules
|
||||
for (module in mods) {
|
||||
if (module.commands.contains(cmd)) {
|
||||
module.commandResponse(sender, cmd, args, isPrivate)
|
||||
return true
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ class FeedReader(
|
|||
private val url: String
|
||||
) : Runnable {
|
||||
// Maximum number of feed items to display
|
||||
@Suppress("MagicNumber")
|
||||
private val maxItems = 5
|
||||
|
||||
/**
|
||||
|
|
|
@ -207,6 +207,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
}
|
||||
var retries = 0
|
||||
while (retries++ < MAX_RECONNECT && !isConnected) {
|
||||
@Suppress("MagicNumber")
|
||||
sleep(10)
|
||||
try {
|
||||
connect(ircServer, ircPort)
|
||||
|
@ -240,6 +241,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
/**
|
||||
* Responds with the default help.
|
||||
*/
|
||||
@Suppress("MagicNumber")
|
||||
fun helpDefault(sender: String, isOp: Boolean, isPrivate: Boolean) {
|
||||
send(sender, "Type a URL on $channel to post it.", isPrivate)
|
||||
send(sender, "For more information on a specific command, type:", isPrivate)
|
||||
|
@ -305,6 +307,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
if (weblogUrl.isNotBlank()) {
|
||||
version = weblogUrl
|
||||
}
|
||||
@Suppress("MagicNumber")
|
||||
sleep(5)
|
||||
connect()
|
||||
}
|
||||
|
@ -361,6 +364,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
timer.cancel()
|
||||
twitter.shutdown()
|
||||
twitter.notification("$name stopped by $sender on $channel")
|
||||
@Suppress("MagicNumber")
|
||||
sleep(3)
|
||||
quitServer("The Bot Is Out There!")
|
||||
exitProcess(0)
|
||||
|
@ -467,6 +471,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
*/
|
||||
fun sleep(secs: Int) {
|
||||
try {
|
||||
@Suppress("MagicNumber")
|
||||
Thread.sleep(secs * 1000L)
|
||||
} catch (ignore: InterruptedException) {
|
||||
// Do nothing
|
||||
|
|
|
@ -51,6 +51,7 @@ import java.util.stream.Collectors
|
|||
/**
|
||||
* Miscellaneous utilities.
|
||||
*/
|
||||
@Suppress("TooManyFunctions")
|
||||
object Utils {
|
||||
private val searchFlags = arrayOf("%c", "%n")
|
||||
|
||||
|
@ -234,6 +235,7 @@ object Utils {
|
|||
/**
|
||||
* Converts milliseconds to year month week day hour and minutes.
|
||||
*/
|
||||
@Suppress("MagicNumber")
|
||||
@JvmStatic
|
||||
fun uptime(uptime: Long): String {
|
||||
val info = StringBuilder()
|
||||
|
|
|
@ -63,6 +63,7 @@ class AddLog(bot: Mobibot) : AbstractCommand(bot) {
|
|||
return
|
||||
}
|
||||
}
|
||||
@Suppress("MagicNumber")
|
||||
bot.sendList(sender, history, 4, isPrivate, isIndent = true)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import net.thauvin.erik.mobibot.Mobibot
|
|||
import net.thauvin.erik.mobibot.Utils
|
||||
|
||||
class Cycle(bot: Mobibot) : AbstractCommand(bot) {
|
||||
@Suppress("MagicNumber")
|
||||
private val wait = 10
|
||||
override val name = "cycle"
|
||||
override val help = listOf("To have the bot leave the channel and come back:", Utils.helpFormat("%c $name"))
|
||||
|
|
|
@ -140,6 +140,7 @@ class Ignore(bot: Mobibot) : AbstractCommand(bot) {
|
|||
|
||||
if (ignored.size > 0) {
|
||||
bot.send(sender, "The following nicks are ignored:", isPrivate)
|
||||
@Suppress("MagicNumber")
|
||||
bot.sendList(sender, ignored.sorted(), 8, isPrivate, isIndent = true)
|
||||
} else {
|
||||
bot.send(sender, "No one is currently ${Utils.bold("ignored")}.", isPrivate)
|
||||
|
|
|
@ -58,6 +58,7 @@ class Modules(bot: Mobibot) : AbstractCommand(bot) {
|
|||
send(sender, "There are no enabled modules.", isPrivate)
|
||||
} else {
|
||||
send(sender, "The enabled modules are: ", isPrivate)
|
||||
@Suppress("MagicNumber")
|
||||
sendList(sender, modulesNames, 7, isPrivate, isIndent = true)
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -60,6 +60,7 @@ class Recap(bot: Mobibot) : AbstractCommand(bot) {
|
|||
Utils.utcDateTime(LocalDateTime.now(Clock.systemUTC()))
|
||||
+ " - $sender" + (if (isAction) " " else ": ") + message
|
||||
)
|
||||
@Suppress("MagicNumber")
|
||||
if (recaps.size > 10) {
|
||||
recaps.removeAt(0)
|
||||
}
|
||||
|
|
|
@ -62,6 +62,7 @@ class Users(bot: Mobibot) : AbstractCommand(bot) {
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
bot.sendList(sender, nicks.sorted(), 8, isPrivate, isIndent = true)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -65,6 +65,7 @@ class Comment(bot: Mobibot) : AbstractCommand(bot) {
|
|||
isOp: Boolean,
|
||||
isPrivate: Boolean
|
||||
) {
|
||||
@Suppress("MagicNumber")
|
||||
val cmds = args.substring(1).split("[.:]".toRegex(), 3)
|
||||
val index = cmds[0].toInt() - 1
|
||||
|
||||
|
|
|
@ -40,6 +40,7 @@ import net.thauvin.erik.mobibot.entries.EntriesUtils
|
|||
import net.thauvin.erik.mobibot.entries.EntryLink
|
||||
|
||||
class View(bot: Mobibot) : AbstractCommand(bot) {
|
||||
@Suppress("MagicNumber")
|
||||
private val maxEntries = 8
|
||||
override val name = VIEW_CMD
|
||||
override val help = listOf(
|
||||
|
|
|
@ -53,9 +53,11 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) {
|
|||
private val serializedObject: String
|
||||
|
||||
// Maximum number of days to keep messages
|
||||
@Suppress("MagicNumber")
|
||||
private var maxDays = 7
|
||||
|
||||
// Message maximum queue size
|
||||
@Suppress("MagicNumber")
|
||||
private var maxSize = 50
|
||||
|
||||
/**
|
||||
|
@ -227,8 +229,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) {
|
|||
save()
|
||||
}
|
||||
} else if (message.sender.equals(nickname, ignoreCase = true) && message.isReceived
|
||||
&& !message.isNotified
|
||||
) {
|
||||
&& !message.isNotified) {
|
||||
bot.send(
|
||||
nickname,
|
||||
"Your message ${reverseColor("[ID " + message.id + ']')} was sent to " +
|
||||
|
|
|
@ -71,6 +71,53 @@ object EntriesMgr {
|
|||
// Maximum number of backlogs to keep
|
||||
private const val maxBacklogs = 10
|
||||
|
||||
// Daily backup
|
||||
private fun dailyBackup(
|
||||
bot: Mobibot,
|
||||
history: MutableList<String>
|
||||
) {
|
||||
if (bot.backlogsUrl.isNotBlank()) {
|
||||
if (!history.contains(bot.today)) {
|
||||
history.add(bot.today)
|
||||
while (history.size > maxBacklogs) {
|
||||
history.removeAt(0)
|
||||
}
|
||||
}
|
||||
OutputStreamWriter(
|
||||
Files.newOutputStream(Paths.get(bot.logsDir + NAV_XML)), StandardCharsets.UTF_8
|
||||
).use { fw ->
|
||||
val output = SyndFeedOutput()
|
||||
val rss: SyndFeed = SyndFeedImpl()
|
||||
val items: MutableList<SyndEntry> = mutableListOf()
|
||||
var item: SyndEntry
|
||||
with(rss) {
|
||||
feedType = "rss_2.0"
|
||||
title = "${bot.channel} IRC Links Backlogs"
|
||||
description = "Backlogs of Links from ${bot.ircServer} on ${bot.channel}"
|
||||
link = bot.backlogsUrl
|
||||
publishedDate = Calendar.getInstance().time
|
||||
}
|
||||
var date: String
|
||||
items.clear()
|
||||
for (i in history.size - 1 downTo 0) {
|
||||
date = history[i]
|
||||
item = SyndEntryImpl()
|
||||
with(item) {
|
||||
link = bot.backlogsUrl + date + ".xml"
|
||||
title = date
|
||||
description = SyndContentImpl().apply { value = "Links for $date" }
|
||||
}
|
||||
items.add(item)
|
||||
}
|
||||
rss.entries = items
|
||||
if (bot.logger.isDebugEnabled) bot.logger.debug("Writing the backlog feed.")
|
||||
output.output(rss, fw)
|
||||
}
|
||||
} else {
|
||||
bot.logger.warn("Unable to generate the backlogs feed. No property configured.")
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the backlogs.
|
||||
*/
|
||||
|
@ -139,7 +186,7 @@ object EntriesMgr {
|
|||
if (bot.logsDir.isNotBlank() && bot.weblogUrl.isNotBlank()) {
|
||||
try {
|
||||
val output = SyndFeedOutput()
|
||||
var rss: SyndFeed = SyndFeedImpl()
|
||||
val rss: SyndFeed = SyndFeedImpl()
|
||||
val items: MutableList<SyndEntry> = mutableListOf()
|
||||
var item: SyndEntry
|
||||
OutputStreamWriter(
|
||||
|
@ -153,12 +200,12 @@ object EntriesMgr {
|
|||
publishedDate = Calendar.getInstance().time
|
||||
language = "en"
|
||||
}
|
||||
var buff: StringBuilder
|
||||
val buff: StringBuilder = StringBuilder()
|
||||
var comment: EntryComment
|
||||
for (i in entries.size - 1 downTo 0) {
|
||||
with(entries[i]) {
|
||||
buff = StringBuilder()
|
||||
.append("Posted by <b>")
|
||||
buff.setLength(0)
|
||||
buff.append("Posted by <b>")
|
||||
.append(nick)
|
||||
.append("</b> on <a href=\"irc://")
|
||||
.append(bot.ircServer).append('/')
|
||||
|
@ -199,43 +246,7 @@ object EntriesMgr {
|
|||
), StandardCharsets.UTF_8
|
||||
).use { fw -> output.output(rss, fw) }
|
||||
if (isDayBackup) {
|
||||
if (bot.backlogsUrl.isNotBlank()) {
|
||||
if (!history.contains(bot.today)) {
|
||||
history.add(bot.today)
|
||||
while (history.size > maxBacklogs) {
|
||||
history.removeAt(0)
|
||||
}
|
||||
}
|
||||
OutputStreamWriter(
|
||||
Files.newOutputStream(Paths.get(bot.logsDir + NAV_XML)), StandardCharsets.UTF_8
|
||||
).use { fw ->
|
||||
rss = SyndFeedImpl()
|
||||
with(rss) {
|
||||
feedType = "rss_2.0"
|
||||
title = "${bot.channel} IRC Links Backlogs"
|
||||
description = "Backlogs of Links from ${bot.ircServer} on ${bot.channel}"
|
||||
link = bot.backlogsUrl
|
||||
publishedDate = Calendar.getInstance().time
|
||||
}
|
||||
var date: String
|
||||
items.clear()
|
||||
for (i in history.size - 1 downTo 0) {
|
||||
date = history[i]
|
||||
item = SyndEntryImpl()
|
||||
with(item) {
|
||||
link = bot.backlogsUrl + date + ".xml"
|
||||
title = date
|
||||
description = SyndContentImpl().apply { value = "Links for $date" }
|
||||
}
|
||||
items.add(item)
|
||||
}
|
||||
rss.entries = items
|
||||
if (bot.logger.isDebugEnabled) bot.logger.debug("Writing the backlog feed.")
|
||||
output.output(rss, fw)
|
||||
}
|
||||
} else {
|
||||
bot.logger.warn("Unable to generate the backlogs feed. No property configured.")
|
||||
}
|
||||
dailyBackup(bot, history)
|
||||
}
|
||||
} catch (e: FeedException) {
|
||||
if (bot.logger.isWarnEnabled) bot.logger.warn("Unable to generate the entries feed.", e)
|
||||
|
|
|
@ -86,6 +86,7 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
|
|||
}
|
||||
} else if (args.contains(CURRENCY_RATES_KEYWORD)) {
|
||||
send(sender, "The currency rates for ${Utils.bold(pubDate)} are:", isPrivate)
|
||||
@Suppress("MagicNumber")
|
||||
sendList(sender, currencyRates(), 3, isPrivate, isIndent = true)
|
||||
} else {
|
||||
helpResponse(sender, isPrivate)
|
||||
|
@ -122,6 +123,7 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
|
|||
isPrivate
|
||||
)
|
||||
send(sender, "The supported currencies are: ", isPrivate)
|
||||
@Suppress("MagicNumber")
|
||||
sendList(sender, ArrayList(EXCHANGE_RATES.keys), 11, isPrivate, isIndent = true)
|
||||
}
|
||||
}
|
||||
|
@ -150,6 +152,7 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
|
|||
/**
|
||||
* Converts from a currency to another.
|
||||
*/
|
||||
@Suppress("MagicNumber")
|
||||
@JvmStatic
|
||||
fun convertCurrency(query: String): Message {
|
||||
val cmds = query.split(" ")
|
||||
|
@ -185,6 +188,7 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
|
|||
fun currencyRates(): List<String> {
|
||||
val rates = mutableListOf<String>()
|
||||
for ((key, value) in EXCHANGE_RATES) {
|
||||
@Suppress("MagicNumber")
|
||||
rates.add(" $key: ${StringUtils.leftPad(value, 8)}")
|
||||
}
|
||||
return rates
|
||||
|
|
|
@ -73,6 +73,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))
|
||||
}
|
||||
|
||||
|
|
|
@ -145,6 +145,7 @@ class Twitter(bot: Mobibot) : ThreadedModule(bot) {
|
|||
if (bot.logger.isDebugEnabled) {
|
||||
bot.logger.debug("Scheduling {} for posting on Twitter.", EntriesUtils.buildLinkCmd(index))
|
||||
}
|
||||
@Suppress("MagicNumber")
|
||||
bot.timer.schedule(TwitterTimer(bot, index), Constants.TIMER_DELAY * 60L * 1000L)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
|
|||
}
|
||||
|
||||
private fun getTemps(d: Double?): String {
|
||||
@Suppress("MagicNumber")
|
||||
val c = (d!! - 32) * 5 / 9
|
||||
return "${d.roundToInt()} °F, ${c.roundToInt()} °C"
|
||||
}
|
||||
|
@ -186,6 +187,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
|
|||
}
|
||||
|
||||
private fun wind(w: Double): String {
|
||||
@Suppress("MagicNumber")
|
||||
val kmh = w * 1.60934
|
||||
return "${w.roundToInt()} mph, ${kmh.roundToInt()} km/h"
|
||||
}
|
||||
|
|
|
@ -60,6 +60,7 @@ class WorldTime(bot: Mobibot) : AbstractModule(bot) {
|
|||
/**
|
||||
* Returns the current Internet (beat) Time.
|
||||
*/
|
||||
@Suppress("MagicNumber")
|
||||
private fun internetTime(): String {
|
||||
val zdt = ZonedDateTime.now(ZoneId.of("UTC+01:00"))
|
||||
val beats = ((zdt[ChronoField.SECOND_OF_MINUTE] + zdt[ChronoField.MINUTE_OF_HOUR] * 60
|
||||
|
@ -171,6 +172,7 @@ class WorldTime(bot: Mobibot) : AbstractModule(bot) {
|
|||
countries["ZULU"] = "Zulu"
|
||||
countries["INTERNET"] = BEATS_KEYWORD
|
||||
countries["BEATS"] = BEATS_KEYWORD
|
||||
@Suppress("MagicNumber")
|
||||
ZoneId.getAvailableZoneIds().stream()
|
||||
.filter { tz: String ->
|
||||
!tz.contains("/") && tz.length == 3 && !countries.containsKey(tz)
|
||||
|
@ -191,6 +193,7 @@ class WorldTime(bot: Mobibot) : AbstractModule(bot) {
|
|||
with(bot) {
|
||||
if (args.isEmpty()) {
|
||||
send(sender, "The supported countries/zones are: ", isPrivate)
|
||||
@Suppress("MagicNumber")
|
||||
sendList(sender, ArrayList(COUNTRIES_MAP.keys), 17, isPrivate = false)
|
||||
} else {
|
||||
val msg = time(args)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue