Added tags to Mastodon post

This commit is contained in:
Erik C. Thauvin 2022-12-07 11:50:19 -08:00
parent 2b2d046835
commit e510a77af1
18 changed files with 99 additions and 103 deletions

View file

@ -86,6 +86,7 @@
<ID>ThrowsCount:WolframAlpha.kt$WolframAlpha.Companion$@JvmStatic @Throws(ModuleException::class) fun queryWolfram(query: String, units: String = IMPERIAL, appId: String?): String</ID> <ID>ThrowsCount:WolframAlpha.kt$WolframAlpha.Companion$@JvmStatic @Throws(ModuleException::class) fun queryWolfram(query: String, units: String = IMPERIAL, appId: String?): String</ID>
<ID>TooGenericExceptionCaught:StockQuote.kt$StockQuote.Companion$e: NullPointerException</ID> <ID>TooGenericExceptionCaught:StockQuote.kt$StockQuote.Companion$e: NullPointerException</ID>
<ID>TooGenericExceptionCaught:Weather2.kt$Weather2.Companion$e: NullPointerException</ID> <ID>TooGenericExceptionCaught:Weather2.kt$Weather2.Companion$e: NullPointerException</ID>
<ID>TooManyFunctions:EntryLink.kt$EntryLink : Serializable</ID>
<ID>TooManyFunctions:Mobibot.kt$Mobibot : ListenerAdapter</ID> <ID>TooManyFunctions:Mobibot.kt$Mobibot : ListenerAdapter</ID>
<ID>TooManyFunctions:Tell.kt$Tell : AbstractCommand</ID> <ID>TooManyFunctions:Tell.kt$Tell : AbstractCommand</ID>
</CurrentIssues> </CurrentIssues>

View file

@ -46,8 +46,8 @@ import java.util.Properties
*/ */
class Addons(private val props: Properties) { class Addons(private val props: Properties) {
private val logger: Logger = LoggerFactory.getLogger(Addons::class.java) private val logger: Logger = LoggerFactory.getLogger(Addons::class.java)
private val disabledModules = props.getProperty("disabled-modules", "").split(LinksManager.TAG_MATCH.toRegex()) private val disabledModules = props.getProperty("disabled-modules", "").split(LinksManager.TAG_MATCH)
private val disableCommands = props.getProperty("disabled-commands", "").split(LinksManager.TAG_MATCH.toRegex()) private val disableCommands = props.getProperty("disabled-commands", "").split(LinksManager.TAG_MATCH)
val commands: MutableList<AbstractCommand> = mutableListOf() val commands: MutableList<AbstractCommand> = mutableListOf()
val modules: MutableList<AbstractModule> = mutableListOf() val modules: MutableList<AbstractModule> = mutableListOf()

View file

@ -55,13 +55,9 @@ class Pinboard {
if (poster.apiToken.isNotBlank()) { if (poster.apiToken.isNotBlank()) {
runBlocking { runBlocking {
launch { launch {
poster.addPin( with(entry) {
entry.link, poster.addPin(link, title, postedBy(ircServer), formatTags(), date.toTimestamp())
entry.title, }
entry.postedBy(ircServer),
entry.pinboardTags,
entry.date.toTimestamp()
)
} }
} }
} }
@ -98,7 +94,7 @@ class Pinboard {
if (oldUrl != link) { if (oldUrl != link) {
poster.deletePin(oldUrl) poster.deletePin(oldUrl)
} }
poster.addPin(link, title, entry.postedBy(ircServer), pinboardTags, date.toTimestamp()) poster.addPin(link, title, postedBy(ircServer), formatTags(), date.toTimestamp())
} }
} }
} }
@ -106,7 +102,7 @@ class Pinboard {
} }
/** /**
* Format a date to a UTC timestamp. * Formats a date to a UTC timestamp.
*/ */
private fun Date.toTimestamp(): String { private fun Date.toTimestamp(): String {
return ZonedDateTime.ofInstant( return ZonedDateTime.ofInstant(
@ -115,6 +111,13 @@ class Pinboard {
).format(DateTimeFormatter.ISO_INSTANT) ).format(DateTimeFormatter.ISO_INSTANT)
} }
/**
* Formats the tags for pinboard.
*/
private fun EntryLink.formatTags(): String {
return nick + formatTags(",", ",")
}
/** /**
* Returns the pinboard.in extended attribution line. * Returns the pinboard.in extended attribution line.
*/ */

View file

@ -141,7 +141,7 @@ class Ignore : AbstractCommand() {
override fun setProperty(key: String, value: String) { override fun setProperty(key: String, value: String) {
super.setProperty(key, value) super.setProperty(key, value)
if (IGNORE_PROP == key) { if (IGNORE_PROP == key) {
ignored.addAll(value.split(LinksManager.TAG_MATCH.toRegex())) ignored.addAll(value.split(LinksManager.TAG_MATCH)
} }
} }

View file

@ -38,7 +38,7 @@ import net.thauvin.erik.mobibot.Utils.helpFormat
import net.thauvin.erik.mobibot.Utils.isChannelOp import net.thauvin.erik.mobibot.Utils.isChannelOp
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.entries.EntriesUtils.buildComment import net.thauvin.erik.mobibot.entries.EntriesUtils.printComment
import net.thauvin.erik.mobibot.entries.EntriesUtils.toLinkLabel import net.thauvin.erik.mobibot.entries.EntriesUtils.toLinkLabel
import net.thauvin.erik.mobibot.entries.EntryLink import net.thauvin.erik.mobibot.entries.EntryLink
import org.pircbotx.hooks.types.GenericMessageEvent import org.pircbotx.hooks.types.GenericMessageEvent
@ -111,7 +111,7 @@ class Comment : AbstractCommand() {
if (event.isChannelOp(channel) && cmd.length > 1) { if (event.isChannelOp(channel) && cmd.length > 1) {
val comment = entry.getComment(commentIndex) val comment = entry.getComment(commentIndex)
comment.nick = cmd.substring(1) comment.nick = cmd.substring(1)
event.sendMessage(buildComment(entryIndex, commentIndex, comment)) event.sendMessage(printComment(entryIndex, commentIndex, comment))
LinksManager.entries.save() LinksManager.entries.save()
} else { } else {
event.sendMessage("Please ask a channel op to change the author of this comment for you.") event.sendMessage("Please ask a channel op to change the author of this comment for you.")
@ -142,11 +142,11 @@ class Comment : AbstractCommand() {
event: GenericMessageEvent event: GenericMessageEvent
) { ) {
entry.setComment(commentIndex, cmd, event.user.nick) entry.setComment(commentIndex, cmd, event.user.nick)
event.sendMessage(buildComment(entryIndex, commentIndex, entry.getComment(commentIndex))) event.sendMessage(printComment(entryIndex, commentIndex, entry.getComment(commentIndex)))
LinksManager.entries.save() LinksManager.entries.save()
} }
private fun showComment(entry: EntryLink, entryIndex: Int, commentIndex: Int, event: GenericMessageEvent) { private fun showComment(entry: EntryLink, entryIndex: Int, commentIndex: Int, event: GenericMessageEvent) {
event.sendMessage(buildComment(entryIndex, commentIndex, entry.getComment(commentIndex))) event.sendMessage(printComment(entryIndex, commentIndex, entry.getComment(commentIndex)))
} }
} }

View file

@ -42,7 +42,7 @@ import net.thauvin.erik.mobibot.Utils.today
import net.thauvin.erik.mobibot.commands.AbstractCommand import net.thauvin.erik.mobibot.commands.AbstractCommand
import net.thauvin.erik.mobibot.commands.Ignore.Companion.isNotIgnored import net.thauvin.erik.mobibot.commands.Ignore.Companion.isNotIgnored
import net.thauvin.erik.mobibot.entries.Entries import net.thauvin.erik.mobibot.entries.Entries
import net.thauvin.erik.mobibot.entries.EntriesUtils.buildLink import net.thauvin.erik.mobibot.entries.EntriesUtils.printLink
import net.thauvin.erik.mobibot.entries.EntriesUtils.toLinkLabel import net.thauvin.erik.mobibot.entries.EntriesUtils.toLinkLabel
import net.thauvin.erik.mobibot.entries.EntryLink import net.thauvin.erik.mobibot.entries.EntryLink
import net.thauvin.erik.mobibot.social.SocialManager import net.thauvin.erik.mobibot.social.SocialManager
@ -65,10 +65,10 @@ class LinksManager : AbstractCommand() {
} }
companion object { companion object {
const val LINK_MATCH = "^[hH][tT][tT][pP](|[sS])://.*" val LINK_MATCH = "^[hH][tT][tT][pP](|[sS])://.*".toRegex()
const val KEYWORDS_PROP = "tags-keywords" const val KEYWORDS_PROP = "tags-keywords"
const val TAGS_PROP = "tags" const val TAGS_PROP = "tags"
const val TAG_MATCH = ", *| +" val TAG_MATCH = ", *| +".toRegex()
/** /**
* Entries array * Entries array
@ -116,7 +116,7 @@ class LinksManager : AbstractCommand() {
val data = cmds[1].trim().split("${Tags.COMMAND}:", limit = 2) val data = cmds[1].trim().split("${Tags.COMMAND}:", limit = 2)
title = data[0].trim() title = data[0].trim()
if (data.size > 1) { if (data.size > 1) {
tags.addAll(data[1].split(TAG_MATCH.toRegex())) tags.addAll(data[1].split(TAG_MATCH))
} }
} }
@ -136,7 +136,7 @@ class LinksManager : AbstractCommand() {
val entry = EntryLink(link, title, sender, login, channel, tags) val entry = EntryLink(link, title, sender, login, channel, tags)
entries.links.add(entry) entries.links.add(entry)
val index = entries.links.lastIndexOf(entry) val index = entries.links.lastIndexOf(entry)
event.sendMessage(buildLink(index, entry)) event.sendMessage(printLink(index, entry))
pinboard.addPin(event.bot().serverHostname, entry) pinboard.addPin(event.bot().serverHostname, entry)
@ -156,7 +156,7 @@ class LinksManager : AbstractCommand() {
override fun helpResponse(channel: String, topic: String, event: GenericMessageEvent): Boolean = false override fun helpResponse(channel: String, topic: String, event: GenericMessageEvent): Boolean = false
override fun matches(message: String): Boolean { override fun matches(message: String): Boolean {
return message.matches(LINK_MATCH.toRegex()) return message.matches(LINK_MATCH)
} }
internal fun fetchTitle(link: String): String { internal fun fetchTitle(link: String): String {
@ -179,7 +179,7 @@ class LinksManager : AbstractCommand() {
return try { return try {
val match = entries.links.single { it.link == link } val match = entries.links.single { it.link == link }
event.sendMessage( event.sendMessage(
"Duplicate".bold() + " >> " + buildLink(entries.links.indexOf(match), match) "Duplicate".bold() + " >> " + printLink(entries.links.indexOf(match), match)
) )
true true
} catch (ignore: NoSuchElementException) { } catch (ignore: NoSuchElementException) {
@ -200,9 +200,9 @@ class LinksManager : AbstractCommand() {
override fun setProperty(key: String, value: String) { override fun setProperty(key: String, value: String) {
super.setProperty(key, value) super.setProperty(key, value)
if (KEYWORDS_PROP == key) { if (KEYWORDS_PROP == key) {
keywords.addAll(value.split(TAG_MATCH.toRegex())) keywords.addAll(value.split(TAG_MATCH))
} else if (TAGS_PROP == key) { } else if (TAGS_PROP == key) {
defaultTags.addAll(value.split(TAG_MATCH.toRegex())) defaultTags.addAll(value.split(TAG_MATCH))
} }
} }
} }

View file

@ -94,7 +94,7 @@ class Posting : AbstractCommand() {
val entry: EntryLink = entries.links[entryIndex] val entry: EntryLink = entries.links[entryIndex]
val commentIndex = entry.addComment(cmd, event.user.nick) val commentIndex = entry.addComment(cmd, event.user.nick)
val comment = entry.getComment(commentIndex) val comment = entry.getComment(commentIndex)
event.sendMessage(EntriesUtils.buildComment(entryIndex, commentIndex, comment)) event.sendMessage(EntriesUtils.printComment(entryIndex, commentIndex, comment))
entries.save() entries.save()
} }
@ -103,7 +103,7 @@ class Posting : AbstractCommand() {
val entry: EntryLink = entries.links[entryIndex] val entry: EntryLink = entries.links[entryIndex]
entry.title = cmd.substring(1).trim() entry.title = cmd.substring(1).trim()
LinksManager.pinboard.updatePin(event.bot().serverHostname, entry.link, entry) LinksManager.pinboard.updatePin(event.bot().serverHostname, entry.link, entry)
event.sendMessage(EntriesUtils.buildLink(entryIndex, entry)) event.sendMessage(EntriesUtils.printLink(entryIndex, entry))
entries.save() entries.save()
} }
} }
@ -112,11 +112,11 @@ class Posting : AbstractCommand() {
val entry: EntryLink = entries.links[entryIndex] val entry: EntryLink = entries.links[entryIndex]
if (entry.login == event.user.login || event.isChannelOp(channel)) { if (entry.login == event.user.login || event.isChannelOp(channel)) {
val link = cmd.substring(1) val link = cmd.substring(1)
if (link.matches(LinksManager.LINK_MATCH.toRegex())) { if (link.matches(LinksManager.LINK_MATCH)) {
val oldLink = entry.link val oldLink = entry.link
entry.link = link entry.link = link
LinksManager.pinboard.updatePin(event.bot().serverHostname, oldLink, entry) LinksManager.pinboard.updatePin(event.bot().serverHostname, oldLink, entry)
event.sendMessage(EntriesUtils.buildLink(entryIndex, entry)) event.sendMessage(EntriesUtils.printLink(entryIndex, entry))
entries.save() entries.save()
} }
} }
@ -128,7 +128,7 @@ class Posting : AbstractCommand() {
val entry: EntryLink = entries.links[index] val entry: EntryLink = entries.links[index]
entry.nick = cmd.substring(1) entry.nick = cmd.substring(1)
LinksManager.pinboard.updatePin(event.bot().serverHostname, entry.link, entry) LinksManager.pinboard.updatePin(event.bot().serverHostname, entry.link, entry)
event.sendMessage(EntriesUtils.buildLink(index, entry)) event.sendMessage(EntriesUtils.printLink(index, entry))
entries.save() entries.save()
} }
} else { } else {
@ -151,14 +151,14 @@ class Posting : AbstractCommand() {
private fun showEntry(index: Int, event: GenericMessageEvent) { private fun showEntry(index: Int, event: GenericMessageEvent) {
val entry: EntryLink = entries.links[index] val entry: EntryLink = entries.links[index]
event.sendMessage(EntriesUtils.buildLink(index, entry)) event.sendMessage(EntriesUtils.printLink(index, entry))
if (entry.tags.isNotEmpty()) { if (entry.tags.isNotEmpty()) {
event.sendMessage(EntriesUtils.buildTags(index, entry)) event.sendMessage(EntriesUtils.printTags(index, entry))
} }
if (entry.comments.isNotEmpty()) { if (entry.comments.isNotEmpty()) {
val comments = entry.comments val comments = entry.comments
for (i in comments.indices) { for (i in comments.indices) {
event.sendMessage(EntriesUtils.buildComment(index, i, comments[i])) event.sendMessage(EntriesUtils.printComment(index, i, comments[i]))
} }
} }
} }

View file

@ -67,14 +67,14 @@ class Tags : AbstractCommand() {
if (entry.login == event.user.login || event.isChannelOp(channel)) { if (entry.login == event.user.login || event.isChannelOp(channel)) {
entry.setTags(cmd) entry.setTags(cmd)
LinksManager.pinboard.updatePin(event.bot().serverHostname, entry.link, entry) LinksManager.pinboard.updatePin(event.bot().serverHostname, entry.link, entry)
event.sendMessage(EntriesUtils.buildTags(index, entry)) event.sendMessage(EntriesUtils.printTags(index, entry))
LinksManager.entries.save() LinksManager.entries.save()
} else { } else {
event.sendMessage("Please ask a channel op to change the tags for you.") event.sendMessage("Please ask a channel op to change the tags for you.")
} }
} else { } else {
if (entry.tags.isNotEmpty()) { if (entry.tags.isNotEmpty()) {
event.sendMessage(EntriesUtils.buildTags(index, entry)) event.sendMessage(EntriesUtils.printTags(index, entry))
} else { } else {
event.sendMessage("The entry has no tags. Why don't add some?") event.sendMessage("The entry has no tags. Why don't add some?")
} }

View file

@ -97,11 +97,11 @@ class View : AbstractCommand() {
entry = entries.links[index] entry = entries.links[index]
if (query.isNotBlank()) { if (query.isNotBlank()) {
if (entry.matches(query)) { if (entry.matches(query)) {
event.sendMessage(EntriesUtils.buildLink(index, entry, true)) event.sendMessage(EntriesUtils.printLink(index, entry, true))
sent++ sent++
} }
} else { } else {
event.sendMessage(EntriesUtils.buildLink(index, entry, true)) event.sendMessage(EntriesUtils.printLink(index, entry, true))
sent++ sent++
} }
index++ index++

View file

@ -40,18 +40,18 @@ import net.thauvin.erik.mobibot.Utils.green
*/ */
object EntriesUtils { object EntriesUtils {
/** /**
* Builds an entry's comment for display on the channel. * Prints an entry's comment for display on the channel.
*/ */
@JvmStatic @JvmStatic
fun buildComment(entryIndex: Int, commentIndex: Int, comment: EntryComment): String = fun printComment(entryIndex: Int, commentIndex: Int, comment: EntryComment): String =
("${entryIndex.toLinkLabel()}.${commentIndex + 1}: [${comment.nick}] ${comment.comment}") ("${entryIndex.toLinkLabel()}.${commentIndex + 1}: [${comment.nick}] ${comment.comment}")
/** /**
* Builds an entry's link for display on the channel. * Prints an entry's link for display on the channel.
*/ */
@JvmStatic @JvmStatic
@JvmOverloads @JvmOverloads
fun buildLink(entryIndex: Int, entry: EntryLink, isView: Boolean = false): String { fun printLink(entryIndex: Int, entry: EntryLink, isView: Boolean = false): String {
val buff = StringBuilder().append(entryIndex.toLinkLabel()).append(": ") val buff = StringBuilder().append(entryIndex.toLinkLabel()).append(": ")
.append('[').append(entry.nick).append(']') .append('[').append(entry.nick).append(']')
if (isView && entry.comments.isNotEmpty()) { if (isView && entry.comments.isNotEmpty()) {
@ -70,14 +70,14 @@ object EntriesUtils {
} }
/** /**
* Build an entry's tags/categories for display on the channel. * Prints an entry's tags/categories for display on the channel. e.g. L1T: tag1, tag2
*/ */
@JvmStatic @JvmStatic
fun buildTags(entryIndex: Int, entry: EntryLink): String = fun printTags(entryIndex: Int, entry: EntryLink): String =
entryIndex.toLinkLabel() + "${Constants.TAG_CMD}: " + entry.pinboardTags.replace(",", ", ") entryIndex.toLinkLabel() + "${Constants.TAG_CMD}: " + entry.formatTags(", ")
/** /**
* Build link label based on its index. e.g: L1 * Builds link label based on its index. e.g: L1
*/ */
@JvmStatic @JvmStatic
fun Int.toLinkLabel(): String = Constants.LINK_CMD + (this + 1) fun Int.toLinkLabel(): String = Constants.LINK_CMD + (this + 1)

View file

@ -127,24 +127,18 @@ class EntryLink(
return comments.remove(entryComment) return comments.remove(entryComment)
} }
/**
* Formats the tags.
*/
fun formatTags(sep: String, prefix: String = "") : String {
return tags.joinToString(separator = sep, prefix = prefix){it.name}
}
/** /**
* Returns a comment. * Returns a comment.
*/ */
fun getComment(index: Int): EntryComment = comments[index] fun getComment(index: Int): EntryComment = comments[index]
/**
* Returns the tags formatted for pinboard.in
*/
val pinboardTags: String
get() {
val pinboardTags = StringBuilder(nick)
for (tag in tags) {
pinboardTags.append(',')
pinboardTags.append(tag.name)
}
return pinboardTags.toString()
}
/** /**
* Returns true if a string is contained in the link, title, or nick. * Returns true if a string is contained in the link, title, or nick.
*/ */

View file

@ -160,7 +160,7 @@ class FeedsManager private constructor() {
item.description = SyndContentImpl().apply { value = buff.toString() } item.description = SyndContentImpl().apply { value = buff.toString() }
item.title = title item.title = title
item.publishedDate = date item.publishedDate = date
item.author = "${channel.substring(1)}@${entries.ircServer} ($nick)" item.author = "${channel.removePrefix("#")}@${entries.ircServer} ($nick)"
item.categories = tags item.categories = tags
items.add(item) items.add(item)
} }

View file

@ -113,7 +113,7 @@ abstract class AbstractModule {
*/ */
open val isValidProperties: Boolean open val isValidProperties: Boolean
get() { get() {
for (s in propertyKeys) { for (s in properties.keys) {
if (properties[s].isNullOrBlank()) { if (properties[s].isNullOrBlank()) {
return false return false
} }

View file

@ -52,22 +52,21 @@ class Mastodon : SocialModule() {
get() = properties[HANDLE_PROP] get() = properties[HANDLE_PROP]
override val isAutoPost: Boolean override val isAutoPost: Boolean
get() = isEnabled && properties[AUTO_POST_PROP].toBoolean()
override val isValidProperties: Boolean override val isValidProperties: Boolean
get() { get() = !(properties[INSTANCE_PROP].isNullOrBlank() || properties[ACCESS_TOKEN_PROP].isNullOrBlank())
for (s in propertyKeys) {
if (AUTO_POST_PROP != s && HANDLE_PROP != s && properties[s].isNullOrBlank()) {
return false
}
}
return true
}
/** /**
* Formats the entry for posting. * Formats the entry for posting.
*/ */
override fun formatEntry(entry: EntryLink): String { override fun formatEntry(entry: EntryLink): String {
return "${entry.title} via ${entry.nick} on ${entry.channel}\n\n${entry.link}" return "${entry.title} (via ${entry.nick} on ${entry.channel})${formatTags(entry)}\n\n${entry.link}"
}
private fun formatTags(entry: EntryLink): String {
return entry.tags.filter { !it.name.equals(entry.channel.removePrefix("#"), true) }
.joinToString(separator = " ", prefix = "\n\n") { "#${it.name}" }
} }
/** /**

View file

@ -49,14 +49,8 @@ class Twitter : SocialModule() {
get() = isEnabled && properties[AUTO_POST_PROP].toBoolean() get() = isEnabled && properties[AUTO_POST_PROP].toBoolean()
override val isValidProperties: Boolean override val isValidProperties: Boolean
get() { get() = !(properties[CONSUMER_KEY_PROP].isNullOrBlank() || properties[CONSUMER_SECRET_PROP].isNullOrBlank()
for (s in propertyKeys) { || properties[TOKEN_PROP].isNullOrBlank() || properties[TOKEN_SECRET_PROP].isNullOrBlank())
if (AUTO_POST_PROP != s && HANDLE_PROP != s && properties[s].isNullOrBlank()) {
return false
}
}
return true
}
/** /**
* Formats the entry for posting. * Formats the entry for posting.

View file

@ -36,9 +36,9 @@ import assertk.assertThat
import assertk.assertions.contains import assertk.assertions.contains
import assertk.assertions.isEqualTo import assertk.assertions.isEqualTo
import net.thauvin.erik.mobibot.Constants import net.thauvin.erik.mobibot.Constants
import net.thauvin.erik.mobibot.entries.EntriesUtils.buildComment import net.thauvin.erik.mobibot.entries.EntriesUtils.printComment
import net.thauvin.erik.mobibot.entries.EntriesUtils.buildLink import net.thauvin.erik.mobibot.entries.EntriesUtils.printLink
import net.thauvin.erik.mobibot.entries.EntriesUtils.buildTags import net.thauvin.erik.mobibot.entries.EntriesUtils.printTags
import net.thauvin.erik.mobibot.entries.EntriesUtils.toLinkLabel import net.thauvin.erik.mobibot.entries.EntriesUtils.toLinkLabel
import org.testng.annotations.Test import org.testng.annotations.Test
@ -60,33 +60,33 @@ class EntriesUtilsTest {
} }
@Test(groups = ["entries"]) @Test(groups = ["entries"])
fun buildLinkLabelTest() { fun printCommentTest() {
assertThat(1.toLinkLabel()).isEqualTo("${Constants.LINK_CMD}2") assertThat(printComment(0, 0, comment)).isEqualTo("${Constants.LINK_CMD}1.1: [nick] comment")
} }
@Test(groups = ["entries"]) @Test(groups = ["entries"])
fun buildCommentTest() { fun printLinkTest() {
assertThat(buildComment(0, 0, comment)).isEqualTo("${Constants.LINK_CMD}1.1: [nick] comment")
}
@Test(groups = ["entries"])
fun buildLinkTest() {
for (i in links.indices) { for (i in links.indices) {
assertThat( assertThat(
buildLink(i - 1, links[i]), "link $i" printLink(i - 1, links[i]), "link $i"
).isEqualTo("L$i: [Skynx$i] \u0002Mobitopia$i\u0002 ( \u000303https://www.mobitopia.org/$i\u000F )") ).isEqualTo("L$i: [Skynx$i] \u0002Mobitopia$i\u0002 ( \u000303https://www.mobitopia.org/$i\u000F )")
} }
assertThat(links.first().addComment(comment), "addComment()").isEqualTo(0) assertThat(links.first().addComment(comment), "addComment()").isEqualTo(0)
assertThat(buildLink(0, links.first(), isView = true), "buildLink(isView=true)").contains("[+1]") assertThat(printLink(0, links.first(), isView = true), "printLink(isView=true)").contains("[+1]")
} }
@Test(groups = ["entries"]) @Test(groups = ["entries"])
fun buildTagsTest() { fun printTagsTest() {
for (i in links.indices) { for (i in links.indices) {
assertThat( assertThat(
buildTags(i - 1, links[i]), "tag $i" printTags(i - 1, links[i]), "tag $i"
).isEqualTo("L${i}T: Skynx$i, tag1, tag2, tag3, tag4, tag5") ).isEqualTo("L${i}T: tag1, tag2, tag3, tag4, tag5")
} }
} }
@Test(groups = ["entries"])
fun toLinkLabelTest() {
assertThat(1.toLinkLabel()).isEqualTo("${Constants.LINK_CMD}2")
}
} }

View file

@ -40,6 +40,7 @@ import assertk.assertions.isFalse
import assertk.assertions.isTrue import assertk.assertions.isTrue
import assertk.assertions.prop import assertk.assertions.prop
import assertk.assertions.size import assertk.assertions.size
import assertk.assertions.startsWith
import com.rometools.rome.feed.synd.SyndCategory import com.rometools.rome.feed.synd.SyndCategory
import com.rometools.rome.feed.synd.SyndCategoryImpl import com.rometools.rome.feed.synd.SyndCategoryImpl
import org.testng.annotations.Test import org.testng.annotations.Test
@ -94,13 +95,11 @@ class EntryLinkTest {
@Test(groups = ["entries"]) @Test(groups = ["entries"])
fun testConstructor() { fun testConstructor() {
val tag = "test" val tags = listOf(SyndCategoryImpl().apply { name = "tag1" }, SyndCategoryImpl().apply { name = "tag2" })
val tags = listOf(SyndCategoryImpl().apply { name = tag })
val link = EntryLink("link", "title", "nick", "channel", Date(), tags) val link = EntryLink("link", "title", "nick", "channel", Date(), tags)
assertThat(link, "link").all { assertThat(link, "link").all {
prop(EntryLink::tags).size().isEqualTo(tags.size) prop(EntryLink::tags).size().isEqualTo(tags.size)
prop(EntryLink::tags).index(0).prop(SyndCategory::getName).isEqualTo(tag) prop(EntryLink::tags).index(0).prop(SyndCategory::getName).isEqualTo("tag1")
prop(EntryLink::pinboardTags).isEqualTo("nick,$tag")
} }
} }
@ -122,11 +121,17 @@ class EntryLinkTest {
assertThat(tag.name, "tag.name($i)").isEqualTo("tag${i + 1}") assertThat(tag.name, "tag.name($i)").isEqualTo("tag${i + 1}")
} }
assertThat(entryLink::tags).size().isEqualTo(5) assertThat(entryLink::tags).size().isEqualTo(5)
entryLink.setTags("-tag5") entryLink.setTags("-tag5, tag4")
entryLink.setTags("+mobitopia") entryLink.setTags("+mobitopia")
entryLink.setTags("tag4")
entryLink.setTags("-mobitopia") entryLink.setTags("-mobitopia")
assertThat(entryLink::pinboardTags).isEqualTo(entryLink.nick + ",tag1,tag2,tag3,tag4,mobitopia") assertThat(
entryLink.formatTags(","),
"formatTags(',')"
).isEqualTo("tag1,tag2,tag3,tag4,mobitopia")
entryLink.setTags("-tag4 tag5")
assertThat(
entryLink.formatTags(" ", ","), "formatTag(' ',',')"
).isEqualTo(",tag1 tag2 tag3 mobitopia tag5")
val size = entryLink.tags.size val size = entryLink.tags.size
entryLink.setTags("") entryLink.setTags("")
assertThat(entryLink.tags, "setTags('')").size().isEqualTo(size) assertThat(entryLink.tags, "setTags('')").size().isEqualTo(size)

View file

@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle #Generated by the Semver Plugin for Gradle
#Mon Dec 05 21:57:24 PST 2022 #Wed Dec 07 02:53:01 PST 2022
version.buildmeta=814 version.buildmeta=857
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+814 version.semver=0.8.0-rc+857