@@ -66,13 +66,13 @@
-
-
+
+
-
+
@@ -85,7 +85,7 @@
-
+
diff --git a/build.gradle b/build.gradle
index 46d3c27..08a3b86 100644
--- a/build.gradle
+++ b/build.gradle
@@ -4,11 +4,11 @@ plugins {
id 'com.github.ben-manes.versions' version '0.28.0'
id 'com.github.spotbugs' version '4.0.4'
id 'idea'
- id 'io.gitlab.arturbosch.detekt' version '1.7.0-beta2'
+ id 'io.gitlab.arturbosch.detekt' version '1.7.0'
id 'jacoco'
id 'java'
id 'net.thauvin.erik.gradle.semver' version '1.0.4'
- id 'org.jetbrains.kotlin.jvm' version '1.3.70'
+ id 'org.jetbrains.kotlin.jvm' version '1.3.71'
id 'org.sonarqube' version '2.8'
id 'pmd'
}
@@ -25,7 +25,7 @@ mainClassName = packageName + '.Mobibot'
ext {
versions = [
- kotlin : '1.3.70',
+ kotlin : '1.3.71',
log4j : '2.13.1',
spotbugs : '4.0.1'
]
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 5f7d5c4..b133221 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,35 +1,3 @@
-#
-# gradle-wrapper.properties
-#
-# Copyright (c) 2004-2020, Erik C. Thauvin (erik@thauvin.net)
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# Neither the name of this project nor the names of its contributors may be
-# used to endorse or promote products derived from this software without
-# specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-rc-3-bin.zip
diff --git a/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java b/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java
index 6511d10..6906800 100644
--- a/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java
+++ b/src/generated/java/net/thauvin/erik/mobibot/ReleaseInfo.java
@@ -14,13 +14,13 @@ import java.time.*;
public final class ReleaseInfo {
public static final String PROJECT = "mobibot";
public static final LocalDateTime BUILDDATE =
- LocalDateTime.ofInstant(Instant.ofEpochMilli(1584991174842L), ZoneId.systemDefault());
+ LocalDateTime.ofInstant(Instant.ofEpochMilli(1585027973338L), ZoneId.systemDefault());
public static final int MAJOR = 0;
public static final int MINOR = 7;
public static final int PATCH = 3;
public static final String PRERELEASE = "beta";
- public static final String BUILDMETA = "704";
- public static final String VERSION = "0.7.3-beta+704";
+ public static final String BUILDMETA = "712";
+ public static final String VERSION = "0.7.3-beta+712";
/**
* Disables the default constructor.
diff --git a/src/main/java/net/thauvin/erik/mobibot/Utils.java b/src/main/java/net/thauvin/erik/mobibot/Utils.java
index 1049078..1489ecf 100644
--- a/src/main/java/net/thauvin/erik/mobibot/Utils.java
+++ b/src/main/java/net/thauvin/erik/mobibot/Utils.java
@@ -208,6 +208,16 @@ public final class Utils {
}
}
+ /**
+ * Makes the given string red.
+ *
+ * @param s The string.
+ * @return The red string.
+ */
+ public static String red(final String s) {
+ return colorize(s, Colors.RED);
+ }
+
/**
* Makes the given string reverse color.
*
diff --git a/src/main/java/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt b/src/main/java/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt
index 387bc29..a6418db 100644
--- a/src/main/java/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt
+++ b/src/main/java/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt
@@ -37,7 +37,6 @@ import net.thauvin.erik.mobibot.Utils
import kotlin.random.Random
-
/**
* Simple module example in Kotlin.
*/
@@ -58,51 +57,60 @@ class RockPaperScissors : AbstractModule() {
WIN, LOSE, DRAW
}
+
companion object {
/**
- * Returns the the randomly picked shape and result.
+ * Returns the the randomly picked shape, result and action (cuts, crushes, covers, vs.)
*/
- fun winLoseOrDraw(hand: Shapes): Pair {
+ fun winLoseOrDraw(hand: Shapes): Triple {
val botHand = Shapes.values()[Random.nextInt(0, Shapes.values().size)]
val result: Results
+ val action: String
if (botHand == hand) {
result = Results.DRAW
+ action = "vs."
} else {
- when (botHand) {
- Shapes.ROCK -> {
- result = if (hand == Shapes.PAPER) {
- Results.WIN
- } else {
- Results.LOSE
- }
+ val shapes = arrayOf(hand, botHand)
+ if (shapes.contains(Shapes.ROCK) && shapes.contains(Shapes.SCISSORS)) {
+ action = "crushes"
+ result = if (hand == Shapes.ROCK) {
+ Results.WIN
+ } else {
+ Results.LOSE
}
- Shapes.PAPER -> {
- result = if (hand == Shapes.ROCK) {
- Results.LOSE
- } else {
- Results.WIN
- }
+ } else if (shapes.contains(Shapes.PAPER) && shapes.contains(Shapes.ROCK)) {
+ action = "covers"
+ result = if (hand == Shapes.PAPER) {
+ Results.WIN
+ } else {
+ Results.LOSE
}
- Shapes.SCISSORS -> {
- result = if (hand == Shapes.ROCK) {
- Results.WIN
- } else {
- Results.LOSE
- }
+ } else { // SCISSORS vs. PAPER
+ action = "cuts"
+ result = if (hand == Shapes.SCISSORS) {
+ Results.WIN
+ } else {
+ Results.LOSE
}
}
}
- return Pair(botHand, result)
+ return Triple(botHand, result, action)
}
}
override fun commandResponse(bot: Mobibot?, sender: String?, cmd: String?, args: String?, isPrivate: Boolean) {
val result = winLoseOrDraw(Shapes.valueOf(cmd!!.toUpperCase()))
- val picked = "picked ${Utils.bold(result.first.value)}."
when (result.second) {
- Results.WIN -> bot!!.action("$picked You win.")
- Results.LOSE -> bot!!.action("$picked You lose.")
- else -> bot!!.action("$picked We have a draw.")
+ Results.WIN -> bot!!.action(
+ "${Utils.green(cmd)} ${Utils.bold(result.third)} ${Utils.red(result.first.value)} ~ You win ~"
+ )
+ Results.LOSE -> bot!!.action(
+ "${Utils.green(result.first.value)} ${Utils.bold(result.third)} ${Utils.red(cmd)} ~ You lose ~"
+ )
+ else -> bot!!.action(
+ "${Utils.green(cmd)} ${Utils.bold(result.third)} ${Utils.green(result.first.value)}"
+ + " ~ The game is tied ~"
+ )
}
}
diff --git a/version.properties b/version.properties
index a8206a8..baa7520 100644
--- a/version.properties
+++ b/version.properties
@@ -1,41 +1,9 @@
-#
-# version.properties
-#
-# Copyright (c) 2004-2020, Erik C. Thauvin (erik@thauvin.net)
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# Redistributions of source code must retain the above copyright notice, this
-# list of conditions and the following disclaimer.
-#
-# Redistributions in binary form must reproduce the above copyright notice,
-# this list of conditions and the following disclaimer in the documentation
-# and/or other materials provided with the distribution.
-#
-# Neither the name of this project nor the names of its contributors may be
-# used to endorse or promote products derived from this software without
-# specific prior written permission.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
-# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
-# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
-# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
-# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
#Generated by the Semver Plugin for Gradle
-#Mon Mar 23 12:19:33 PDT 2020
-version.buildmeta=704
+#Mon Mar 23 22:32:51 PDT 2020
+version.buildmeta=712
version.major=0
version.minor=7
version.patch=3
version.prerelease=beta
version.project=mobibot
-version.semver=0.7.3-beta+704
+version.semver=0.7.3-beta+712