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, "For more information on a specific command, type:", isPrivate)
|
||||||
send(
|
send(
|
||||||
sender,
|
sender,
|
||||||
helpIndent(helpFormat("""%c ${Constants.HELP_CMD} <command>""", nick, isPrivate)),
|
helpIndent(helpFormat("%c ${Constants.HELP_CMD} <command>", nick, isPrivate)),
|
||||||
isPrivate
|
isPrivate
|
||||||
)
|
)
|
||||||
send(sender, "The commands are:", 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")
|
logger.debug(">>> $sender: $message")
|
||||||
tell.send(sender, true)
|
tell.send(sender, true)
|
||||||
if (message.matches("(?i)${Pattern.quote(nick)}:.*".toRegex())) { // mobibot: <command>
|
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 cmd = cmds[0].toLowerCase()
|
||||||
val args = if (cmds.size > 1) {
|
val args = if (cmds.size > 1) {
|
||||||
cmds[1].trim()
|
cmds[1].trim()
|
||||||
|
@ -399,7 +399,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
||||||
if (logger.isDebugEnabled) {
|
if (logger.isDebugEnabled) {
|
||||||
logger.debug(">>> $sender : $message")
|
logger.debug(">>> $sender : $message")
|
||||||
}
|
}
|
||||||
val cmds = message.split(" ".toRegex(), 2).toTypedArray()
|
val cmds = message.split(" ".toRegex(), 2)
|
||||||
val cmd = cmds[0].toLowerCase()
|
val cmd = cmds[0].toLowerCase()
|
||||||
val args = if (cmds.size > 1) {
|
val args = if (cmds.size > 1) {
|
||||||
cmds[1].trim()
|
cmds[1].trim()
|
||||||
|
@ -503,7 +503,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
||||||
fun sendList(
|
fun sendList(
|
||||||
nick: String,
|
nick: String,
|
||||||
list: List<String>,
|
list: List<String>,
|
||||||
size: Int,
|
maxPerLine: Int,
|
||||||
isPrivate: Boolean,
|
isPrivate: Boolean,
|
||||||
isBold: Boolean
|
isBold: Boolean
|
||||||
) {
|
) {
|
||||||
|
@ -511,22 +511,16 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
||||||
while (i < list.size) {
|
while (i < list.size) {
|
||||||
send(
|
send(
|
||||||
nick,
|
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
|
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.
|
* Sets the pinboard authentication.
|
||||||
*/
|
*/
|
||||||
|
@ -690,7 +684,7 @@ class Mobibot(nickname: String, channel: String, logsDirPath: String, p: Propert
|
||||||
this.channel = channel
|
this.channel = channel
|
||||||
logsDir = logsDirPath
|
logsDir = logsDirPath
|
||||||
|
|
||||||
// Set the logger level
|
// Set the default logger level
|
||||||
loggerLevel = logger.level
|
loggerLevel = logger.level
|
||||||
|
|
||||||
// Load the current entries and backlogs, if any
|
// 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)
|
login = p.getProperty("login", name)
|
||||||
version = ReleaseInfo.PROJECT + ' ' + ReleaseInfo.VERSION
|
version = ReleaseInfo.PROJECT + ' ' + ReleaseInfo.VERSION
|
||||||
// setMessageDelay(1000);
|
// 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
|
// Set the URLs
|
||||||
weblogUrl = p.getProperty("weblog", "")
|
weblogUrl = p.getProperty("weblog", "")
|
||||||
|
|
|
@ -71,7 +71,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
|
|
||||||
// Delete message.
|
// Delete message.
|
||||||
private fun deleteMessage(sender: String, args: String, isOp: Boolean, isPrivate: Boolean) {
|
private fun deleteMessage(sender: String, args: String, isOp: Boolean, isPrivate: Boolean) {
|
||||||
val split = args.split(" ").toTypedArray()
|
val split = args.split(" ")
|
||||||
if (split.size == 2) {
|
if (split.size == 2) {
|
||||||
val id = split[1]
|
val id = split[1]
|
||||||
var deleted = false
|
var deleted = false
|
||||||
|
@ -176,7 +176,7 @@ class Tell(bot: Mobibot) : AbstractCommand(bot) {
|
||||||
|
|
||||||
// New message.
|
// New message.
|
||||||
private fun newMessage(sender: String, args: String, isOp: Boolean, isPrivate: Boolean) {
|
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 (split.size == 2 && split[1].isNotBlank() && split[1].contains(" ")) {
|
||||||
if (messages.size < maxSize) {
|
if (messages.size < maxSize) {
|
||||||
val message = TellMessage(sender, split[0], split[1].trim())
|
val message = TellMessage(sender, split[0], split[1].trim())
|
||||||
|
|
|
@ -172,7 +172,7 @@ class EntryLink : Serializable {
|
||||||
* Sets the tags.
|
* Sets the tags.
|
||||||
*/
|
*/
|
||||||
fun setTags(tags: String) {
|
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
|
@JvmStatic
|
||||||
fun convertCurrency(query: String): Message {
|
fun convertCurrency(query: String): Message {
|
||||||
val cmds = query.split(" ").toTypedArray()
|
val cmds = query.split(" ")
|
||||||
return if (cmds.size == 4) {
|
return if (cmds.size == 4) {
|
||||||
if (cmds[3] == cmds[1] || "0" == cmds[0]) {
|
if (cmds[3] == cmds[1] || "0" == cmds[0]) {
|
||||||
PublicMessage("You're kidding, right?")
|
PublicMessage("You're kidding, right?")
|
||||||
|
|
|
@ -126,13 +126,9 @@ class Lookup(bot: Mobibot) : AbstractModule(bot) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs a whois IP query.
|
* 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)
|
@Throws(IOException::class)
|
||||||
private fun whois(query: String): Array<String> {
|
private fun whois(query: String): List<String> {
|
||||||
return whois(query, WHOIS_HOST)
|
return whois(query, WHOIS_HOST)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -141,9 +137,9 @@ class Lookup(bot: Mobibot) : AbstractModule(bot) {
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
@Throws(IOException::class)
|
@Throws(IOException::class)
|
||||||
fun whois(query: String, host: String): Array<String> {
|
fun whois(query: String, host: String): List<String> {
|
||||||
val whoisClient = WhoisClient()
|
val whoisClient = WhoisClient()
|
||||||
val lines: Array<String>
|
val lines: List<String>
|
||||||
with(whoisClient) {
|
with(whoisClient) {
|
||||||
try {
|
try {
|
||||||
defaultTimeout = Constants.CONNECT_TIMEOUT
|
defaultTimeout = Constants.CONNECT_TIMEOUT
|
||||||
|
@ -151,9 +147,9 @@ class Lookup(bot: Mobibot) : AbstractModule(bot) {
|
||||||
soTimeout = Constants.CONNECT_TIMEOUT
|
soTimeout = Constants.CONNECT_TIMEOUT
|
||||||
setSoLinger(false, 0)
|
setSoLinger(false, 0)
|
||||||
lines = if (WHOIS_HOST == host) {
|
lines = if (WHOIS_HOST == host) {
|
||||||
query("n - $query").split("\n").toTypedArray()
|
query("n - $query").split("\n")
|
||||||
} else {
|
} else {
|
||||||
query(query).split("\n").toTypedArray()
|
query(query).split("\n")
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
disconnect()
|
disconnect()
|
||||||
|
|
|
@ -107,7 +107,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
val messages = ArrayList<Message>()
|
val messages = ArrayList<Message>()
|
||||||
owm.unit = OWM.Unit.IMPERIAL
|
owm.unit = OWM.Unit.IMPERIAL
|
||||||
if (query.isNotBlank()) {
|
if (query.isNotBlank()) {
|
||||||
val argv = query.split(",").toTypedArray()
|
val argv = query.split(",")
|
||||||
if (argv.size in 1..2) {
|
if (argv.size in 1..2) {
|
||||||
val city = argv[0].trim()
|
val city = argv[0].trim()
|
||||||
val country: String = if (argv.size > 1 && argv[1].isNotBlank()) {
|
val country: String = if (argv.size > 1 && argv[1].isNotBlank()) {
|
||||||
|
|
|
@ -52,7 +52,7 @@ class LookupTest {
|
||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
fun testWhois() {
|
fun testWhois() {
|
||||||
val result = whois("17.178.96.59", Lookup.WHOIS_HOST)
|
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
|
.`as`("whois(17.178.96.59/Apple Inc.").isTrue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue