Converted ArrayList to List (tokenizer, etc.) whenever possible.
This commit is contained in:
parent
5a669601da
commit
ece6ae98a0
7 changed files with 26 additions and 32 deletions
|
@ -255,7 +255,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
send(sender, "For more information on a specific command, type:", isPrivate)
|
||||
send(
|
||||
sender,
|
||||
helpIndent(helpFormat("""%c ${Constants.HELP_CMD} <command>""", nick, isPrivate)),
|
||||
helpIndent(helpFormat("%c ${Constants.HELP_CMD} <command>", nick, isPrivate)),
|
||||
isPrivate
|
||||
)
|
||||
send(sender, "The commands are:", isPrivate)
|
||||
|
@ -353,7 +353,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
logger.debug(">>> $sender: $message")
|
||||
tell.send(sender, true)
|
||||
if (message.matches("(?i)${Pattern.quote(nick)}:.*".toRegex())) { // mobibot: <command>
|
||||
val cmds = message.substring(message.indexOf(':') + 1).trim().split(" ".toRegex(), 2).toTypedArray()
|
||||
val cmds = message.substring(message.indexOf(':') + 1).trim().split(" ".toRegex(), 2)
|
||||
val cmd = cmds[0].toLowerCase()
|
||||
val args = if (cmds.size > 1) {
|
||||
cmds[1].trim()
|
||||
|
@ -399,7 +399,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
if (logger.isDebugEnabled) {
|
||||
logger.debug(">>> $sender : $message")
|
||||
}
|
||||
val cmds = message.split(" ".toRegex(), 2).toTypedArray()
|
||||
val cmds = message.split(" ".toRegex(), 2)
|
||||
val cmd = cmds[0].toLowerCase()
|
||||
val args = if (cmds.size > 1) {
|
||||
cmds[1].trim()
|
||||
|
@ -503,7 +503,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
fun sendList(
|
||||
nick: String,
|
||||
list: List<String>,
|
||||
size: Int,
|
||||
maxPerLine: Int,
|
||||
isPrivate: Boolean,
|
||||
isBold: Boolean
|
||||
) {
|
||||
|
@ -511,22 +511,16 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
while (i < list.size) {
|
||||
send(
|
||||
nick,
|
||||
helpIndent(list.subList(i, list.size.coerceAtMost(i + size)).joinToString(" ", truncated = ""), isBold),
|
||||
helpIndent(
|
||||
list.subList(i, list.size.coerceAtMost(i + maxPerLine)).joinToString(" ", truncated = ""),
|
||||
isBold
|
||||
),
|
||||
isPrivate
|
||||
)
|
||||
i += size
|
||||
i += maxPerLine
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the bot's identification.
|
||||
*/
|
||||
private fun setIdentity(pwd: String, nick: String, msg: String) {
|
||||
identPwd = pwd
|
||||
identNick = nick
|
||||
identMsg = msg
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the pinboard authentication.
|
||||
*/
|
||||
|
@ -690,7 +684,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
this.channel = channel
|
||||
logsDir = logsDirPath
|
||||
|
||||
// Set the logger level
|
||||
// Set the default logger level
|
||||
loggerLevel = logger.level
|
||||
|
||||
// Load the current entries and backlogs, if any
|
||||
|
@ -707,7 +701,11 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
|||
login = p.getProperty("login", name)
|
||||
version = ReleaseInfo.PROJECT + ' ' + ReleaseInfo.VERSION
|
||||
// setMessageDelay(1000);
|
||||
setIdentity(p.getProperty("ident", ""), p.getProperty("ident-nick", ""), p.getProperty("ident-msg", ""))
|
||||
|
||||
// Set NICKSERV identification
|
||||
identPwd = p.getProperty("ident", "")
|
||||
identNick = p.getProperty("ident-nick", "")
|
||||
identMsg = p.getProperty("ident-msg", "")
|
||||
|
||||
// Set the URLs
|
||||
weblogUrl = p.getProperty("weblog", "")
|
||||
|
|
|
@ -71,7 +71,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) {
|
|||
|
||||
// Delete message.
|
||||
private fun deleteMessage(sender: String, args: String, isOp: Boolean, isPrivate: Boolean) {
|
||||
val split = args.split(" ").toTypedArray()
|
||||
val split = args.split(" ")
|
||||
if (split.size == 2) {
|
||||
val id = split[1]
|
||||
var deleted = false
|
||||
|
@ -176,7 +176,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) {
|
|||
|
||||
// New message.
|
||||
private fun newMessage(sender: String, args: String, isOp: Boolean, isPrivate: Boolean) {
|
||||
val split = args.split(" ".toRegex(), 2).toTypedArray()
|
||||
val split = args.split(" ".toRegex(), 2)
|
||||
if (split.size == 2 && split[1].isNotBlank() && split[1].contains(" ")) {
|
||||
if (messages.size < maxSize) {
|
||||
val message = TellMessage(sender, split[0], split[1].trim())
|
||||
|
|
|
@ -172,7 +172,7 @@ class EntryLink : Serializable {
|
|||
* Sets the tags.
|
||||
*/
|
||||
fun setTags(tags: String) {
|
||||
setTags(tags.split(LinksMgr.TAG_MATCH).toTypedArray().toList())
|
||||
setTags(tags.split(LinksMgr.TAG_MATCH))
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -152,7 +152,7 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) {
|
|||
*/
|
||||
@JvmStatic
|
||||
fun convertCurrency(query: String): Message {
|
||||
val cmds = query.split(" ").toTypedArray()
|
||||
val cmds = query.split(" ")
|
||||
return if (cmds.size == 4) {
|
||||
if (cmds[3] == cmds[1] || "0" == cmds[0]) {
|
||||
PublicMessage("You're kidding, right?")
|
||||
|
|
|
@ -126,13 +126,9 @@ class Lookup(bot: Mobibot) : AbstractModule(bot) {
|
|||
|
||||
/**
|
||||
* Performs a whois IP query.
|
||||
*
|
||||
* @param query The IP address.
|
||||
* @return The IP whois data, if any.
|
||||
* @throws java.io.IOException If a connection error occurs.
|
||||
*/
|
||||
@Throws(IOException::class)
|
||||
private fun whois(query: String): Array<String> {
|
||||
private fun whois(query: String): List<String> {
|
||||
return whois(query, WHOIS_HOST)
|
||||
}
|
||||
|
||||
|
@ -141,9 +137,9 @@ class Lookup(bot: Mobibot) : AbstractModule(bot) {
|
|||
*/
|
||||
@JvmStatic
|
||||
@Throws(IOException::class)
|
||||
fun whois(query: String, host: String): Array<String> {
|
||||
fun whois(query: String, host: String): List<String> {
|
||||
val whoisClient = WhoisClient()
|
||||
val lines: Array<String>
|
||||
val lines: List<String>
|
||||
with(whoisClient) {
|
||||
try {
|
||||
defaultTimeout = Constants.CONNECT_TIMEOUT
|
||||
|
@ -151,9 +147,9 @@ class Lookup(bot: Mobibot) : AbstractModule(bot) {
|
|||
soTimeout = Constants.CONNECT_TIMEOUT
|
||||
setSoLinger(false, 0)
|
||||
lines = if (WHOIS_HOST == host) {
|
||||
query("n - $query").split("\n").toTypedArray()
|
||||
query("n - $query").split("\n")
|
||||
} else {
|
||||
query(query).split("\n").toTypedArray()
|
||||
query(query).split("\n")
|
||||
}
|
||||
} finally {
|
||||
disconnect()
|
||||
|
|
|
@ -107,7 +107,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
|
|||
val messages = ArrayList<Message>()
|
||||
owm.unit = OWM.Unit.IMPERIAL
|
||||
if (query.isNotBlank()) {
|
||||
val argv = query.split(",").toTypedArray()
|
||||
val argv = query.split(",")
|
||||
if (argv.size in 1..2) {
|
||||
val city = argv[0].trim()
|
||||
val country: String = if (argv.size > 1 && argv[1].isNotBlank()) {
|
||||
|
|
|
@ -52,7 +52,7 @@ class LookupTest {
|
|||
@Throws(Exception::class)
|
||||
fun testWhois() {
|
||||
val result = whois("17.178.96.59", Lookup.WHOIS_HOST)
|
||||
Assertions.assertThat(Arrays.stream(result).anyMatch { m: String -> m.contains("Apple Inc.") })
|
||||
Assertions.assertThat(result.stream().anyMatch { m: String -> m.contains("Apple Inc.") })
|
||||
.`as`("whois(17.178.96.59/Apple Inc.").isTrue
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue