diff --git a/config/detekt/baseline.xml b/config/detekt/baseline.xml index 0b6f182..b92e51b 100644 --- a/config/detekt/baseline.xml +++ b/config/detekt/baseline.xml @@ -15,6 +15,7 @@ LongParameterList:Mobibot.kt$Mobibot$( nick: String, list: List<String>, maxPerLine: Int, isPrivate: Boolean, isBold: Boolean = false, isIndent: Boolean = false ) LongParameterList:Twitter.kt$Twitter.Companion$( consumerKey: String?, consumerSecret: String?, token: String?, tokenSecret: String?, handle: String?, message: String, isDm: Boolean ) NestedBlockDepth:Addons.kt$Addons$ fun add(command: AbstractCommand, props: Properties) + NestedBlockDepth:Calc.kt$Calc$override fun commandResponse( sender: String, cmd: String, args: String, isPrivate: Boolean ) NestedBlockDepth:Comment.kt$Comment$override fun commandResponse( sender: String, login: String, args: String, isOp: Boolean, isPrivate: Boolean ) NestedBlockDepth:CryptoPrices.kt$CryptoPrices$ override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) NestedBlockDepth:CurrencyConverter.kt$CurrencyConverter$ override fun run(sender: String, cmd: String, args: String, isPrivate: Boolean) diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/War.java b/src/main/java/net/thauvin/erik/mobibot/modules/War.java index 1f86130..2e83533 100644 --- a/src/main/java/net/thauvin/erik/mobibot/modules/War.java +++ b/src/main/java/net/thauvin/erik/mobibot/modules/War.java @@ -51,11 +51,17 @@ public final class War extends AbstractModule { private static final SecureRandom RANDOM = new SecureRandom(); // War command private static final String WAR_CMD = "war"; - // Deck of card - private static final String[] WAR_DECK = - {"Ace", "King", "Queen", "Jack", "10", "9", "8", "7", "6", "5", "4", "3", "2"}; - // Suits for the deck of card - private static final String[] WAR_SUITS = {"Hearts", "Spades", "Diamonds", "Clubs"}; + + private static final String[] HEARTS = + {"🂱", "🂾", "🂽", "🂼", "🂻", "🂺", "🂹", "🂸", "🂷", "🂶", "🂵", "🂴", "🂳", "🂲"}; + private static final String[] SPADES = + {"🂡", "🂮", "🂭", "🂬", "🂫", "🂪", "🂩", "🂨", "🂧", "🂦", "🂥", "🂤", "🂣", "🂢"}; + private static final String[] DIAMONDS = + {"🃁", "🃎", "🃍", "🃌", "🃋", "🃊", "🃉", "🃈", "🃇", "🃆", "🃅", "🃄", "🃃", "🃂"}; + private static final String[] CLUBS = + {"🃑", "🃞", "🃝", "🃜", "🃛", "🃚", "🃙", "🃘", "🃗", "🃖", "🃕", "🃔", "🃓", "🃒"}; + + private static final String[][] DECK = {HEARTS, SPADES, DIAMONDS, CLUBS}; /** * The default constructor. @@ -81,13 +87,11 @@ public final class War extends AbstractModule { int y; while (true) { - i = RANDOM.nextInt(WAR_DECK.length); - y = RANDOM.nextInt(WAR_DECK.length); + i = RANDOM.nextInt(HEARTS.length); + y = RANDOM.nextInt(HEARTS.length); - getBot().send(sender + " drew the " + bold(WAR_DECK[i]) + " of " - + bold(WAR_SUITS[RANDOM.nextInt(WAR_SUITS.length)])); - getBot().action("drew the " + bold(WAR_DECK[y]) + " of " - + bold(WAR_SUITS[RANDOM.nextInt(WAR_SUITS.length)])); + getBot().send(sender + " drew: " + DECK[RANDOM.nextInt(DECK.length)][i]); + getBot().action("drew: " + DECK[RANDOM.nextInt(DECK.length)][y]); if (i != y) { break; diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/Utils.kt b/src/main/kotlin/net/thauvin/erik/mobibot/Utils.kt index 986230a..a16c01b 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/Utils.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/Utils.kt @@ -99,12 +99,12 @@ object Utils { * Capitalize a string. */ @JvmStatic - fun String.capitalise(): String = this.replaceFirstChar { it.uppercase() } + fun String.capitalise(): String = this.lowercase().replaceFirstChar { it.uppercase() } /** * Capitalize words */ - fun String.capitalizeWords(): String = split(" ").map { it.lowercase().capitalise() }.joinToString(" ") + fun String.capitalizeWords(): String = split(" ").joinToString(" ") { it.capitalise() } /** diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Dice.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Dice.kt index ec3a0e6..57e78ca 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Dice.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Dice.kt @@ -32,7 +32,6 @@ package net.thauvin.erik.mobibot.modules import net.thauvin.erik.mobibot.Mobibot -import net.thauvin.erik.mobibot.Utils.bold import net.thauvin.erik.mobibot.Utils.helpFormat import kotlin.random.Random @@ -46,22 +45,20 @@ class Dice(bot: Mobibot) : AbstractModule(bot) { args: String, isPrivate: Boolean ) { + val botRoll = roll() val roll = roll() - val playerRoll = roll() + val botTotal = botRoll.first + botRoll.second val total = roll.first + roll.second - val playerTotal = playerRoll.first + playerRoll.second with(bot) { send( channel, - "$sender rolled two dice: ${bold(playerRoll.first)} and ${bold(playerRoll.second)}" - + " for a total of ${bold(playerTotal)}", + "$sender rolled ${total}: ${DICE_FACES[roll.first]} ${DICE_FACES[roll.second]}", isPrivate ) action( - "rolled two dice: ${bold(roll.first)} and ${bold(roll.second)}" + - " for a total of ${bold(total)}" + "rolled ${botTotal}: ${DICE_FACES[botRoll.first]} ${DICE_FACES[botRoll.second]}" ) - when (winLoseOrTie(total, playerTotal)) { + when (winLoseOrTie(botTotal, total)) { Result.WIN -> action("wins.") Result.LOSE -> action("lost.") else -> action("tied.") @@ -74,14 +71,16 @@ class Dice(bot: Mobibot) : AbstractModule(bot) { } private fun roll(): Pair { - @Suppress("MagicNumber") - return Random.nextInt(1, 7) to Random.nextInt(1, 7) + return Random.nextInt(1, DICE_FACES.size) to Random.nextInt(1, DICE_FACES.size) } companion object { // Dice command private const val DICE_CMD = "dice" + // Dice faces + private val DICE_FACES = arrayOf("", "⚀", "⚁", "⚂", "⚃", "⚄", "⚅") + fun winLoseOrTie(bot: Int, player: Int): Result { return when { bot > player -> { diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt index bfcbe23..33b1fce 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt @@ -33,10 +33,8 @@ package net.thauvin.erik.mobibot.modules import net.thauvin.erik.mobibot.Mobibot -import net.thauvin.erik.mobibot.Utils.bold -import net.thauvin.erik.mobibot.Utils.green +import net.thauvin.erik.mobibot.Utils.capitalise import net.thauvin.erik.mobibot.Utils.helpFormat -import net.thauvin.erik.mobibot.Utils.red import kotlin.random.Random @@ -67,19 +65,26 @@ class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) { override fun beats(hand: Hands): Boolean { return hand == SCISSORS } + + override var emoji = "\u270A" }, PAPER("covers") { override fun beats(hand: Hands): Boolean { return hand == ROCK } + + override var emoji = "\u270B" }, SCISSORS("cuts") { override fun beats(hand: Hands): Boolean { return hand == PAPER } + + override var emoji = "\u270C" }; abstract fun beats(hand: Hands): Boolean + abstract var emoji: String } companion object { @@ -100,18 +105,16 @@ class RockPaperScissors(bot: Mobibot) : AbstractModule(bot) { val hand = Hands.valueOf(cmd.uppercase()) val botHand = Hands.values()[Random.nextInt(0, Hands.values().size)] with(bot) { + send("${hand.emoji} vs. ${botHand.emoji}") when { hand == botHand -> { - send("${green(hand.name)} vs. ${green(botHand.name)}") action("tied.") } hand.beats(botHand) -> { - send("${green(hand.name)} ${bold(hand.action)} ${red(botHand.name)}") - action("lost.") + action("lost. ${hand.name.capitalise()} ${hand.action} ${botHand.name.lowercase()}.") } else -> { - send("${green(botHand.name)} ${bold(botHand.action)} ${red(hand.name)}") - action("wins.") + action("wins. ${botHand.name.capitalise()} ${botHand.action} ${hand.name.lowercase()}.") } } }