Cleaned up code
This commit is contained in:
parent
d700aa06df
commit
4c90870f4a
61 changed files with 496 additions and 481 deletions
|
@ -128,12 +128,15 @@ object Utils {
|
|||
isNullOrEmpty() -> {
|
||||
""
|
||||
}
|
||||
|
||||
color == DEFAULT_COLOR -> {
|
||||
this
|
||||
}
|
||||
|
||||
Colors.BOLD == color || Colors.REVERSE == color -> {
|
||||
color + this + color
|
||||
}
|
||||
|
||||
else -> {
|
||||
color + this + Colors.NORMAL
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ class NickComparator : Comparator<String>, Serializable {
|
|||
}
|
||||
|
||||
companion object {
|
||||
@Suppress("ConstPropertyName")
|
||||
private const val serialVersionUID = 1L
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import java.io.Serializable
|
|||
|
||||
data class SeenNick(val nick: String, val lastSeen: Long) : Serializable {
|
||||
companion object {
|
||||
@Suppress("ConstPropertyName")
|
||||
private const val serialVersionUID = 1L
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,6 +89,7 @@ class Tell(private val serialObject: String) : AbstractCommand() {
|
|||
args.isBlank() -> {
|
||||
helpResponse(channel, args, event)
|
||||
}
|
||||
|
||||
args.startsWith(View.VIEW_CMD) -> {
|
||||
if (event.isChannelOp(channel) && "${View.VIEW_CMD} $TELL_ALL_KEYWORD" == args) {
|
||||
viewAll(event)
|
||||
|
@ -96,9 +97,11 @@ class Tell(private val serialObject: String) : AbstractCommand() {
|
|||
viewMessages(event)
|
||||
}
|
||||
}
|
||||
|
||||
args.startsWith("$TELL_DEL_KEYWORD ") -> {
|
||||
deleteMessage(channel, args, event)
|
||||
}
|
||||
|
||||
else -> {
|
||||
newMessage(channel, args, event)
|
||||
}
|
||||
|
|
|
@ -98,6 +98,7 @@ class TellMessage(
|
|||
}
|
||||
|
||||
companion object {
|
||||
@Suppress("ConstPropertyName")
|
||||
private const val serialVersionUID = 2L
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ data class EntryComment(var comment: String, var nick: String) : Serializable {
|
|||
|
||||
companion object {
|
||||
// Serial version UID
|
||||
@Suppress("ConstPropertyName")
|
||||
private const val serialVersionUID: Long = 1L
|
||||
}
|
||||
}
|
||||
|
|
|
@ -207,6 +207,7 @@ class EntryLink(
|
|||
|
||||
companion object {
|
||||
// Serial version UID
|
||||
@Suppress("ConstPropertyName")
|
||||
private const val serialVersionUID: Long = 1L
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,17 +55,17 @@ class FeedsManager private constructor() {
|
|||
private val logger: Logger = LoggerFactory.getLogger(FeedsManager::class.java)
|
||||
|
||||
// The file containing the current entries.
|
||||
private const val currentXml = "current.xml"
|
||||
private const val CURRENT_XML = "current.xml"
|
||||
|
||||
// The .xml extension.
|
||||
private const val dotXml = ".xml"
|
||||
private const val DOT_XML = ".xml"
|
||||
|
||||
/**
|
||||
* Loads the current feed.
|
||||
*/
|
||||
@JvmStatic
|
||||
@Throws(IOException::class, FeedException::class)
|
||||
fun loadFeed(entries: Entries, currentFile: String = currentXml): String {
|
||||
fun loadFeed(entries: Entries, currentFile: String = CURRENT_XML): String {
|
||||
entries.links.clear()
|
||||
val xml = Paths.get("${entries.logsDir}${currentFile}")
|
||||
var pubDate = today()
|
||||
|
@ -110,7 +110,7 @@ class FeedsManager private constructor() {
|
|||
* Saves the feeds.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun saveFeed(entries: Entries, currentFile: String = currentXml) {
|
||||
fun saveFeed(entries: Entries, currentFile: String = CURRENT_XML) {
|
||||
if (logger.isDebugEnabled) logger.debug("Saving the feeds...")
|
||||
if (entries.logsDir.isNotBlank()) {
|
||||
try {
|
||||
|
@ -167,7 +167,7 @@ class FeedsManager private constructor() {
|
|||
OutputStreamWriter(
|
||||
Files.newOutputStream(
|
||||
Paths.get(
|
||||
entries.logsDir + today() + dotXml
|
||||
entries.logsDir + today() + DOT_XML
|
||||
)
|
||||
), StandardCharsets.UTF_8
|
||||
).use { fw -> output.output(rss, fw) }
|
||||
|
|
|
@ -78,6 +78,7 @@ class CurrencyConverter : AbstractModule() {
|
|||
SYMBOLS.isEmpty() -> {
|
||||
event.respond(EMPTY_SYMBOLS_TABLE)
|
||||
}
|
||||
|
||||
args.matches("\\d+([,\\d]+)?(\\.\\d+)? [a-zA-Z]{3}+ (to|in) [a-zA-Z]{3}+".toRegex()) -> {
|
||||
val msg = convertCurrency(properties[API_KEY_PROP], args)
|
||||
event.respond(msg.msg)
|
||||
|
@ -85,10 +86,12 @@ class CurrencyConverter : AbstractModule() {
|
|||
helpResponse(event)
|
||||
}
|
||||
}
|
||||
|
||||
args.contains(CODES_KEYWORD) -> {
|
||||
event.sendMessage("The supported currency codes are:")
|
||||
event.sendList(SYMBOLS.keys.toList(), 11, isIndent = true)
|
||||
}
|
||||
|
||||
else -> {
|
||||
helpResponse(event)
|
||||
}
|
||||
|
|
|
@ -39,6 +39,7 @@ class ModuleException @JvmOverloads constructor(
|
|||
cause: Throwable? = null
|
||||
) : Exception(message, cause) {
|
||||
companion object {
|
||||
@Suppress("ConstPropertyName")
|
||||
private const val serialVersionUID = 1L
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,33 +44,33 @@ import java.lang.reflect.Method
|
|||
*/
|
||||
class ModuleExceptionTest {
|
||||
companion object {
|
||||
const val debugMessage = "debugMessage"
|
||||
const val message = "message"
|
||||
const val DEBUG_MESSAGE = "debugMessage"
|
||||
const val MESSAGE = "message"
|
||||
}
|
||||
|
||||
@DataProvider(name = "dp")
|
||||
fun createData(@Suppress("UNUSED_PARAMETER") m: Method?): Array<Array<Any>> {
|
||||
return arrayOf(
|
||||
arrayOf(ModuleException(debugMessage, message, IOException("URL http://foobar.com"))),
|
||||
arrayOf(ModuleException(debugMessage, message, IOException("URL http://foobar.com?"))),
|
||||
arrayOf(ModuleException(debugMessage, message))
|
||||
arrayOf(ModuleException(DEBUG_MESSAGE, MESSAGE, IOException("URL http://foobar.com"))),
|
||||
arrayOf(ModuleException(DEBUG_MESSAGE, MESSAGE, IOException("URL http://foobar.com?"))),
|
||||
arrayOf(ModuleException(DEBUG_MESSAGE, MESSAGE))
|
||||
)
|
||||
}
|
||||
|
||||
@Test(dataProvider = "dp")
|
||||
fun testGetDebugMessage(e: ModuleException) {
|
||||
assertThat(e::debugMessage).isEqualTo(debugMessage)
|
||||
assertThat(e::debugMessage).isEqualTo(DEBUG_MESSAGE)
|
||||
}
|
||||
|
||||
@Test(dataProvider = "dp")
|
||||
fun testGetMessage(e: ModuleException) {
|
||||
assertThat(e).hasMessage(message)
|
||||
assertThat(e).hasMessage(MESSAGE)
|
||||
}
|
||||
|
||||
@Test(groups = ["modules"])
|
||||
fun testSanitizeMessage() {
|
||||
val apiKey = "1234567890"
|
||||
var e = ModuleException(debugMessage, message, IOException("URL http://foo.com?apiKey=$apiKey&userID=me"))
|
||||
var e = ModuleException(DEBUG_MESSAGE, MESSAGE, IOException("URL http://foo.com?apiKey=$apiKey&userID=me"))
|
||||
assertThat(
|
||||
e.sanitize(apiKey, "", "me").message, "ModuleException(debugMessage, message, IOException(url))"
|
||||
).isNotNull().all {
|
||||
|
@ -78,21 +78,21 @@ class ModuleExceptionTest {
|
|||
doesNotContain(apiKey, "me")
|
||||
}
|
||||
|
||||
e = ModuleException(debugMessage, message, null)
|
||||
assertThat(e.sanitize(apiKey), "ModuleException(debugMessage, message, null)").hasMessage(message)
|
||||
e = ModuleException(DEBUG_MESSAGE, MESSAGE, null)
|
||||
assertThat(e.sanitize(apiKey), "ModuleException(debugMessage, message, null)").hasMessage(MESSAGE)
|
||||
|
||||
e = ModuleException(debugMessage, message, IOException())
|
||||
assertThat(e.sanitize(apiKey), "ModuleException(debugMessage, message, IOException())").hasMessage(message)
|
||||
e = ModuleException(DEBUG_MESSAGE, MESSAGE, IOException())
|
||||
assertThat(e.sanitize(apiKey), "ModuleException(debugMessage, message, IOException())").hasMessage(MESSAGE)
|
||||
|
||||
e = ModuleException(debugMessage, apiKey)
|
||||
e = ModuleException(DEBUG_MESSAGE, apiKey)
|
||||
assertThat(e.sanitize(apiKey).message, "ModuleException(debugMessage, apiKey)").isNotNull()
|
||||
.doesNotContain(apiKey)
|
||||
|
||||
val msg: String? = null
|
||||
e = ModuleException(debugMessage, msg, IOException(msg))
|
||||
e = ModuleException(DEBUG_MESSAGE, msg, IOException(msg))
|
||||
assertThat(e.sanitize(apiKey).message, "ModuleException(debugMessage, msg, IOException(msg))").isNull()
|
||||
|
||||
e = ModuleException(debugMessage, msg, IOException("foo is $apiKey"))
|
||||
e = ModuleException(DEBUG_MESSAGE, msg, IOException("foo is $apiKey"))
|
||||
assertThat(
|
||||
e.sanitize(" ", apiKey, "foo").message,
|
||||
"ModuleException(debugMessage, msg, IOException(foo is $apiKey))"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue