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