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