Added toLinkLabel extension function.
This commit is contained in:
parent
0cf98c6ca4
commit
fe6ddf267d
7 changed files with 22 additions and 31 deletions
10
.idea/runConfigurations.xml
generated
10
.idea/runConfigurations.xml
generated
|
@ -1,10 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="RunConfigurationProducerService">
|
||||
<option name="ignoredProducers">
|
||||
<set>
|
||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
||||
</set>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
|
@ -39,7 +39,7 @@ import net.thauvin.erik.mobibot.Utils.isChannelOp
|
|||
import net.thauvin.erik.mobibot.Utils.sendMessage
|
||||
import net.thauvin.erik.mobibot.commands.AbstractCommand
|
||||
import net.thauvin.erik.mobibot.entries.EntriesUtils.buildComment
|
||||
import net.thauvin.erik.mobibot.entries.EntriesUtils.buildLinkLabel
|
||||
import net.thauvin.erik.mobibot.entries.EntriesUtils.toLinkLabel
|
||||
import net.thauvin.erik.mobibot.entries.EntryLink
|
||||
import org.pircbotx.hooks.types.GenericMessageEvent
|
||||
|
||||
|
@ -97,7 +97,7 @@ class Comment : AbstractCommand() {
|
|||
}
|
||||
|
||||
override fun matches(message: String): Boolean {
|
||||
return message.matches("^${Constants.LINK_CMD}[0-9]+\\.[0-9]+:.*".toRegex())
|
||||
return message.matches("^${Constants.LINK_CMD}\\d+\\.\\d+:.*".toRegex())
|
||||
}
|
||||
|
||||
private fun changeAuthor(
|
||||
|
@ -127,7 +127,7 @@ class Comment : AbstractCommand() {
|
|||
) {
|
||||
if (isChannelOp(channel, event) || event.user.nick == entry.getComment(commentIndex).nick) {
|
||||
entry.deleteComment(commentIndex)
|
||||
event.sendMessage("Comment ${buildLinkLabel(entryIndex)}.${commentIndex + 1} removed.")
|
||||
event.sendMessage("Comment ${entryIndex.toLinkLabel()}.${commentIndex + 1} removed.")
|
||||
LinksMgr.entries.save()
|
||||
} else {
|
||||
event.sendMessage("Please ask a channel op to delete this comment for you.")
|
||||
|
|
|
@ -43,7 +43,7 @@ import net.thauvin.erik.mobibot.commands.AbstractCommand
|
|||
import net.thauvin.erik.mobibot.commands.Ignore.Companion.isNotIgnored
|
||||
import net.thauvin.erik.mobibot.entries.Entries
|
||||
import net.thauvin.erik.mobibot.entries.EntriesUtils.buildLink
|
||||
import net.thauvin.erik.mobibot.entries.EntriesUtils.buildLinkLabel
|
||||
import net.thauvin.erik.mobibot.entries.EntriesUtils.toLinkLabel
|
||||
import net.thauvin.erik.mobibot.entries.EntryLink
|
||||
import net.thauvin.erik.mobibot.modules.Twitter
|
||||
import org.jsoup.Jsoup
|
||||
|
@ -147,7 +147,7 @@ class LinksMgr : AbstractCommand() {
|
|||
|
||||
if (Constants.NO_TITLE == entry.title) {
|
||||
event.sendMessage("Please specify a title, by typing:")
|
||||
event.sendMessage(helpFormat("${buildLinkLabel(index)}:|This is the title"))
|
||||
event.sendMessage(helpFormat("${index.toLinkLabel()}:|This is the title"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,6 +41,7 @@ import net.thauvin.erik.mobibot.Utils.sendMessage
|
|||
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.EntriesUtils.toLinkLabel
|
||||
import net.thauvin.erik.mobibot.entries.EntryLink
|
||||
import org.pircbotx.hooks.types.GenericMessageEvent
|
||||
|
||||
|
@ -86,7 +87,7 @@ class Posting : AbstractCommand() {
|
|||
}
|
||||
|
||||
override fun matches(message: String): Boolean {
|
||||
return message.matches("${Constants.LINK_CMD}[0-9]+:.*".toRegex())
|
||||
return message.matches("${Constants.LINK_CMD}\\d+:.*".toRegex())
|
||||
}
|
||||
|
||||
private fun addComment(cmd: String, entryIndex: Int, event: GenericMessageEvent) {
|
||||
|
@ -141,7 +142,7 @@ class Posting : AbstractCommand() {
|
|||
LinksMgr.pinboard.deletePin(entry)
|
||||
LinksMgr.twitter.removeEntry(index)
|
||||
entries.links.removeAt(index)
|
||||
event.sendMessage("Entry ${EntriesUtils.buildLinkLabel(index)} removed.")
|
||||
event.sendMessage("Entry ${index.toLinkLabel()} removed.")
|
||||
entries.save()
|
||||
} else {
|
||||
event.sendMessage("Please ask a channel op to remove this entry for you.")
|
||||
|
|
|
@ -39,18 +39,12 @@ import net.thauvin.erik.mobibot.Utils.green
|
|||
* Entries utilities.
|
||||
*/
|
||||
object EntriesUtils {
|
||||
/**
|
||||
* Build link label based on its index. e.g: L1
|
||||
*/
|
||||
@JvmStatic
|
||||
fun buildLinkLabel(index: Int): String = Constants.LINK_CMD + (index + 1)
|
||||
|
||||
/**
|
||||
* Builds an entry's comment for display on the channel.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun buildComment(entryIndex: Int, commentIndex: Int, comment: EntryComment): String =
|
||||
("${buildLinkLabel(entryIndex)}.${commentIndex + 1}: [${comment.nick}] ${comment.comment}")
|
||||
("${entryIndex.toLinkLabel()}.${commentIndex + 1}: [${comment.nick}] ${comment.comment}")
|
||||
|
||||
/**
|
||||
* Builds an entry's link for display on the channel.
|
||||
|
@ -58,7 +52,7 @@ object EntriesUtils {
|
|||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun buildLink(entryIndex: Int, entry: EntryLink, isView: Boolean = false): String {
|
||||
val buff = StringBuilder().append(buildLinkLabel(entryIndex)).append(": ")
|
||||
val buff = StringBuilder().append(entryIndex.toLinkLabel()).append(": ")
|
||||
.append('[').append(entry.nick).append(']')
|
||||
if (isView && entry.comments.isNotEmpty()) {
|
||||
buff.append("[+").append(entry.comments.size).append(']')
|
||||
|
@ -80,5 +74,11 @@ object EntriesUtils {
|
|||
*/
|
||||
@JvmStatic
|
||||
fun buildTags(entryIndex: Int, entry: EntryLink): String =
|
||||
buildLinkLabel(entryIndex) + "${Constants.TAG_CMD}: " + entry.pinboardTags.replace(",", ", ")
|
||||
entryIndex.toLinkLabel() + "${Constants.TAG_CMD}: " + entry.pinboardTags.replace(",", ", ")
|
||||
|
||||
/**
|
||||
* Build link label based on its index. e.g: L1
|
||||
*/
|
||||
@JvmStatic
|
||||
fun Int.toLinkLabel(): String = Constants.LINK_CMD + (this + 1)
|
||||
}
|
||||
|
|
|
@ -37,7 +37,7 @@ import net.thauvin.erik.mobibot.Constants
|
|||
import net.thauvin.erik.mobibot.TwitterTimer
|
||||
import net.thauvin.erik.mobibot.Utils.helpFormat
|
||||
import net.thauvin.erik.mobibot.commands.links.LinksMgr
|
||||
import net.thauvin.erik.mobibot.entries.EntriesUtils
|
||||
import net.thauvin.erik.mobibot.entries.EntriesUtils.toLinkLabel
|
||||
import org.pircbotx.hooks.types.GenericMessageEvent
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
@ -135,7 +135,7 @@ class Twitter : ThreadedModule() {
|
|||
launch {
|
||||
try {
|
||||
if (logger.isDebugEnabled) {
|
||||
logger.debug("Posting {} to Twitter.", EntriesUtils.buildLinkLabel(index))
|
||||
logger.debug("Posting {} to Twitter.", index.toLinkLabel())
|
||||
}
|
||||
post(message = msg, isDm = false)
|
||||
} catch (e: ModuleException) {
|
||||
|
@ -151,7 +151,7 @@ class Twitter : ThreadedModule() {
|
|||
if (isAutoPost) {
|
||||
addEntry(index)
|
||||
if (logger.isDebugEnabled) {
|
||||
logger.debug("Scheduling {} for posting on Twitter.", EntriesUtils.buildLinkLabel(index))
|
||||
logger.debug("Scheduling {} for posting on Twitter.", index.toLinkLabel())
|
||||
}
|
||||
timer.schedule(TwitterTimer(this, index), Constants.TIMER_DELAY * 60L * 1000L)
|
||||
}
|
||||
|
|
|
@ -38,8 +38,8 @@ import assertk.assertions.isEqualTo
|
|||
import net.thauvin.erik.mobibot.Constants
|
||||
import net.thauvin.erik.mobibot.entries.EntriesUtils.buildComment
|
||||
import net.thauvin.erik.mobibot.entries.EntriesUtils.buildLink
|
||||
import net.thauvin.erik.mobibot.entries.EntriesUtils.buildLinkLabel
|
||||
import net.thauvin.erik.mobibot.entries.EntriesUtils.buildTags
|
||||
import net.thauvin.erik.mobibot.entries.EntriesUtils.toLinkLabel
|
||||
import org.testng.annotations.Test
|
||||
|
||||
class EntriesUtilsTest {
|
||||
|
@ -61,7 +61,7 @@ class EntriesUtilsTest {
|
|||
|
||||
@Test
|
||||
fun buildLinkLabelTest() {
|
||||
assertThat(buildLinkLabel(1)).isEqualTo("${Constants.LINK_CMD}2")
|
||||
assertThat(1.toLinkLabel()).isEqualTo("${Constants.LINK_CMD}2")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue