This commit is contained in:
Erik C. Thauvin 2021-05-13 21:37:16 -07:00
parent 11a75a7179
commit 790bd3159e
23 changed files with 67 additions and 69 deletions

View file

@ -14,6 +14,9 @@
<option name="JD_INDENT_ON_CONTINUATION" value="true" />
</JavaCodeStyleSettings>
<JetCodeStyleSettings>
<option name="PACKAGES_TO_USE_STAR_IMPORTS">
<value />
</option>
<option name="NAME_COUNT_TO_USE_STAR_IMPORT" value="2147483647" />
<option name="NAME_COUNT_TO_USE_STAR_IMPORT_FOR_MEMBERS" value="2147483647" />
<option name="CODE_STYLE_DEFAULTS" value="KOTLIN_OFFICIAL" />

View file

@ -1,6 +1,5 @@
<component name="ProjectCodeStyleConfiguration">
<state>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
<option name="PREFERRED_PROJECT_CODE_STYLE" value="Erik's Code Style" />
</state>
</component>

View file

@ -116,12 +116,6 @@ detekt {
baseline = file("${projectDir}/config/detekt/baseline.xml")
}
javadoc {
options.tags = ['created']
options.author = true
options.links('http://www.jibble.org/javadocs/pircbot/', 'http://docs.oracle.com/javase/8/docs/api/')
}
jar {
manifest.attributes('Main-Class': mainClassName,
'Class-Path': '. ./lib/' + configurations.runtimeClasspath.collect { it.getName() }.join(' ./lib/'))

View file

@ -34,6 +34,7 @@
<ID>NestedBlockDepth:Tell.kt$Tell$ @JvmOverloads fun send(nickname: String, isMessage: Boolean = false)</ID>
<ID>NestedBlockDepth:Tell.kt$Tell$// Delete message. private fun deleteMessage(sender: String, args: String, isOp: Boolean, isPrivate: Boolean)</ID>
<ID>NestedBlockDepth:TellMessagesMgr.kt$TellMessagesMgr$ fun save(file: String, messages: List&lt;TellMessage?&gt;?, logger: Logger)</ID>
<ID>NestedBlockDepth:TwitterOAuth.kt$TwitterOAuth$ @Throws(TwitterException::class, IOException::class) @JvmStatic fun main(args: Array&lt;String&gt;)</ID>
<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&lt;Message&gt;</ID>
<ID>NestedBlockDepth:WorldTime.kt$WorldTime$override fun commandResponse( sender: String, cmd: String, args: String, isPrivate: Boolean )</ID>

View file

@ -27,7 +27,7 @@ tell-max-size=50
#pinboard-api-token=user\:TOKEN
#
# Configure app at: https://apps.twitter.com/
# Configure app at: https://developer.twitter.com/en/apps
# and then: java -cp mobibot.jar net.thauvin.erik.mobibot.TwitterOAuth <consumerKey> <consumerSecret>
#
#twitter-consumerKey=

View file

@ -48,6 +48,8 @@ import static net.thauvin.erik.mobibot.Utils.bold;
* @since 1.0
*/
public final class War extends AbstractModule {
// Random
private static final SecureRandom RANDOM = new SecureRandom();
// War command
private static final String WAR_CMD = "war";
// Deck of card
@ -55,8 +57,6 @@ public final class War extends AbstractModule {
new String[]{ "Ace", "King", "Queen", "Jack", "10", "9", "8", "7", "6", "5", "4", "3", "2" };
// Suits for the deck of card
private static final String[] WAR_SUITS = new String[]{ "Hearts", "Spades", "Diamonds", "Clubs" };
// Random
private static final SecureRandom RANDOM = new SecureRandom();
/**
* The default constructor.

View file

@ -33,7 +33,7 @@ package net.thauvin.erik.mobibot
import net.thauvin.erik.mobibot.commands.AbstractCommand
import net.thauvin.erik.mobibot.modules.AbstractModule
import java.util.*
import java.util.Properties
/**
* Modules and Commands addons.
@ -100,8 +100,8 @@ class Addons {
val mods = if (isPrivate) modules.filter { it.isPrivateMsgEnabled } else modules
for (module in mods) {
if (module.commands.contains(cmd)) {
module.commandResponse(sender, cmd, args, isPrivate)
return true
module.commandResponse(sender, cmd, args, isPrivate)
return true
}
}
return false

View file

@ -31,7 +31,7 @@
*/
package net.thauvin.erik.mobibot
import java.util.*
import java.util.Locale
/**
* The `Constants`.

View file

@ -64,8 +64,8 @@ import net.thauvin.erik.mobibot.commands.links.View
import net.thauvin.erik.mobibot.commands.tell.Tell
import net.thauvin.erik.mobibot.entries.EntriesMgr
import net.thauvin.erik.mobibot.entries.EntryLink
import net.thauvin.erik.mobibot.modules.CryptoPrices
import net.thauvin.erik.mobibot.modules.Calc
import net.thauvin.erik.mobibot.modules.CryptoPrices
import net.thauvin.erik.mobibot.modules.CurrencyConverter
import net.thauvin.erik.mobibot.modules.Dice
import net.thauvin.erik.mobibot.modules.GoogleSearch
@ -99,7 +99,8 @@ import java.io.IOException
import java.io.PrintStream
import java.nio.file.Files
import java.nio.file.Paths
import java.util.*
import java.util.Properties
import java.util.Timer
import java.util.logging.ConsoleHandler
import java.util.regex.Pattern
import kotlin.system.exitProcess
@ -358,7 +359,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
helpResponse(sender, args, true)
} else if (isOp && Constants.KILL_CMD == cmd) { // kill
twitter.notification("$name killed by $sender on $channel")
sendRawLine("QUIT : Poof!")
sendRawLine("QUIT :Poof!")
exitProcess(0)
} else if (isOp && Constants.DIE_CMD == cmd) { // die
send("$sender has just signed my death sentence.")
@ -492,8 +493,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
* Returns the bot's version.
*/
override fun onVersion(sourceNick: String, sourceLogin: String, sourceHostname: String, target: String) {
sendRawLine("NOTICE " + sourceNick + " :\u0001VERSION " + ReleaseInfo.PROJECT + ' ' + ReleaseInfo.VERSION
+ "\u0001")
sendRawLine("NOTICE $sourceNick :\u0001VERSION ${ReleaseInfo.PROJECT} ${ReleaseInfo.VERSION}\u0001")
}
companion object {

View file

@ -32,7 +32,6 @@
package net.thauvin.erik.mobibot
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.async
import kotlinx.coroutines.runBlocking
import net.thauvin.erik.mobibot.entries.EntryLink
@ -40,7 +39,7 @@ import net.thauvin.erik.pinboard.PinboardPoster
import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.util.*
import java.util.Date
/**
* Handles posts to pinboard.in.

View file

@ -32,7 +32,7 @@
package net.thauvin.erik.mobibot
import java.util.*
import java.util.TimerTask
class TwitterTimer(var bot: Mobibot, private var index: Int) : TimerTask() {
override fun run() {

View file

@ -44,7 +44,7 @@ import java.nio.charset.StandardCharsets
import java.time.LocalDateTime
import java.time.ZoneId
import java.time.format.DateTimeFormatter
import java.util.*
import java.util.Date
import java.util.concurrent.TimeUnit
import java.util.stream.Collectors

View file

@ -327,7 +327,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) {
const val MAX_DAYS_PROP = "tell-max-days"
/**
* Max size proeprty.
* Max size property.
*/
const val MAX_SIZE_PROP = "tell-max-size"

View file

@ -47,7 +47,7 @@ import java.io.OutputStreamWriter
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Paths
import java.util.*
import java.util.Calendar
/**
* Manages the feed entries.

View file

@ -36,7 +36,8 @@ import com.rometools.rome.feed.synd.SyndCategoryImpl
import net.thauvin.erik.mobibot.commands.links.LinksMgr
import org.apache.commons.lang3.StringUtils
import java.io.Serializable
import java.util.*
import java.util.Calendar
import java.util.Date
/**
* The class used to store link entries.

View file

@ -52,10 +52,10 @@ class Calc(bot: Mobibot) : AbstractModule(bot) {
try {
bot.send(calculate(args))
} catch (e: IllegalArgumentException) {
if (bot.logger.isWarnEnabled) bot.logger.warn("Failed to calcualte: $args", e)
if (bot.logger.isWarnEnabled) bot.logger.warn("Failed to calculate: $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)
if (bot.logger.isWarnEnabled) bot.logger.warn("Unable to calculate: $args", e)
bot.send("No idea. I must've some form of Dyscalculia.")
}
} else {

View file

@ -79,7 +79,7 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
const val INVALID_SYMBOL = "Invalid symbol."
// Alpha Advantage URL
private const val ALAPHAVANTAGE_URL = "https://www.alphavantage.co/query?function="
private const val ALPHAVANTAGE_URL = "https://www.alphavantage.co/query?function="
// Quote command
private const val STOCK_CMD = "stock"
@ -122,7 +122,8 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
fun getQuote(symbol: String, apiKey: String?): List<Message> {
if (apiKey.isNullOrBlank()) {
throw ModuleException(
"${Utils.capitalize(STOCK_CMD)} is disabled. The API key is missing.")
"${Utils.capitalize(STOCK_CMD)} is disabled. The API key is missing."
)
}
return if (symbol.isNotBlank()) {
val debugMessage = "getQuote($symbol)"
@ -132,10 +133,10 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
with(messages) {
// Search for symbol/keywords
response = Utils.urlReader(
URL(
"${ALAPHAVANTAGE_URL}SYMBOL_SEARCH&keywords=" + Utils.encodeUrl(symbol)
+ "&apikey=" + Utils.encodeUrl(apiKey)
)
URL(
"${ALPHAVANTAGE_URL}SYMBOL_SEARCH&keywords=" + Utils.encodeUrl(symbol)
+ "&apikey=" + Utils.encodeUrl(apiKey)
)
)
var json = getJsonResponse(response, debugMessage)
val symbols = json.getJSONArray("bestMatches")
@ -146,11 +147,11 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
// Get quote for symbol
response = Utils.urlReader(
URL(
"${ALAPHAVANTAGE_URL}GLOBAL_QUOTE&symbol="
+ Utils.encodeUrl(symbolInfo.getString("1. symbol"))
+ "&apikey=" + Utils.encodeUrl(apiKey)
)
URL(
"${ALPHAVANTAGE_URL}GLOBAL_QUOTE&symbol="
+ Utils.encodeUrl(symbolInfo.getString("1. symbol"))
+ "&apikey=" + Utils.encodeUrl(apiKey)
)
)
json = getJsonResponse(response, debugMessage)
val quote = json.getJSONObject("Global Quote")
@ -159,36 +160,36 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
return messages
}
add(
PublicMessage(
"Symbol: " + Utils.unescapeXml(quote.getString("01. symbol"))
+ " [" + Utils.unescapeXml(symbolInfo.getString("2. name")) + ']'
)
PublicMessage(
"Symbol: " + Utils.unescapeXml(quote.getString("01. symbol"))
+ " [" + Utils.unescapeXml(symbolInfo.getString("2. name")) + ']'
)
)
add(PublicMessage(" Price: " + Utils.unescapeXml(quote.getString("05. price"))))
add(
PublicMessage(
" Previous: " + Utils.unescapeXml(quote.getString("08. previous close"))
)
PublicMessage(
" Previous: " + Utils.unescapeXml(quote.getString("08. previous close"))
)
)
add(NoticeMessage(" Open: " + Utils.unescapeXml(quote.getString("02. open"))))
add(NoticeMessage(" High: " + Utils.unescapeXml(quote.getString("03. high"))))
add(NoticeMessage(" Low: " + Utils.unescapeXml(quote.getString("04. low"))))
add(
NoticeMessage(
" Volume: " + Utils.unescapeXml(quote.getString("06. volume"))
)
NoticeMessage(
" Volume: " + Utils.unescapeXml(quote.getString("06. volume"))
)
)
add(
NoticeMessage(
" Latest: "
+ Utils.unescapeXml(quote.getString("07. latest trading day"))
)
NoticeMessage(
" Latest: "
+ Utils.unescapeXml(quote.getString("07. latest trading day"))
)
)
add(
NoticeMessage(
" Change: " + Utils.unescapeXml(quote.getString("09. change")) + " ["
+ Utils.unescapeXml(quote.getString("10. change percent")) + ']'
)
NoticeMessage(
" Change: " + Utils.unescapeXml(quote.getString("09. change")) + " ["
+ Utils.unescapeXml(quote.getString("10. change percent")) + ']'
)
)
}
}

View file

@ -42,7 +42,6 @@ import net.thauvin.erik.mobibot.msg.NoticeMessage
import twitter4j.TwitterException
import twitter4j.TwitterFactory
import twitter4j.conf.ConfigurationBuilder
import java.util.*
/**
* The Twitter module.

View file

@ -102,7 +102,8 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
fun getWeather(query: String, apiKey: String?): List<Message> {
if (apiKey.isNullOrBlank()) {
throw ModuleException(
"${Utils.capitalize(WEATHER_CMD)} is disabled. The API key is missing.")
"${Utils.capitalize(WEATHER_CMD)} is disabled. The API key is missing."
)
}
val owm = OWM(apiKey)
val messages = mutableListOf<Message>()

View file

@ -41,8 +41,8 @@ import java.time.ZoneId
import java.time.ZonedDateTime
import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoField
import java.util.*
import kotlin.collections.ArrayList
import java.util.Collections
import java.util.Locale
/**
* The WorldTime module.
@ -146,7 +146,7 @@ class WorldTime(bot: Mobibot) : AbstractModule(bot) {
countries["MX"] = "America/Mexico_City"
countries["NL"] = "Europe/Amsterdam"
countries["NO"] = "Europe/Oslo"
countries["NP"] = "Asia/Katmandu"
countries["NP"] = "Asia/Kathmandu"
countries["NZ"] = "Pacific/Auckland"
countries["PDT"] = "America/Los_Angeles"
countries["PH"] = "Asia/Manila"

View file

@ -35,7 +35,7 @@ import org.testng.annotations.BeforeSuite
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Paths
import java.util.*
import java.util.Properties
/**
* Access to `local.properties`.

View file

@ -56,7 +56,7 @@ import java.io.File
import java.io.IOException
import java.net.URL
import java.time.LocalDateTime
import java.util.*
import java.util.Calendar
/**
* The `Utils Test` class.

View file

@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle
#Wed May 12 19:01:23 PDT 2021
version.buildmeta=751
#Thu May 13 21:34:31 PDT 2021
version.buildmeta=771
version.major=0
version.minor=8
version.patch=0
version.prerelease=beta
version.project=mobibot
version.semver=0.8.0-beta+751
version.semver=0.8.0-beta+771