Switched to MutableList vs ArrayList whenever possible.
Made sure logging level is enabled before logging.
This commit is contained in:
parent
ece6ae98a0
commit
5a831f2c7c
20 changed files with 75 additions and 98 deletions
|
@ -18,7 +18,6 @@
|
||||||
<ID>MagicNumber:CurrencyConverter.kt$CurrencyConverter$11</ID>
|
<ID>MagicNumber:CurrencyConverter.kt$CurrencyConverter$11</ID>
|
||||||
<ID>MagicNumber:CurrencyConverter.kt$CurrencyConverter$3</ID>
|
<ID>MagicNumber:CurrencyConverter.kt$CurrencyConverter$3</ID>
|
||||||
<ID>MagicNumber:CurrencyConverter.kt$CurrencyConverter.Companion$3</ID>
|
<ID>MagicNumber:CurrencyConverter.kt$CurrencyConverter.Companion$3</ID>
|
||||||
<ID>MagicNumber:CurrencyConverter.kt$CurrencyConverter.Companion$33</ID>
|
|
||||||
<ID>MagicNumber:CurrencyConverter.kt$CurrencyConverter.Companion$4</ID>
|
<ID>MagicNumber:CurrencyConverter.kt$CurrencyConverter.Companion$4</ID>
|
||||||
<ID>MagicNumber:CurrencyConverter.kt$CurrencyConverter.Companion$8</ID>
|
<ID>MagicNumber:CurrencyConverter.kt$CurrencyConverter.Companion$8</ID>
|
||||||
<ID>MagicNumber:Cycle.kt$Cycle$10</ID>
|
<ID>MagicNumber:Cycle.kt$Cycle$10</ID>
|
||||||
|
@ -54,8 +53,9 @@
|
||||||
<ID>MemberNameEqualsClassName:WorldTime.kt$WorldTime.Companion$ @JvmStatic fun worldTime(query: String): Message</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: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:Comment.kt$Comment$override fun commandResponse( sender: String, login: String, args: String, isOp: Boolean, isPrivate: Boolean )</ID>
|
||||||
|
<ID>NestedBlockDepth:CurrencyConverter.kt$CurrencyConverter$override fun helpResponse(sender: String, isPrivate: Boolean)</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:EntriesMgr.kt$EntriesMgr.Companion$ @Throws(IOException::class, FeedException::class) fun loadEntries(file: String, channel: String, entries: ArrayList<EntryLink>): String</ID>
|
<ID>NestedBlockDepth:EntriesMgr.kt$EntriesMgr.Companion$ @Throws(IOException::class, FeedException::class) fun loadEntries(file: String, channel: String, entries: MutableList<EntryLink>): String</ID>
|
||||||
<ID>NestedBlockDepth:EntriesMgr.kt$EntriesMgr.Companion$ fun saveEntries( bot: Mobibot, entries: List<EntryLink>, history: MutableList<String>, isDayBackup: Boolean )</ID>
|
<ID>NestedBlockDepth:EntriesMgr.kt$EntriesMgr.Companion$ fun saveEntries( bot: Mobibot, entries: List<EntryLink>, history: MutableList<String>, isDayBackup: Boolean )</ID>
|
||||||
<ID>NestedBlockDepth:EntryLink.kt$EntryLink$ private fun setTags(tags: List<String?>)</ID>
|
<ID>NestedBlockDepth:EntryLink.kt$EntryLink$ private fun setTags(tags: List<String?>)</ID>
|
||||||
<ID>NestedBlockDepth:FeedReader.kt$FeedReader$ override fun run()</ID>
|
<ID>NestedBlockDepth:FeedReader.kt$FeedReader$ override fun run()</ID>
|
||||||
|
|
|
@ -34,17 +34,16 @@ package net.thauvin.erik.mobibot
|
||||||
import net.thauvin.erik.mobibot.commands.AbstractCommand
|
import net.thauvin.erik.mobibot.commands.AbstractCommand
|
||||||
import net.thauvin.erik.mobibot.modules.AbstractModule
|
import net.thauvin.erik.mobibot.modules.AbstractModule
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modules and Commands addons.
|
* Modules and Commands addons.
|
||||||
*/
|
*/
|
||||||
class Addons {
|
class Addons {
|
||||||
val commands: MutableList<AbstractCommand> = ArrayList()
|
val commands: MutableList<AbstractCommand> = mutableListOf()
|
||||||
val modules: MutableList<AbstractModule> = ArrayList()
|
val modules: MutableList<AbstractModule> = mutableListOf()
|
||||||
val modulesNames: MutableList<String> = ArrayList()
|
val modulesNames: MutableList<String> = mutableListOf()
|
||||||
val names: MutableList<String> = ArrayList()
|
val names: MutableList<String> = mutableListOf()
|
||||||
val ops: MutableList<String> = ArrayList()
|
val ops: MutableList<String> = mutableListOf()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a module with properties.
|
* Add a module with properties.
|
||||||
|
|
|
@ -69,10 +69,10 @@ class FeedReader(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: MalformedURLException) {
|
} catch (e: MalformedURLException) {
|
||||||
logger.debug("Invalid feed URL.", e)
|
if (logger.isDebugEnabled) logger.debug("Invalid feed URL.", e)
|
||||||
send(sender, "The feed URL is invalid.", false)
|
send(sender, "The feed URL is invalid.", false)
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.debug("Unable to fetch the feed.", e)
|
if (logger.isDebugEnabled) logger.debug("Unable to fetch the feed.", e)
|
||||||
send(sender, "An error has occurred while fetching the feed: ${e.message}", false)
|
send(sender, "An error has occurred while fetching the feed: ${e.message}", false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -136,25 +136,25 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
||||||
private val pinboard: PinboardPoster = PinboardPoster()
|
private val pinboard: PinboardPoster = PinboardPoster()
|
||||||
|
|
||||||
/** Tell command. */
|
/** Tell command. */
|
||||||
val tell: Tell
|
val tell: Tell = Tell(this)
|
||||||
|
|
||||||
/** Today's date. */
|
/** Today's date. */
|
||||||
val today = today()
|
val today = today()
|
||||||
|
|
||||||
/** Twitter module. */
|
/** Twitter module. */
|
||||||
val twitter: Twitter
|
val twitter: Twitter = Twitter(this)
|
||||||
|
|
||||||
/** The backlogs URL. */
|
/** The backlogs URL. */
|
||||||
var backlogsUrl = ""
|
val backlogsUrl: String
|
||||||
|
|
||||||
// Ident message
|
// Ident message
|
||||||
private var identMsg = ""
|
private val identMsg: String
|
||||||
|
|
||||||
// Ident nick
|
// Ident nick
|
||||||
private var identNick = ""
|
private val identNick: String
|
||||||
|
|
||||||
// NickServ ident password
|
// NickServ ident password
|
||||||
private var identPwd = ""
|
private val identPwd: String
|
||||||
|
|
||||||
// Is pinboard enabled?
|
// Is pinboard enabled?
|
||||||
private var isPinboardEnabled = false
|
private var isPinboardEnabled = false
|
||||||
|
@ -163,7 +163,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
||||||
val timer = Timer(true)
|
val timer = Timer(true)
|
||||||
|
|
||||||
/** Weblog URL */
|
/** Weblog URL */
|
||||||
var weblogUrl = ""
|
val weblogUrl: String
|
||||||
|
|
||||||
/** The current channel name. */
|
/** The current channel name. */
|
||||||
private val channelName: String
|
private val channelName: String
|
||||||
|
@ -212,7 +212,9 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
||||||
connect(ircServer, ircPort)
|
connect(ircServer, ircPort)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
if (retries == MAX_RECONNECT) {
|
if (retries == MAX_RECONNECT) {
|
||||||
|
if (logger.isDebugEnabled) {
|
||||||
logger.debug("Unable to reconnect to $ircServer, after $MAX_RECONNECT retries.", ex)
|
logger.debug("Unable to reconnect to $ircServer, after $MAX_RECONNECT retries.", ex)
|
||||||
|
}
|
||||||
e.printStackTrace(System.err)
|
e.printStackTrace(System.err)
|
||||||
exitProcess(1)
|
exitProcess(1)
|
||||||
}
|
}
|
||||||
|
@ -350,7 +352,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
||||||
hostname: String,
|
hostname: String,
|
||||||
message: String
|
message: String
|
||||||
) {
|
) {
|
||||||
logger.debug(">>> $sender: $message")
|
if (logger.isDebugEnabled) logger.debug(">>> $sender: $message")
|
||||||
tell.send(sender, true)
|
tell.send(sender, true)
|
||||||
if (message.matches("(?i)${Pattern.quote(nick)}:.*".toRegex())) { // mobibot: <command>
|
if (message.matches("(?i)${Pattern.quote(nick)}:.*".toRegex())) { // mobibot: <command>
|
||||||
val cmds = message.substring(message.indexOf(':') + 1).trim().split(" ".toRegex(), 2)
|
val cmds = message.substring(message.indexOf(':') + 1).trim().split(" ".toRegex(), 2)
|
||||||
|
@ -396,9 +398,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
||||||
hostname: String,
|
hostname: String,
|
||||||
message: String
|
message: String
|
||||||
) {
|
) {
|
||||||
if (logger.isDebugEnabled) {
|
if (logger.isDebugEnabled) logger.debug(">>> $sender : $message")
|
||||||
logger.debug(">>> $sender : $message")
|
|
||||||
}
|
|
||||||
val cmds = message.split(" ".toRegex(), 2)
|
val cmds = message.split(" ".toRegex(), 2)
|
||||||
val cmd = cmds[0].toLowerCase()
|
val cmd = cmds[0].toLowerCase()
|
||||||
val args = if (cmds.size > 1) {
|
val args = if (cmds.size > 1) {
|
||||||
|
@ -467,10 +467,10 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
||||||
fun send(sender: String, message: String?, isPrivate: Boolean) {
|
fun send(sender: String, message: String?, isPrivate: Boolean) {
|
||||||
if (message != null && sender.isNotBlank()) {
|
if (message != null && sender.isNotBlank()) {
|
||||||
if (isPrivate) {
|
if (isPrivate) {
|
||||||
logger.debug("Sending message to $sender : $message")
|
if (logger.isDebugEnabled) logger.debug("Sending message to $sender : $message")
|
||||||
sendMessage(sender, message)
|
sendMessage(sender, message)
|
||||||
} else {
|
} else {
|
||||||
logger.debug("Sending notice to $sender: $message")
|
if (logger.isDebugEnabled) logger.debug("Sending notice to $sender: $message")
|
||||||
sendNotice(sender, message)
|
sendNotice(sender, message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -684,13 +684,13 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
||||||
this.channel = channel
|
this.channel = channel
|
||||||
logsDir = logsDirPath
|
logsDir = logsDirPath
|
||||||
|
|
||||||
// Set the default logger level
|
// Store the default logger level
|
||||||
loggerLevel = logger.level
|
loggerLevel = logger.level
|
||||||
|
|
||||||
// Load the current entries and backlogs, if any
|
// Load the current entries and backlogs, if any
|
||||||
try {
|
try {
|
||||||
startup(logsDir + EntriesMgr.CURRENT_XML, logsDir + EntriesMgr.NAV_XML, this.channel)
|
startup(logsDir + EntriesMgr.CURRENT_XML, logsDir + EntriesMgr.NAV_XML, this.channel)
|
||||||
logger.debug("Last feed: $startDate")
|
if (logger.isDebugEnabled) logger.debug("Last feed: $startDate")
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
logger.error("An error occurred while loading the logs.", e)
|
logger.error("An error occurred while loading the logs.", e)
|
||||||
}
|
}
|
||||||
|
@ -712,7 +712,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
||||||
backlogsUrl = ensureDir(p.getProperty("backlogs", weblogUrl), true)
|
backlogsUrl = ensureDir(p.getProperty("backlogs", weblogUrl), true)
|
||||||
|
|
||||||
// Set the pinboard authentication
|
// Set the pinboard authentication
|
||||||
setPinboardAuth(p.getProperty("pinboard-api-token"))
|
setPinboardAuth(p.getProperty("pinboard-api-token", ""))
|
||||||
|
|
||||||
// Load the commands
|
// Load the commands
|
||||||
addons.add(AddLog(this), p)
|
addons.add(AddLog(this), p)
|
||||||
|
@ -730,7 +730,6 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
||||||
addons.add(Versions(this), p)
|
addons.add(Versions(this), p)
|
||||||
|
|
||||||
// Tell command
|
// Tell command
|
||||||
tell = Tell(this)
|
|
||||||
addons.add(tell, p)
|
addons.add(tell, p)
|
||||||
|
|
||||||
// Load the links commands
|
// Load the links commands
|
||||||
|
@ -755,7 +754,6 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
||||||
addons.add(WorldTime(this), p)
|
addons.add(WorldTime(this), p)
|
||||||
|
|
||||||
// Twitter module
|
// Twitter module
|
||||||
twitter = Twitter(this)
|
|
||||||
addons.add(twitter, p)
|
addons.add(twitter, p)
|
||||||
|
|
||||||
// Sort the addons
|
// Sort the addons
|
||||||
|
|
|
@ -36,7 +36,6 @@ import net.thauvin.erik.mobibot.Mobibot
|
||||||
import net.thauvin.erik.mobibot.Utils
|
import net.thauvin.erik.mobibot.Utils
|
||||||
import java.time.Clock
|
import java.time.Clock
|
||||||
import java.time.LocalDateTime
|
import java.time.LocalDateTime
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class Recap(bot: Mobibot) : AbstractCommand(bot) {
|
class Recap(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
override val name = "recap"
|
override val name = "recap"
|
||||||
|
@ -49,7 +48,7 @@ class Recap(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
override val isVisible = true
|
override val isVisible = true
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private val recaps = ArrayList<String>(0)
|
private val recaps = mutableListOf<String>()
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun recapCount(): Int {
|
fun recapCount(): Int {
|
||||||
|
|
|
@ -35,7 +35,6 @@ package net.thauvin.erik.mobibot.commands
|
||||||
import net.thauvin.erik.mobibot.Mobibot
|
import net.thauvin.erik.mobibot.Mobibot
|
||||||
import net.thauvin.erik.mobibot.Utils
|
import net.thauvin.erik.mobibot.Utils
|
||||||
import org.jibble.pircbot.User
|
import org.jibble.pircbot.User
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
class Users(bot: Mobibot) : AbstractCommand(bot) {
|
class Users(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
override val name = "users"
|
override val name = "users"
|
||||||
|
@ -56,7 +55,7 @@ class Users(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
isPrivate: Boolean
|
isPrivate: Boolean
|
||||||
) {
|
) {
|
||||||
val users: Array<User> = bot.getUsers(bot.channel)
|
val users: Array<User> = bot.getUsers(bot.channel)
|
||||||
val nicks = ArrayList<String>()
|
val nicks = mutableListOf<String>()
|
||||||
users.forEach { user ->
|
users.forEach { user ->
|
||||||
if (bot.isOp(user.nick)) {
|
if (bot.isOp(user.nick)) {
|
||||||
nicks.add("@${user.nick}")
|
nicks.add("@${user.nick}")
|
||||||
|
|
|
@ -44,8 +44,8 @@ import org.jsoup.Jsoup
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
|
|
||||||
class LinksMgr(bot: Mobibot) : AbstractCommand(bot) {
|
class LinksMgr(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
private val keywords: MutableList<String> = ArrayList()
|
private val keywords: MutableList<String> = mutableListOf()
|
||||||
private val defaultTags: MutableList<String> = ArrayList()
|
private val defaultTags: MutableList<String> = mutableListOf()
|
||||||
|
|
||||||
override val name = Constants.LINK_CMD
|
override val name = Constants.LINK_CMD
|
||||||
override val help = emptyList<String>()
|
override val help = emptyList<String>()
|
||||||
|
@ -65,11 +65,11 @@ class LinksMgr(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
|
|
||||||
// Entries array
|
// Entries array
|
||||||
@JvmField
|
@JvmField
|
||||||
val entries = ArrayList<EntryLink>(0)
|
val entries = mutableListOf<EntryLink>()
|
||||||
|
|
||||||
// History/backlogs array
|
// History/backlogs array
|
||||||
@JvmField
|
@JvmField
|
||||||
val history = ArrayList<String>(0)
|
val history = mutableListOf<String>()
|
||||||
|
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
|
@ -207,7 +207,7 @@ class LinksMgr(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun matchTagKeywords(title: String, tags: ArrayList<String>) {
|
private fun matchTagKeywords(title: String, tags: MutableList<String>) {
|
||||||
for (match in keywords) {
|
for (match in keywords) {
|
||||||
val m = Regex.escape(match)
|
val m = Regex.escape(match)
|
||||||
if (title.matches("(?i).*\\b$m\\b.*".toRegex())) {
|
if (title.matches("(?i).*\\b$m\\b.*".toRegex())) {
|
||||||
|
|
|
@ -41,14 +41,13 @@ import net.thauvin.erik.mobibot.Utils.Companion.reverseColor
|
||||||
import net.thauvin.erik.mobibot.Utils.Companion.utcDateTime
|
import net.thauvin.erik.mobibot.Utils.Companion.utcDateTime
|
||||||
import net.thauvin.erik.mobibot.commands.AbstractCommand
|
import net.thauvin.erik.mobibot.commands.AbstractCommand
|
||||||
import net.thauvin.erik.mobibot.commands.links.View
|
import net.thauvin.erik.mobibot.commands.links.View
|
||||||
import java.util.concurrent.CopyOnWriteArrayList
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `Tell` command.
|
* The `Tell` command.
|
||||||
*/
|
*/
|
||||||
class Tell(bot: Mobibot) : AbstractCommand(bot) {
|
class Tell(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
// Messages queue
|
// Messages queue
|
||||||
private val messages: MutableList<TellMessage> = CopyOnWriteArrayList()
|
private val messages: MutableList<TellMessage> = mutableListOf()
|
||||||
|
|
||||||
// Serialized object file
|
// Serialized object file
|
||||||
private val serializedObject: String
|
private val serializedObject: String
|
||||||
|
@ -63,9 +62,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
* Cleans the messages queue.
|
* Cleans the messages queue.
|
||||||
*/
|
*/
|
||||||
private fun clean(): Boolean {
|
private fun clean(): Boolean {
|
||||||
if (bot.logger.isDebugEnabled) {
|
if (bot.logger.isDebugEnabled) bot.logger.debug("Cleaning the messages.")
|
||||||
bot.logger.debug("Cleaning the messages.")
|
|
||||||
}
|
|
||||||
return TellMessagesMgr.clean(messages, maxDays)
|
return TellMessagesMgr.clean(messages, maxDays)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -66,9 +66,7 @@ internal class TellMessagesMgr private constructor() {
|
||||||
ObjectInputStream(
|
ObjectInputStream(
|
||||||
BufferedInputStream(Files.newInputStream(Paths.get(file)))
|
BufferedInputStream(Files.newInputStream(Paths.get(file)))
|
||||||
).use { input ->
|
).use { input ->
|
||||||
if (logger.isDebugEnabled) {
|
if (logger.isDebugEnabled) logger.debug("Loading the messages.")
|
||||||
logger.debug("Loading the messages.")
|
|
||||||
}
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
return input.readObject() as List<TellMessage>
|
return input.readObject() as List<TellMessage>
|
||||||
}
|
}
|
||||||
|
@ -79,7 +77,7 @@ internal class TellMessagesMgr private constructor() {
|
||||||
} catch (e: ClassNotFoundException) {
|
} catch (e: ClassNotFoundException) {
|
||||||
logger.error("An error occurred loading the messages queue.", e)
|
logger.error("An error occurred loading the messages queue.", e)
|
||||||
}
|
}
|
||||||
return ArrayList()
|
return listOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,9 +87,7 @@ internal class TellMessagesMgr private constructor() {
|
||||||
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 ->
|
||||||
if (logger.isDebugEnabled) {
|
if (logger.isDebugEnabled) logger.debug("Saving the messages.")
|
||||||
logger.debug("Saving the messages.")
|
|
||||||
}
|
|
||||||
output.writeObject(messages)
|
output.writeObject(messages)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,7 +48,6 @@ 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.util.*
|
import java.util.*
|
||||||
import kotlin.collections.ArrayList
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Manages the feed entries.
|
* Manages the feed entries.
|
||||||
|
@ -79,7 +78,7 @@ class EntriesMgr private constructor() {
|
||||||
* Loads the backlogs.
|
* Loads the backlogs.
|
||||||
*/
|
*/
|
||||||
@Throws(IOException::class, FeedException::class)
|
@Throws(IOException::class, FeedException::class)
|
||||||
fun loadBacklogs(file: String, history: ArrayList<String>) {
|
fun loadBacklogs(file: String, history: MutableList<String>) {
|
||||||
history.clear()
|
history.clear()
|
||||||
val input = SyndFeedInput()
|
val input = SyndFeedInput()
|
||||||
InputStreamReader(Files.newInputStream(Paths.get(file)), StandardCharsets.UTF_8).use { reader ->
|
InputStreamReader(Files.newInputStream(Paths.get(file)), StandardCharsets.UTF_8).use { reader ->
|
||||||
|
@ -95,7 +94,7 @@ class EntriesMgr private constructor() {
|
||||||
* Loads the current entries.
|
* Loads the current entries.
|
||||||
*/
|
*/
|
||||||
@Throws(IOException::class, FeedException::class)
|
@Throws(IOException::class, FeedException::class)
|
||||||
fun loadEntries(file: String, channel: String, entries: ArrayList<EntryLink>): String {
|
fun loadEntries(file: String, channel: String, entries: MutableList<EntryLink>): String {
|
||||||
entries.clear()
|
entries.clear()
|
||||||
val input = SyndFeedInput()
|
val input = SyndFeedInput()
|
||||||
var today: String
|
var today: String
|
||||||
|
@ -139,14 +138,12 @@ class EntriesMgr private constructor() {
|
||||||
history: MutableList<String>,
|
history: MutableList<String>,
|
||||||
isDayBackup: Boolean
|
isDayBackup: Boolean
|
||||||
) {
|
) {
|
||||||
if (bot.logger.isDebugEnabled) {
|
if (bot.logger.isDebugEnabled) bot.logger.debug("Saving the feeds...")
|
||||||
bot.logger.debug("Saving the feeds...")
|
|
||||||
}
|
|
||||||
if (bot.logsDir.isNotBlank() && bot.weblogUrl.isNotBlank()) {
|
if (bot.logsDir.isNotBlank() && bot.weblogUrl.isNotBlank()) {
|
||||||
try {
|
try {
|
||||||
val output = SyndFeedOutput()
|
val output = SyndFeedOutput()
|
||||||
var rss: SyndFeed = SyndFeedImpl()
|
var rss: SyndFeed = SyndFeedImpl()
|
||||||
val items: MutableList<SyndEntry> = ArrayList(0)
|
val items: MutableList<SyndEntry> = mutableListOf()
|
||||||
var item: SyndEntry
|
var item: SyndEntry
|
||||||
OutputStreamWriter(
|
OutputStreamWriter(
|
||||||
Files.newOutputStream(Paths.get(bot.logsDir + CURRENT_XML)), StandardCharsets.UTF_8
|
Files.newOutputStream(Paths.get(bot.logsDir + CURRENT_XML)), StandardCharsets.UTF_8
|
||||||
|
@ -194,9 +191,7 @@ class EntriesMgr private constructor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
rss.entries = items
|
rss.entries = items
|
||||||
if (bot.logger.isDebugEnabled) {
|
if (bot.logger.isDebugEnabled) bot.logger.debug("Writing the entries feed.")
|
||||||
bot.logger.debug("Writing the entries feed.")
|
|
||||||
}
|
|
||||||
output.output(rss, fw)
|
output.output(rss, fw)
|
||||||
}
|
}
|
||||||
OutputStreamWriter(
|
OutputStreamWriter(
|
||||||
|
@ -238,9 +233,7 @@ class EntriesMgr private constructor() {
|
||||||
items.add(item)
|
items.add(item)
|
||||||
}
|
}
|
||||||
rss.entries = items
|
rss.entries = items
|
||||||
if (bot.logger.isDebugEnabled) {
|
if (bot.logger.isDebugEnabled) bot.logger.debug("Writing the backlog feed.")
|
||||||
bot.logger.debug("Writing the backlog feed.")
|
|
||||||
}
|
|
||||||
output.output(rss, fw)
|
output.output(rss, fw)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -248,13 +241,15 @@ class EntriesMgr private constructor() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: FeedException) {
|
} catch (e: FeedException) {
|
||||||
bot.logger.warn("Unable to generate the entries feed.", e)
|
if (bot.logger.isWarnEnabled) bot.logger.warn("Unable to generate the entries feed.", e)
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
bot.logger.warn("Unable to generate the entries feed.", e)
|
if (bot.logger.isWarnEnabled) bot.logger.warn("Unable to generate the entries feed.", e)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if (bot.logger.isWarnEnabled) {
|
||||||
bot.logger.warn("Unable to generate the entries feed. A required property is missing.")
|
bot.logger.warn("Unable to generate the entries feed. A required property is missing.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,17 +37,16 @@ import net.thauvin.erik.mobibot.commands.links.LinksMgr
|
||||||
import org.apache.commons.lang3.StringUtils
|
import org.apache.commons.lang3.StringUtils
|
||||||
import java.io.Serializable
|
import java.io.Serializable
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.CopyOnWriteArrayList
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class used to store link entries.
|
* The class used to store link entries.
|
||||||
*/
|
*/
|
||||||
class EntryLink : Serializable {
|
class EntryLink : Serializable {
|
||||||
// Link's comments
|
// Link's comments
|
||||||
val comments: MutableList<EntryComment> = CopyOnWriteArrayList()
|
val comments: MutableList<EntryComment> = mutableListOf()
|
||||||
|
|
||||||
// Tags/categories
|
// Tags/categories
|
||||||
val tags: MutableList<SyndCategory> = CopyOnWriteArrayList()
|
val tags: MutableList<SyndCategory> = mutableListOf()
|
||||||
|
|
||||||
// Channel
|
// Channel
|
||||||
var channel: String
|
var channel: String
|
||||||
|
|
|
@ -33,8 +33,6 @@ package net.thauvin.erik.mobibot.modules
|
||||||
|
|
||||||
import net.thauvin.erik.mobibot.Mobibot
|
import net.thauvin.erik.mobibot.Mobibot
|
||||||
import net.thauvin.erik.mobibot.Utils
|
import net.thauvin.erik.mobibot.Utils
|
||||||
import java.util.*
|
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The `Module` abstract class.
|
* The `Module` abstract class.
|
||||||
|
@ -44,11 +42,11 @@ abstract class AbstractModule(val bot: Mobibot) {
|
||||||
* The module's commands, if any.
|
* The module's commands, if any.
|
||||||
*/
|
*/
|
||||||
@JvmField
|
@JvmField
|
||||||
val commands: MutableList<String> = ArrayList()
|
val commands: MutableList<String> = mutableListOf()
|
||||||
|
|
||||||
@JvmField
|
@JvmField
|
||||||
val help: MutableList<String> = ArrayList()
|
val help: MutableList<String> = mutableListOf()
|
||||||
val properties: MutableMap<String, String> = ConcurrentHashMap()
|
val properties: MutableMap<String, String> = mutableMapOf()
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Responds to a command.
|
* Responds to a command.
|
||||||
|
|
|
@ -43,7 +43,6 @@ import org.jdom2.input.SAXBuilder
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.text.NumberFormat
|
import java.text.NumberFormat
|
||||||
import java.util.*
|
|
||||||
import javax.xml.XMLConstants
|
import javax.xml.XMLConstants
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,7 +72,7 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
try {
|
try {
|
||||||
loadRates()
|
loadRates()
|
||||||
} catch (e: ModuleException) {
|
} catch (e: ModuleException) {
|
||||||
logger.warn(e.debugMessage, e)
|
if (bot.logger.isWarnEnabled)logger.warn(e.debugMessage, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -100,7 +99,7 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
try {
|
try {
|
||||||
loadRates()
|
loadRates()
|
||||||
} catch (e: ModuleException) {
|
} catch (e: ModuleException) {
|
||||||
logger.debug(e.debugMessage, e)
|
if (logger.isDebugEnabled) logger.debug(e.debugMessage, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (EXCHANGE_RATES.isEmpty()) {
|
if (EXCHANGE_RATES.isEmpty()) {
|
||||||
|
@ -139,7 +138,7 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
private const val EMPTY_RATE_TABLE = "Sorry, but the exchange rate table is empty."
|
private const val EMPTY_RATE_TABLE = "Sorry, but the exchange rate table is empty."
|
||||||
|
|
||||||
// Exchange rates
|
// Exchange rates
|
||||||
private val EXCHANGE_RATES: MutableMap<String, String> = TreeMap()
|
private val EXCHANGE_RATES: MutableMap<String, String> = mutableMapOf()
|
||||||
|
|
||||||
// Exchange rates table URL
|
// Exchange rates table URL
|
||||||
private const val EXCHANGE_TABLE_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
|
private const val EXCHANGE_TABLE_URL = "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
|
||||||
|
@ -183,7 +182,7 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun currencyRates(): List<String> {
|
fun currencyRates(): List<String> {
|
||||||
val rates = ArrayList<String>(33)
|
val rates = mutableListOf<String>()
|
||||||
for ((key, value) in EXCHANGE_RATES) {
|
for ((key, value) in EXCHANGE_RATES) {
|
||||||
rates.add(" $key: ${StringUtils.leftPad(value, 8)}")
|
rates.add(" $key: ${StringUtils.leftPad(value, 8)}")
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,6 @@ import org.json.JSONException
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The GoogleSearch module.
|
* The GoogleSearch module.
|
||||||
|
@ -62,7 +61,7 @@ class GoogleSearch(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
send(sender, msg)
|
send(sender, msg)
|
||||||
}
|
}
|
||||||
} catch (e: ModuleException) {
|
} catch (e: ModuleException) {
|
||||||
logger.warn(e.debugMessage, e)
|
if (logger.isWarnEnabled) logger.warn(e.debugMessage, e)
|
||||||
send(sender, e.message, isPrivate)
|
send(sender, e.message, isPrivate)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -91,7 +90,7 @@ class GoogleSearch(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
throw ModuleException("${StringUtils.capitalize(GOOGLE_CMD)} is disabled. The API keys are missing.")
|
throw ModuleException("${StringUtils.capitalize(GOOGLE_CMD)} is disabled. The API keys are missing.")
|
||||||
}
|
}
|
||||||
return if (query.isNotBlank()) {
|
return if (query.isNotBlank()) {
|
||||||
val results = ArrayList<Message>()
|
val results = mutableListOf<Message>()
|
||||||
try {
|
try {
|
||||||
val url = URL(
|
val url = URL(
|
||||||
"https://www.googleapis.com/customsearch/v1?key=$apiKey&cx=$cseKey" +
|
"https://www.googleapis.com/customsearch/v1?key=$apiKey&cx=$cseKey" +
|
||||||
|
|
|
@ -60,7 +60,7 @@ class Joke(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
try {
|
try {
|
||||||
bot.send(Utils.cyan(randomJoke().msg))
|
bot.send(Utils.cyan(randomJoke().msg))
|
||||||
} catch (e: ModuleException) {
|
} catch (e: ModuleException) {
|
||||||
bot.logger.warn(e.debugMessage, e)
|
if (bot.logger.isWarnEnabled) bot.logger.warn(e.debugMessage, e)
|
||||||
bot.send(sender, e.message, isPrivate)
|
bot.send(sender, e.message, isPrivate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,9 @@ class Lookup(bot: Mobibot) : AbstractModule(bot) {
|
||||||
send("Unknown host.")
|
send("Unknown host.")
|
||||||
}
|
}
|
||||||
} catch (ioe: IOException) {
|
} catch (ioe: IOException) {
|
||||||
logger.debug("Unable to perform whois IP lookup: {}", args, ioe)
|
if (logger.isDebugEnabled) {
|
||||||
|
logger.debug("Unable to perform whois IP lookup: $args", ioe)
|
||||||
|
}
|
||||||
send("Unable to perform whois IP lookup: ${ioe.message}")
|
send("Unable to perform whois IP lookup: ${ioe.message}")
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -41,7 +41,6 @@ import org.json.JSONException
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.net.URL
|
import java.net.URL
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The StockQuote module.
|
* The StockQuote module.
|
||||||
|
@ -59,7 +58,7 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
send(sender, msg)
|
send(sender, msg)
|
||||||
}
|
}
|
||||||
} catch (e: ModuleException) {
|
} catch (e: ModuleException) {
|
||||||
logger.warn(e.debugMessage, e)
|
if (logger.isWarnEnabled) logger.warn(e.debugMessage, e)
|
||||||
send(e.message)
|
send(e.message)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -126,7 +125,7 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
}
|
}
|
||||||
return if (symbol.isNotBlank()) {
|
return if (symbol.isNotBlank()) {
|
||||||
val debugMessage = "getQuote($symbol)"
|
val debugMessage = "getQuote($symbol)"
|
||||||
val messages = ArrayList<Message>()
|
val messages = mutableListOf<Message>()
|
||||||
var response: String
|
var response: String
|
||||||
try {
|
try {
|
||||||
with(messages) {
|
with(messages) {
|
||||||
|
|
|
@ -91,11 +91,9 @@ class Twitter(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
Thread {
|
Thread {
|
||||||
try {
|
try {
|
||||||
post(message = msg, isDm = true)
|
post(message = msg, isDm = true)
|
||||||
if (logger.isDebugEnabled) {
|
if (logger.isDebugEnabled) logger.debug("Notified @$handle: $msg")
|
||||||
logger.debug("Notified @{}: {}", handle, msg)
|
|
||||||
}
|
|
||||||
} catch (e: ModuleException) {
|
} catch (e: ModuleException) {
|
||||||
logger.warn("Failed to notify @{}: {}", handle, msg, e)
|
if (logger.isWarnEnabled) logger.warn("Failed to notify @$handle: $msg", e)
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
@ -133,7 +131,7 @@ class Twitter(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
}
|
}
|
||||||
post(message = msg, isDm = false)
|
post(message = msg, isDm = false)
|
||||||
} catch (e: ModuleException) {
|
} catch (e: ModuleException) {
|
||||||
logger.warn("Failed to post entry on Twitter.", e)
|
if (bot.logger.isWarnEnabled) logger.warn("Failed to post entry on Twitter.", e)
|
||||||
}
|
}
|
||||||
}.start()
|
}.start()
|
||||||
removeEntry(index)
|
removeEntry(index)
|
||||||
|
@ -167,7 +165,7 @@ class Twitter(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
isPrivate
|
isPrivate
|
||||||
)
|
)
|
||||||
} catch (e: ModuleException) {
|
} catch (e: ModuleException) {
|
||||||
logger.warn(e.debugMessage, e)
|
if (logger.isWarnEnabled) logger.warn(e.debugMessage, e)
|
||||||
send(sender, e.message, isPrivate)
|
send(sender, e.message, isPrivate)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,7 +42,6 @@ import net.thauvin.erik.mobibot.msg.Message
|
||||||
import net.thauvin.erik.mobibot.msg.NoticeMessage
|
import net.thauvin.erik.mobibot.msg.NoticeMessage
|
||||||
import net.thauvin.erik.mobibot.msg.PublicMessage
|
import net.thauvin.erik.mobibot.msg.PublicMessage
|
||||||
import org.jibble.pircbot.Colors
|
import org.jibble.pircbot.Colors
|
||||||
import java.util.*
|
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -64,7 +63,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e: ModuleException) {
|
} catch (e: ModuleException) {
|
||||||
bot.logger.debug(e.debugMessage, e)
|
if (bot.logger.isDebugEnabled) bot.logger.debug(e.debugMessage, e)
|
||||||
bot.send(e.message)
|
bot.send(e.message)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -104,7 +103,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
throw ModuleException("${WEATHER_CMD.capitalize()} is disabled. The API key is missing.")
|
throw ModuleException("${WEATHER_CMD.capitalize()} is disabled. The API key is missing.")
|
||||||
}
|
}
|
||||||
val owm = OWM(apiKey)
|
val owm = OWM(apiKey)
|
||||||
val messages = ArrayList<Message>()
|
val messages = mutableListOf<Message>()
|
||||||
owm.unit = OWM.Unit.IMPERIAL
|
owm.unit = OWM.Unit.IMPERIAL
|
||||||
if (query.isNotBlank()) {
|
if (query.isNotBlank()) {
|
||||||
val argv = query.split(",")
|
val argv = query.split(",")
|
||||||
|
|
|
@ -41,6 +41,7 @@ import java.time.ZonedDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
import java.time.temporal.ChronoField
|
import java.time.temporal.ChronoField
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The WorldTime module.
|
* The WorldTime module.
|
||||||
|
@ -94,7 +95,7 @@ class WorldTime(bot: Mobibot) : AbstractModule(bot) {
|
||||||
|
|
||||||
init {
|
init {
|
||||||
// Initialize the countries map
|
// Initialize the countries map
|
||||||
val countries = TreeMap<String, String>()
|
val countries = mutableMapOf<String, String>()
|
||||||
countries["AE"] = "Asia/Dubai"
|
countries["AE"] = "Asia/Dubai"
|
||||||
countries["AF"] = "Asia/Kabul"
|
countries["AF"] = "Asia/Kabul"
|
||||||
countries["AQ"] = "Antarctica/South_Pole"
|
countries["AQ"] = "Antarctica/South_Pole"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue