Minor cleanup

This commit is contained in:
Erik C. Thauvin 2023-01-12 00:57:20 -08:00
parent 6894e05610
commit 66ca972b9b
12 changed files with 44 additions and 42 deletions

View file

@ -68,7 +68,7 @@ jobs:
env: env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew sonarqube run: ./gradlew sonar
- name: Cleanup Gradle Cache - name: Cleanup Gradle Cache
run: | run: |

View file

@ -1,8 +1,10 @@
# mobibot # mobibot
[![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ethauvin_mobibot&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=ethauvin_mobibot) [![License (3-Clause BSD)](https://img.shields.io/badge/license-BSD%203--Clause-blue.svg)](https://opensource.org/licenses/BSD-3-Clause)
[![Kotlin](https://img.shields.io/badge/kotlin-1.8.0-blue)](https://kotlinlang.org/)
[![GitHub CI](https://github.com/ethauvin/mobibot/actions/workflows/gradle.yml/badge.svg)](https://github.com/ethauvin/mobibot/actions/workflows/gradle.yml) [![CircleCI](https://circleci.com/gh/ethauvin/mobibot/tree/master.svg?style=shield)](https://circleci.com/gh/ethauvin/mobibot/tree/master) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ethauvin_mobibot&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=ethauvin_mobibot)
[![GitHub CI](https://github.com/ethauvin/mobibot/actions/workflows/gradle.yml/badge.svg)](https://github.com/ethauvin/mobibot/actions/workflows/gradle.yml)
[![CircleCI](https://circleci.com/gh/ethauvin/mobibot/tree/master.svg?style=shield)](https://circleci.com/gh/ethauvin/mobibot/tree/master)
Some very basic instructions: Some very basic instructions:

View file

@ -55,7 +55,7 @@ dependencies {
implementation 'commons-net:commons-net:3.9.0' implementation 'commons-net:commons-net:3.9.0'
// Google // Google
implementation 'com.google.code.gson:gson:2.10' implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.google.guava:guava:31.1-jre' implementation 'com.google.guava:guava:31.1-jre'
// Kotlin // Kotlin
@ -82,7 +82,7 @@ dependencies {
implementation 'net.thauvin.erik:cryptoprice:1.0.0' implementation 'net.thauvin.erik:cryptoprice:1.0.0'
implementation 'net.thauvin.erik:jokeapi:0.9-SNAPSHOT' implementation 'net.thauvin.erik:jokeapi:0.9-SNAPSHOT'
implementation 'net.thauvin.erik:pinboard-poster:1.0.3' implementation 'net.thauvin.erik:pinboard-poster:1.0.3'
implementation 'net.thauvin.erik:urlencoder:1.0.1' implementation 'net.thauvin.erik:urlencoder:1.3.0'
testImplementation 'com.willowtreeapps.assertk:assertk-jvm:0.25' testImplementation 'com.willowtreeapps.assertk:assertk-jvm:0.25'
// testImplementation 'org.mockito.kotlin:mockito-kotlin:4.0.0' // testImplementation 'org.mockito.kotlin:mockito-kotlin:4.0.0'
@ -188,7 +188,7 @@ sonarqube {
} }
} }
tasks.sonarqube { tasks.sonar {
dependsOn 'koverReport' dependsOn 'koverReport'
} }
@ -219,6 +219,6 @@ task deploy {
task release { task release {
group = 'Publishing' group = 'Publishing'
description = 'Releases new version.' description = 'Releases new version.'
dependsOn(clean, wrapper, check, deploy) dependsOn(clean, check, deploy)
mustRunAfter clean mustRunAfter clean
} }

View file

@ -11,6 +11,7 @@
<ID>LongParameterList:Comment.kt$Comment$( channel: String, cmd: String, entry: EntryLink, entryIndex: Int, commentIndex: Int, event: GenericMessageEvent )</ID> <ID>LongParameterList:Comment.kt$Comment$( channel: String, cmd: String, entry: EntryLink, entryIndex: Int, commentIndex: Int, event: GenericMessageEvent )</ID>
<ID>LongParameterList:EntryLink.kt$EntryLink$( // Link's comments val comments: MutableList&lt;EntryComment&gt; = mutableListOf(), // Tags/categories val tags: MutableList&lt;SyndCategory&gt; = mutableListOf(), // Channel var channel: String, // Creation date var date: Date = Calendar.getInstance().time, // Link's URL var link: String, // Author's login var login: String = "", // Author's nickname var nick: String, // Link's title var title: String )</ID> <ID>LongParameterList:EntryLink.kt$EntryLink$( // Link's comments val comments: MutableList&lt;EntryComment&gt; = mutableListOf(), // Tags/categories val tags: MutableList&lt;SyndCategory&gt; = mutableListOf(), // Channel var channel: String, // Creation date var date: Date = Calendar.getInstance().time, // Link's URL var link: String, // Author's login var login: String = "", // Author's nickname var nick: String, // Link's title var title: String )</ID>
<ID>LongParameterList:Twitter.kt$Twitter.Companion$( consumerKey: String?, consumerSecret: String?, token: String?, tokenSecret: String?, handle: String?, message: String, isDm: Boolean )</ID> <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$200</ID>
<ID>MagicNumber:Comment.kt$Comment$3</ID> <ID>MagicNumber:Comment.kt$Comment$3</ID>
<ID>MagicNumber:CryptoPrices.kt$CryptoPrices$10</ID> <ID>MagicNumber:CryptoPrices.kt$CryptoPrices$10</ID>
@ -48,7 +49,7 @@
<ID>MaxLineLength:TwitterOAuth.kt$TwitterOAuth$*</ID> <ID>MaxLineLength:TwitterOAuth.kt$TwitterOAuth$*</ID>
<ID>NestedBlockDepth:Addons.kt$Addons$fun add(command: AbstractCommand): Boolean</ID> <ID>NestedBlockDepth:Addons.kt$Addons$fun add(command: AbstractCommand): Boolean</ID>
<ID>NestedBlockDepth:Addons.kt$Addons$fun add(module: AbstractModule): Boolean</ID> <ID>NestedBlockDepth:Addons.kt$Addons$fun add(module: AbstractModule): Boolean</ID>
<ID>NestedBlockDepth:ChatGpt.kt$ChatGpt.Companion$@JvmStatic @Throws(ModuleException::class) fun chat(query: String, apiKey: String?): String</ID> <ID>NestedBlockDepth:ChatGpt.kt$ChatGpt.Companion$@JvmStatic @Throws(ModuleException::class) fun chat(query: String, apiKey: String?, maxTokens: Int): String</ID>
<ID>NestedBlockDepth:Comment.kt$Comment$override fun commandResponse(channel: String, args: String, event: GenericMessageEvent)</ID> <ID>NestedBlockDepth:Comment.kt$Comment$override fun commandResponse(channel: String, args: String, event: GenericMessageEvent)</ID>
<ID>NestedBlockDepth:CurrencyConverter.kt$CurrencyConverter.Companion$@JvmStatic fun convertCurrency(query: String): Message</ID> <ID>NestedBlockDepth:CurrencyConverter.kt$CurrencyConverter.Companion$@JvmStatic fun convertCurrency(query: String): Message</ID>
<ID>NestedBlockDepth:EntryLink.kt$EntryLink$private fun setTags(tags: List&lt;String?&gt;)</ID> <ID>NestedBlockDepth:EntryLink.kt$EntryLink$private fun setTags(tags: List&lt;String?&gt;)</ID>
@ -64,8 +65,8 @@
<ID>NestedBlockDepth:StockQuote.kt$StockQuote.Companion$@JvmStatic @Throws(ModuleException::class) fun getQuote(symbol: String, apiKey: String?): List&lt;Message&gt;</ID> <ID>NestedBlockDepth:StockQuote.kt$StockQuote.Companion$@JvmStatic @Throws(ModuleException::class) fun getQuote(symbol: String, apiKey: String?): List&lt;Message&gt;</ID>
<ID>NestedBlockDepth:Tell.kt$Tell$fun send(event: GenericUserEvent)</ID> <ID>NestedBlockDepth:Tell.kt$Tell$fun send(event: GenericUserEvent)</ID>
<ID>NestedBlockDepth:TwitterOAuth.kt$TwitterOAuth$@JvmStatic fun main(args: Array&lt;String&gt;)</ID> <ID>NestedBlockDepth:TwitterOAuth.kt$TwitterOAuth$@JvmStatic fun main(args: Array&lt;String&gt;)</ID>
<ID>NestedBlockDepth:Utils.kt$Utils$@JvmStatic fun loadData(file: String, default: Any, logger: Logger, description: String): Any</ID> <ID>NestedBlockDepth:Utils.kt$Utils$@JvmStatic fun loadSerialData(file: String, default: Any, logger: Logger, description: String): Any</ID>
<ID>NestedBlockDepth:Utils.kt$Utils$@JvmStatic fun saveData(file: String, data: Any, logger: Logger, description: String)</ID> <ID>NestedBlockDepth:Utils.kt$Utils$@JvmStatic fun saveSerialData(file: String, data: Any, logger: Logger, description: String)</ID>
<ID>NestedBlockDepth:Weather2.kt$Weather2$override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent)</ID> <ID>NestedBlockDepth:Weather2.kt$Weather2$override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent)</ID>
<ID>NestedBlockDepth:Weather2.kt$Weather2.Companion$@JvmStatic @Throws(ModuleException::class) fun getWeather(query: String, apiKey: String?): List&lt;Message&gt;</ID> <ID>NestedBlockDepth:Weather2.kt$Weather2.Companion$@JvmStatic @Throws(ModuleException::class) fun getWeather(query: String, apiKey: String?): List&lt;Message&gt;</ID>
<ID>PrintStackTrace:TwitterOAuth.kt$TwitterOAuth$ioe</ID> <ID>PrintStackTrace:TwitterOAuth.kt$TwitterOAuth$ioe</ID>
@ -76,7 +77,7 @@
<ID>SwallowedException:GoogleSearchTest.kt$GoogleSearchTest$e: ModuleException</ID> <ID>SwallowedException:GoogleSearchTest.kt$GoogleSearchTest$e: ModuleException</ID>
<ID>SwallowedException:StockQuoteTest.kt$StockQuoteTest$e: ModuleException</ID> <ID>SwallowedException:StockQuoteTest.kt$StockQuoteTest$e: ModuleException</ID>
<ID>SwallowedException:WolframAlphaTest.kt$WolframAlphaTest$e: ModuleException</ID> <ID>SwallowedException:WolframAlphaTest.kt$WolframAlphaTest$e: ModuleException</ID>
<ID>ThrowsCount:ChatGpt.kt$ChatGpt.Companion$@JvmStatic @Throws(ModuleException::class) fun chat(query: String, apiKey: String?): String</ID> <ID>ThrowsCount:ChatGpt.kt$ChatGpt.Companion$@JvmStatic @Throws(ModuleException::class) fun chat(query: String, apiKey: String?, maxTokens: Int): String</ID>
<ID>ThrowsCount:GoogleSearch.kt$GoogleSearch.Companion$@JvmStatic @Throws(ModuleException::class) fun searchGoogle( query: String, apiKey: String?, cseKey: String?, quotaUser: String = ReleaseInfo.PROJECT ): List&lt;Message&gt;</ID> <ID>ThrowsCount:GoogleSearch.kt$GoogleSearch.Companion$@JvmStatic @Throws(ModuleException::class) fun searchGoogle( query: String, apiKey: String?, cseKey: String?, quotaUser: String = ReleaseInfo.PROJECT ): List&lt;Message&gt;</ID>
<ID>ThrowsCount:Joke.kt$Joke.Companion$@JvmStatic @Throws(ModuleException::class) fun randomJoke(): List&lt;Message&gt;</ID> <ID>ThrowsCount:Joke.kt$Joke.Companion$@JvmStatic @Throws(ModuleException::class) fun randomJoke(): List&lt;Message&gt;</ID>
<ID>ThrowsCount:Mastodon.kt$Mastodon.Companion$@JvmStatic @Throws(ModuleException::class) fun toot(apiKey: String?, instance: String?, handle: String?, message: String, isDm: Boolean): String</ID> <ID>ThrowsCount:Mastodon.kt$Mastodon.Companion$@JvmStatic @Throws(ModuleException::class) fun toot(apiKey: String?, instance: String?, handle: String?, message: String, isDm: Boolean): String</ID>

View file

@ -28,12 +28,12 @@ tell-max-size=50
#disabled-modules=dice, joke #disabled-modules=dice, joke
# #
# Credentials for: http://pinboard.in/ # API Token for: https://pinboard.in/settings/password
# #
#pinboard-api-token=user\:TOKEN #pinboard-api-token=user\:TOKEN
# #
# Configure app at: https://developer.twitter.com/en/apps # Configure app at: https://developer.twitter.com/
# and then: java -cp mobibot.jar net.thauvin.erik.mobibot.TwitterOAuth <consumerKey> <consumerSecret> # and then: java -cp mobibot.jar net.thauvin.erik.mobibot.TwitterOAuth <consumerKey> <consumerSecret>
# #
#twitter-consumerKey= #twitter-consumerKey=
@ -61,14 +61,14 @@ tell-max-size=50
#mastodon-auto-post=true #mastodon-auto-post=true
# #
# Create custom search engine at: https://cse.google.com/ # Create custom search engine at: https://programmablesearchengine.google.com/
# and get API key from: https://console.developers.google.com/ # and get API key from: https://console.cloud.google.com/apis
# #
#google-api= #google-api=
#google-cse-cx= #google-cse-cx=
# #
# Get OpenWeatherMap API key from: https://openweathermap.org/ # Get OpenWeatherMap API key from: https://openweathermap.org/api
# #
#owm-api-key= #owm-api-key=
@ -87,3 +87,4 @@ tell-max-size=50
# ChatGPT/OpenAI API key from: https://beta.openai.com/account/api-keys # ChatGPT/OpenAI API key from: https://beta.openai.com/account/api-keys
# #
#chatgpt-api-key= #chatgpt-api-key=
#chatgpt-max-tokens=1024

View file

@ -47,7 +47,6 @@ import java.io.ObjectInputStream
import java.io.ObjectOutputStream import java.io.ObjectOutputStream
import java.net.HttpURLConnection import java.net.HttpURLConnection
import java.net.URL import java.net.URL
import java.nio.charset.StandardCharsets
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Paths import java.nio.file.Paths
import java.time.LocalDateTime import java.time.LocalDateTime
@ -189,7 +188,7 @@ object Utils {
} }
/** /**
* Returns {@code true} if the specified user is an operator on the [channel]. * Returns `true` if the specified user is an operator on the [channel].
*/ */
@JvmStatic @JvmStatic
fun GenericMessageEvent.isChannelOp(channel: String): Boolean { fun GenericMessageEvent.isChannelOp(channel: String): Boolean {
@ -197,7 +196,7 @@ object Utils {
} }
/** /**
* Returns {@code true} if a HTTP status code indicates a successful response. * Returns `true` if a HTTP status code indicates a successful response.
*/ */
@JvmStatic @JvmStatic
fun Int.isHttpSuccess() = this in 200..399 fun Int.isHttpSuccess() = this in 200..399
@ -214,10 +213,10 @@ object Utils {
} }
/** /**
* Load data. * Load serial data from file.
*/ */
@JvmStatic @JvmStatic
fun loadData(file: String, default: Any, logger: Logger, description: String): Any { fun loadSerialData(file: String, default: Any, logger: Logger, description: String): Any {
val serialFile = Paths.get(file) val serialFile = Paths.get(file)
if (serialFile.exists() && serialFile.fileSize() > 0) { if (serialFile.exists() && serialFile.fileSize() > 0) {
try { try {
@ -237,7 +236,7 @@ object Utils {
} }
/** /**
* Returns {@code true} if the list does not contain the given string. * Returns `true` if the list does not contain the given string.
*/ */
@JvmStatic @JvmStatic
fun List<String>.notContains(text: String, ignoreCase: Boolean = false) = this.none { it.equals(text, ignoreCase) } fun List<String>.notContains(text: String, ignoreCase: Boolean = false) = this.none { it.equals(text, ignoreCase) }
@ -290,7 +289,7 @@ object Utils {
* Save data * Save data
*/ */
@JvmStatic @JvmStatic
fun saveData(file: String, data: Any, logger: Logger, description: String) { fun saveSerialData(file: String, data: Any, logger: Logger, description: String) {
try { try {
BufferedOutputStream(Files.newOutputStream(Paths.get(file))).use { bos -> BufferedOutputStream(Files.newOutputStream(Paths.get(file))).use { bos ->
ObjectOutputStream(bos).use { output -> ObjectOutputStream(bos).use { output ->

View file

@ -35,8 +35,8 @@ package net.thauvin.erik.mobibot.commands.seen
import com.google.common.collect.ImmutableSortedSet import com.google.common.collect.ImmutableSortedSet
import net.thauvin.erik.mobibot.Utils.bot import net.thauvin.erik.mobibot.Utils.bot
import net.thauvin.erik.mobibot.Utils.helpFormat import net.thauvin.erik.mobibot.Utils.helpFormat
import net.thauvin.erik.mobibot.Utils.loadData import net.thauvin.erik.mobibot.Utils.loadSerialData
import net.thauvin.erik.mobibot.Utils.saveData import net.thauvin.erik.mobibot.Utils.saveSerialData
import net.thauvin.erik.mobibot.Utils.sendMessage import net.thauvin.erik.mobibot.Utils.sendMessage
import net.thauvin.erik.mobibot.commands.AbstractCommand import net.thauvin.erik.mobibot.commands.AbstractCommand
import net.thauvin.erik.mobibot.commands.Info.Companion.toUptime import net.thauvin.erik.mobibot.commands.Info.Companion.toUptime
@ -107,7 +107,7 @@ class Seen(private val serialObject: String) : AbstractCommand() {
if (isEnabled()) { if (isEnabled()) {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
seenNicks.putAll( seenNicks.putAll(
loadData( loadSerialData(
serialObject, serialObject,
TreeMap<String, SeenNick>(), TreeMap<String, SeenNick>(),
logger, logger,
@ -118,7 +118,7 @@ class Seen(private val serialObject: String) : AbstractCommand() {
} }
fun save() { fun save() {
saveData(serialObject, seenNicks, logger, "seen nicknames") saveSerialData(serialObject, seenNicks, logger, "seen nicknames")
} }
init { init {

View file

@ -31,8 +31,8 @@
*/ */
package net.thauvin.erik.mobibot.commands.tell package net.thauvin.erik.mobibot.commands.tell
import net.thauvin.erik.mobibot.Utils.loadData import net.thauvin.erik.mobibot.Utils.loadSerialData
import net.thauvin.erik.mobibot.Utils.saveData import net.thauvin.erik.mobibot.Utils.saveSerialData
import org.slf4j.Logger import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.time.Clock import java.time.Clock
@ -60,7 +60,7 @@ object TellManager {
@JvmStatic @JvmStatic
fun load(file: String): List<TellMessage> { fun load(file: String): List<TellMessage> {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
return loadData(file, emptyList<TellMessage>(), logger, "message queue") as List<TellMessage> return loadSerialData(file, emptyList<TellMessage>(), logger, "message queue") as List<TellMessage>
} }
/** /**
@ -69,7 +69,7 @@ object TellManager {
@JvmStatic @JvmStatic
fun save(file: String, messages: List<TellMessage?>?) { fun save(file: String, messages: List<TellMessage?>?) {
if (messages != null) { if (messages != null) {
saveData(file, messages, logger, "messages") saveSerialData(file, messages, logger, "messages")
} }
} }
} }

View file

@ -66,12 +66,12 @@ class TellMessage(
var id: String = queued.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss")) var id: String = queued.format(DateTimeFormatter.ofPattern("yyyyMMddHHmmss"))
/** /**
* Returns {@code true} if a notification was sent. * Returns `true` if a notification was sent.
*/ */
var isNotified = false var isNotified = false
/** /**
* Returns {@code true} if the message was received. * Returns `true` if the message was received.
*/ */
var isReceived = false var isReceived = false
set(value) { set(value) {

View file

@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle #Generated by the Semver Plugin for Gradle
#Thu Jan 05 16:20:43 PST 2023 #Thu Jan 12 00:57:56 PST 2023
version.buildmeta=948 version.buildmeta=975
version.major=0 version.major=0
version.minor=8 version.minor=8
version.patch=0 version.patch=0
version.prerelease=rc version.prerelease=rc
version.project=mobibot version.project=mobibot
version.semver=0.8.0-rc+948 version.semver=0.8.0-rc+975

View file

@ -1,6 +1,5 @@
<!DOCTYPE html <!DOCTYPE html>
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html lang="en">
<html xmlns="http://www.w3.org/1999/xhtml">
<head> <head>
<title>mobibot</title> <title>mobibot</title>