Cleanup.
This commit is contained in:
parent
6644400a23
commit
48c2ad65c0
11 changed files with 29 additions and 24 deletions
|
@ -102,6 +102,11 @@ object Constants {
|
||||||
*/
|
*/
|
||||||
const val PROPS_ARG = "properties"
|
const val PROPS_ARG = "properties"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The tag command
|
||||||
|
*/
|
||||||
|
const val TAG_CMD = "T"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The timer delay in minutes.
|
* The timer delay in minutes.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -34,10 +34,10 @@ package net.thauvin.erik.mobibot
|
||||||
import com.rometools.rome.io.FeedException
|
import com.rometools.rome.io.FeedException
|
||||||
import com.rometools.rome.io.SyndFeedInput
|
import com.rometools.rome.io.SyndFeedInput
|
||||||
import com.rometools.rome.io.XmlReader
|
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.green
|
||||||
import net.thauvin.erik.mobibot.Utils.helpFormat
|
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.io.IOException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
|
|
||||||
|
@ -62,10 +62,10 @@ class FeedReader(
|
||||||
send(sender, it)
|
send(sender, it)
|
||||||
}
|
}
|
||||||
} catch (e: FeedException) {
|
} 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)
|
send(sender, "An error has occured while parsing the feed: ${e.message}", false)
|
||||||
} catch (e: IOException) {
|
} 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)
|
send(sender, "An error has occurred while fetching the feed: ${e.message}", false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -74,7 +74,7 @@ class FeedReader(
|
||||||
companion object {
|
companion object {
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@Throws(FeedException::class, IOException::class)
|
@Throws(FeedException::class, IOException::class)
|
||||||
fun readFeed(url: String, maxItems: Int = 5) : List<Message> {
|
fun readFeed(url: String, maxItems: Int = 5): List<Message> {
|
||||||
val messages = mutableListOf<Message>()
|
val messages = mutableListOf<Message>()
|
||||||
val input = SyndFeedInput()
|
val input = SyndFeedInput()
|
||||||
XmlReader(URL(url)).use { reader ->
|
XmlReader(URL(url)).use { reader ->
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
package net.thauvin.erik.mobibot.commands
|
package net.thauvin.erik.mobibot.commands
|
||||||
|
|
||||||
import net.thauvin.erik.mobibot.Mobibot
|
import net.thauvin.erik.mobibot.Mobibot
|
||||||
import net.thauvin.erik.mobibot.Utils.helpFormat
|
|
||||||
|
|
||||||
class Die(bot: Mobibot) : AbstractCommand(bot) {
|
class Die(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
override val name = "die"
|
override val name = "die"
|
||||||
|
|
|
@ -33,7 +33,6 @@
|
||||||
package net.thauvin.erik.mobibot.commands
|
package net.thauvin.erik.mobibot.commands
|
||||||
|
|
||||||
import net.thauvin.erik.mobibot.Mobibot
|
import net.thauvin.erik.mobibot.Mobibot
|
||||||
import net.thauvin.erik.mobibot.Utils.helpFormat
|
|
||||||
|
|
||||||
class Kill(bot: Mobibot) : AbstractCommand(bot) {
|
class Kill(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
override val name = "kill"
|
override val name = "kill"
|
||||||
|
|
|
@ -42,8 +42,8 @@ import net.thauvin.erik.mobibot.entries.EntryLink
|
||||||
class Tags(bot: Mobibot) : AbstractCommand(bot) {
|
class Tags(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
override val name = COMMAND
|
override val name = COMMAND
|
||||||
override val help = listOf(
|
override val help = listOf(
|
||||||
"To categorize or tag a URL, use its label and a T:",
|
"To categorize or tag a URL, use its label and a ${Constants.TAG_CMD}:",
|
||||||
helpFormat("${Constants.LINK_CMD}1T:<+tag|-tag> [...]")
|
helpFormat("${Constants.LINK_CMD}1${Constants.TAG_CMD}:<+tag|-tag> [...]")
|
||||||
)
|
)
|
||||||
override val isOp = false
|
override val isOp = false
|
||||||
override val isPublic = true
|
override val isPublic = true
|
||||||
|
@ -60,7 +60,7 @@ class Tags(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
isOp: Boolean,
|
isOp: Boolean,
|
||||||
isPrivate: 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
|
val index = cmds[0].toInt() - 1
|
||||||
|
|
||||||
if (index < LinksMgr.entries.size) {
|
if (index < LinksMgr.entries.size) {
|
||||||
|
@ -86,6 +86,6 @@ class Tags(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun matches(message: String): Boolean {
|
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())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,7 +229,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
bot.send(
|
bot.send(
|
||||||
nickname,
|
nickname,
|
||||||
"Your message ${reverseColor("[ID " + message.id + ']')} was sent to "
|
"Your message ${reverseColor("[ID " + message.id + ']')} was sent to "
|
||||||
+ "${bold(message.recipient)} on ${message.receptionDate.toUtcDateTime()}",
|
+ "${bold(message.recipient)} on ${message.receptionDate.toUtcDateTime()}",
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
message.isNotified = true
|
message.isNotified = true
|
||||||
|
@ -252,8 +252,8 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
for (message in messages) {
|
for (message in messages) {
|
||||||
bot.send(
|
bot.send(
|
||||||
sender, bold(message.sender) + ARROW + bold(message.recipient)
|
sender, bold(message.sender) + ARROW + bold(message.recipient)
|
||||||
+ " [ID: " + message.id + ", "
|
+ " [ID: " + message.id + ", "
|
||||||
+ (if (message.isReceived) "DELIVERED" else "QUEUED") + ']',
|
+ (if (message.isReceived) "DELIVERED" else "QUEUED") + ']',
|
||||||
isPrivate
|
isPrivate
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -275,16 +275,16 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
bot.send(
|
bot.send(
|
||||||
sender,
|
sender,
|
||||||
bold(message.sender) + ARROW + bold(message.recipient)
|
bold(message.sender) + ARROW + bold(message.recipient)
|
||||||
+ " [${message.receptionDate.toUtcDateTime()}, ID: "
|
+ " [${message.receptionDate.toUtcDateTime()}, ID: "
|
||||||
+ bold(message.id) + ", DELIVERED]",
|
+ bold(message.id) + ", DELIVERED]",
|
||||||
isPrivate
|
isPrivate
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
bot.send(
|
bot.send(
|
||||||
sender,
|
sender,
|
||||||
bold(message.sender) + ARROW + bold(message.recipient)
|
bold(message.sender) + ARROW + bold(message.recipient)
|
||||||
+ " [${message.queued.toUtcDateTime()}, ID: "
|
+ " [${message.queued.toUtcDateTime()}, ID: "
|
||||||
+ bold(message.id) + ", QUEUED]",
|
+ bold(message.id) + ", QUEUED]",
|
||||||
isPrivate
|
isPrivate
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -95,7 +95,7 @@ class TellMessage internal constructor(
|
||||||
|
|
||||||
override fun toString(): String {
|
override fun toString(): String {
|
||||||
return ("TellMessage{id='$id', isNotified=$isNotified, isReceived=$isReceived, message='$message', " +
|
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 {
|
companion object {
|
||||||
|
|
|
@ -248,7 +248,8 @@ object EntriesMgr {
|
||||||
} catch (e: FeedException) {
|
} catch (e: FeedException) {
|
||||||
if (bot.logger.isWarnEnabled) bot.logger.warn("Unable to generate the entries feed.", e)
|
if (bot.logger.isWarnEnabled) bot.logger.warn("Unable to generate the entries feed.", e)
|
||||||
} catch (e: IOException) {
|
} 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 {
|
} else {
|
||||||
if (bot.logger.isWarnEnabled) {
|
if (bot.logger.isWarnEnabled) {
|
||||||
|
|
|
@ -76,5 +76,5 @@ object EntriesUtils {
|
||||||
* Build an entry's tags/categories for display on the channel.
|
* Build an entry's tags/categories for display on the channel.
|
||||||
*/
|
*/
|
||||||
fun buildTags(entryIndex: Int, entry: EntryLink): String =
|
fun buildTags(entryIndex: Int, entry: EntryLink): String =
|
||||||
buildLinkCmd(entryIndex) + "T: " + entry.pinboardTags.replace(",", ", ")
|
buildLinkCmd(entryIndex) + "${Constants.TAG_CMD}: " + entry.pinboardTags.replace(",", ", ")
|
||||||
}
|
}
|
||||||
|
|
|
@ -175,7 +175,8 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
add(NoticeMessage(" High: " + unescapeXml(quote.getString("03. high"))))
|
add(NoticeMessage(" High: " + unescapeXml(quote.getString("03. high"))))
|
||||||
add(NoticeMessage(" Low: " + unescapeXml(quote.getString("04. low"))))
|
add(NoticeMessage(" Low: " + unescapeXml(quote.getString("04. low"))))
|
||||||
add(NoticeMessage(" Volume: " + unescapeXml(quote.getString("06. volume"))))
|
add(NoticeMessage(" Volume: " + unescapeXml(quote.getString("06. volume"))))
|
||||||
add(NoticeMessage(
|
add(
|
||||||
|
NoticeMessage(
|
||||||
" Latest: " + unescapeXml(quote.getString("07. latest trading day"))
|
" Latest: " + unescapeXml(quote.getString("07. latest trading day"))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -53,11 +53,11 @@ class FeedReaderTest {
|
||||||
|
|
||||||
messages = readFeed("https://lorem-rss.herokuapp.com/feed?length=0")
|
messages = readFeed("https://lorem-rss.herokuapp.com/feed?length=0")
|
||||||
assertThat(messages[0].msg).describedAs("nothing to view").contains("nothing")
|
assertThat(messages[0].msg).describedAs("nothing to view").contains("nothing")
|
||||||
|
|
||||||
messages = readFeed("https://lorem-rss.herokuapp.com/feed?length=42", 42)
|
messages = readFeed("https://lorem-rss.herokuapp.com/feed?length=42", 42)
|
||||||
assertThat(messages.size).describedAs("messages = 84").isEqualTo(84)
|
assertThat(messages.size).describedAs("messages = 84").isEqualTo(84)
|
||||||
assertThat(messages.last().msg).describedAs("example entry url").contains("http://example.com/test/")
|
assertThat(messages.last().msg).describedAs("example entry url").contains("http://example.com/test/")
|
||||||
|
|
||||||
assertThatThrownBy { readFeed("blah") }.describedAs("invalid URL")
|
assertThatThrownBy { readFeed("blah") }.describedAs("invalid URL")
|
||||||
.isInstanceOf(MalformedURLException::class.java)
|
.isInstanceOf(MalformedURLException::class.java)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue