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