diff --git a/config/detekt/baseline.xml b/config/detekt/baseline.xml
index b5b10a7..2080b7b 100644
--- a/config/detekt/baseline.xml
+++ b/config/detekt/baseline.xml
@@ -51,9 +51,6 @@
MagicNumber:WorldTime.kt$WorldTime.Companion$3600
MagicNumber:WorldTime.kt$WorldTime.Companion$60
MagicNumber:WorldTime.kt$WorldTime.Companion$86.4
- MemberNameEqualsClassName:Calc.kt$Calc.Companion$ @JvmStatic fun calc(query: String): String
- MemberNameEqualsClassName:Lookup.kt$Lookup.Companion$ @JvmStatic @Throws(UnknownHostException::class) fun lookup(query: String): String
- MemberNameEqualsClassName:WorldTime.kt$WorldTime.Companion$ @JvmStatic fun worldTime(query: String): Message
NestedBlockDepth:Addons.kt$Addons$ fun add(command: AbstractCommand, props: Properties)
NestedBlockDepth:Comment.kt$Comment$override fun commandResponse( sender: String, login: String, args: String, isOp: Boolean, isPrivate: Boolean )
NestedBlockDepth:CurrencyConverter.kt$CurrencyConverter$ override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean)
@@ -75,14 +72,8 @@
NestedBlockDepth:Weather2.kt$Weather2$ override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean)
NestedBlockDepth:Weather2.kt$Weather2.Companion$ @JvmStatic @Throws(ModuleException::class) fun getWeather(query: String, apiKey: String?): List<Message>
NestedBlockDepth:WorldTime.kt$WorldTime$override fun commandResponse( sender: String, cmd: String, args: String, isPrivate: Boolean )
- PrintStackTrace:Mobibot.kt$Mobibot$e
- PrintStackTrace:Mobibot.kt$Mobibot.Companion$e
ReturnCount:Addons.kt$Addons$ fun exec(sender: String, login: String, cmd: String, args: String, isOp: Boolean, isPrivate: Boolean): Boolean
ReturnCount:Addons.kt$Addons$ fun help(sender: String, topic: String, isOp: Boolean, isPrivate: Boolean): Boolean
- SwallowedException:Calc.kt$Calc.Companion$catch (e: IllegalArgumentException) { "No idea. This is the kind of math I don't get." }
- SwallowedException:GoogleSearchTest.kt$GoogleSearchTest$catch (e: ModuleException) { // Avoid displaying api keys in CI logs if ("true" == System.getenv("CI") && apiKey.isNotBlank() && cseKey.isNotBlank()) { throw ModuleException(e.debugMessage, e.getSanitizedMessage(apiKey, cseKey)) } else { throw e } }
- SwallowedException:StockQuoteTest.kt$StockQuoteTest$catch (e: ModuleException) { // Avoid displaying api keys in CI logs if ("true" == System.getenv("CI") && apiKey.isNotBlank()) { throw ModuleException(e.debugMessage, e.getSanitizedMessage(apiKey)) } else { throw e } }
- SwallowedException:TwitterTest.kt$TwitterTest$catch (e: UnknownHostException) { "Unknown Host" }
ThrowsCount:GoogleSearch.kt$GoogleSearch.Companion$ @JvmStatic @Throws(ModuleException::class) fun searchGoogle(query: String, apiKey: String?, cseKey: String?): List<Message>
ThrowsCount:StockQuote.kt$StockQuote.Companion$ @JvmStatic @Throws(ModuleException::class) fun getQuote(symbol: String, apiKey: String?): List<Message>
ThrowsCount:StockQuote.kt$StockQuote.Companion$@Throws(ModuleException::class) private fun getJsonResponse(response: String, debugMessage: String): JSONObject
diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/Mobibot.kt b/src/main/kotlin/net/thauvin/erik/mobibot/Mobibot.kt
index a230ec3..ffa13a5 100644
--- a/src/main/kotlin/net/thauvin/erik/mobibot/Mobibot.kt
+++ b/src/main/kotlin/net/thauvin/erik/mobibot/Mobibot.kt
@@ -202,6 +202,9 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
try {
connect(ircServer, ircPort)
} catch (e: Exception) {
+ if (logger.isDebugEnabled) {
+ logger.debug("Unable to connect to $ircServer, will try again.", e)
+ }
var retries = 0
while (retries++ < MAX_RECONNECT && !isConnected) {
sleep(10)
@@ -212,7 +215,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
if (logger.isDebugEnabled) {
logger.debug("Unable to reconnect to $ircServer, after $MAX_RECONNECT retries.", ex)
}
- e.printStackTrace(System.err)
+ System.err.println("An error has occurred while reconnecting; ${ex.message}")
exitProcess(1)
}
}
@@ -528,7 +531,6 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
commandLine = parser.parse(options, args)
} catch (e: ParseException) {
System.err.println("CLI Parsing failed. Reason: ${e.message}")
- e.printStackTrace(System.err)
exitProcess(1)
}
when {
@@ -550,13 +552,11 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
).use { fis ->
p.load(fis)
}
- } catch (e: FileNotFoundException) {
+ } catch (ignore: FileNotFoundException) {
System.err.println("Unable to find properties file.")
- e.printStackTrace(System.err)
exitProcess(1)
- } catch (e: IOException) {
+ } catch (ignore: IOException) {
System.err.println("Unable to open properties file.")
- e.printStackTrace(System.err)
exitProcess(1)
}
val nickname = p.getProperty("nick", Mobibot::class.java.name.lowercase())
@@ -574,9 +574,8 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
), true
)
System.setOut(stdout)
- } catch (e: IOException) {
+ } catch (ignore: IOException) {
System.err.println("Unable to open output (stdout) log file.")
- e.printStackTrace(System.err)
exitProcess(1)
}
try {
@@ -586,9 +585,8 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
), true
)
System.setErr(stderr)
- } catch (e: IOException) {
+ } catch (ignore: IOException) {
System.err.println("Unable to open error (stderr) log file.")
- e.printStackTrace(System.err)
exitProcess(1)
}
}
diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Calc.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Calc.kt
index 31c928f..9704461 100644
--- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Calc.kt
+++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Calc.kt
@@ -32,6 +32,7 @@
package net.thauvin.erik.mobibot.modules
import net.objecthunter.exp4j.ExpressionBuilder
+import net.objecthunter.exp4j.tokenizer.UnknownFunctionOrVariableException
import net.thauvin.erik.mobibot.Mobibot
import net.thauvin.erik.mobibot.Utils
import java.text.DecimalFormat
@@ -47,7 +48,15 @@ class Calc(bot: Mobibot) : AbstractModule(bot) {
isPrivate: Boolean
) {
if (args.isNotBlank()) {
- bot.send(calc(args))
+ try {
+ bot.send(calculate(args))
+ } catch (e: IllegalArgumentException) {
+ if (bot.logger.isWarnEnabled) bot.logger.warn("Failed to calcualte: $args", e)
+ bot.send("No idea. This is the kind of math I don't get.")
+ } catch (e: UnknownFunctionOrVariableException) {
+ if (bot.logger.isWarnEnabled) bot.logger.warn("Unable to calcualte: $args", e)
+ bot.send("No idea. I must've some form of Dyscalculia.")
+ }
} else {
helpResponse(sender, isPrivate)
}
@@ -61,14 +70,11 @@ class Calc(bot: Mobibot) : AbstractModule(bot) {
* Performs a calculation. e.g.: 1 + 1 * 2
*/
@JvmStatic
- fun calc(query: String): String {
+ @Throws(IllegalArgumentException::class)
+ fun calculate(query: String): String {
val decimalFormat = DecimalFormat("#.##")
- return try {
- val calc = ExpressionBuilder(query).build()
- query.replace(" ", "") + " = " + Utils.bold(decimalFormat.format(calc.evaluate()))
- } catch (e: IllegalArgumentException) {
- "No idea. This is the kind of math I don't get."
- }
+ val calc = ExpressionBuilder(query).build()
+ return query.replace(" ", "") + " = " + Utils.bold(decimalFormat.format(calc.evaluate()))
}
}
diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Lookup.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Lookup.kt
index 150888b..6ead8e7 100644
--- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Lookup.kt
+++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Lookup.kt
@@ -52,7 +52,7 @@ class Lookup(bot: Mobibot) : AbstractModule(bot) {
if (args.matches("(\\S.)+(\\S)+".toRegex())) {
with(bot) {
try {
- lookup(args).split(',').forEach {
+ nslookup(args).split(',').forEach {
send(it.trim())
}
} catch (ignore: UnknownHostException) {
@@ -105,7 +105,7 @@ class Lookup(bot: Mobibot) : AbstractModule(bot) {
*/
@JvmStatic
@Throws(UnknownHostException::class)
- fun lookup(query: String): String {
+ fun nslookup(query: String): String {
val buffer = StringBuilder()
val results = InetAddress.getAllByName(query)
var hostInfo: String
diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/WorldTime.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/WorldTime.kt
index ccda94b..d93f0b1 100644
--- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/WorldTime.kt
+++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/WorldTime.kt
@@ -68,10 +68,10 @@ class WorldTime(bot: Mobibot) : AbstractModule(bot) {
}
/**
- * Returns the world time.
+ * Returns the time for the given timezone/city.
*/
@JvmStatic
- fun worldTime(query: String): Message {
+ fun time(query: String): Message {
val tz = COUNTRIES_MAP[(query.substring(query.indexOf(' ') + 1).trim()).uppercase()]
val response: String = if (tz != null) {
if (BEATS_KEYWORD == tz) {
@@ -193,7 +193,7 @@ class WorldTime(bot: Mobibot) : AbstractModule(bot) {
send(sender, "The supported countries/zones are: ", isPrivate)
sendList(sender, ArrayList(COUNTRIES_MAP.keys), 17, isPrivate = false)
} else {
- val msg = worldTime(args)
+ val msg = time(args)
if (isPrivate) {
send(sender, msg.msg, true)
} else {
diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/CalcTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/CalcTest.kt
index 45f3848..a397f5a 100644
--- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/CalcTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/CalcTest.kt
@@ -31,9 +31,11 @@
*/
package net.thauvin.erik.mobibot.modules
+import net.objecthunter.exp4j.tokenizer.UnknownFunctionOrVariableException
import net.thauvin.erik.mobibot.Utils
-import net.thauvin.erik.mobibot.modules.Calc.Companion.calc
+import net.thauvin.erik.mobibot.modules.Calc.Companion.calculate
import org.assertj.core.api.Assertions.assertThat
+import org.assertj.core.api.Assertions.assertThatThrownBy
import org.testng.annotations.Test
/**
@@ -41,10 +43,11 @@ import org.testng.annotations.Test
*/
class CalcTest {
@Test
- fun testCalc() {
- assertThat(calc("1 + 1")).`as`("calc(1+1)").isEqualTo("1+1 = %s", Utils.bold(2))
- assertThat(calc("1 -3")).`as`("calc(1 -3)").isEqualTo("1-3 = %s", Utils.bold(-2))
- assertThat(calc("pi+π+e+φ")).`as`("calc(pi+π+e+φ)").isEqualTo("pi+π+e+φ = %s", Utils.bold("10.62"))
- assertThat(calc("one + one")).`as`("calc(one + one)").startsWith("No idea.")
+ fun testCalculate() {
+ assertThat(calculate("1 + 1")).`as`("calculate(1+1)").isEqualTo("1+1 = %s", Utils.bold(2))
+ assertThat(calculate("1 -3")).`as`("calculate(1 -3)").isEqualTo("1-3 = %s", Utils.bold(-2))
+ assertThat(calculate("pi+π+e+φ")).`as`("calculate(pi+π+e+φ)").isEqualTo("pi+π+e+φ = %s", Utils.bold("10.62"))
+ assertThatThrownBy { calculate("one + one") }.`as`("calculate(one+one)")
+ .isInstanceOf(UnknownFunctionOrVariableException::class.java)
}
}
diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt
index c7f0aef..2dca819 100644
--- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt
@@ -64,7 +64,7 @@ class GoogleSearchTest : LocalProperties() {
} catch (e: ModuleException) {
// Avoid displaying api keys in CI logs
if ("true" == System.getenv("CI") && apiKey.isNotBlank() && cseKey.isNotBlank()) {
- throw ModuleException(e.debugMessage, e.getSanitizedMessage(apiKey, cseKey))
+ throw ModuleException(e.debugMessage, e.getSanitizedMessage(apiKey, cseKey), e)
} else {
throw e
}
diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/LookupTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/LookupTest.kt
index b623d83..3b94181 100644
--- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/LookupTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/LookupTest.kt
@@ -31,7 +31,7 @@
*/
package net.thauvin.erik.mobibot.modules
-import net.thauvin.erik.mobibot.modules.Lookup.Companion.lookup
+import net.thauvin.erik.mobibot.modules.Lookup.Companion.nslookup
import net.thauvin.erik.mobibot.modules.Lookup.Companion.whois
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test
@@ -43,7 +43,7 @@ class LookupTest {
@Test
@Throws(Exception::class)
fun testLookup() {
- val result = lookup("apple.com")
+ val result = nslookup("apple.com")
assertThat(result).`as`("lookup(apple.com)").contains("17.253.144.10")
}
diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt
index 5053d22..c12b33e 100644
--- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt
@@ -62,7 +62,7 @@ class StockQuoteTest : LocalProperties() {
} catch (e: ModuleException) {
// Avoid displaying api keys in CI logs
if ("true" == System.getenv("CI") && apiKey.isNotBlank()) {
- throw ModuleException(e.debugMessage, e.getSanitizedMessage(apiKey))
+ throw ModuleException(e.debugMessage, e.getSanitizedMessage(apiKey), e)
} else {
throw e
}
diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/TwitterTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/TwitterTest.kt
index 4c309c6..10a9d79 100644
--- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/TwitterTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/TwitterTest.kt
@@ -47,7 +47,7 @@ class TwitterTest : LocalProperties() {
val ciName = System.getenv("CI_NAME")
return ciName ?: try {
InetAddress.getLocalHost().hostName
- } catch (e: UnknownHostException) {
+ } catch (ignore: UnknownHostException) {
"Unknown Host"
}
}
diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/WordTimeTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/WordTimeTest.kt
index dd696c9..4243383 100644
--- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/WordTimeTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/WordTimeTest.kt
@@ -32,7 +32,7 @@
package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.mobibot.Utils
-import net.thauvin.erik.mobibot.modules.WorldTime.Companion.worldTime
+import net.thauvin.erik.mobibot.modules.WorldTime.Companion.time
import org.assertj.core.api.Assertions.assertThat
import org.testng.annotations.Test
@@ -41,9 +41,9 @@ import org.testng.annotations.Test
*/
class WordTimeTest {
@Test
- fun testWorldTime() {
- assertThat(worldTime("PST").msg).`as`("PST").endsWith(Utils.bold("Los Angeles"))
- assertThat(worldTime("BLAH").isError).`as`("BLAH").isTrue
- assertThat(worldTime("BEATS").msg).`as`("BEATS").contains("@")
+ fun testTime() {
+ assertThat(time("PST").msg).`as`("PST").endsWith(Utils.bold("Los Angeles"))
+ assertThat(time("BLAH").isError).`as`("BLAH").isTrue
+ assertThat(time("BEATS").msg).`as`("BEATS").contains("@")
}
}
diff --git a/version.properties b/version.properties
index e99ce5a..bff0913 100644
--- a/version.properties
+++ b/version.properties
@@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle
-#Fri Apr 30 21:34:46 PDT 2021
-version.buildmeta=538
+#Sat May 01 21:41:40 PDT 2021
+version.buildmeta=568
version.major=0
version.minor=8
version.patch=0
version.prerelease=beta
version.project=mobibot
-version.semver=0.8.0-beta+538
+version.semver=0.8.0-beta+568