Added all keyword to seen command

This commit is contained in:
Erik C. Thauvin 2023-06-17 21:30:55 -07:00
parent 66b8adb743
commit d8291e2156
7 changed files with 41 additions and 15 deletions

2
.idea/kotlinc.xml generated
View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<project version="4"> <project version="4">
<component name="KotlinJpsPluginSettings"> <component name="KotlinJpsPluginSettings">
<option name="version" value="1.8.21" /> <option name="version" value="1.8.22" />
</component> </component>
</project> </project>

View file

@ -3,15 +3,15 @@ import io.gitlab.arturbosch.detekt.DetektCreateBaselineTask
plugins { plugins {
id 'application' id 'application'
id 'com.github.ben-manes.versions' version '0.46.0' id 'com.github.ben-manes.versions' version '0.47.0'
id 'idea' id 'idea'
id 'io.gitlab.arturbosch.detekt' version '1.22.0' id 'io.gitlab.arturbosch.detekt' version '1.23.0'
id 'java' id 'java'
id 'net.thauvin.erik.gradle.semver' version '1.0.4' id 'net.thauvin.erik.gradle.semver' version '1.0.4'
id 'org.jetbrains.kotlin.jvm' version '1.8.21' id 'org.jetbrains.kotlin.jvm' version '1.8.22'
id 'org.jetbrains.kotlin.kapt' version '1.8.21' id 'org.jetbrains.kotlin.kapt' version '1.8.22'
id 'org.jetbrains.kotlinx.kover' version '0.7.0' id 'org.jetbrains.kotlinx.kover' version '0.7.1'
id 'org.sonarqube' version '4.0.0.2929' id 'org.sonarqube' version '4.2.1.3168'
id 'pmd' id 'pmd'
} }
@ -59,11 +59,11 @@ dependencies {
// Google // Google
implementation 'com.google.code.gson:gson:2.10.1' implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.google.guava:guava:31.1-jre' implementation 'com.google.guava:guava:32.0.1-jre'
// Kotlin // Kotlin
implementation platform('org.jetbrains.kotlin:kotlin-bom') implementation platform('org.jetbrains.kotlin:kotlin-bom')
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8' implementation 'org.jetbrains.kotlin:kotlin-stdlib'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1' implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.1'
implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.5' implementation 'org.jetbrains.kotlinx:kotlinx-cli:0.3.5'

View file

@ -27,6 +27,7 @@
<ID>MagicNumber:Mastodon.kt$Mastodon.Companion$200</ID> <ID>MagicNumber:Mastodon.kt$Mastodon.Companion$200</ID>
<ID>MagicNumber:Mobibot.kt$Mobibot$8</ID> <ID>MagicNumber:Mobibot.kt$Mobibot$8</ID>
<ID>MagicNumber:Modules.kt$Modules$7</ID> <ID>MagicNumber:Modules.kt$Modules$7</ID>
<ID>MagicNumber:Seen.kt$Seen$8</ID>
<ID>MagicNumber:SocialManager.kt$SocialManager$1000L</ID> <ID>MagicNumber:SocialManager.kt$SocialManager$1000L</ID>
<ID>MagicNumber:SocialManager.kt$SocialManager$60L</ID> <ID>MagicNumber:SocialManager.kt$SocialManager$60L</ID>
<ID>MagicNumber:StockQuote.kt$StockQuote.Companion$10</ID> <ID>MagicNumber:StockQuote.kt$StockQuote.Companion$10</ID>
@ -69,6 +70,7 @@
<ID>ReturnCount:Addons.kt$Addons$fun exec(channel: String, cmd: String, args: String, event: GenericMessageEvent): Boolean</ID> <ID>ReturnCount:Addons.kt$Addons$fun exec(channel: String, cmd: String, args: String, event: GenericMessageEvent): Boolean</ID>
<ID>ReturnCount:Addons.kt$Addons$fun help(channel: String, topic: String, event: GenericMessageEvent): Boolean</ID> <ID>ReturnCount:Addons.kt$Addons$fun help(channel: String, topic: String, event: GenericMessageEvent): Boolean</ID>
<ID>ReturnCount:ExceptionSanitizer.kt$ExceptionSanitizer$fun ModuleException.sanitize(vararg sanitize: String): ModuleException</ID> <ID>ReturnCount:ExceptionSanitizer.kt$ExceptionSanitizer$fun ModuleException.sanitize(vararg sanitize: String): ModuleException</ID>
<ID>ReturnCount:Seen.kt$Seen$override fun commandResponse(channel: String, args: String, event: GenericMessageEvent)</ID>
<ID>SwallowedException:GoogleSearchTest.kt$GoogleSearchTest$e: ModuleException</ID> <ID>SwallowedException:GoogleSearchTest.kt$GoogleSearchTest$e: ModuleException</ID>
<ID>SwallowedException:StockQuoteTest.kt$StockQuoteTest$e: ModuleException</ID> <ID>SwallowedException:StockQuoteTest.kt$StockQuoteTest$e: ModuleException</ID>
<ID>SwallowedException:WolframAlphaTest.kt$WolframAlphaTest$e: ModuleException</ID> <ID>SwallowedException:WolframAlphaTest.kt$WolframAlphaTest$e: ModuleException</ID>

View file

@ -32,10 +32,14 @@
package net.thauvin.erik.mobibot.commands.seen package net.thauvin.erik.mobibot.commands.seen
import com.google.common.collect.ImmutableSortedSet import com.google.common.collect.ImmutableSortedSet
import net.thauvin.erik.mobibot.Utils
import net.thauvin.erik.mobibot.Utils.bold
import net.thauvin.erik.mobibot.Utils.bot import net.thauvin.erik.mobibot.Utils.bot
import net.thauvin.erik.mobibot.Utils.helpFormat import net.thauvin.erik.mobibot.Utils.helpFormat
import net.thauvin.erik.mobibot.Utils.isChannelOp
import net.thauvin.erik.mobibot.Utils.loadSerialData import net.thauvin.erik.mobibot.Utils.loadSerialData
import net.thauvin.erik.mobibot.Utils.saveSerialData import net.thauvin.erik.mobibot.Utils.saveSerialData
import net.thauvin.erik.mobibot.Utils.sendList
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.commands.Info.Companion.toUptime import net.thauvin.erik.mobibot.commands.Info.Companion.toUptime
@ -43,15 +47,19 @@ import org.pircbotx.User
import org.pircbotx.hooks.types.GenericMessageEvent import org.pircbotx.hooks.types.GenericMessageEvent
import org.slf4j.Logger import org.slf4j.Logger
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.util.TreeMap import java.util.*
class Seen(private val serialObject: String) : AbstractCommand() { class Seen(private val serialObject: String) : AbstractCommand() {
private val logger: Logger = LoggerFactory.getLogger(Seen::class.java) private val logger: Logger = LoggerFactory.getLogger(Seen::class.java)
private val allKeyword = "all"
val seenNicks = TreeMap<String, SeenNick>(NickComparator()) val seenNicks = TreeMap<String, SeenNick>(NickComparator())
override val name = "seen" override val name = "seen"
override val help = listOf("To view when a nickname was last seen:", helpFormat("%c $name <nick>")) override val help = listOf("To view when a nickname was last seen:", helpFormat("%c $name <nick>"))
private val helpOp = help.plus(
arrayOf("To view all ${"seen".bold()} nicks:", helpFormat("%c $name $allKeyword"))
)
override val isOpOnly = false override val isOpOnly = false
override val isPublic = true override val isPublic = true
override val isVisible = true override val isVisible = true
@ -61,6 +69,11 @@ class Seen(private val serialObject: String) : AbstractCommand() {
if (isEnabled()) { if (isEnabled()) {
if (args.isNotBlank() && !args.contains(' ')) { if (args.isNotBlank() && !args.contains(' ')) {
val ch = event.bot().userChannelDao.getChannel(channel) val ch = event.bot().userChannelDao.getChannel(channel)
if (args.equals(allKeyword) && ch.isOp(event.user) && seenNicks.isNotEmpty()) {
event.sendMessage("The ${"seen".bold()} nicks are:")
event.sendList(seenNicks.keys.toList(), 8, separator = ", ", isIndent = true)
return
}
ch.users.forEach { ch.users.forEach {
if (args.equals(it.nick, true)) { if (args.equals(it.nick, true)) {
event.sendMessage("${it.nick} is on ${channel}.") event.sendMessage("${it.nick} is on ${channel}.")
@ -102,6 +115,17 @@ class Seen(private val serialObject: String) : AbstractCommand() {
fun count(): Int = seenNicks.size fun count(): Int = seenNicks.size
override fun helpResponse(channel: String, topic: String, event: GenericMessageEvent): Boolean {
return if (event.isChannelOp(channel)) {
for (h in helpOp) {
event.sendMessage(Utils.helpCmdSyntax(h, event.bot().nick, true))
}
true
} else {
super.helpResponse(channel, topic, event)
}
}
fun load() { fun load() {
if (isEnabled()) { if (isEnabled()) {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")

View file

@ -46,6 +46,6 @@ data class EntryComment(var comment: String, var nick: String) : Serializable {
companion object { companion object {
// Serial version UID // Serial version UID
const val serialVersionUID = 1L private const val serialVersionUID: Long = 1L
} }
} }

View file

@ -208,6 +208,6 @@ class EntryLink(
companion object { companion object {
// Serial version UID // Serial version UID
const val serialVersionUID = 1L private const val serialVersionUID: Long = 1L
} }
} }

View file

@ -1,9 +1,9 @@
#Generated by the Semver Plugin for Gradle #Generated by the Semver Plugin for Gradle
#Tue May 23 08:26:47 PDT 2023 #Sat Jun 17 21:28:53 PDT 2023
version.buildmeta=1087 version.buildmeta=1098
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+1087 version.semver=0.8.0-rc+1098