diff --git a/config/detekt/baseline.xml b/config/detekt/baseline.xml
index 07b0938..32e2375 100644
--- a/config/detekt/baseline.xml
+++ b/config/detekt/baseline.xml
@@ -11,6 +11,7 @@
LongParameterList:Comment.kt$Comment$( bot: Mobibot, sender: String, isOp: Boolean, entry: EntryLink, index: Int, commentIndex: Int )
LongParameterList:Comment.kt$Comment$(bot: Mobibot, cmd: String, sender: String, entry: EntryLink, index: Int, commentIndex: Int)
LongParameterList:Twitter.kt$Twitter.Companion$( consumerKey: String?, consumerSecret: String?, token: String?, tokenSecret: String?, handle: String?, message: String, isDm: Boolean )
+ MagicNumber:AddLog.kt$AddLog$4
MagicNumber:Comment.kt$Comment$3
MagicNumber:CurrencyConverter.kt$CurrencyConverter$11
MagicNumber:CurrencyConverter.kt$CurrencyConverter$3
diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/AddLog.kt b/src/main/java/net/thauvin/erik/mobibot/commands/AddLog.kt
index f7639a5..2848369 100644
--- a/src/main/java/net/thauvin/erik/mobibot/commands/AddLog.kt
+++ b/src/main/java/net/thauvin/erik/mobibot/commands/AddLog.kt
@@ -33,8 +33,8 @@
package net.thauvin.erik.mobibot.commands
import net.thauvin.erik.mobibot.Mobibot
-import net.thauvin.erik.mobibot.commands.links.LinksMgr.Companion.addHistory
-import net.thauvin.erik.mobibot.commands.links.LinksMgr.Companion.getHistory
+
+import net.thauvin.erik.mobibot.commands.links.LinksMgr.Companion.history
import net.thauvin.erik.mobibot.entries.EntriesMgr
import java.io.File
@@ -52,15 +52,18 @@ class AddLog(bot: Mobibot) : AbstractCommand(bot) {
isOp: Boolean,
isPrivate: Boolean
) {
- if (isOp && args.isNotBlank()) {
- // e.g: 2014-04-01
- val backlog = File("${bot.logsDir}$args${EntriesMgr.XML_EXT}")
- if (backlog.exists()) {
- addHistory(0, args)
- bot.send(sender, getHistory().toString(), isPrivate)
- } else {
- bot.send(sender, "The specified log could not be found.", isPrivate)
+ if (isOp) {
+ if (args.isNotBlank()) {
+ // e.g: 2014-04-01
+ val backlog = File("${bot.logsDir}$args${EntriesMgr.XML_EXT}")
+ if (backlog.exists()) {
+ history.add(0, args)
+ } else {
+ bot.send(sender, "The specified log could not be found.", isPrivate)
+ return
+ }
}
+ bot.sendList(sender, history, 4, isPrivate, false)
}
}
}
diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Info.java b/src/main/java/net/thauvin/erik/mobibot/commands/Info.java
index 1282d78..e9c9975 100644
--- a/src/main/java/net/thauvin/erik/mobibot/commands/Info.java
+++ b/src/main/java/net/thauvin/erik/mobibot/commands/Info.java
@@ -93,7 +93,7 @@ public class Info extends AbstractCommand {
info.append(Utils.uptime(ManagementFactory.getRuntimeMXBean().getUptime()))
.append(" [Entries: ")
- .append(LinksMgr.getEntriesCount());
+ .append(LinksMgr.entries.size());
if (isOp) {
if (getBot().getTell().isEnabled()) {
diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/links/Comment.kt b/src/main/java/net/thauvin/erik/mobibot/commands/links/Comment.kt
index 00b718a..65941cf 100644
--- a/src/main/java/net/thauvin/erik/mobibot/commands/links/Comment.kt
+++ b/src/main/java/net/thauvin/erik/mobibot/commands/links/Comment.kt
@@ -68,8 +68,8 @@ class Comment(bot: Mobibot) : AbstractCommand(bot) {
val cmds = args.substring(1).split("[.:]".toRegex(), 3)
val index = cmds[0].toInt() - 1
- if (index < LinksMgr.entriesCount) {
- val entry: EntryLink = LinksMgr.getEntry(index)
+ if (index < LinksMgr.entries.size) {
+ val entry: EntryLink = LinksMgr.entries[index]
val commentIndex = cmds[1].toInt() - 1
if (commentIndex < entry.comments.size) {
when (val cmd = cmds[2].trim()) {
diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/links/LinksMgr.kt b/src/main/java/net/thauvin/erik/mobibot/commands/links/LinksMgr.kt
index ac5257d..cd4104b 100644
--- a/src/main/java/net/thauvin/erik/mobibot/commands/links/LinksMgr.kt
+++ b/src/main/java/net/thauvin/erik/mobibot/commands/links/LinksMgr.kt
@@ -40,7 +40,6 @@ import net.thauvin.erik.mobibot.commands.Ignore
import net.thauvin.erik.mobibot.entries.EntriesMgr
import net.thauvin.erik.mobibot.entries.EntriesUtils
import net.thauvin.erik.mobibot.entries.EntryLink
-import org.apache.logging.log4j.LogManager
import org.jsoup.Jsoup
import java.io.IOException
@@ -65,23 +64,22 @@ class LinksMgr(bot: Mobibot) : AbstractCommand(bot) {
const val TAG_MATCH = ", *| +"
// Entries array
- private val entries = ArrayList(0)
+ @JvmField
+ val entries = ArrayList(0)
// History/backlogs array
- private val history = ArrayList(0)
+ @JvmField
+ val history = ArrayList(0)
- @JvmStatic
- val entriesCount
- get() = entries.size
@JvmStatic
var startDate: String = Utils.today()
private set
- @JvmStatic
- fun addHistory(index: Int, entry: String) {
- history.add(index, entry)
- }
+ // @JvmStatic
+ // fun addHistory(index: Int, entry: String) {
+ // history.add(index, entry)
+ // }
/**
* Saves the entries.
@@ -93,20 +91,15 @@ class LinksMgr(bot: Mobibot) : AbstractCommand(bot) {
EntriesMgr.saveEntries(bot, entries, history, isDayBackup)
}
- @JvmStatic
- fun removeEntry(index: Int) {
- entries.removeAt(index)
- }
-
- @JvmStatic
- fun getEntry(index: Int): EntryLink {
- return entries[index]
- }
-
- @JvmStatic
- fun getHistory(): List {
- return history
- }
+ // @JvmStatic
+ // fun removeEntry(index: Int) {
+ // entries.removeAt(index)
+ // }
+ //
+ // @JvmStatic
+ // fun getEntry(index: Int): EntryLink {
+ // return entries[index]
+ // }
@JvmStatic
fun startup(current: String, backlogs: String, channel: String) {
diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/links/Posting.kt b/src/main/java/net/thauvin/erik/mobibot/commands/links/Posting.kt
index bf275f5..71ec786 100644
--- a/src/main/java/net/thauvin/erik/mobibot/commands/links/Posting.kt
+++ b/src/main/java/net/thauvin/erik/mobibot/commands/links/Posting.kt
@@ -36,6 +36,7 @@ import net.thauvin.erik.mobibot.Constants
import net.thauvin.erik.mobibot.Mobibot
import net.thauvin.erik.mobibot.Utils
import net.thauvin.erik.mobibot.commands.AbstractCommand
+import net.thauvin.erik.mobibot.commands.links.LinksMgr.Companion.entries
import net.thauvin.erik.mobibot.entries.EntriesUtils
import net.thauvin.erik.mobibot.entries.EntryLink
@@ -67,7 +68,7 @@ class Posting(bot: Mobibot) : AbstractCommand(bot) {
val cmds = args.substring(1).split(":", limit = 2)
val index = cmds[0].toInt() - 1
- if (index < LinksMgr.entriesCount) {
+ if (index < entries.size) {
when (val cmd = cmds[1].trim()) {
"" -> showEntry(index)
"-" -> removeEntry(sender, login, isOp, index) // L1:-
@@ -88,7 +89,7 @@ class Posting(bot: Mobibot) : AbstractCommand(bot) {
}
private fun addComment(cmd: String, sender: String, index: Int) {
- val entry: EntryLink = LinksMgr.getEntry(index)
+ val entry: EntryLink = entries[index]
val commentIndex = entry.addComment(cmd, sender)
val comment = entry.getComment(commentIndex)
bot.send(sender, EntriesUtils.buildComment(index, commentIndex, comment), false)
@@ -97,7 +98,7 @@ class Posting(bot: Mobibot) : AbstractCommand(bot) {
private fun changeTitle(cmd: String, index: Int) {
if (cmd.length > 1) {
- val entry: EntryLink = LinksMgr.getEntry(index)
+ val entry: EntryLink = entries[index]
entry.title = cmd.substring(1).trim()
bot.updatePin(entry.link, entry)
bot.send(EntriesUtils.buildLink(index, entry))
@@ -106,7 +107,7 @@ class Posting(bot: Mobibot) : AbstractCommand(bot) {
}
private fun changeUrl(cmd: String, login: String, isOp: Boolean, index: Int) {
- val entry: EntryLink = LinksMgr.getEntry(index)
+ val entry: EntryLink = entries[index]
if (entry.login == login || isOp) {
val link = cmd.substring(1)
if (link.matches(LinksMgr.LINK_MATCH.toRegex())) {
@@ -122,7 +123,7 @@ class Posting(bot: Mobibot) : AbstractCommand(bot) {
private fun changeAuthor(cmd: String, sender: String, isOp: Boolean, index: Int) {
if (isOp) {
if (cmd.length > 1) {
- val entry: EntryLink = LinksMgr.getEntry(index)
+ val entry: EntryLink = entries[index]
entry.nick = cmd.substring(1)
bot.send(EntriesUtils.buildLink(index, entry))
LinksMgr.saveEntries(bot, false)
@@ -133,10 +134,10 @@ class Posting(bot: Mobibot) : AbstractCommand(bot) {
}
private fun removeEntry(sender: String, login: String, isOp: Boolean, index: Int) {
- val entry: EntryLink = LinksMgr.getEntry(index)
+ val entry: EntryLink = LinksMgr.entries[index]
if (entry.login == login || isOp) {
bot.deletePin(index, entry)
- LinksMgr.removeEntry(index)
+ entries.removeAt(index)
bot.send("Entry ${EntriesUtils.buildLinkCmd(index)} removed.")
LinksMgr.saveEntries(bot, false)
} else {
@@ -145,7 +146,7 @@ class Posting(bot: Mobibot) : AbstractCommand(bot) {
}
private fun showEntry(index: Int) {
- val entry: EntryLink = LinksMgr.getEntry(index)
+ val entry: EntryLink = entries[index]
bot.send(EntriesUtils.buildLink(index, entry))
if (entry.hasTags()) {
bot.send(EntriesUtils.buildTags(index, entry))
diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/links/Tags.kt b/src/main/java/net/thauvin/erik/mobibot/commands/links/Tags.kt
index 28b57c9..9a9a73e 100644
--- a/src/main/java/net/thauvin/erik/mobibot/commands/links/Tags.kt
+++ b/src/main/java/net/thauvin/erik/mobibot/commands/links/Tags.kt
@@ -63,9 +63,9 @@ class Tags(bot: Mobibot) : AbstractCommand(bot) {
val cmds = args.substring(1).split("T:", limit = 2)
val index = cmds[0].toInt() - 1
- if (index < LinksMgr.entriesCount) {
+ if (index < LinksMgr.entries.size) {
val cmd = cmds[1].trim()
- val entry: EntryLink = LinksMgr.getEntry(index)
+ val entry: EntryLink = LinksMgr.entries[index]
if (cmd.isNotEmpty()) {
if (entry.login == login || isOp) {
entry.setTags(cmd)
diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/links/View.kt b/src/main/java/net/thauvin/erik/mobibot/commands/links/View.kt
index 98dd423..dbafa4a 100644
--- a/src/main/java/net/thauvin/erik/mobibot/commands/links/View.kt
+++ b/src/main/java/net/thauvin/erik/mobibot/commands/links/View.kt
@@ -35,8 +35,7 @@ package net.thauvin.erik.mobibot.commands.links
import net.thauvin.erik.mobibot.Mobibot
import net.thauvin.erik.mobibot.Utils
import net.thauvin.erik.mobibot.commands.AbstractCommand
-import net.thauvin.erik.mobibot.commands.links.LinksMgr.Companion.entriesCount
-import net.thauvin.erik.mobibot.commands.links.LinksMgr.Companion.getEntry
+import net.thauvin.erik.mobibot.commands.links.LinksMgr.Companion.entries
import net.thauvin.erik.mobibot.entries.EntriesUtils
import net.thauvin.erik.mobibot.entries.EntryLink
@@ -62,7 +61,7 @@ class View(bot: Mobibot) : AbstractCommand(bot) {
isOp: Boolean,
isPrivate: Boolean
) {
- if (entriesCount != 0) {
+ if (entries.size != 0) {
showPosts(bot, args, sender)
} else {
bot.send(sender, "There is currently nothing to view. Why don't you post something?", isPrivate)
@@ -70,7 +69,7 @@ class View(bot: Mobibot) : AbstractCommand(bot) {
}
private fun showPosts(bot: Mobibot, args: String, sender: String) {
- val max = entriesCount
+ val max = entries.size
var lcArgs = args.toLowerCase()
var i = 0
if (lcArgs.isEmpty() && max > maxEntries) {
@@ -96,7 +95,7 @@ class View(bot: Mobibot) : AbstractCommand(bot) {
var entry: EntryLink
var sent = 0
while (i < max && sent < maxEntries) {
- entry = getEntry(i)
+ entry = entries[i]
if (lcArgs.isNotBlank()) {
if (entry.matches(lcArgs)) {
bot.send(sender, EntriesUtils.buildLink(i, entry, true), false)
diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.kt b/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.kt
index 014846f..392cf85 100644
--- a/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.kt
+++ b/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.kt
@@ -35,8 +35,7 @@ import net.thauvin.erik.mobibot.Constants
import net.thauvin.erik.mobibot.Mobibot
import net.thauvin.erik.mobibot.TwitterTimer
import net.thauvin.erik.mobibot.Utils
-import net.thauvin.erik.mobibot.commands.links.LinksMgr.Companion.entriesCount
-import net.thauvin.erik.mobibot.commands.links.LinksMgr.Companion.getEntry
+import net.thauvin.erik.mobibot.commands.links.LinksMgr
import net.thauvin.erik.mobibot.entries.EntriesUtils
import net.thauvin.erik.mobibot.msg.Message
import net.thauvin.erik.mobibot.msg.NoticeMessage
@@ -125,8 +124,8 @@ class Twitter(bot: Mobibot) : ThreadedModule(bot) {
*/
fun postEntry(index: Int) {
with(bot) {
- if (isAutoPost && hasEntry(index) && entriesCount >= index) {
- val entry = getEntry(index)
+ if (isAutoPost && hasEntry(index) && LinksMgr.entries.size >= index) {
+ val entry = LinksMgr.entries[index]
val msg = "${entry.title} ${entry.link} via ${entry.nick} on $channel"
Thread {
try {