Added Utils.capitalize()
This commit is contained in:
parent
7b2b496a94
commit
8b8cbb39f8
7 changed files with 24 additions and 11 deletions
|
@ -81,7 +81,15 @@ object Utils {
|
||||||
val replace = arrayOf(if (isPrivate) "/msg $botNick" else "$botNick:", botNick)
|
val replace = arrayOf(if (isPrivate) "/msg $botNick" else "$botNick:", botNick)
|
||||||
return StringUtils.replaceEach(text, searchFlags, replace)
|
return StringUtils.replaceEach(text, searchFlags, replace)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Capitalize a string.
|
||||||
|
*/
|
||||||
|
@JvmStatic
|
||||||
|
fun capitalize(s: String?): String {
|
||||||
|
return s!!.replaceFirstChar { it.uppercase() }
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Colorize a string.
|
* Colorize a string.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -36,7 +36,6 @@ import net.thauvin.erik.mobibot.Mobibot;
|
||||||
import net.thauvin.erik.mobibot.ReleaseInfo;
|
import net.thauvin.erik.mobibot.ReleaseInfo;
|
||||||
import net.thauvin.erik.mobibot.Utils;
|
import net.thauvin.erik.mobibot.Utils;
|
||||||
import net.thauvin.erik.mobibot.commands.links.LinksMgr;
|
import net.thauvin.erik.mobibot.commands.links.LinksMgr;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.lang.management.ManagementFactory;
|
import java.lang.management.ManagementFactory;
|
||||||
|
@ -44,7 +43,7 @@ import java.util.List;
|
||||||
|
|
||||||
public class Info extends AbstractCommand {
|
public class Info extends AbstractCommand {
|
||||||
private final List<String> allVersions = List.of(
|
private final List<String> allVersions = List.of(
|
||||||
StringUtils.capitalize(ReleaseInfo.PROJECT) + " " + ReleaseInfo.VERSION
|
Utils.capitalize(ReleaseInfo.PROJECT) + " " + ReleaseInfo.VERSION
|
||||||
+ " (" + Utils.green(ReleaseInfo.WEBSITE) + ')',
|
+ " (" + Utils.green(ReleaseInfo.WEBSITE) + ')',
|
||||||
"Written by " + ReleaseInfo.AUTHOR + " (" + Utils.green(ReleaseInfo.AUTHOR_URL) + ')');
|
"Written by " + ReleaseInfo.AUTHOR + " (" + Utils.green(ReleaseInfo.AUTHOR_URL) + ')');
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,6 @@ import net.thauvin.erik.mobibot.Mobibot
|
||||||
import net.thauvin.erik.mobibot.Utils
|
import net.thauvin.erik.mobibot.Utils
|
||||||
import net.thauvin.erik.mobibot.msg.Message
|
import net.thauvin.erik.mobibot.msg.Message
|
||||||
import net.thauvin.erik.mobibot.msg.NoticeMessage
|
import net.thauvin.erik.mobibot.msg.NoticeMessage
|
||||||
import org.apache.commons.lang3.StringUtils
|
|
||||||
import org.jibble.pircbot.Colors
|
import org.jibble.pircbot.Colors
|
||||||
import org.json.JSONException
|
import org.json.JSONException
|
||||||
import org.json.JSONObject
|
import org.json.JSONObject
|
||||||
|
@ -87,7 +86,7 @@ class GoogleSearch(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
@Throws(ModuleException::class)
|
@Throws(ModuleException::class)
|
||||||
fun searchGoogle(query: String, apiKey: String?, cseKey: String?): List<Message> {
|
fun searchGoogle(query: String, apiKey: String?, cseKey: String?): List<Message> {
|
||||||
if (apiKey.isNullOrBlank() || cseKey.isNullOrBlank()) {
|
if (apiKey.isNullOrBlank() || cseKey.isNullOrBlank()) {
|
||||||
throw ModuleException("${StringUtils.capitalize(GOOGLE_CMD)} is disabled. The API keys are missing.")
|
throw ModuleException("${Utils.capitalize(GOOGLE_CMD)} is disabled. The API keys are missing.")
|
||||||
}
|
}
|
||||||
return if (query.isNotBlank()) {
|
return if (query.isNotBlank()) {
|
||||||
val results = mutableListOf<Message>()
|
val results = mutableListOf<Message>()
|
||||||
|
|
|
@ -122,7 +122,7 @@ class StockQuote(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
fun getQuote(symbol: String, apiKey: String?): List<Message> {
|
fun getQuote(symbol: String, apiKey: String?): List<Message> {
|
||||||
if (apiKey.isNullOrBlank()) {
|
if (apiKey.isNullOrBlank()) {
|
||||||
throw ModuleException(
|
throw ModuleException(
|
||||||
"${STOCK_CMD.replaceFirstChar { it.uppercase() }} is disabled. The API key is missing.")
|
"${Utils.capitalize(STOCK_CMD)} is disabled. The API key is missing.")
|
||||||
}
|
}
|
||||||
return if (symbol.isNotBlank()) {
|
return if (symbol.isNotBlank()) {
|
||||||
val debugMessage = "getQuote($symbol)"
|
val debugMessage = "getQuote($symbol)"
|
||||||
|
|
|
@ -101,7 +101,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
fun getWeather(query: String, apiKey: String?): List<Message> {
|
fun getWeather(query: String, apiKey: String?): List<Message> {
|
||||||
if (apiKey.isNullOrBlank()) {
|
if (apiKey.isNullOrBlank()) {
|
||||||
throw ModuleException(
|
throw ModuleException(
|
||||||
"${WEATHER_CMD.replaceFirstChar { it.uppercase() }} is disabled. The API key is missing.")
|
"${Utils.capitalize(WEATHER_CMD)} is disabled. The API key is missing.")
|
||||||
}
|
}
|
||||||
val owm = OWM(apiKey)
|
val owm = OWM(apiKey)
|
||||||
val messages = mutableListOf<Message>()
|
val messages = mutableListOf<Message>()
|
||||||
|
@ -149,7 +149,7 @@ class Weather2(bot: Mobibot) : ThreadedModule(bot) {
|
||||||
for (w in list) {
|
for (w in list) {
|
||||||
if (w != null) {
|
if (w != null) {
|
||||||
condition.append(' ')
|
condition.append(' ')
|
||||||
.append(w.getDescription().replaceFirstChar { it.uppercase() })
|
.append(Utils.capitalize(w.getDescription()))
|
||||||
.append('.')
|
.append('.')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
package net.thauvin.erik.mobibot
|
package net.thauvin.erik.mobibot
|
||||||
|
|
||||||
import net.thauvin.erik.mobibot.Utils.bold
|
import net.thauvin.erik.mobibot.Utils.bold
|
||||||
|
import net.thauvin.erik.mobibot.Utils.capitalize
|
||||||
import net.thauvin.erik.mobibot.Utils.colorize
|
import net.thauvin.erik.mobibot.Utils.colorize
|
||||||
import net.thauvin.erik.mobibot.Utils.cyan
|
import net.thauvin.erik.mobibot.Utils.cyan
|
||||||
import net.thauvin.erik.mobibot.Utils.ensureDir
|
import net.thauvin.erik.mobibot.Utils.ensureDir
|
||||||
|
@ -77,6 +78,12 @@ class UtilsTest {
|
||||||
Assertions.assertThat(bold(ascii)).`as`("bold(ascii)").isEqualTo(Colors.BOLD + ascii + Colors.BOLD)
|
Assertions.assertThat(bold(ascii)).`as`("bold(ascii)").isEqualTo(Colors.BOLD + ascii + Colors.BOLD)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testCapitalize() {
|
||||||
|
Assertions.assertThat(capitalize("test")).`as`("capitalize(test)").isEqualTo("Test")
|
||||||
|
Assertions.assertThat(capitalize("Test")).`as`("capitalize(Test)").isEqualTo("Test")
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testColorize() {
|
fun testColorize() {
|
||||||
Assertions.assertThat(colorize(ascii, Colors.REVERSE)).`as`("colorize(reverse)").isEqualTo(
|
Assertions.assertThat(colorize(ascii, Colors.REVERSE)).`as`("colorize(reverse)").isEqualTo(
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#Generated by the Semver Plugin for Gradle
|
#Generated by the Semver Plugin for Gradle
|
||||||
#Mon Apr 26 18:00:07 PDT 2021
|
#Mon Apr 26 22:03:01 PDT 2021
|
||||||
version.buildmeta=462
|
version.buildmeta=474
|
||||||
version.major=0
|
version.major=0
|
||||||
version.minor=8
|
version.minor=8
|
||||||
version.patch=0
|
version.patch=0
|
||||||
version.prerelease=beta
|
version.prerelease=beta
|
||||||
version.project=mobibot
|
version.project=mobibot
|
||||||
version.semver=0.8.0-beta+462
|
version.semver=0.8.0-beta+474
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue