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)
|
||||
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('.')
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue