diff --git a/config/detekt/baseline.xml b/config/detekt/baseline.xml
index 57c71a4..da082db 100644
--- a/config/detekt/baseline.xml
+++ b/config/detekt/baseline.xml
@@ -13,6 +13,7 @@
LongParameterList:Twitter.kt$Twitter.Companion$( consumerKey: String?, consumerSecret: String?, token: String?, tokenSecret: String?, handle: String?, message: String, isDm: Boolean )
MagicNumber:ChatGpt.kt$ChatGpt$400
MagicNumber:ChatGpt.kt$ChatGpt.Companion$200
+ MagicNumber:ChatGpt.kt$ChatGpt.Companion$429
MagicNumber:Comment.kt$Comment$3
MagicNumber:CryptoPrices.kt$CryptoPrices$10
MagicNumber:CurrencyConverter.kt$CurrencyConverter$11
diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/CryptoPrices.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/CryptoPrices.kt
index 66a33ae..05647bd 100644
--- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/CryptoPrices.kt
+++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/CryptoPrices.kt
@@ -65,7 +65,7 @@ class CryptoPrices : AbstractModule() {
}
val debugMessage = "crypto($cmd $args)"
- if (args == CURRENCY_CODES_KEYWORD) {
+ if (args == CODES_KEYWORD) {
event.sendMessage("The supported currencies are:")
event.sendList(ArrayList(CURRENCIES.keys), 10, isIndent = true)
} else if (args.matches("\\w+( [a-zA-Z]{3}+)?".toRegex())) {
@@ -100,7 +100,7 @@ class CryptoPrices : AbstractModule() {
private val CURRENCIES: MutableMap = mutableMapOf()
// Currency codes keyword
- private const val CURRENCY_CODES_KEYWORD = "codes"
+ private const val CODES_KEYWORD = "codes"
/**
* Get current market price.
@@ -153,7 +153,7 @@ class CryptoPrices : AbstractModule() {
add(helpFormat("%c $CRYPTO_CMD ETH EUR"))
add(helpFormat("%c $CRYPTO_CMD ETH2 GPB"))
add("To list the supported currencies:")
- add(helpFormat("%c $CRYPTO_CMD $CURRENCY_CODES_KEYWORD"))
+ add(helpFormat("%c $CRYPTO_CMD $CODES_KEYWORD"))
}
loadCurrencies()
}
diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearch.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearch.kt
index 76451db..02af2b6 100644
--- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearch.kt
+++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearch.kt
@@ -67,8 +67,8 @@ class GoogleSearch : AbstractModule() {
try {
val results = searchGoogle(
args,
- properties[GOOGLE_API_KEY_PROP],
- properties[GOOGLE_CSE_KEY_PROP],
+ properties[API_KEY_PROP],
+ properties[CSE_KEY_PROP],
event.user.nick
)
for (msg in results) {
@@ -91,10 +91,10 @@ class GoogleSearch : AbstractModule() {
companion object {
// Google API Key property
- const val GOOGLE_API_KEY_PROP = "google-api-key"
+ const val API_KEY_PROP = "google-api-key"
// Google Custom Search Engine ID property
- const val GOOGLE_CSE_KEY_PROP = "google-cse-cx"
+ const val CSE_KEY_PROP = "google-cse-cx"
// Google command
private const val GOOGLE_CMD = "google"
@@ -158,6 +158,6 @@ class GoogleSearch : AbstractModule() {
commands.add(GOOGLE_CMD)
help.add("To search Google:")
help.add(helpFormat("%c $GOOGLE_CMD "))
- initProperties(GOOGLE_API_KEY_PROP, GOOGLE_CSE_KEY_PROP)
+ initProperties(API_KEY_PROP, CSE_KEY_PROP)
}
}
diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/StockQuote.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/StockQuote.kt
index ffca08b..6df2317 100644
--- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/StockQuote.kt
+++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/StockQuote.kt
@@ -63,7 +63,7 @@ class StockQuote : AbstractModule() {
override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent) {
if (args.isNotBlank()) {
try {
- val messages = getQuote(args, properties[ALPHAVANTAGE_API_KEY_PROP])
+ val messages = getQuote(args, properties[API_KEY_PROP])
for (msg in messages) {
event.sendMessage(channel, msg)
}
@@ -80,17 +80,17 @@ class StockQuote : AbstractModule() {
companion object {
/**
- * The Alpha Advantage property key.
+ * The API property key.
*/
- const val ALPHAVANTAGE_API_KEY_PROP = "alphavantage-api-key"
+ const val API_KEY_PROP = "alphavantage-api-key"
/**
* The Invalid Symbol error string.
*/
const val INVALID_SYMBOL = "Invalid symbol."
- // Alpha Advantage URL
- private const val ALPHAVANTAGE_URL = "https://www.alphavantage.co/query?function="
+ // API URL
+ private const val API_URL = "https://www.alphavantage.co/query?function="
// Quote command
private const val STOCK_CMD = "stock"
@@ -145,7 +145,7 @@ class StockQuote : AbstractModule() {
with(messages) {
// Search for symbol/keywords
response = URL(
- "${ALPHAVANTAGE_URL}SYMBOL_SEARCH&keywords=" + symbol.encodeUrl() + "&apikey="
+ "${API_URL}SYMBOL_SEARCH&keywords=" + symbol.encodeUrl() + "&apikey="
+ apiKey.encodeUrl()
).reader().body
var json = getJsonResponse(response, debugMessage)
@@ -157,7 +157,7 @@ class StockQuote : AbstractModule() {
// Get quote for symbol
response = URL(
- "${ALPHAVANTAGE_URL}GLOBAL_QUOTE&symbol="
+ "${API_URL}GLOBAL_QUOTE&symbol="
+ symbolInfo.getString("1. symbol").encodeUrl() + "&apikey="
+ apiKey.encodeUrl()
).reader().body
@@ -232,6 +232,6 @@ class StockQuote : AbstractModule() {
commands.add(STOCK_CMD)
help.add("To retrieve a stock quote:")
help.add(helpFormat("%c $STOCK_CMD "))
- initProperties(ALPHAVANTAGE_API_KEY_PROP)
+ initProperties(API_KEY_PROP)
}
}
diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Twitter.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Twitter.kt
index 4fc3770..ddb82b2 100644
--- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Twitter.kt
+++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Twitter.kt
@@ -84,7 +84,7 @@ class Twitter : SocialModule() {
const val TOKEN_PROP = "twitter-token"
const val TOKEN_SECRET_PROP = "twitter-tokenSecret"
- // Twitter command
+ // Twitter commands
private const val TWITTER_CMD = "twitter"
private const val TWEET_CMD = "tweet"
@@ -118,7 +118,7 @@ class Twitter : SocialModule() {
dm.text
}
} catch (e: TwitterException) {
- throw ModuleException("twitterPost($message)", "An error has occurred: ${e.message}", e)
+ throw ModuleException("tweet($message)", "An error has occurred: ${e.message}", e)
}
}
}
@@ -126,7 +126,7 @@ class Twitter : SocialModule() {
init {
commands.add(TWITTER_CMD)
commands.add(TWEET_CMD)
- help.add("To tweet on Twitter:")
+ help.add("To $TWEET_CMD on $name:")
help.add(helpFormat("%c $TWEET_CMD "))
properties[AUTO_POST_PROP] = "false"
initProperties(CONSUMER_KEY_PROP, CONSUMER_SECRET_PROP, HANDLE_PROP, TOKEN_PROP, TOKEN_SECRET_PROP)
diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Weather2.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Weather2.kt
index 5c5ae67..ec963fe 100644
--- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Weather2.kt
+++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Weather2.kt
@@ -65,7 +65,7 @@ class Weather2 : AbstractModule() {
override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent) {
if (args.isNotBlank()) {
try {
- val messages = getWeather(args, properties[OWM_API_KEY_PROP])
+ val messages = getWeather(args, properties[API_KEY_PROP])
if (messages[0].isError) {
helpResponse(event)
} else {
@@ -88,7 +88,7 @@ class Weather2 : AbstractModule() {
/**
* The OpenWeatherMap API Key property.
*/
- const val OWM_API_KEY_PROP = "owm-api-key"
+ const val API_KEY_PROP = "owm-api-key"
// Weather command
private const val WEATHER_CMD = "weather"
@@ -246,6 +246,6 @@ class Weather2 : AbstractModule() {
add(helpFormat("%c $WEATHER_CMD paris, fr"))
add("The default ISO 3166 country code is ${"US".bold()}. Zip codes supported in most countries.")
}
- initProperties(OWM_API_KEY_PROP)
+ initProperties(API_KEY_PROP)
}
}
diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/WolframAlpha.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/WolframAlpha.kt
index 56d3a3d..204ad17 100644
--- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/WolframAlpha.kt
+++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/WolframAlpha.kt
@@ -66,9 +66,9 @@ class WolframAlpha : AbstractModule() {
units = if (query.size == 2) {
getUnits(query[1].trim())
} else {
- getUnits(properties[WOLFRAM_UNITS_PROP])
+ getUnits(properties[UNITS_PROP])
},
- appId = properties[WOLFRAM_APPID_KEY]
+ appId = properties[APPID_KEY_PROP]
)
)
} catch (e: ModuleException) {
@@ -86,12 +86,13 @@ class WolframAlpha : AbstractModule() {
/**
* The Wolfram Alpha API Key property.
*/
- const val WOLFRAM_APPID_KEY = "wolfram-appid"
+ const val APPID_KEY_PROP = "wolfram-appid"
/**
* The Wolfram units properties
*/
- const val WOLFRAM_UNITS_PROP = "wolfram-units"
+ const val UNITS_PROP = "wolfram-units"
+
const val METRIC = "metric"
const val IMPERIAL = "imperial"
@@ -137,6 +138,6 @@ class WolframAlpha : AbstractModule() {
add(Utils.helpFormat("%c $WOLFRAM_CMD days until christmas"))
add(Utils.helpFormat("%c $WOLFRAM_CMD distance earth moon units=metric"))
}
- initProperties(WOLFRAM_APPID_KEY, WOLFRAM_UNITS_PROP)
+ initProperties(APPID_KEY_PROP, UNITS_PROP)
}
}
diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/ChatGptTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/ChatGptTest.kt
index 98f0052..6c30297 100644
--- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/ChatGptTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/ChatGptTest.kt
@@ -34,10 +34,8 @@ package net.thauvin.erik.mobibot.modules
import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.hasNoCause
-import assertk.assertions.isEqualTo
import assertk.assertions.isFailure
import assertk.assertions.isInstanceOf
-import assertk.assertions.message
import net.thauvin.erik.mobibot.LocalProperties
import org.testng.annotations.Test
@@ -52,7 +50,7 @@ class ChatGptTest : LocalProperties() {
@Test(groups = ["modules", "no-ci"])
fun testChat() {
- val apiKey = getProperty(ChatGpt.CHATGPT_API_KEY)
+ val apiKey = getProperty(ChatGpt.API_KEY_PROP)
assertThat(
ChatGpt.chat("how do I make an HTTP request in Javascript?", apiKey, 100)
).contains("XMLHttpRequest")
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 8d12ab4..9d052cf 100644
--- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/GoogleSearchTest.kt
@@ -75,8 +75,8 @@ class GoogleSearchTest : LocalProperties() {
@Test(groups = ["no-ci", "modules"])
@Throws(ModuleException::class)
fun testSearchGoogle() {
- val apiKey = getProperty(GoogleSearch.GOOGLE_API_KEY_PROP)
- val cseKey = getProperty(GoogleSearch.GOOGLE_CSE_KEY_PROP)
+ val apiKey = getProperty(GoogleSearch.API_KEY_PROP)
+ val cseKey = getProperty(GoogleSearch.CSE_KEY_PROP)
try {
var query = "mobibot"
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 162550f..2721469 100644
--- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/StockQuoteTest.kt
@@ -59,7 +59,7 @@ class StockQuoteTest : LocalProperties() {
@Test(groups = ["modules"])
@Throws(ModuleException::class)
fun testGetQuote() {
- val apiKey = getProperty(StockQuote.ALPHAVANTAGE_API_KEY_PROP)
+ val apiKey = getProperty(StockQuote.API_KEY_PROP)
try {
var symbol = "apple inc"
val messages = getQuote(symbol, apiKey)
diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt
index 6c67536..f1949d6 100644
--- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt
+++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt
@@ -46,7 +46,7 @@ import assertk.assertions.prop
import net.aksingh.owmjapis.api.APIException
import net.aksingh.owmjapis.core.OWM
import net.thauvin.erik.mobibot.LocalProperties
-import net.thauvin.erik.mobibot.modules.Weather2.Companion.OWM_API_KEY_PROP
+import net.thauvin.erik.mobibot.modules.Weather2.Companion.API_KEY_PROP
import net.thauvin.erik.mobibot.modules.Weather2.Companion.ftoC
import net.thauvin.erik.mobibot.modules.Weather2.Companion.getCountry
import net.thauvin.erik.mobibot.modules.Weather2.Companion.getWeather
@@ -86,7 +86,7 @@ class Weather2Test : LocalProperties() {
@Throws(ModuleException::class)
fun testWeather() {
var query = "98204"
- var messages = getWeather(query, getProperty(OWM_API_KEY_PROP))
+ var messages = getWeather(query, getProperty(API_KEY_PROP))
assertThat(messages, "getWeather($query)").index(0).prop(Message::msg).all {
contains("Everett, United States")
contains("US")
@@ -94,7 +94,7 @@ class Weather2Test : LocalProperties() {
assertThat(messages, "getWeather($query)").index(messages.size - 1).prop(Message::msg).endsWith("98204%2CUS")
query = "San Francisco"
- messages = getWeather(query, getProperty(OWM_API_KEY_PROP))
+ messages = getWeather(query, getProperty(API_KEY_PROP))
assertThat(messages, "getWeather($query)").index(0).prop(Message::msg).all {
contains("San Francisco")
contains("US")
@@ -102,7 +102,7 @@ class Weather2Test : LocalProperties() {
assertThat(messages, "getWeather($query)").index(messages.size - 1).prop(Message::msg).endsWith("5391959")
query = "London, GB"
- messages = getWeather(query, getProperty(OWM_API_KEY_PROP))
+ messages = getWeather(query, getProperty(API_KEY_PROP))
assertThat(messages, "getWeather($query)").index(0).prop(Message::msg).all {
contains("London, United Kingdom")
contains("GB")
@@ -111,7 +111,7 @@ class Weather2Test : LocalProperties() {
try {
query = "Foo, US"
- getWeather(query, getProperty(OWM_API_KEY_PROP))
+ getWeather(query, getProperty(API_KEY_PROP))
} catch (e: ModuleException) {
assertThat(e.cause, "getWeather($query)").isNotNull().isInstanceOf(APIException::class.java)
}
diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/WolframAlphaTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/WolframAlphaTest.kt
index f0fb424..0d9ed9a 100644
--- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/WolframAlphaTest.kt
+++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/WolframAlphaTest.kt
@@ -58,7 +58,7 @@ class WolframAlphaTest : LocalProperties() {
@Test(groups = ["modules", "no-ci"])
@Throws(ModuleException::class)
fun queryWolframTest() {
- val apiKey = getProperty(WolframAlpha.WOLFRAM_APPID_KEY)
+ val apiKey = getProperty(WolframAlpha.APPID_KEY_PROP)
try {
var query = "SFO to SEA"
assertThat(queryWolfram(query, appId = apiKey), "queryWolfram($query)").contains("miles")
diff --git a/version.properties b/version.properties
index c049177..8d6a471 100644
--- a/version.properties
+++ b/version.properties
@@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle
-#Thu Jan 12 00:57:56 PST 2023
-version.buildmeta=975
+#Thu Jan 12 23:03:48 PST 2023
+version.buildmeta=982
version.major=0
version.minor=8
version.patch=0
version.prerelease=rc
version.project=mobibot
-version.semver=0.8.0-rc+975
+version.semver=0.8.0-rc+982