Cleanup.
This commit is contained in:
parent
67f618da71
commit
9f3dc273f0
12 changed files with 49 additions and 51 deletions
|
@ -51,9 +51,6 @@
|
|||
<ID>MagicNumber:WorldTime.kt$WorldTime.Companion$3600</ID>
|
||||
<ID>MagicNumber:WorldTime.kt$WorldTime.Companion$60</ID>
|
||||
<ID>MagicNumber:WorldTime.kt$WorldTime.Companion$86.4</ID>
|
||||
<ID>MemberNameEqualsClassName:Calc.kt$Calc.Companion$ @JvmStatic fun calc(query: String): String</ID>
|
||||
<ID>MemberNameEqualsClassName:Lookup.kt$Lookup.Companion$ @JvmStatic @Throws(UnknownHostException::class) fun lookup(query: String): String</ID>
|
||||
<ID>MemberNameEqualsClassName:WorldTime.kt$WorldTime.Companion$ @JvmStatic fun worldTime(query: String): Message</ID>
|
||||
<ID>NestedBlockDepth:Addons.kt$Addons$ fun add(command: AbstractCommand, props: Properties)</ID>
|
||||
<ID>NestedBlockDepth:Comment.kt$Comment$override fun commandResponse( sender: String, login: String, args: String, isOp: Boolean, isPrivate: Boolean )</ID>
|
||||
<ID>NestedBlockDepth:CurrencyConverter.kt$CurrencyConverter$ override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean)</ID>
|
||||
|
@ -75,14 +72,8 @@
|
|||
<ID>NestedBlockDepth:Weather2.kt$Weather2$ override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean)</ID>
|
||||
<ID>NestedBlockDepth:Weather2.kt$Weather2.Companion$ @JvmStatic @Throws(ModuleException::class) fun getWeather(query: String, apiKey: String?): List<Message></ID>
|
||||
<ID>NestedBlockDepth:WorldTime.kt$WorldTime$override fun commandResponse( sender: String, cmd: String, args: String, isPrivate: Boolean )</ID>
|
||||
<ID>PrintStackTrace:Mobibot.kt$Mobibot$e</ID>
|
||||
<ID>PrintStackTrace:Mobibot.kt$Mobibot.Companion$e</ID>
|
||||
<ID>ReturnCount:Addons.kt$Addons$ fun exec(sender: String, login: String, cmd: String, args: String, isOp: Boolean, isPrivate: Boolean): Boolean</ID>
|
||||
<ID>ReturnCount:Addons.kt$Addons$ fun help(sender: String, topic: String, isOp: Boolean, isPrivate: Boolean): Boolean</ID>
|
||||
<ID>SwallowedException:Calc.kt$Calc.Companion$catch (e: IllegalArgumentException) { "No idea. This is the kind of math I don't get." }</ID>
|
||||
<ID>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 } }</ID>
|
||||
<ID>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 } }</ID>
|
||||
<ID>SwallowedException:TwitterTest.kt$TwitterTest$catch (e: UnknownHostException) { "Unknown Host" }</ID>
|
||||
<ID>ThrowsCount:GoogleSearch.kt$GoogleSearch.Companion$ @JvmStatic @Throws(ModuleException::class) fun searchGoogle(query: String, apiKey: String?, cseKey: String?): List<Message></ID>
|
||||
<ID>ThrowsCount:StockQuote.kt$StockQuote.Companion$ @JvmStatic @Throws(ModuleException::class) fun getQuote(symbol: String, apiKey: String?): List<Message></ID>
|
||||
<ID>ThrowsCount:StockQuote.kt$StockQuote.Companion$@Throws(ModuleException::class) private fun getJsonResponse(response: String, debugMessage: String): JSONObject</ID>
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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("@")
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue