Added Debug command.
Converted Utils classes to objects.
This commit is contained in:
parent
f6656f1166
commit
1c2234a9a2
19 changed files with 605 additions and 566 deletions
|
@ -34,7 +34,7 @@ package net.thauvin.erik.mobibot
|
|||
import java.util.*
|
||||
|
||||
/**
|
||||
* The `Constants` class.
|
||||
* The `Constants`.
|
||||
*/
|
||||
object Constants {
|
||||
/**
|
||||
|
@ -77,6 +77,11 @@ object Constants {
|
|||
*/
|
||||
const val HELP_CMD = "help"
|
||||
|
||||
/**
|
||||
* The kill command.
|
||||
*/
|
||||
const val KILL_CMD = "kill"
|
||||
|
||||
/**
|
||||
* The link command.
|
||||
*/
|
||||
|
|
|
@ -34,16 +34,17 @@ package net.thauvin.erik.mobibot
|
|||
import net.thauvin.erik.mobibot.PinboardUtils.addPin
|
||||
import net.thauvin.erik.mobibot.PinboardUtils.deletePin
|
||||
import net.thauvin.erik.mobibot.PinboardUtils.updatePin
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.colorize
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.ensureDir
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.getIntProperty
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.helpFormat
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.helpIndent
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.isoLocalDate
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.today
|
||||
import net.thauvin.erik.mobibot.Utils.colorize
|
||||
import net.thauvin.erik.mobibot.Utils.ensureDir
|
||||
import net.thauvin.erik.mobibot.Utils.getIntProperty
|
||||
import net.thauvin.erik.mobibot.Utils.helpFormat
|
||||
import net.thauvin.erik.mobibot.Utils.helpIndent
|
||||
import net.thauvin.erik.mobibot.Utils.isoLocalDate
|
||||
import net.thauvin.erik.mobibot.Utils.today
|
||||
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.Ignore
|
||||
import net.thauvin.erik.mobibot.commands.Info
|
||||
import net.thauvin.erik.mobibot.commands.Me
|
||||
|
@ -92,7 +93,6 @@ import org.apache.commons.cli.ParseException
|
|||
import org.apache.logging.log4j.Level
|
||||
import org.apache.logging.log4j.LogManager
|
||||
import org.apache.logging.log4j.Logger
|
||||
import org.apache.logging.log4j.core.config.Configurator
|
||||
import org.jibble.pircbot.PircBot
|
||||
import java.io.BufferedOutputStream
|
||||
import java.io.FileNotFoundException
|
||||
|
@ -126,8 +126,8 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
/** Logger. */
|
||||
val logger: Logger = LogManager.getLogger(Mobibot::class.java)
|
||||
|
||||
// Logger default level
|
||||
private val loggerLevel: Level
|
||||
/** Logger default level. */
|
||||
val loggerLevel: Level
|
||||
|
||||
/** Log directory. */
|
||||
val logsDir: String
|
||||
|
@ -407,17 +407,10 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
val isOp = isOp(sender)
|
||||
if (cmd.startsWith(Constants.HELP_CMD)) { // help
|
||||
helpResponse(sender, args, true)
|
||||
} else if (isOp && "kill" == cmd) { // kill
|
||||
} else if (isOp && Constants.KILL_CMD == cmd) { // kill
|
||||
twitter.notification("$name killed by $sender on $channel")
|
||||
sendRawLine("QUIT : Poof!")
|
||||
exitProcess(0)
|
||||
} else if (isOp && Constants.DEBUG_CMD == cmd) { // debug
|
||||
if (logger.isDebugEnabled) {
|
||||
Configurator.setLevel(logger.name, loggerLevel)
|
||||
} else {
|
||||
Configurator.setLevel(logger.name, Level.DEBUG)
|
||||
}
|
||||
send(sender, "Debug logging is " + if (logger.isDebugEnabled) "enabled." else "disabled.", true)
|
||||
} else if (isOp && Constants.DIE_CMD == cmd) { // die
|
||||
send("$sender has just signed my death sentence.")
|
||||
timer.cancel()
|
||||
|
@ -718,6 +711,7 @@ 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(Debug(this), p)
|
||||
addons.add(Ignore(this), p)
|
||||
addons.add(Info(this), p)
|
||||
addons.add(Me(this), p)
|
||||
|
|
|
@ -43,7 +43,7 @@ import java.time.format.DateTimeFormatter
|
|||
import java.util.*
|
||||
|
||||
/**
|
||||
* The class to handle posts to pinboard.in.
|
||||
* Handles posts to pinboard.in.
|
||||
*/
|
||||
object PinboardUtils {
|
||||
/**
|
||||
|
|
|
@ -49,261 +49,240 @@ import java.util.concurrent.TimeUnit
|
|||
import java.util.stream.Collectors
|
||||
|
||||
/**
|
||||
* Miscellaneous utilities class.
|
||||
* Miscellaneous utilities.
|
||||
*/
|
||||
class Utils private constructor() {
|
||||
companion object {
|
||||
private val searchFlags = arrayOf("%c", "%n")
|
||||
object Utils {
|
||||
private val searchFlags = arrayOf("%c", "%n")
|
||||
|
||||
/**
|
||||
* Makes the given int bold.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun bold(i: Int): String {
|
||||
return bold(i.toString())
|
||||
/**
|
||||
* Makes the given int bold.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun bold(i: Int): String = bold(i.toString())
|
||||
|
||||
/**
|
||||
* Makes the given string bold.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun bold(s: String?): String = colorize(s, Colors.BOLD)
|
||||
|
||||
/**
|
||||
* Colorize a string.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun colorize(s: String?, color: String): String {
|
||||
return if (s.isNullOrBlank()) {
|
||||
Colors.NORMAL
|
||||
} else if (Colors.BOLD == color || Colors.REVERSE == color) {
|
||||
color + s + color
|
||||
} else {
|
||||
color + s + Colors.NORMAL
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the given string bold.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun bold(s: String?): String {
|
||||
return colorize(s, Colors.BOLD)
|
||||
}
|
||||
/**
|
||||
* Makes the given string cyan.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun cyan(s: String?): String = colorize(s, Colors.CYAN)
|
||||
|
||||
/**
|
||||
* Colorize a string.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun colorize(s: String?, color: String): String {
|
||||
if (s.isNullOrBlank()) {
|
||||
return Colors.NORMAL
|
||||
} else if (Colors.BOLD == color || Colors.REVERSE == color) {
|
||||
return color + s + color
|
||||
}
|
||||
return color + s + Colors.NORMAL
|
||||
}
|
||||
/**
|
||||
* URL encodes the given string.
|
||||
*/
|
||||
fun encodeUrl(s: String): String = URLEncoder.encode(s, StandardCharsets.UTF_8)
|
||||
|
||||
/**
|
||||
* Makes the given string cyan.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun cyan(s: String?): String {
|
||||
return colorize(s, Colors.CYAN)
|
||||
}
|
||||
|
||||
/**
|
||||
* URL encodes the given string.
|
||||
*/
|
||||
fun encodeUrl(s: String): String {
|
||||
return URLEncoder.encode(s, StandardCharsets.UTF_8)
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the given location (File/URL) has a trailing slash (`/`) to indicate a directory.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun ensureDir(location: String, isUrl: Boolean): String {
|
||||
return if (location.isNotEmpty()) {
|
||||
if (isUrl) {
|
||||
if (location[location.length - 1] == '/') {
|
||||
location
|
||||
} else {
|
||||
"$location/"
|
||||
}
|
||||
/**
|
||||
* Ensures that the given location (File/URL) has a trailing slash (`/`) to indicate a directory.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun ensureDir(location: String, isUrl: Boolean): String {
|
||||
return if (location.isNotEmpty()) {
|
||||
if (isUrl) {
|
||||
if (location[location.length - 1] == '/') {
|
||||
location
|
||||
} else {
|
||||
if (location[location.length - 1] == File.separatorChar) {
|
||||
location
|
||||
} else {
|
||||
location + File.separatorChar
|
||||
}
|
||||
"$location/"
|
||||
}
|
||||
} else {
|
||||
location
|
||||
if (location[location.length - 1] == File.separatorChar) {
|
||||
location
|
||||
} else {
|
||||
location + File.separatorChar
|
||||
}
|
||||
}
|
||||
} else {
|
||||
location
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a property as an int.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getIntProperty(property: String?, def: Int): Int {
|
||||
return if (property == null) {
|
||||
/**
|
||||
* Returns a property as an int.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun getIntProperty(property: String?, def: Int): Int {
|
||||
return if (property == null) {
|
||||
def
|
||||
} else {
|
||||
try {
|
||||
property.toInt()
|
||||
} catch (ignore: NumberFormatException) {
|
||||
def
|
||||
} else {
|
||||
try {
|
||||
property.toInt()
|
||||
} catch (ignore: NumberFormatException) {
|
||||
def
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the given string green.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun green(s: String?): String {
|
||||
return colorize(s, Colors.DARK_GREEN)
|
||||
}
|
||||
|
||||
/**
|
||||
* Formats a help command by replacing `%c` with the bot's pub/priv command, and `%n` with the bot's
|
||||
* nick.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun helpFormat(text: String, botNick: String, isPrivate: Boolean): String {
|
||||
val replace = arrayOf(if (isPrivate) "/msg $botNick" else "$botNick:", botNick)
|
||||
return StringUtils.replaceEach(text, searchFlags, replace)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns indented help string.
|
||||
*/
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun helpIndent(help: String, isBold: Boolean = true): String {
|
||||
return " " + if (isBold) bold(help) else help
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified date as an ISO local date string.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun isoLocalDate(date: Date): String {
|
||||
return isoLocalDate(LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified date as an ISO local date string.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun isoLocalDate(date: LocalDateTime): String {
|
||||
return date.format(DateTimeFormatter.ISO_LOCAL_DATE)
|
||||
}
|
||||
|
||||
/**
|
||||
* Obfuscates the given string.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun obfuscate(s: String): String {
|
||||
return if (s.isNotBlank()) {
|
||||
StringUtils.repeat('x', s.length)
|
||||
} else s
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plural form of a word, if count > 1.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun plural(count: Long, word: String, plural: String): String {
|
||||
return if (count > 1) {
|
||||
plural
|
||||
} else {
|
||||
word
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the given string red.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun red(s: String?): String {
|
||||
return colorize(s, Colors.RED)
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the given string reverse color.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun reverseColor(s: String?): String {
|
||||
return colorize(s, Colors.REVERSE)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns today's date.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun today(): String {
|
||||
return isoLocalDate(LocalDateTime.now())
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts XML/XHTML entities to plain text.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun unescapeXml(str: String): String {
|
||||
return Jsoup.parse(str).text()
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts milliseconds to year month week day hour and minutes.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun uptime(uptime: Long): String {
|
||||
val info = StringBuilder()
|
||||
var days = TimeUnit.MILLISECONDS.toDays(uptime)
|
||||
val years = days / 365
|
||||
days %= 365
|
||||
val months = days / 30
|
||||
days %= 30
|
||||
val weeks = days / 7
|
||||
days %= 7
|
||||
val hours = TimeUnit.MILLISECONDS.toHours(uptime) - TimeUnit.DAYS.toHours(
|
||||
TimeUnit.MILLISECONDS.toDays(uptime)
|
||||
)
|
||||
val minutes = TimeUnit.MILLISECONDS.toMinutes(uptime) - TimeUnit.HOURS.toMinutes(
|
||||
TimeUnit.MILLISECONDS.toHours(uptime)
|
||||
)
|
||||
with(info) {
|
||||
if (years > 0) {
|
||||
append(years).append(plural(years, " year ", " years "))
|
||||
}
|
||||
if (months > 0) {
|
||||
append(weeks).append(plural(months, " month ", " months "))
|
||||
}
|
||||
if (weeks > 0) {
|
||||
append(weeks).append(plural(weeks, " week ", " weeks "))
|
||||
}
|
||||
if (days > 0) {
|
||||
append(days).append(plural(days, " day ", " days "))
|
||||
}
|
||||
if (hours > 0) {
|
||||
append(hours).append(plural(hours, " hour ", " hours "))
|
||||
}
|
||||
append(minutes).append(plural(minutes, " minute", " minutes"))
|
||||
return toString()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads contents of a URL.
|
||||
*/
|
||||
@JvmStatic
|
||||
@Throws(IOException::class)
|
||||
fun urlReader(url: URL): String {
|
||||
BufferedReader(InputStreamReader(url.openStream(), StandardCharsets.UTF_8))
|
||||
.use { reader -> return reader.lines().collect(Collectors.joining(System.lineSeparator())) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified date formatted as `yyyy-MM-dd HH:mm`.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun utcDateTime(date: Date): String {
|
||||
return utcDateTime(LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified date formatted as `yyyy-MM-dd HH:mm`.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun utcDateTime(date: LocalDateTime?): String {
|
||||
return if (date != null) {
|
||||
date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the given string green.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun green(s: String?): String = colorize(s, Colors.DARK_GREEN)
|
||||
|
||||
/**
|
||||
* Formats a help command by replacing `%c` with the bot's pub/priv command, and `%n` with the bot's
|
||||
* nick.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun helpFormat(text: String, botNick: String, isPrivate: Boolean): String {
|
||||
val replace = arrayOf(if (isPrivate) "/msg $botNick" else "$botNick:", botNick)
|
||||
return StringUtils.replaceEach(text, searchFlags, replace)
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns indented help string.
|
||||
*/
|
||||
@JvmStatic
|
||||
@JvmOverloads
|
||||
fun helpIndent(help: String, isBold: Boolean = true): String {
|
||||
return " " + if (isBold) bold(help) else help
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified date as an ISO local date string.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun isoLocalDate(date: Date): String {
|
||||
return isoLocalDate(LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified date as an ISO local date string.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun isoLocalDate(date: LocalDateTime): String = date.format(DateTimeFormatter.ISO_LOCAL_DATE)
|
||||
|
||||
/**
|
||||
* Obfuscates the given string.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun obfuscate(s: String): String {
|
||||
return if (s.isNotBlank()) {
|
||||
StringUtils.repeat('x', s.length)
|
||||
} else s
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plural form of a word, if count > 1.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun plural(count: Long, word: String, plural: String): String {
|
||||
return if (count > 1) {
|
||||
plural
|
||||
} else {
|
||||
word
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Makes the given string red.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun red(s: String?): String = colorize(s, Colors.RED)
|
||||
|
||||
/**
|
||||
* Makes the given string reverse color.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun reverseColor(s: String?): String = colorize(s, Colors.REVERSE)
|
||||
|
||||
/**
|
||||
* Returns today's date.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun today(): String = isoLocalDate(LocalDateTime.now())
|
||||
|
||||
/**
|
||||
* Converts XML/XHTML entities to plain text.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun unescapeXml(str: String): String = Jsoup.parse(str).text()
|
||||
|
||||
/**
|
||||
* Converts milliseconds to year month week day hour and minutes.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun uptime(uptime: Long): String {
|
||||
val info = StringBuilder()
|
||||
var days = TimeUnit.MILLISECONDS.toDays(uptime)
|
||||
val years = days / 365
|
||||
days %= 365
|
||||
val months = days / 30
|
||||
days %= 30
|
||||
val weeks = days / 7
|
||||
days %= 7
|
||||
val hours = TimeUnit.MILLISECONDS.toHours(uptime) - TimeUnit.DAYS.toHours(
|
||||
TimeUnit.MILLISECONDS.toDays(uptime)
|
||||
)
|
||||
val minutes = TimeUnit.MILLISECONDS.toMinutes(uptime) - TimeUnit.HOURS.toMinutes(
|
||||
TimeUnit.MILLISECONDS.toHours(uptime)
|
||||
)
|
||||
with(info) {
|
||||
if (years > 0) {
|
||||
append(years).append(plural(years, " year ", " years "))
|
||||
}
|
||||
if (months > 0) {
|
||||
append(weeks).append(plural(months, " month ", " months "))
|
||||
}
|
||||
if (weeks > 0) {
|
||||
append(weeks).append(plural(weeks, " week ", " weeks "))
|
||||
}
|
||||
if (days > 0) {
|
||||
append(days).append(plural(days, " day ", " days "))
|
||||
}
|
||||
if (hours > 0) {
|
||||
append(hours).append(plural(hours, " hour ", " hours "))
|
||||
}
|
||||
append(minutes).append(plural(minutes, " minute", " minutes"))
|
||||
return toString()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads contents of a URL.
|
||||
*/
|
||||
@JvmStatic
|
||||
@Throws(IOException::class)
|
||||
fun urlReader(url: URL): String {
|
||||
BufferedReader(InputStreamReader(url.openStream(), StandardCharsets.UTF_8))
|
||||
.use { reader -> return reader.lines().collect(Collectors.joining(System.lineSeparator())) }
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified date formatted as `yyyy-MM-dd HH:mm`.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun utcDateTime(date: Date): String {
|
||||
return utcDateTime(LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()))
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified date formatted as `yyyy-MM-dd HH:mm`.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun utcDateTime(date: LocalDateTime?): String {
|
||||
return if (date != null) {
|
||||
date.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))
|
||||
} else {
|
||||
""
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
58
src/main/java/net/thauvin/erik/mobibot/commands/Debug.kt
Normal file
58
src/main/java/net/thauvin/erik/mobibot/commands/Debug.kt
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* Debug.kt
|
||||
*
|
||||
* Copyright (c) 2004-2020, 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 org.apache.logging.log4j.Level
|
||||
import org.apache.logging.log4j.core.config.Configurator
|
||||
|
||||
class Debug(bot: Mobibot) : AbstractCommand(bot) {
|
||||
override val name = "debug"
|
||||
override val help = emptyList<String>()
|
||||
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) {
|
||||
with(bot) {
|
||||
if (logger.isDebugEnabled) {
|
||||
Configurator.setLevel(logger.name, loggerLevel)
|
||||
} else {
|
||||
Configurator.setLevel(logger.name, Level.DEBUG)
|
||||
}
|
||||
send(sender, "Debug logging is " + if (logger.isDebugEnabled) "enabled." else "disabled.", true)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -32,13 +32,13 @@
|
|||
package net.thauvin.erik.mobibot.commands.tell
|
||||
|
||||
import net.thauvin.erik.mobibot.Mobibot
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.bold
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.getIntProperty
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.helpFormat
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.helpIndent
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.plural
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.reverseColor
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.utcDateTime
|
||||
import net.thauvin.erik.mobibot.Utils.bold
|
||||
import net.thauvin.erik.mobibot.Utils.getIntProperty
|
||||
import net.thauvin.erik.mobibot.Utils.helpFormat
|
||||
import net.thauvin.erik.mobibot.Utils.helpIndent
|
||||
import net.thauvin.erik.mobibot.Utils.plural
|
||||
import net.thauvin.erik.mobibot.Utils.reverseColor
|
||||
import net.thauvin.erik.mobibot.Utils.utcDateTime
|
||||
import net.thauvin.erik.mobibot.commands.AbstractCommand
|
||||
import net.thauvin.erik.mobibot.commands.links.View
|
||||
|
||||
|
|
|
@ -42,7 +42,6 @@ import java.nio.file.Files
|
|||
import java.nio.file.Paths
|
||||
import java.time.Clock
|
||||
import java.time.LocalDateTime
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* The Tell Messages Manager.
|
||||
|
|
|
@ -40,7 +40,7 @@ import com.rometools.rome.io.FeedException
|
|||
import com.rometools.rome.io.SyndFeedInput
|
||||
import com.rometools.rome.io.SyndFeedOutput
|
||||
import net.thauvin.erik.mobibot.Mobibot
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.isoLocalDate
|
||||
import net.thauvin.erik.mobibot.Utils.isoLocalDate
|
||||
import java.io.IOException
|
||||
import java.io.InputStreamReader
|
||||
import java.io.OutputStreamWriter
|
||||
|
|
|
@ -32,52 +32,49 @@
|
|||
package net.thauvin.erik.mobibot.entries
|
||||
|
||||
import net.thauvin.erik.mobibot.Constants
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.bold
|
||||
import net.thauvin.erik.mobibot.Utils.Companion.green
|
||||
import net.thauvin.erik.mobibot.Utils.bold
|
||||
import net.thauvin.erik.mobibot.Utils.green
|
||||
|
||||
/**
|
||||
* The `Utils` class.
|
||||
* Entries utilities.
|
||||
*/
|
||||
class EntriesUtils private constructor() {
|
||||
companion object {
|
||||
/**
|
||||
* Build link cmd based on its index. e.g: L1
|
||||
*/
|
||||
fun buildLinkCmd(index: Int): String = Constants.LINK_CMD + (index + 1)
|
||||
object EntriesUtils {
|
||||
/**
|
||||
* Build link cmd based on its index. e.g: L1
|
||||
*/
|
||||
fun buildLinkCmd(index: Int): String = Constants.LINK_CMD + (index + 1)
|
||||
|
||||
/**
|
||||
* Builds an entry's comment for display on the channel.
|
||||
*/
|
||||
fun buildComment(entryIndex: Int, commentIndex: Int, comment: EntryComment): String =
|
||||
(buildLinkCmd(entryIndex) + '.' + (commentIndex + 1) + ": [" + comment.nick + "] "
|
||||
+ comment.comment)
|
||||
/**
|
||||
* Builds an entry's comment for display on the channel.
|
||||
*/
|
||||
fun buildComment(entryIndex: Int, commentIndex: Int, comment: EntryComment): String =
|
||||
("${buildLinkCmd(entryIndex)}.${commentIndex + 1}: [${comment.nick}] ${comment.comment}")
|
||||
|
||||
/**
|
||||
* Builds an entry's link for display on the channel.
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun buildLink(entryIndex: Int, entry: EntryLink, isView: Boolean = false): String {
|
||||
val buff = StringBuilder().append(buildLinkCmd(entryIndex)).append(": ")
|
||||
.append('[').append(entry.nick).append(']')
|
||||
if (isView && entry.hasComments()) {
|
||||
buff.append("[+").append(entry.comments.size).append(']')
|
||||
}
|
||||
buff.append(' ')
|
||||
with(entry) {
|
||||
if (Constants.NO_TITLE == title) {
|
||||
buff.append(title)
|
||||
} else {
|
||||
buff.append(bold(title))
|
||||
}
|
||||
buff.append(" ( ").append(green(link)).append(" )")
|
||||
}
|
||||
return buff.toString()
|
||||
/**
|
||||
* Builds an entry's link for display on the channel.
|
||||
*/
|
||||
@JvmOverloads
|
||||
fun buildLink(entryIndex: Int, entry: EntryLink, isView: Boolean = false): String {
|
||||
val buff = StringBuilder().append(buildLinkCmd(entryIndex)).append(": ")
|
||||
.append('[').append(entry.nick).append(']')
|
||||
if (isView && entry.hasComments()) {
|
||||
buff.append("[+").append(entry.comments.size).append(']')
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an entry's tags/categories for display on the channel.
|
||||
*/
|
||||
fun buildTags(entryIndex: Int, entry: EntryLink): String =
|
||||
buildLinkCmd(entryIndex) + "T: " + entry.pinboardTags.replace(",", ", ")
|
||||
buff.append(' ')
|
||||
with(entry) {
|
||||
if (Constants.NO_TITLE == title) {
|
||||
buff.append(title)
|
||||
} else {
|
||||
buff.append(bold(title))
|
||||
}
|
||||
buff.append(" ( ").append(green(link)).append(" )")
|
||||
}
|
||||
return buff.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
* Build an entry's tags/categories for display on the channel.
|
||||
*/
|
||||
fun buildTags(entryIndex: Int, entry: EntryLink): String =
|
||||
buildLinkCmd(entryIndex) + "T: " + entry.pinboardTags.replace(",", ", ")
|
||||
}
|
||||
|
|
|
@ -72,7 +72,7 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
|
|||
try {
|
||||
loadRates()
|
||||
} catch (e: ModuleException) {
|
||||
if (bot.logger.isWarnEnabled)logger.warn(e.debugMessage, e)
|
||||
if (bot.logger.isWarnEnabled) logger.warn(e.debugMessage, e)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Message.java
|
||||
* Message.kt
|
||||
*
|
||||
* Copyright (c) 2004-2020, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
|
@ -41,19 +41,19 @@ open class Message {
|
|||
var DEFAULT_COLOR = Colors.NORMAL
|
||||
}
|
||||
|
||||
/** Color */
|
||||
/** Message color. */
|
||||
var color = DEFAULT_COLOR
|
||||
|
||||
/** Error */
|
||||
/** Error flag. */
|
||||
var isError = false
|
||||
|
||||
/** Notice */
|
||||
/** Notice flag. */
|
||||
var isNotice = false
|
||||
|
||||
/** Private */
|
||||
/** Private flag. */
|
||||
var isPrivate = false
|
||||
|
||||
/** Message text*/
|
||||
/** Message text. */
|
||||
var msg = ""
|
||||
|
||||
/** Creates a new message. */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue