diff --git a/src/main/java/net/thauvin/erik/mobibot/Addons.kt b/src/main/java/net/thauvin/erik/mobibot/Addons.kt index a9b91b0..147aea0 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Addons.kt +++ b/src/main/java/net/thauvin/erik/mobibot/Addons.kt @@ -49,7 +49,7 @@ class Addons { * Add a module with properties. */ fun add(module: AbstractModule, props: Properties) { - module.apply { + with(module) { if (hasProperties()) { propertyKeys.forEach { setProperty(it, props.getProperty(it, "")) @@ -68,7 +68,7 @@ class Addons { * Add a command with properties. */ fun add(command: AbstractCommand, props: Properties) { - command.apply { + with(command) { if (properties.isNotEmpty()) { properties.keys.forEach { setProperty(it, props.getProperty(it, "")) diff --git a/src/main/java/net/thauvin/erik/mobibot/FeedReader.kt b/src/main/java/net/thauvin/erik/mobibot/FeedReader.kt index 0d437ef..23b124a 100644 --- a/src/main/java/net/thauvin/erik/mobibot/FeedReader.kt +++ b/src/main/java/net/thauvin/erik/mobibot/FeedReader.kt @@ -54,7 +54,7 @@ class FeedReader( * Fetches the Feed's items. */ override fun run() { - bot.apply { + with(bot) { try { val input = SyndFeedInput() XmlReader(URL(url)).use { reader -> diff --git a/src/main/java/net/thauvin/erik/mobibot/PinboardUtils.kt b/src/main/java/net/thauvin/erik/mobibot/PinboardUtils.kt index ad6cda7..addf76b 100644 --- a/src/main/java/net/thauvin/erik/mobibot/PinboardUtils.kt +++ b/src/main/java/net/thauvin/erik/mobibot/PinboardUtils.kt @@ -80,7 +80,7 @@ object PinboardUtils { @JvmStatic fun updatePin(poster: PinboardPoster, ircServer: String, oldUrl: String, entry: EntryLink) = runBlocking { val update = GlobalScope.async { - entry.apply { + with(entry) { if (oldUrl != link) { poster.deletePin(oldUrl) poster.addPin( diff --git a/src/main/java/net/thauvin/erik/mobibot/Utils.kt b/src/main/java/net/thauvin/erik/mobibot/Utils.kt index a8e7b63..4e49c89 100644 --- a/src/main/java/net/thauvin/erik/mobibot/Utils.kt +++ b/src/main/java/net/thauvin/erik/mobibot/Utils.kt @@ -244,7 +244,7 @@ object Utils { val minutes = TimeUnit.MILLISECONDS.toMinutes(uptime) - TimeUnit.HOURS.toMinutes( TimeUnit.MILLISECONDS.toHours(uptime) ) - info.apply { + with(info) { if (years > 0) { append(years).append(plural(years, " year ", " years ")) } diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/ChannelFeed.kt b/src/main/java/net/thauvin/erik/mobibot/commands/ChannelFeed.kt index f183340..3eee724 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/ChannelFeed.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/ChannelFeed.kt @@ -61,7 +61,7 @@ class ChannelFeed(bot: Mobibot, channel: String) : AbstractCommand(bot) { isOp: Boolean, isPrivate: Boolean ) { - properties[FEED_PROP].apply { + with(properties[FEED_PROP]) { if (!isNullOrBlank()) { Thread(FeedReader(bot, sender, this)).start() } else { diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Cycle.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Cycle.kt index 6390b3f..49832f2 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Cycle.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Cycle.kt @@ -51,7 +51,7 @@ class Cycle(bot: Mobibot) : AbstractCommand(bot) { isOp: Boolean, isPrivate: Boolean ) { - bot.apply { + with(bot) { if (isOp) { send("$sender has just asked me to leave. I'll be back!") sleep(wait) diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Debug.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Debug.kt index 54b8d6e..fa6b462 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Debug.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Debug.kt @@ -46,7 +46,7 @@ class Debug(bot: Mobibot) : AbstractCommand(bot) { override fun commandResponse(sender: String, login: String, args: String, isOp: Boolean, isPrivate: Boolean) { if (isOp) { - bot.apply { + with(bot) { if (logger.isDebugEnabled) { Configurator.setLevel(logger.name, loggerLevel) } else { diff --git a/src/main/java/net/thauvin/erik/mobibot/commands/Modules.kt b/src/main/java/net/thauvin/erik/mobibot/commands/Modules.kt index d42aa33..a9493fa 100644 --- a/src/main/java/net/thauvin/erik/mobibot/commands/Modules.kt +++ b/src/main/java/net/thauvin/erik/mobibot/commands/Modules.kt @@ -52,7 +52,7 @@ class Modules(bot: Mobibot) : AbstractCommand(bot) { isOp: Boolean, isPrivate: Boolean ) { - bot.apply { + with(bot) { if (isOp) { if (modulesNames.isEmpty()) { send(sender, "There are no enabled modules.", isPrivate) diff --git a/src/main/java/net/thauvin/erik/mobibot/entries/EntriesMgr.kt b/src/main/java/net/thauvin/erik/mobibot/entries/EntriesMgr.kt index d4a63ac..9cbd247 100644 --- a/src/main/java/net/thauvin/erik/mobibot/entries/EntriesMgr.kt +++ b/src/main/java/net/thauvin/erik/mobibot/entries/EntriesMgr.kt @@ -103,7 +103,7 @@ object EntriesMgr { val items = feed.entries var entry: EntryLink for (i in items.indices.reversed()) { - items[i].apply { + with(items[i]) { entry = EntryLink( link, title, @@ -145,7 +145,7 @@ object EntriesMgr { OutputStreamWriter( Files.newOutputStream(Paths.get(bot.logsDir + CURRENT_XML)), StandardCharsets.UTF_8 ).use { fw -> - rss.apply { + with(rss) { feedType = "rss_2.0" title = bot.channel + " IRC Links" description = "Links from ${bot.ircServer} on ${bot.channel}" @@ -156,7 +156,7 @@ object EntriesMgr { var buff: StringBuilder var comment: EntryComment for (i in entries.size - 1 downTo 0) { - entries[i].apply { + with(entries[i]) { buff = StringBuilder() .append("Posted by ") .append(nick) @@ -210,7 +210,7 @@ object EntriesMgr { Files.newOutputStream(Paths.get(bot.logsDir + NAV_XML)), StandardCharsets.UTF_8 ).use { fw -> rss = SyndFeedImpl() - rss.apply { + with(rss) { feedType = "rss_2.0" title = "${bot.channel} IRC Links Backlogs" description = "Backlogs of Links from ${bot.ircServer} on ${bot.channel}" @@ -222,7 +222,7 @@ object EntriesMgr { for (i in history.size - 1 downTo 0) { date = history[i] item = SyndEntryImpl() - item.apply { + with(item) { link = bot.backlogsUrl + date + ".xml" title = date description = SyndContentImpl().apply { value = "Links for $date" } diff --git a/src/main/java/net/thauvin/erik/mobibot/entries/EntriesUtils.kt b/src/main/java/net/thauvin/erik/mobibot/entries/EntriesUtils.kt index edbd5ac..5f83aa2 100644 --- a/src/main/java/net/thauvin/erik/mobibot/entries/EntriesUtils.kt +++ b/src/main/java/net/thauvin/erik/mobibot/entries/EntriesUtils.kt @@ -61,7 +61,7 @@ object EntriesUtils { buff.append("[+").append(entry.comments.size).append(']') } buff.append(' ') - entry.apply { + with(entry) { if (Constants.NO_TITLE == title) { buff.append(title) } else { diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt b/src/main/java/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt index 07e5bca..a617f0b 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/CurrencyConverter.kt @@ -94,7 +94,7 @@ class CurrencyConverter(bot: Mobibot) : ThreadedModule(bot) { } override fun helpResponse(sender: String, isPrivate: Boolean): Boolean { - bot.apply { + with(bot) { if (EXCHANGE_RATES.isEmpty()) { try { loadRates() diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Dice.kt b/src/main/java/net/thauvin/erik/mobibot/modules/Dice.kt index ace71ae..fb20e9d 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Dice.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Dice.kt @@ -49,7 +49,7 @@ class Dice(bot: Mobibot) : AbstractModule(bot) { val playerRoll = roll() val total = roll.first + roll.second val playerTotal = playerRoll.first + playerRoll.second - bot.apply { + with(bot) { send( channel, "$sender rolled two dice: ${Utils.bold(playerRoll.first)} and ${Utils.bold(playerRoll.second)}" diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/GoogleSearch.kt b/src/main/java/net/thauvin/erik/mobibot/modules/GoogleSearch.kt index de38941..bbaec32 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/GoogleSearch.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/GoogleSearch.kt @@ -50,7 +50,7 @@ class GoogleSearch(bot: Mobibot) : ThreadedModule(bot) { * Searches Google. */ override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) { - bot.apply { + with(bot) { if (args.isNotBlank()) { try { val results = searchGoogle( diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Lookup.kt b/src/main/java/net/thauvin/erik/mobibot/modules/Lookup.kt index 31dbc9f..71a3037 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Lookup.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Lookup.kt @@ -50,7 +50,7 @@ class Lookup(bot: Mobibot) : AbstractModule(bot) { isPrivate: Boolean ) { if (args.matches("(\\S.)+(\\S)+".toRegex())) { - bot.apply { + with(bot) { try { lookup(args).split(',').forEach { send(it.trim()) @@ -142,7 +142,7 @@ class Lookup(bot: Mobibot) : AbstractModule(bot) { fun whois(query: String, host: String): List { val whoisClient = WhoisClient() val lines: List - whoisClient.apply { + with(whoisClient) { try { defaultTimeout = Constants.CONNECT_TIMEOUT connect(host) diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt b/src/main/java/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt index 11071c2..e22496a 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt @@ -42,13 +42,13 @@ import kotlin.random.Random */ class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) { init { - commands.apply { + with(commands) { add(Hands.ROCK.name.toLowerCase()) add(Hands.PAPER.name.toLowerCase()) add(Hands.SCISSORS.name.toLowerCase()) } - help.apply { + with(help) { add("To play Rock Paper Scissors:") add( Utils.helpFormat( @@ -96,7 +96,7 @@ class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) { override fun commandResponse(sender: String, cmd: String, args: String, isPrivate: Boolean) { val hand = Hands.valueOf(cmd.toUpperCase()) val botHand = Hands.values()[Random.nextInt(0, Hands.values().size)] - bot.apply { + with(bot) { when { hand == botHand -> { send("${Utils.green(hand.name)} vs. ${Utils.green(botHand.name)}") diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.kt b/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.kt index 101e387..a43eca2 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/StockQuote.kt @@ -50,7 +50,7 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) { * Returns the specified stock quote from Alpha Avantage. */ override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) { - bot.apply { + with(bot) { if (args.isNotBlank()) { try { val messages = getQuote(args, properties[ALPHAVANTAGE_API_KEY_PROP]) @@ -128,7 +128,7 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) { val messages = mutableListOf() var response: String try { - messages.apply { + with(messages) { // Search for symbol/keywords response = Utils.urlReader( URL( diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.kt b/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.kt index 4535329..beb3793 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Twitter.kt @@ -86,7 +86,7 @@ class Twitter(bot: Mobibot) : ThreadedModule(bot) { * Send a notification to the registered Twitter handle. */ fun notification(msg: String) { - bot.apply { + with(bot) { if (isEnabled && !handle.isNullOrBlank()) { Thread { try { @@ -120,7 +120,7 @@ class Twitter(bot: Mobibot) : ThreadedModule(bot) { * Post an entry to twitter. */ fun postEntry(index: Int) { - bot.apply { + with(bot) { if (isAutoPost && hasEntry(index) && LinksMgr.entries.size >= index) { val entry = LinksMgr.entries[index] val msg = "${entry.title} ${entry.link} via ${entry.nick} on $channel" @@ -157,7 +157,7 @@ class Twitter(bot: Mobibot) : ThreadedModule(bot) { * Posts to twitter. */ override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) { - bot.apply { + with(bot) { try { send( sender, diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.kt b/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.kt index 3ee4532..a6133b4 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/Weather2.kt @@ -124,7 +124,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) { messages.add( PublicMessage("City: ${cwd.cityName} [${country.toUpperCase()}]") ) - cwd.mainData.apply { + with(cwd.mainData) { if (this != null) { if (hasTemp()) { messages.add(PublicMessage("Temperature: ${getTemps(temp)}")) @@ -135,7 +135,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) { } } if (cwd.hasWindData()) { - cwd.windData.apply { + with(cwd.windData) { if (this != null && hasSpeed() && speed != null) { messages.add(NoticeMessage("Wind: ${wind(speed!!)}")) } diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.kt b/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.kt index 487cba1..ed7ad74 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.kt +++ b/src/main/java/net/thauvin/erik/mobibot/modules/WorldTime.kt @@ -188,7 +188,7 @@ class WorldTime(bot: Mobibot) : AbstractModule(bot) { args: String, isPrivate: Boolean ) { - bot.apply { + with(bot) { if (args.isEmpty()) { send(sender, "The supported countries/zones are: ", isPrivate) sendList(sender, ArrayList(COUNTRIES_MAP.keys), 17, isPrivate = false)