diff --git a/config/detekt/baseline.xml b/config/detekt/baseline.xml
index 07ee2ba..0b6f182 100644
--- a/config/detekt/baseline.xml
+++ b/config/detekt/baseline.xml
@@ -24,7 +24,6 @@
NestedBlockDepth:EntriesMgr.kt$EntriesMgr$ fun saveEntries( bot: Mobibot, entries: List<EntryLink>, history: MutableList<String>, isDayBackup: Boolean )
NestedBlockDepth:EntriesMgr.kt$EntriesMgr$// Daily backup private fun dailyBackup( bot: Mobibot, history: MutableList<String> )
NestedBlockDepth:EntryLink.kt$EntryLink$ private fun setTags(tags: List<String?>)
- NestedBlockDepth:FeedReader.kt$FeedReader$ override fun run()
NestedBlockDepth:GoogleSearch.kt$GoogleSearch$ override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean)
NestedBlockDepth:LinksMgr.kt$LinksMgr$override fun commandResponse( sender: String, login: String, args: String, isOp: Boolean, isPrivate: Boolean )
NestedBlockDepth:Lookup.kt$Lookup$override fun commandResponse( sender: String, cmd: String, args: String, isPrivate: Boolean )
@@ -45,7 +44,6 @@
ThrowsCount:StockQuote.kt$StockQuote.Companion$@Throws(ModuleException::class) private fun getJsonResponse(response: String, debugMessage: String): JSONObject
ThrowsCount:Weather2.kt$Weather2.Companion$ @JvmStatic @Throws(ModuleException::class) fun getWeather(query: String, apiKey: String?): List<Message>
TooGenericExceptionCaught:CryptoPrices.kt$CryptoPrices$e: Exception
- TooGenericExceptionCaught:FeedReader.kt$FeedReader$e: Exception
TooGenericExceptionCaught:Mobibot.kt$Mobibot$e: Exception
TooGenericExceptionCaught:Mobibot.kt$Mobibot$ex: Exception
TooGenericExceptionCaught:StockQuote.kt$StockQuote.Companion$e: NullPointerException
diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/Mobibot.kt b/src/main/kotlin/net/thauvin/erik/mobibot/Mobibot.kt
index c6390f0..0cb7100 100644
--- a/src/main/kotlin/net/thauvin/erik/mobibot/Mobibot.kt
+++ b/src/main/kotlin/net/thauvin/erik/mobibot/Mobibot.kt
@@ -45,8 +45,10 @@ import net.thauvin.erik.mobibot.commands.AddLog
import net.thauvin.erik.mobibot.commands.ChannelFeed
import net.thauvin.erik.mobibot.commands.Cycle
import net.thauvin.erik.mobibot.commands.Debug
+import net.thauvin.erik.mobibot.commands.Die
import net.thauvin.erik.mobibot.commands.Ignore
import net.thauvin.erik.mobibot.commands.Info
+import net.thauvin.erik.mobibot.commands.Kill
import net.thauvin.erik.mobibot.commands.Me
import net.thauvin.erik.mobibot.commands.Modules
import net.thauvin.erik.mobibot.commands.Msg
@@ -260,7 +262,6 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
}
}
-
/**
* Responds with the default, commands or modules help.
*/
@@ -468,6 +469,24 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
}
}
+ /**
+ * Shutdown the bot.
+ */
+ fun shutdown(sender: String, now: Boolean = false) {
+ if (now) { // kill
+ twitter.notification("$name killed by $sender on $channel")
+ sendRawLine("QUIT :Poof!")
+ } else {
+ timer.cancel()
+ twitter.shutdown()
+ twitter.notification("$name stopped by $sender on $channel")
+ @Suppress("MagicNumber")
+ sleep(3)
+ quitServer("The Bot Is Out There!")
+ }
+ exitProcess(0)
+ }
+
/**
* Sleeps for the specified number of seconds.
*/
@@ -654,9 +673,11 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
addons.add(AddLog(this), p)
addons.add(ChannelFeed(this, channelName), p)
addons.add(Cycle(this), p)
+ addons.add(Die(this), p)
addons.add(Debug(this), p)
addons.add(Ignore(this), p)
addons.add(Info(this), p)
+ addons.add(Kill(this), p)
addons.add(Me(this), p)
addons.add(Modules(this), p)
addons.add(Msg(this), p)
diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/commands/Die.kt b/src/main/kotlin/net/thauvin/erik/mobibot/commands/Die.kt
new file mode 100644
index 0000000..eba2dcc
--- /dev/null
+++ b/src/main/kotlin/net/thauvin/erik/mobibot/commands/Die.kt
@@ -0,0 +1,57 @@
+/*
+ * Die.kt
+ *
+ * Copyright (c) 2004-2021, Erik C. Thauvin (erik@thauvin.net)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of this project nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package net.thauvin.erik.mobibot.commands
+
+import net.thauvin.erik.mobibot.Mobibot
+import net.thauvin.erik.mobibot.Utils.helpFormat
+
+class Die(bot: Mobibot) : AbstractCommand(bot) {
+ override val name = "die"
+ override val help = emptyList()
+ override val isOp = true
+ override val isPublic = false
+ override val isVisible = false
+
+ override fun commandResponse(
+ sender: String,
+ login: String,
+ args: String,
+ isOp: Boolean,
+ isPrivate: Boolean
+ ) {
+ if (isOp) {
+ bot.send("$sender has just signed my death sentence.")
+ bot.shutdown(sender)
+ }
+ }
+}
diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/commands/Kill.kt b/src/main/kotlin/net/thauvin/erik/mobibot/commands/Kill.kt
new file mode 100644
index 0000000..6055798
--- /dev/null
+++ b/src/main/kotlin/net/thauvin/erik/mobibot/commands/Kill.kt
@@ -0,0 +1,56 @@
+/*
+ * Kill.kt
+ *
+ * Copyright (c) 2004-2021, Erik C. Thauvin (erik@thauvin.net)
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * Neither the name of this project nor the names of its contributors may be
+ * used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package net.thauvin.erik.mobibot.commands
+
+import net.thauvin.erik.mobibot.Mobibot
+import net.thauvin.erik.mobibot.Utils.helpFormat
+
+class Kill(bot: Mobibot) : AbstractCommand(bot) {
+ override val name = "kill"
+ override val help = emptyList()
+ override val isOp = true
+ override val isPublic = false
+ override val isVisible = false
+
+ override fun commandResponse(
+ sender: String,
+ login: String,
+ args: String,
+ isOp: Boolean,
+ isPrivate: Boolean
+ ) {
+ if (isOp) {
+ bot.shutdown(sender, true)
+ }
+ }
+}