Minor cleanup

This commit is contained in:
Erik C. Thauvin 2023-01-12 23:06:21 -08:00
parent c3d1930592
commit a1ea25ae74
13 changed files with 42 additions and 42 deletions

View file

@ -13,6 +13,7 @@
<ID>LongParameterList:Twitter.kt$Twitter.Companion$( consumerKey: String?, consumerSecret: String?, token: String?, tokenSecret: String?, handle: String?, message: String, isDm: Boolean )</ID>
<ID>MagicNumber:ChatGpt.kt$ChatGpt$400</ID>
<ID>MagicNumber:ChatGpt.kt$ChatGpt.Companion$200</ID>
<ID>MagicNumber:ChatGpt.kt$ChatGpt.Companion$429</ID>
<ID>MagicNumber:Comment.kt$Comment$3</ID>
<ID>MagicNumber:CryptoPrices.kt$CryptoPrices$10</ID>
<ID>MagicNumber:CurrencyConverter.kt$CurrencyConverter$11</ID>

View file

@ -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<String, String> = 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()
}

View file

@ -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 <query>"))
initProperties(GOOGLE_API_KEY_PROP, GOOGLE_CSE_KEY_PROP)
initProperties(API_KEY_PROP, CSE_KEY_PROP)
}
}

View file

@ -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 <symbol|keywords>"))
initProperties(ALPHAVANTAGE_API_KEY_PROP)
initProperties(API_KEY_PROP)
}
}

View file

@ -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 <message>"))
properties[AUTO_POST_PROP] = "false"
initProperties(CONSUMER_KEY_PROP, CONSUMER_SECRET_PROP, HANDLE_PROP, TOKEN_PROP, TOKEN_SECRET_PROP)

View file

@ -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)
}
}

View file

@ -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)
}
}

View file

@ -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")

View file

@ -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"

View file

@ -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)

View file

@ -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)
}

View file

@ -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")

View file

@ -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