diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/Constants.kt b/src/main/kotlin/net/thauvin/erik/mobibot/Constants.kt index d1b33b3..4b93ac1 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/Constants.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/Constants.kt @@ -102,6 +102,11 @@ object Constants { */ const val PROPS_ARG = "properties" + /** + * The tag command + */ + const val TAG_CMD = "T" + /** * The timer delay in minutes. */ diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/FeedReader.kt b/src/main/kotlin/net/thauvin/erik/mobibot/FeedReader.kt index 9cb929b..884ca78 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/FeedReader.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/FeedReader.kt @@ -34,10 +34,10 @@ package net.thauvin.erik.mobibot import com.rometools.rome.io.FeedException import com.rometools.rome.io.SyndFeedInput import com.rometools.rome.io.XmlReader -import net.thauvin.erik.mobibot.msg.Message -import net.thauvin.erik.mobibot.msg.PublicMessage import net.thauvin.erik.mobibot.Utils.green import net.thauvin.erik.mobibot.Utils.helpFormat +import net.thauvin.erik.mobibot.msg.Message +import net.thauvin.erik.mobibot.msg.PublicMessage import java.io.IOException import java.net.URL @@ -62,10 +62,10 @@ class FeedReader( send(sender, it) } } catch (e: FeedException) { - if (logger.isDebugEnabled) logger.debug("Unabled to parse the feed at ${url}", e) + if (logger.isDebugEnabled) logger.debug("Unabled to parse the feed at $url", e) send(sender, "An error has occured while parsing the feed: ${e.message}", false) } catch (e: IOException) { - if (logger.isDebugEnabled) logger.debug("Unable to fetch the feed at ${url}", e) + if (logger.isDebugEnabled) logger.debug("Unable to fetch the feed at $url", e) send(sender, "An error has occurred while fetching the feed: ${e.message}", false) } } @@ -74,7 +74,7 @@ class FeedReader( companion object { @JvmStatic @Throws(FeedException::class, IOException::class) - fun readFeed(url: String, maxItems: Int = 5) : List { + fun readFeed(url: String, maxItems: Int = 5): List { val messages = mutableListOf() val input = SyndFeedInput() XmlReader(URL(url)).use { reader -> diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/commands/Die.kt b/src/main/kotlin/net/thauvin/erik/mobibot/commands/Die.kt index eba2dcc..c9c6299 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/commands/Die.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/commands/Die.kt @@ -33,7 +33,6 @@ package net.thauvin.erik.mobibot.commands import net.thauvin.erik.mobibot.Mobibot -import net.thauvin.erik.mobibot.Utils.helpFormat class Die(bot: Mobibot) : AbstractCommand(bot) { override val name = "die" diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/commands/Kill.kt b/src/main/kotlin/net/thauvin/erik/mobibot/commands/Kill.kt index 6055798..803ab58 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/commands/Kill.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/commands/Kill.kt @@ -33,7 +33,6 @@ package net.thauvin.erik.mobibot.commands import net.thauvin.erik.mobibot.Mobibot -import net.thauvin.erik.mobibot.Utils.helpFormat class Kill(bot: Mobibot) : AbstractCommand(bot) { override val name = "kill" diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/commands/links/Tags.kt b/src/main/kotlin/net/thauvin/erik/mobibot/commands/links/Tags.kt index 554d6c8..e2b6d8f 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/commands/links/Tags.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/commands/links/Tags.kt @@ -42,8 +42,8 @@ import net.thauvin.erik.mobibot.entries.EntryLink class Tags(bot: Mobibot) : AbstractCommand(bot) { override val name = COMMAND override val help = listOf( - "To categorize or tag a URL, use its label and a T:", - helpFormat("${Constants.LINK_CMD}1T:<+tag|-tag> [...]") + "To categorize or tag a URL, use its label and a ${Constants.TAG_CMD}:", + helpFormat("${Constants.LINK_CMD}1${Constants.TAG_CMD}:<+tag|-tag> [...]") ) override val isOp = false override val isPublic = true @@ -60,7 +60,7 @@ class Tags(bot: Mobibot) : AbstractCommand(bot) { isOp: Boolean, isPrivate: Boolean ) { - val cmds = args.substring(1).split("T:", limit = 2) + val cmds = args.substring(1).split("${Constants.TAG_CMD}:", limit = 2) val index = cmds[0].toInt() - 1 if (index < LinksMgr.entries.size) { @@ -86,6 +86,6 @@ class Tags(bot: Mobibot) : AbstractCommand(bot) { } override fun matches(message: String): Boolean { - return message.matches("^${Constants.LINK_CMD}[0-9]+T:.*".toRegex()) + return message.matches("^${Constants.LINK_CMD}[0-9]+${Constants.TAG_CMD}:.*".toRegex()) } } diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/Tell.kt b/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/Tell.kt index cd59eac..0792eaa 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/Tell.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/Tell.kt @@ -229,7 +229,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) { bot.send( nickname, "Your message ${reverseColor("[ID " + message.id + ']')} was sent to " - + "${bold(message.recipient)} on ${message.receptionDate.toUtcDateTime()}", + + "${bold(message.recipient)} on ${message.receptionDate.toUtcDateTime()}", true ) message.isNotified = true @@ -252,8 +252,8 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) { for (message in messages) { bot.send( sender, bold(message.sender) + ARROW + bold(message.recipient) - + " [ID: " + message.id + ", " - + (if (message.isReceived) "DELIVERED" else "QUEUED") + ']', + + " [ID: " + message.id + ", " + + (if (message.isReceived) "DELIVERED" else "QUEUED") + ']', isPrivate ) } @@ -275,16 +275,16 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) { bot.send( sender, bold(message.sender) + ARROW + bold(message.recipient) - + " [${message.receptionDate.toUtcDateTime()}, ID: " - + bold(message.id) + ", DELIVERED]", + + " [${message.receptionDate.toUtcDateTime()}, ID: " + + bold(message.id) + ", DELIVERED]", isPrivate ) } else { bot.send( sender, bold(message.sender) + ARROW + bold(message.recipient) - + " [${message.queued.toUtcDateTime()}, ID: " - + bold(message.id) + ", QUEUED]", + + " [${message.queued.toUtcDateTime()}, ID: " + + bold(message.id) + ", QUEUED]", isPrivate ) } diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessage.kt b/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessage.kt index 396b854..6a058f6 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessage.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/commands/tell/TellMessage.kt @@ -95,7 +95,7 @@ class TellMessage internal constructor( override fun toString(): String { return ("TellMessage{id='$id', isNotified=$isNotified, isReceived=$isReceived, message='$message', " + - "queued=$queued, received=$receptionDate, recipient='$recipient', sender='$sender'}") + "queued=$queued, received=$receptionDate, recipient='$recipient', sender='$sender'}") } companion object { diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntriesMgr.kt b/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntriesMgr.kt index 0b68da8..6f9ffff 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntriesMgr.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntriesMgr.kt @@ -248,7 +248,8 @@ object EntriesMgr { } catch (e: FeedException) { if (bot.logger.isWarnEnabled) bot.logger.warn("Unable to generate the entries feed.", e) } catch (e: IOException) { - if (bot.logger.isWarnEnabled) bot.logger.warn("Unable to generate the entries feed.", e) + if (bot.logger.isWarnEnabled) + bot.logger.warn("An IO error occurred while generating the entries feed.", e) } } else { if (bot.logger.isWarnEnabled) { diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntriesUtils.kt b/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntriesUtils.kt index 5f83aa2..c0247c3 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntriesUtils.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/entries/EntriesUtils.kt @@ -76,5 +76,5 @@ object EntriesUtils { * Build an entry's tags/categories for display on the channel. */ fun buildTags(entryIndex: Int, entry: EntryLink): String = - buildLinkCmd(entryIndex) + "T: " + entry.pinboardTags.replace(",", ", ") + buildLinkCmd(entryIndex) + "${Constants.TAG_CMD}: " + entry.pinboardTags.replace(",", ", ") } diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/StockQuote.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/StockQuote.kt index 51f49e3..1459914 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/StockQuote.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/StockQuote.kt @@ -175,7 +175,8 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) { 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(NoticeMessage( + add( + NoticeMessage( " Latest: " + unescapeXml(quote.getString("07. latest trading day")) ) ) diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/FeedReaderTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/FeedReaderTest.kt index 0b2185e..3360242 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/FeedReaderTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/FeedReaderTest.kt @@ -53,11 +53,11 @@ class FeedReaderTest { messages = readFeed("https://lorem-rss.herokuapp.com/feed?length=0") assertThat(messages[0].msg).describedAs("nothing to view").contains("nothing") - + messages = readFeed("https://lorem-rss.herokuapp.com/feed?length=42", 42) assertThat(messages.size).describedAs("messages = 84").isEqualTo(84) assertThat(messages.last().msg).describedAs("example entry url").contains("http://example.com/test/") - + assertThatThrownBy { readFeed("blah") }.describedAs("invalid URL") .isInstanceOf(MalformedURLException::class.java)