Moved from Gradle to bld

This commit is contained in:
Erik C. Thauvin 2023-11-10 23:43:20 -08:00
parent 1cd7c5a79e
commit c68c25aa95
240 changed files with 11508 additions and 1650 deletions

View file

@ -0,0 +1,170 @@
/*
* MobibotBuild.java
*
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* 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.
*/
package net.thauvin.erik;
import rife.bld.BuildCommand;
import rife.bld.Project;
import rife.bld.dependencies.Repository;
import rife.bld.extension.CompileKotlinOperation;
import rife.bld.extension.CompileKotlinOptions;
import rife.bld.extension.GeneratedVersionOperation;
import rife.bld.extension.JacocoReportOperation;
import rife.tools.FileUtils;
import rife.tools.exceptions.FileUtilsErrorException;
import java.io.File;
import java.io.IOException;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.Attributes;
import static rife.bld.dependencies.Repository.MAVEN_CENTRAL;
import static rife.bld.dependencies.Repository.MAVEN_LOCAL;
import static rife.bld.dependencies.Scope.compile;
import static rife.bld.dependencies.Scope.test;
public class MobibotBuild extends Project {
public MobibotBuild() {
pkg = "net.thauvin.erik.mobibot";
name = "mobibot";
version = version(0, 8, 0, "rc+" +
DateTimeFormatter.ofPattern("yyyyMMddHHmmss").format(LocalDateTime.now()));
mainClass = pkg + ".Mobibot";
javaRelease = 17;
downloadSources = true;
autoDownloadPurge = true;
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, new Repository("https://jitpack.io"));
var log4j = version(2, 21, 1);
scope(compile)
// PircBotX
.include(dependency("com.github.pircbotx", "pircbotx", "2.3.1"))
// Commons (mostly for PircBotX)
.include(dependency("org.apache.commons", "commons-lang3", "3.13.0"))
.include(dependency("org.apache.commons", "commons-text", "1.11.0"))
.include(dependency("commons-codec", "commons-codec", "1.16.0"))
.include(dependency("commons-net", "commons-net", "3.10.0"))
// Google
.include(dependency("com.google.code.gson", "gson", "2.10.1"))
.include(dependency("com.google.guava", "guava", "32.1.3-jre"))
// Kotlin
.include(dependency("org.jetbrains.kotlin", "kotlin-stdlib", version(1, 9, 20)))
.include(dependency("org.jetbrains.kotlinx", "kotlinx-coroutines-core", "1.7.3"))
.include(dependency("org.jetbrains.kotlinx", "kotlinx-cli-jvm", "0.3.6"))
// Logging
.include(dependency("org.slf4j", "slf4j-api", "2.0.9"))
.include(dependency("org.apache.logging.log4j", "log4j-api", log4j))
.include(dependency("org.apache.logging.log4j", "log4j-core", log4j))
.include(dependency("org.apache.logging.log4j", "log4j-slf4j2-impl", log4j))
.include(dependency("com.rometools", "rome", "2.1.0"))
.include(dependency("com.squareup.okhttp3", "okhttp", "4.12.0"))
.include(dependency("net.aksingh", "owm-japis", "2.5.3.0"))
.include(dependency("net.objecthunter", "exp4j", "0.4.8"))
.include(dependency("org.json", "json", "20231013"))
.include(dependency("org.jsoup", "jsoup", "1.16.2"))
// Thauvin
.include(dependency("net.thauvin.erik", "cryptoprice", "1.0.1"))
.include(dependency("net.thauvin.erik", "jokeapi", "0.9.0"))
.include(dependency("net.thauvin.erik", "pinboard-poster", "1.1.0"))
.include(dependency("net.thauvin.erik.urlencoder", "urlencoder-lib-jvm", "1.4.0"));
scope(test)
.include(dependency("com.willowtreeapps.assertk", "assertk-jvm", version(0, 27, 0)))
.include(dependency("org.jetbrains.kotlin", "kotlin-test-junit5", version(1, 9, 20)))
.include(dependency("org.junit.jupiter", "junit-jupiter", version(5, 10, 1)))
.include(dependency("org.junit.platform", "junit-platform-console-standalone", version(1, 10, 1)));
List<String> jars = new ArrayList<>();
compileClasspathJars().forEach(f -> jars.add("./lib/" + f.getName()));
jarOperation()
.manifestAttribute(Attributes.Name.MAIN_CLASS, mainClass())
.manifestAttribute(Attributes.Name.CLASS_PATH, ". " + String.join(" ", jars));
jarSourcesOperation().sourceDirectories(new File(srcMainDirectory(), "kotlin"));
}
public static void main(String[] args) {
new MobibotBuild().start(args);
}
@Override
public void clean() throws Exception {
FileUtils.deleteDirectory(new File("deploy"));
super.clean();
}
@BuildCommand(summary = "Compiles the Kotlin project")
@Override
public void compile() throws Exception {
releaseInfo();
new CompileKotlinOperation()
.fromProject(this)
.compileOptions(
new CompileKotlinOptions()
.jdkRelease(javaRelease)
.verbose(true)
)
.execute();
}
@BuildCommand(summary = "Copies all needed files to the deploy directory")
public void deploy() throws FileUtilsErrorException {
var deploy = new File("deploy");
var lib = new File(deploy, "lib");
var ignore = lib.mkdirs();
FileUtils.copyDirectory(new File("properties"), deploy);
FileUtils.copyDirectory(libCompileDirectory(), lib);
FileUtils.copy(new File(buildDistDirectory(), jarFileName()), new File(deploy, "mobibot.jar"));
}
@BuildCommand(summary = "Generates JaCoCo Reports")
public void jacoco() throws IOException {
new JacocoReportOperation()
.fromProject(this)
.execute();
}
@BuildCommand(value = "release-info", summary = "Generates the ReleaseInfo class")
public void releaseInfo() {
new GeneratedVersionOperation()
.fromProject(this)
.classTemplate(new File(workDirectory(), "release-info.txt"))
.className("ReleaseInfo")
.packageName(pkg)
.directory(new File(srcMainDirectory(), "kotlin"))
.extension(".kt")
.execute();
}
}

View file

@ -1,108 +0,0 @@
/*
* War.java
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
*
* 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.
*/
package net.thauvin.erik.mobibot.modules;
import net.thauvin.erik.mobibot.Utils;
import org.jetbrains.annotations.NotNull;
import org.pircbotx.hooks.types.GenericMessageEvent;
import java.security.SecureRandom;
import static net.thauvin.erik.mobibot.Utils.bold;
/**
* The War module.
*
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
* @since 1.0
*/
public final class War extends AbstractModule {
private static final String[] CLUBS =
{"🃑", "🃞", "🃝", "🃛", "🃚", "🃙", "🃘", "🃗", "🃖", "🃕", "🃔", "🃓", "🃒"};
private static final String[] DIAMONDS =
{"🃁", "🃎", "🃍", "🃋", "🃊", "🃉", "🃈", "🃇", "🃆", "🃅", "🃄", "🃃", "🃂"};
private static final String[] HEARTS =
{"🂱", "🂾", "🂽", "🂻", "🂺", "🂹", "🂸", "🂷", "🂶", "🂵", "🂴", "🂳", "🂲"};
// Random
private static final SecureRandom RANDOM = new SecureRandom();
private static final String[] SPADES =
{"🂡", "🂮", "🂭", "🂫", "🂪", "🂩", "🂨", "🂧", "🂦", "🂥", "🂤", "🂣", "🂢"};
private static final String[][] DECK = {HEARTS, SPADES, DIAMONDS, CLUBS};
// War command
private static final String WAR_CMD = "war";
/**
* The default constructor.
*/
public War() {
super();
commands.add(WAR_CMD);
help.add("To play war:");
help.add(Utils.helpFormat("%c " + WAR_CMD));
}
@NotNull
@Override
public String getName() {
return "War";
}
/**
* {@inheritDoc}
*/
@Override
public void commandResponse(@NotNull final String channel, @NotNull final String cmd, @NotNull final String args,
@NotNull final GenericMessageEvent event) {
int i;
int y;
do {
i = RANDOM.nextInt(HEARTS.length);
y = RANDOM.nextInt(HEARTS.length);
final String result;
if (i < y) {
result = bold("win");
} else if (i > y) {
result = bold("lose");
} else {
result = bold("tie") + ". This means " + bold("WAR");
}
event.respond(DECK[RANDOM.nextInt(DECK.length)][i] + " " + DECK[RANDOM.nextInt(DECK.length)][y] +
" » You " + result + '!');
} while (i == y);
}
}

View file

@ -1,7 +1,7 @@
/*
* Addons.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Constants.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* FeedReader.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Mobibot.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -51,7 +51,6 @@ import net.thauvin.erik.mobibot.commands.links.*
import net.thauvin.erik.mobibot.commands.seen.Seen
import net.thauvin.erik.mobibot.commands.tell.Tell
import net.thauvin.erik.mobibot.modules.*
import net.thauvin.erik.semver.Version
import org.pircbotx.Configuration
import org.pircbotx.PircBotX
import org.pircbotx.hooks.ListenerAdapter
@ -66,7 +65,6 @@ import java.util.*
import java.util.regex.Pattern
import kotlin.system.exitProcess
@Version(properties = "version.properties", className = "ReleaseInfo", template = "version.mustache", type = "kt")
class Mobibot(nickname: String, val channel: String, logsDirPath: String, p: Properties) : ListenerAdapter() {
// The bot configuration.
private val config: Configuration
@ -257,7 +255,7 @@ class Mobibot(nickname: String, val channel: String, logsDirPath: String, p: Pro
// Output the version
println(
"${ReleaseInfo.PROJECT.capitalise()} ${ReleaseInfo.VERSION}" +
" (${ReleaseInfo.BUILDDATE.toIsoLocalDate()})"
" (${ReleaseInfo.BUILD_DATE.toIsoLocalDate()})"
)
println(ReleaseInfo.WEBSITE)
} else {

View file

@ -1,7 +1,7 @@
/*
* Pinboard.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -0,0 +1,27 @@
/*
* This file is automatically generated
* Do not modify! -- ALL CHANGES WILL BE ERASED!
*/
package net.thauvin.erik.mobibot
import java.time.Instant
import java.time.LocalDateTime
import java.time.ZoneId
/**
* Provides release information.
*/
object ReleaseInfo {
const val PROJECT = "mobibot"
const val VERSION = "0.8.0-rc+20231110234054"
@JvmField
val BUILD_DATE: LocalDateTime = LocalDateTime.ofInstant(
Instant.ofEpochMilli(1699688454937L), ZoneId.systemDefault()
)
const val WEBSITE = "https://www.mobitopia.org/mobibot/"
const val AUTHOR = "Erik C. Thauvin"
const val AUTHOR_URL = "https://erik.thauvin.net/"
}

View file

@ -1,7 +1,7 @@
/*
* Utils.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* AbstractCommand.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* ChannelFeed.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Cycle.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Die.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Ignore.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Info.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Me.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Modules.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Msg.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Nick.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Recap.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Say.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Users.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Versions.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -40,7 +40,7 @@ import org.pircbotx.hooks.types.GenericMessageEvent
class Versions : AbstractCommand() {
private val allVersions = listOf(
"Version: ${ReleaseInfo.VERSION} (${ReleaseInfo.BUILDDATE.toIsoLocalDate()})",
"Version: ${ReleaseInfo.VERSION} (${ReleaseInfo.BUILD_DATE.toIsoLocalDate()})",
"${System.getProperty("os.name")} ${System.getProperty("os.version")} (${System.getProperty("os.arch")})" +
", JVM ${System.getProperty("java.runtime.version")}",
"Kotlin ${KotlinVersion.CURRENT}, PircBotX ${PircBotX.VERSION}"

View file

@ -1,7 +1,7 @@
/*
* Comment.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* LinksManager.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Posting.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Tags.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* View.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* NickComparator.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Seen.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* SeenNick.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Tell.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* TellManager.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* TellMessage.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Entries.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* EntriesUtils.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* EntryComment.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* EntryLink.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* FeedsManager.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* AbstractModule.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Calc.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* ChatGpt.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* CryptoPrices.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -120,7 +120,7 @@ class CryptoPrices : AbstractModule() {
}
/**
* Loads the Fiat currencies..
* Loads the Fiat currencies.
*/
@JvmStatic
@Throws(ModuleException::class)

View file

@ -1,7 +1,7 @@
/*
* CurrencyConverter.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Dice.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* GoogleSearch.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Joke.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Lookup.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Mastodon.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* ModuleException.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Ping.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* RockPaperScissors.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* StockQuote.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -0,0 +1,89 @@
/*
* War.kt
*
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* 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.
*/
package net.thauvin.erik.mobibot.modules
import net.thauvin.erik.mobibot.Utils.bold
import net.thauvin.erik.mobibot.Utils.helpFormat
import org.pircbotx.hooks.types.GenericMessageEvent
import java.security.SecureRandom
/**
* The War module.
*
* @author [Erik C. Thauvin](https://erik.thauvin.net/)
* @since 1.0
*/
class War : AbstractModule() {
override val name = "War"
override fun commandResponse(
channel: String, cmd: String, args: String,
event: GenericMessageEvent
) {
var i: Int
var y: Int
do {
i = RANDOM.nextInt(HEARTS.size)
y = RANDOM.nextInt(HEARTS.size)
val result: String = if (i < y) {
"win".bold()
} else if (i > y) {
"lose".bold()
} else {
"tie".bold() + ". This means " + "WAR".bold()
}
event.respond(
DECK[RANDOM.nextInt(DECK.size)][i] + " " + DECK[RANDOM.nextInt(DECK.size)][y] +
" » You " + result + '!'
)
} while (i == y)
}
companion object {
private val CLUBS = arrayOf("🃑", "🃞", "🃝", "🃛", "🃚", "🃙", "🃘", "🃗", "🃖", "🃕", "🃔", "🃓", "🃒")
private val DIAMONDS = arrayOf("🃁", "🃎", "🃍", "🃋", "🃊", "🃉", "🃈", "🃇", "🃆", "🃅", "🃄", "🃃", "🃂")
private val HEARTS = arrayOf("🂱", "🂾", "🂽", "🂻", "🂺", "🂹", "🂸", "🂷", "🂶", "🂵", "🂴", "🂳", "🂲")
// Random
private val RANDOM = SecureRandom()
private val SPADES = arrayOf("🂡", "🂮", "🂭", "🂫", "🂪", "🂩", "🂨", "🂧", "🂦", "🂥", "🂤", "🂣", "🂢")
private val DECK = arrayOf(HEARTS, SPADES, DIAMONDS, CLUBS)
// War command
private const val WAR_CMD = "war"
}
init {
commands.add(WAR_CMD)
help.add("To play war:")
help.add(helpFormat("%c $WAR_CMD"))
}
}

View file

@ -1,7 +1,7 @@
/*
* Weather2.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* WolframAlpha.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* WorldTime.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* ErrorMessage.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* Message.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -30,8 +30,6 @@
*/
package net.thauvin.erik.mobibot.msg
import net.thauvin.erik.semver.Constants
/**
* The `Message` class.
*/
@ -43,7 +41,7 @@ open class Message @JvmOverloads constructor(
var isPrivate: Boolean = false
) {
companion object {
var DEFAULT_COLOR = Constants.EMPTY
var DEFAULT_COLOR = ""
}
init {

View file

@ -1,7 +1,7 @@
/*
* NoticeMessage.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* PrivateMessage.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* PublicMessage.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* SocialManager.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* SocialModule.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* SocialTimer.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="warn">
<Appenders>
<Console name="stderr" target="SYSTEM_ERR">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
<Console name="input" target="SYSTEM_OUT">
<PatternLayout pattern="%d{UNIX_MILLIS} %msg%n"/>
<Filters>
<ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
</Console>
<Console name="output" target="SYSTEM_OUT">
<PatternLayout pattern="%d{UNIX_MILLIS} >>>%msg%n"/>
<Filters>
<ThresholdFilter level="warn" onMatch="DENY" onMismatch="NEUTRAL"/>
<ThresholdFilter level="debug" onMatch="ACCEPT" onMismatch="DENY"/>
</Filters>
</Console>
</Appenders>
<Loggers>
<Root level="warn" additivity="false">
<AppenderRef ref="stderr"/>
</Root>
<logger level="debug" name="org.pircbotx.InputParser" additivity="false">
<appender-ref ref="input"/>
<appender-ref ref="stderr" level="warn"/>
</logger>
<logger level="debug" name="org.pircbotx.output.OutputRaw" additivity="false">
<appender-ref ref="output"/>
<appender-ref ref="stderr" level="warn"/>
</logger>
<logger level="trace" name="net.thauvin.erik.mobibot" additivity="false">
<appender-ref ref="stderr"/>
</logger>
</Loggers>
</Configuration>

View file

@ -1,7 +1,7 @@
/*
* AddonsTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -42,8 +42,8 @@ import net.thauvin.erik.mobibot.commands.Ignore
import net.thauvin.erik.mobibot.commands.links.Comment
import net.thauvin.erik.mobibot.commands.links.View
import net.thauvin.erik.mobibot.modules.*
import org.testng.annotations.Test
import java.util.*
import kotlin.test.Test
class AddonsTest {
private val p = Properties().apply {

View file

@ -0,0 +1,44 @@
/*
* DisableOnCi.kt
*
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* 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.
*/
package net.thauvin.erik.mobibot
import org.junit.jupiter.api.extension.ExtendWith
/**
* Disables tests on CI annotation.
*
* @author [Erik C. Thauvin](https://erik.thauvin.net/)
* @since 1.0
*/
@Target(AnnotationTarget.TYPE, AnnotationTarget.FUNCTION)
@Retention(AnnotationRetention.RUNTIME)
@ExtendWith(DisableOnCiCondition::class)
annotation class DisabledOnCi

View file

@ -0,0 +1,51 @@
/*
* DisableOnCiCondition.kt
*
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* 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.
*/
package net.thauvin.erik.mobibot
import org.junit.jupiter.api.extension.ConditionEvaluationResult
import org.junit.jupiter.api.extension.ExecutionCondition
import org.junit.jupiter.api.extension.ExtensionContext
/**
* Disables tests on CI condition.
*
* @author [Erik C. Thauvin](https://erik.thauvin.net/)
* @since 1.0
*/
class DisableOnCiCondition : ExecutionCondition {
override fun evaluateExecutionCondition(context: ExtensionContext): ConditionEvaluationResult {
return if (System.getenv("CI") != null) {
ConditionEvaluationResult.disabled("Test disabled on CI")
} else {
ConditionEvaluationResult.enabled("Test enabled")
}
}
}

View file

@ -1,7 +1,7 @@
/*
* ExceptionSanitizer.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:

View file

@ -1,7 +1,7 @@
/*
* FeedReaderTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -37,10 +37,10 @@ import assertk.assertions.*
import com.rometools.rome.io.FeedException
import net.thauvin.erik.mobibot.FeedReader.Companion.readFeed
import net.thauvin.erik.mobibot.msg.Message
import org.testng.annotations.Test
import java.io.IOException
import java.net.MalformedURLException
import java.net.UnknownHostException
import kotlin.test.Test
/**
* The `FeedReader Test` class.

View file

@ -1,7 +1,7 @@
/*
* LocalProperties.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -30,7 +30,6 @@
*/
package net.thauvin.erik.mobibot
import org.testng.annotations.BeforeSuite
import java.io.IOException
import java.net.InetAddress
import java.net.UnknownHostException
@ -42,8 +41,7 @@ import java.util.*
* Access to `local.properties`.
*/
open class LocalProperties {
@BeforeSuite(alwaysRun = true)
fun loadProperties() {
init {
val localPath = Paths.get("local.properties")
if (Files.exists(localPath)) {
try {

View file

@ -1,7 +1,7 @@
/*
* PinboardTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -34,10 +34,10 @@ package net.thauvin.erik.mobibot
import net.thauvin.erik.mobibot.Utils.encodeUrl
import net.thauvin.erik.mobibot.Utils.reader
import net.thauvin.erik.mobibot.entries.EntryLink
import org.testng.Assert.assertFalse
import org.testng.Assert.assertTrue
import org.testng.annotations.Test
import java.net.URL
import kotlin.test.Test
import kotlin.test.assertFalse
import kotlin.test.assertTrue
class PinboardTest : LocalProperties() {
private val pinboard = Pinboard()

View file

@ -1,7 +1,7 @@
/*
* UtilsTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -59,14 +59,14 @@ import net.thauvin.erik.mobibot.Utils.today
import net.thauvin.erik.mobibot.Utils.underline
import net.thauvin.erik.mobibot.Utils.unescapeXml
import net.thauvin.erik.mobibot.msg.Message.Companion.DEFAULT_COLOR
import org.junit.jupiter.api.BeforeEach
import org.pircbotx.Colors
import org.testng.annotations.BeforeClass
import org.testng.annotations.Test
import java.io.File
import java.io.IOException
import java.net.URL
import java.time.LocalDateTime
import java.util.*
import kotlin.test.Test
/**
* The `Utils Test` class.
@ -78,7 +78,7 @@ class UtilsTest {
private val localDateTime = LocalDateTime.of(1952, 2, 17, 12, 30, 0)
private val test = "This is a test."
@BeforeClass
@BeforeEach
fun setUp() {
cal[1952, Calendar.FEBRUARY, 17, 12, 30] = 0
}

View file

@ -1,7 +1,7 @@
/*
* InfoTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -34,10 +34,10 @@ package net.thauvin.erik.mobibot.commands
import assertk.assertThat
import assertk.assertions.isEqualTo
import net.thauvin.erik.mobibot.commands.Info.Companion.toUptime
import org.testng.annotations.Test
import kotlin.test.Test
class InfoTest {
@Test(groups = ["commands"])
@Test
fun testToUptime() {
assertThat(
547800300076L.toUptime(),

View file

@ -1,7 +1,7 @@
/*
* RecapTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -37,10 +37,10 @@ import assertk.assertions.isEqualTo
import assertk.assertions.matches
import assertk.assertions.prop
import assertk.assertions.size
import org.testng.annotations.Test
import kotlin.test.Test
class RecapTest {
@Test(groups = ["commands"])
@Test
fun storeRecapTest() {
for (i in 1..20) {
Recap.storeRecap("sender$i", "test $i", false)

View file

@ -1,7 +1,7 @@
/*
* LinksManagerTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -38,12 +38,12 @@ import assertk.assertions.isEqualTo
import assertk.assertions.isTrue
import assertk.assertions.size
import net.thauvin.erik.mobibot.Constants
import org.testng.annotations.Test
import kotlin.test.Test
class LinksManagerTest {
private val linksManager = LinksManager()
@Test(groups = ["commands", "links"])
@Test
fun fetchTitle() {
assertThat(linksManager.fetchTitle("https://erik.thauvin.net/"), "fetchTitle(Erik)").contains("Erik's Weblog")
assertThat(
@ -52,13 +52,13 @@ class LinksManagerTest {
).isEqualTo(Constants.NO_TITLE)
}
@Test(groups = ["commands", "links"])
@Test
fun testMatches() {
assertThat(linksManager.matches("https://www.example.com/"), "matches(url)").isTrue()
assertThat(linksManager.matches("HTTP://erik.thauvin.net/blog/ Erik's Weblog"), "matches(HTTP)").isTrue()
}
@Test(groups = ["commands", "links"])
@Test
fun matchTagKeywordsTest() {
linksManager.setProperty(LinksManager.KEYWORDS_PROP, "key1 key2,key3")
val tags = mutableListOf<String>()

View file

@ -1,7 +1,7 @@
/*
* ViewTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -36,10 +36,10 @@ import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.prop
import net.thauvin.erik.mobibot.entries.EntryLink
import org.testng.annotations.Test
import kotlin.test.Test
class ViewTest {
@Test(groups = ["commands", "links"])
@Test
fun testParseArgs() {
val view = View()

View file

@ -1,7 +1,7 @@
/*
* SeenTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -34,29 +34,16 @@ package net.thauvin.erik.mobibot.commands.seen
import assertk.all
import assertk.assertThat
import assertk.assertions.*
import org.testng.annotations.AfterClass
import org.testng.annotations.BeforeClass
import org.testng.annotations.Test
import org.junit.AfterClass
import org.junit.BeforeClass
import org.junit.jupiter.api.Order
import kotlin.io.path.deleteIfExists
import kotlin.io.path.fileSize
import kotlin.test.Test
class SeenTest {
private val tmpFile = kotlin.io.path.createTempFile(suffix = ".ser")
private val seen = Seen(tmpFile.toAbsolutePath().toString())
private val nick = "ErikT"
@BeforeClass
fun saveTest() {
seen.add("ErikT")
assertThat(tmpFile.fileSize(), "tmpFile.size").isGreaterThan(0)
}
@AfterClass(alwaysRun = true)
fun afterClass() {
tmpFile.deleteIfExists()
}
@Test(priority = 1, groups = ["commands"])
@Test
@Order(1)
fun loadTest() {
seen.clear()
assertThat(seen::seenNicks).isEmpty()
@ -64,7 +51,8 @@ class SeenTest {
assertThat(seen::seenNicks).key(nick).isNotNull()
}
@Test(groups = ["commands"])
@Test
@Order(2)
fun addTest() {
val last = seen.seenNicks[nick]?.lastSeen
seen.add(nick.lowercase())
@ -75,11 +63,31 @@ class SeenTest {
}
}
@Test(priority = 10, groups = ["commands"])
@Test
@Order(3)
fun clearTest() {
seen.clear()
seen.save()
seen.load()
assertThat(seen::seenNicks).size().isEqualTo(0)
}
companion object {
private val tmpFile = kotlin.io.path.createTempFile(suffix = ".ser")
private val seen = Seen(tmpFile.toAbsolutePath().toString())
private const val nick = "ErikT"
@JvmStatic
@BeforeClass
fun beforeClass() {
seen.add(nick)
assertThat(tmpFile.fileSize(), "tmpFile.size").isGreaterThan(0)
}
@JvmStatic
@AfterClass
fun afterClass() {
tmpFile.deleteIfExists()
}
}
}

View file

@ -1,7 +1,7 @@
/*
* TellMessageTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -36,10 +36,10 @@ import assertk.assertions.isEqualTo
import assertk.assertions.isFalse
import assertk.assertions.isTrue
import assertk.assertions.prop
import org.testng.annotations.Test
import java.time.Duration
import java.time.LocalDateTime
import java.time.temporal.Temporal
import kotlin.test.Test
/**
* The `TellMessageTest` class.
@ -49,7 +49,7 @@ class TellMessageTest {
return Duration.between(date, LocalDateTime.now()).toMinutes() < 1
}
@Test(groups = ["commands", "tell"])
@Test
fun testTellMessage() {
val message = "Test message."
val recipient = "recipient"

View file

@ -1,7 +1,7 @@
/*
* TellMessagesMgrTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -34,16 +34,14 @@ package net.thauvin.erik.mobibot.commands.tell
import assertk.all
import assertk.assertThat
import assertk.assertions.*
import org.testng.annotations.AfterClass
import org.testng.annotations.BeforeClass
import org.testng.annotations.Test
import org.junit.AfterClass
import java.time.LocalDateTime
import kotlin.io.path.createTempFile
import kotlin.io.path.deleteIfExists
import kotlin.io.path.fileSize
import kotlin.test.Test
class TellMessagesMgrTest {
private val testFile = createTempFile(suffix = ".ser")
private val maxDays = 10L
private val testMessages = mutableListOf<TellMessage>().apply {
for (i in 0..5) {
@ -51,18 +49,12 @@ class TellMessagesMgrTest {
}
}
@BeforeClass
fun saveTest() {
init {
TellManager.save(testFile.toAbsolutePath().toString(), testMessages)
assertThat(testFile.fileSize()).isGreaterThan(0)
}
@AfterClass
fun afterClass() {
testFile.deleteIfExists()
}
@Test(groups = ["commands", "tell"])
@Test
fun cleanTest() {
testMessages.add(TellMessage("sender", "recipient", "message").apply {
queued = LocalDateTime.now().minusDays(maxDays)
@ -73,7 +65,7 @@ class TellMessagesMgrTest {
assertThat(testMessages, "testMessages").size().isEqualTo(size - 1)
}
@Test(groups = ["commands", "tell"])
@Test
fun loadTest() {
val messages = TellManager.load(testFile.toAbsolutePath().toString())
for (i in messages.indices) {
@ -84,4 +76,14 @@ class TellMessagesMgrTest {
}
}
}
companion object {
private val testFile = createTempFile(suffix = ".ser")
@JvmStatic
@AfterClass
fun afterClass() {
testFile.deleteIfExists()
}
}
}

View file

@ -1,7 +1,7 @@
/*
* EntriesUtilsTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -39,7 +39,7 @@ import net.thauvin.erik.mobibot.entries.EntriesUtils.printComment
import net.thauvin.erik.mobibot.entries.EntriesUtils.printLink
import net.thauvin.erik.mobibot.entries.EntriesUtils.printTags
import net.thauvin.erik.mobibot.entries.EntriesUtils.toLinkLabel
import org.testng.annotations.Test
import kotlin.test.Test
class EntriesUtilsTest {
private val comment = EntryComment("comment", "nick")
@ -58,12 +58,12 @@ class EntriesUtilsTest {
}
}
@Test(groups = ["entries"])
@Test
fun printCommentTest() {
assertThat(printComment(0, 0, comment)).isEqualTo("${Constants.LINK_CMD}1.1: [nick] comment")
}
@Test(groups = ["entries"])
@Test
fun printLinkTest() {
for (i in links.indices) {
assertThat(
@ -75,7 +75,7 @@ class EntriesUtilsTest {
assertThat(printLink(0, links.first(), isView = true), "printLink(isView=true)").contains("[+1]")
}
@Test(groups = ["entries"])
@Test
fun printTagsTest() {
for (i in links.indices) {
assertThat(
@ -84,7 +84,7 @@ class EntriesUtilsTest {
}
}
@Test(groups = ["entries"])
@Test
fun toLinkLabelTest() {
assertThat(1.toLinkLabel()).isEqualTo("${Constants.LINK_CMD}2")
}

View file

@ -1,7 +1,7 @@
/*
* EntryLinkTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -35,9 +35,9 @@ import assertk.assertThat
import assertk.assertions.*
import com.rometools.rome.feed.synd.SyndCategory
import com.rometools.rome.feed.synd.SyndCategoryImpl
import org.testng.annotations.Test
import java.security.SecureRandom
import java.util.*
import kotlin.test.Test
/**
* The `EntryUtilsTest` class.
@ -52,7 +52,7 @@ class EntryLinkTest {
listOf("tag1", "tag2", "tag3", "TAG4", "Tag5")
)
@Test(groups = ["entries"])
@Test
fun testAddDeleteComment() {
var i = 0
while (i < 5) {
@ -85,7 +85,7 @@ class EntryLinkTest {
assertThat(entryLink.deleteComment(comment), "comment is already deleted").isFalse()
}
@Test(groups = ["entries"])
@Test
fun testConstructor() {
val tags = listOf(SyndCategoryImpl().apply { name = "tag1" }, SyndCategoryImpl().apply { name = "tag2" })
val link = EntryLink("link", "title", "nick", "channel", Date(), tags)
@ -95,7 +95,7 @@ class EntryLinkTest {
}
}
@Test(groups = ["entries"])
@Test
fun testMatches() {
assertThat(entryLink.matches("mobitopia"), "matches(mobitopia)").isTrue()
assertThat(entryLink.matches("skynx"), "match(nick)").isTrue()
@ -106,7 +106,7 @@ class EntryLinkTest {
}
@Test(groups = ["entries"])
@Test
fun testTags() {
val tags: List<SyndCategory> = entryLink.tags
for ((i, tag) in tags.withIndex()) {

View file

@ -1,7 +1,7 @@
/*
* FeedMgrTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -35,27 +35,25 @@ import assertk.all
import assertk.assertThat
import assertk.assertions.*
import net.thauvin.erik.mobibot.Utils.today
import org.testng.annotations.BeforeSuite
import org.testng.annotations.Test
import java.nio.file.Paths
import java.util.*
import kotlin.io.path.deleteIfExists
import kotlin.io.path.fileSize
import kotlin.io.path.name
import kotlin.test.Test
class FeedMgrTest {
private val entries = Entries()
private val channel = "mobibot"
@BeforeSuite(alwaysRun = true)
fun beforeSuite() {
init {
entries.logsDir = "src/test/resources/"
entries.ircServer = "irc.example.com"
entries.channel = channel
entries.backlogs = "https://www.mobitopia.org/mobibot/logs"
}
@Test(groups = ["entries"])
@Test
fun testFeedMgr() {
// Load the feed
assertThat(FeedsManager.loadFeed(entries), "loadFeed()").isEqualTo("2021-10-31")

View file

@ -1,7 +1,7 @@
/*
* CalcTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -37,13 +37,13 @@ import assertk.assertions.isInstanceOf
import net.objecthunter.exp4j.tokenizer.UnknownFunctionOrVariableException
import net.thauvin.erik.mobibot.Utils.bold
import net.thauvin.erik.mobibot.modules.Calc.Companion.calculate
import org.testng.annotations.Test
import kotlin.test.Test
/**
* The `CalcTest` class.
*/
class CalcTest {
@Test(groups = ["modules"])
@Test
fun testCalculate() {
assertThat(calculate("1 + 1"), "calculate(1+1)").isEqualTo("1+1 = ${2.bold()}")
assertThat(calculate("1 -3"), "calculate(1-3)").isEqualTo("1-3 = ${(-2).bold()}")

View file

@ -1,7 +1,7 @@
/*
* ChatGptTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -35,18 +35,20 @@ import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.hasNoCause
import assertk.assertions.isInstanceOf
import net.thauvin.erik.mobibot.DisabledOnCi
import net.thauvin.erik.mobibot.LocalProperties
import org.testng.annotations.Test
import kotlin.test.Test
class ChatGptTest : LocalProperties() {
@Test(groups = ["modules"])
@Test
fun testApiKey() {
assertFailure { ChatGpt.chat("1 gallon to liter", "", 0) }
.isInstanceOf(ModuleException::class.java)
.hasNoCause()
}
@Test(groups = ["modules", "no-ci"])
@Test
@DisabledOnCi
fun testChat() {
val apiKey = getProperty(ChatGpt.API_KEY_PROP)
assertThat(

View file

@ -1,7 +1,7 @@
/*
* CryptoPricesTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -39,20 +39,17 @@ import net.thauvin.erik.crypto.CryptoPrice
import net.thauvin.erik.mobibot.modules.CryptoPrices.Companion.currentPrice
import net.thauvin.erik.mobibot.modules.CryptoPrices.Companion.getCurrencyName
import net.thauvin.erik.mobibot.modules.CryptoPrices.Companion.loadCurrencies
import org.testng.annotations.BeforeClass
import org.testng.annotations.Test
import kotlin.test.Test
/**
* The `CryptoPricesTest` class.
*/
class CryptoPricesTest {
@BeforeClass
@Throws(ModuleException::class)
fun before() {
init {
loadCurrencies()
}
@Test(groups = ["modules"])
@Test
@Throws(ModuleException::class)
fun testMarketPrice() {
var price = currentPrice(listOf("BTC"))
@ -70,7 +67,7 @@ class CryptoPricesTest {
}
}
@Test(groups = ["modules"])
@Test
fun testGetCurrencyName() {
assertThat(getCurrencyName("USD"), "USD").isEqualTo("United States Dollar")
assertThat(getCurrencyName("EUR"), "EUR").isEqualTo("Euro")

View file

@ -1,7 +1,7 @@
/*
* CurrencyConverterTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -42,23 +42,19 @@ import net.thauvin.erik.mobibot.modules.CurrencyConverter.Companion.loadSymbols
import net.thauvin.erik.mobibot.msg.ErrorMessage
import net.thauvin.erik.mobibot.msg.Message
import net.thauvin.erik.mobibot.msg.PublicMessage
import org.testng.annotations.BeforeClass
import org.testng.annotations.Test
import kotlin.test.Test
/**
* The `CurrencyConvertTest` class.
*/
class CurrencyConverterTest : LocalProperties() {
@BeforeClass
@Throws(ModuleException::class)
fun before() {
init {
val apiKey = getProperty(CurrencyConverter.API_KEY_PROP)
loadSymbols(apiKey)
}
@Test(groups = ["modules"])
@Test
fun testConvertCurrency() {
val apiKey = getProperty(CurrencyConverter.API_KEY_PROP)
assertThat(

View file

@ -1,7 +1,7 @@
/*
* DiceTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -35,10 +35,10 @@ package net.thauvin.erik.mobibot.modules
import assertk.assertThat
import assertk.assertions.isEqualTo
import assertk.assertions.matches
import org.testng.annotations.Test
import kotlin.test.Test
class DiceTest {
@Test(groups = ["modules"])
@Test
fun testRoll() {
assertThat(Dice.roll(1, 1), "roll(1d1)").isEqualTo("\u00021\u0002")
assertThat(Dice.roll(2, 1), "roll(2d1)")

View file

@ -1,7 +1,7 @@
/*
* GoogleSearchTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -34,18 +34,19 @@ import assertk.all
import assertk.assertFailure
import assertk.assertThat
import assertk.assertions.*
import net.thauvin.erik.mobibot.DisabledOnCi
import net.thauvin.erik.mobibot.ExceptionSanitizer.sanitize
import net.thauvin.erik.mobibot.LocalProperties
import net.thauvin.erik.mobibot.modules.GoogleSearch.Companion.searchGoogle
import net.thauvin.erik.mobibot.msg.ErrorMessage
import net.thauvin.erik.mobibot.msg.Message
import org.testng.annotations.Test
import kotlin.test.Test
/**
* The `GoogleSearchTest` class.
*/
class GoogleSearchTest : LocalProperties() {
@Test(groups = ["modules"])
@Test
fun testAPIKeys() {
assertThat(
searchGoogle("", "apikey", "cssKey").first(),
@ -63,7 +64,8 @@ class GoogleSearchTest : LocalProperties() {
.hasMessage("API key not valid. Please pass a valid API key.")
}
@Test(groups = ["no-ci", "modules"])
@Test
@DisabledOnCi
@Throws(ModuleException::class)
fun testSearchGoogle() {
val apiKey = getProperty(GoogleSearch.API_KEY_PROP)

View file

@ -1,7 +1,7 @@
/*
* JokeTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -36,13 +36,13 @@ import assertk.assertions.*
import net.thauvin.erik.mobibot.modules.Joke.Companion.randomJoke
import net.thauvin.erik.mobibot.msg.Message
import net.thauvin.erik.mobibot.msg.PublicMessage
import org.testng.annotations.Test
import kotlin.test.Test
/**
* The `JokeTest` class.
*/
class JokeTest {
@Test(groups = ["modules"])
@Test
@Throws(ModuleException::class)
fun testRandomJoke() {
val joke = randomJoke()

View file

@ -1,7 +1,7 @@
/*
* LookupTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -35,13 +35,13 @@ import assertk.assertions.any
import assertk.assertions.contains
import net.thauvin.erik.mobibot.modules.Lookup.Companion.nslookup
import net.thauvin.erik.mobibot.modules.Lookup.Companion.whois
import org.testng.annotations.Test
import kotlin.test.Test
/**
* The `Lookup Test` class.
*/
class LookupTest {
@Test(groups = ["modules"])
@Test
@Throws(Exception::class)
fun testLookup() {
var result = nslookup("apple.com")
@ -51,7 +51,7 @@ class LookupTest {
assertThat(result, "lookup(204.122.16.136)").contains("nix3.thauvin.us")
}
@Test(groups = ["modules"])
@Test
@Throws(Exception::class)
fun testWhois() {
val result = whois("17.178.96.59", Lookup.WHOIS_HOST)

View file

@ -1,7 +1,7 @@
/*
* MastodonTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -34,10 +34,10 @@ import assertk.assertThat
import assertk.assertions.contains
import net.thauvin.erik.mobibot.LocalProperties
import net.thauvin.erik.mobibot.modules.Mastodon.Companion.toot
import org.testng.annotations.Test
import kotlin.test.Test
class MastodonTest : LocalProperties() {
@Test(groups = ["modules"])
@Test
@Throws(ModuleException::class)
fun testToot() {
val msg = "Testing Mastodon API from ${getHostName()}"

View file

@ -1,7 +1,7 @@
/*
* ModuleExceptionTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -34,10 +34,10 @@ import assertk.all
import assertk.assertThat
import assertk.assertions.*
import net.thauvin.erik.mobibot.ExceptionSanitizer.sanitize
import org.testng.annotations.DataProvider
import org.testng.annotations.Test
import org.junit.jupiter.params.ParameterizedTest
import org.junit.jupiter.params.provider.MethodSource
import java.io.IOException
import java.lang.reflect.Method
import kotlin.test.Test
/**
* The `ModuleExceptionTest` class.
@ -46,28 +46,30 @@ class ModuleExceptionTest {
companion object {
const val DEBUG_MESSAGE = "debugMessage"
const val MESSAGE = "message"
@JvmStatic
fun dataProviders(): List<ModuleException> {
return listOf(
ModuleException(DEBUG_MESSAGE, MESSAGE, IOException("URL http://foobar.com")),
ModuleException(DEBUG_MESSAGE, MESSAGE, IOException("URL http://foobar.com?")),
ModuleException(DEBUG_MESSAGE, MESSAGE)
)
}
}
@DataProvider(name = "dp")
fun createData(@Suppress("UNUSED_PARAMETER") m: Method?): Array<Array<Any>> {
return arrayOf(
arrayOf(ModuleException(DEBUG_MESSAGE, MESSAGE, IOException("URL http://foobar.com"))),
arrayOf(ModuleException(DEBUG_MESSAGE, MESSAGE, IOException("URL http://foobar.com?"))),
arrayOf(ModuleException(DEBUG_MESSAGE, MESSAGE))
)
}
@Test(dataProvider = "dp")
@ParameterizedTest
@MethodSource("dataProviders")
fun testGetDebugMessage(e: ModuleException) {
assertThat(e::debugMessage).isEqualTo(DEBUG_MESSAGE)
}
@Test(dataProvider = "dp")
@ParameterizedTest
@MethodSource("dataProviders")
fun testGetMessage(e: ModuleException) {
assertThat(e).hasMessage(MESSAGE)
}
@Test(groups = ["modules"])
@Test
fun testSanitizeMessage() {
val apiKey = "1234567890"
var e = ModuleException(DEBUG_MESSAGE, MESSAGE, IOException("URL http://foo.com?apiKey=$apiKey&userID=me"))

View file

@ -1,7 +1,7 @@
/*
* PingTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -34,18 +34,18 @@ import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.isNotEmpty
import net.thauvin.erik.mobibot.modules.Ping.Companion.randomPing
import org.testng.annotations.Test
import kotlin.test.Test
/**
* The `PingTest` class.
*/
class PingTest {
@Test(groups = ["modules"])
@Test
fun testPingsArray() {
assertThat(Ping.PINGS, "Ping.PINGS").isNotEmpty()
}
@Test(groups = ["modules"])
@Test
fun testRandomPing() {
for (i in 0..9) {
assertThat(Ping.PINGS, "Ping.PINGS[$i]").contains(randomPing())

View file

@ -1,7 +1,7 @@
/*
* RockPaperScissorsTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -34,10 +34,10 @@ package net.thauvin.erik.mobibot.modules
import assertk.assertThat
import assertk.assertions.isEqualTo
import net.thauvin.erik.mobibot.modules.RockPaperScissors.Companion.winLoseOrDraw
import org.testng.annotations.Test
import kotlin.test.Test
class RockPaperScissorsTest {
@Test(groups = ["modules"])
@Test
fun testWinLoseOrDraw() {
assertThat(winLoseOrDraw("scissors", "paper"), "scissors vs. paper").isEqualTo("win")
assertThat(winLoseOrDraw("paper", "rock"), "paper vs. rock").isEqualTo("win")

View file

@ -1,7 +1,7 @@
/*
* StockQuoteTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -39,7 +39,7 @@ import net.thauvin.erik.mobibot.LocalProperties
import net.thauvin.erik.mobibot.modules.StockQuote.Companion.getQuote
import net.thauvin.erik.mobibot.msg.ErrorMessage
import net.thauvin.erik.mobibot.msg.Message
import org.testng.annotations.Test
import kotlin.test.Test
/**
* The `StockQuoteTest` class.
@ -49,7 +49,7 @@ class StockQuoteTest : LocalProperties() {
return "${label}:[ ]+[0-9.]+".prependIndent()
}
@Test(groups = ["modules"])
@Test
@Throws(ModuleException::class)
fun testGetQuote() {
val apiKey = getProperty(StockQuote.API_KEY_PROP)

View file

@ -1,7 +1,7 @@
/*
* Weather2Test.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -43,19 +43,19 @@ import net.thauvin.erik.mobibot.modules.Weather2.Companion.getCountry
import net.thauvin.erik.mobibot.modules.Weather2.Companion.getWeather
import net.thauvin.erik.mobibot.modules.Weather2.Companion.mphToKmh
import net.thauvin.erik.mobibot.msg.Message
import org.testng.annotations.Test
import kotlin.test.Test
/**
* The `Weather2Test` class.
*/
class Weather2Test : LocalProperties() {
@Test(groups = ["modules"])
@Test
fun testFtoC() {
val t = ftoC(32.0)
assertThat(t.second, "32 °F is 0 °C").isEqualTo(0)
}
@Test(groups = ["modules"])
@Test
fun testGetCountry() {
assertThat(getCountry("foo"), "foo is not a valid country").isEqualTo(OWM.Country.UNITED_STATES)
assertThat(getCountry("fr"), "country should France").isEqualTo(OWM.Country.FRANCE)
@ -67,13 +67,13 @@ class Weather2Test : LocalProperties() {
}
}
@Test(groups = ["modules"])
@Test
fun testMphToKmh() {
val w = mphToKmh(0.62)
assertThat(w.second, "0.62 mph is 1 km/h").isEqualTo(1)
}
@Test(groups = ["modules"])
@Test
@Throws(ModuleException::class)
fun testWeather() {
var query = "98204"

View file

@ -1,7 +1,7 @@
/*
* WolframAlphaTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -36,13 +36,14 @@ import assertk.assertThat
import assertk.assertions.contains
import assertk.assertions.hasMessage
import assertk.assertions.isInstanceOf
import net.thauvin.erik.mobibot.DisabledOnCi
import net.thauvin.erik.mobibot.ExceptionSanitizer.sanitize
import net.thauvin.erik.mobibot.LocalProperties
import net.thauvin.erik.mobibot.modules.WolframAlpha.Companion.queryWolfram
import org.testng.annotations.Test
import kotlin.test.Test
class WolframAlphaTest : LocalProperties() {
@Test(groups = ["modules"])
@Test
fun testAppId() {
assertFailure { queryWolfram("1 gallon to liter", appId = "DEMO") }
.isInstanceOf(ModuleException::class.java)
@ -52,7 +53,8 @@ class WolframAlphaTest : LocalProperties() {
.isInstanceOf(ModuleException::class.java)
}
@Test(groups = ["modules", "no-ci"])
@Test
@DisabledOnCi
@Throws(ModuleException::class)
fun queryWolframTest() {
val apiKey = getProperty(WolframAlpha.APPID_KEY_PROP)

View file

@ -1,7 +1,7 @@
/*
* WordTimeTest.kt
*
* Copyright 2004-2023 Erik C. Thauvin (erik@thauvin.net)
* Copyright 2021-2023 Erik C. Thauvin (erik@thauvin.net)
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
@ -39,14 +39,14 @@ import net.thauvin.erik.mobibot.modules.WorldTime.Companion.BEATS_KEYWORD
import net.thauvin.erik.mobibot.modules.WorldTime.Companion.COUNTRIES_MAP
import net.thauvin.erik.mobibot.modules.WorldTime.Companion.time
import org.pircbotx.Colors
import org.testng.annotations.Test
import java.time.ZoneId
import kotlin.test.Test
/**
* The `WordTimeTest` class.
*/
class WordTimeTest {
@Test(groups = ["modules"])
@Test
fun testTime() {
assertThat(time(), "time()").matches(
("The time is ${Colors.BOLD}\\d{1,2}:\\d{2}${Colors.BOLD} " +
@ -61,7 +61,7 @@ class WordTimeTest {
assertThat(time("BEAT"), "time($BEATS_KEYWORD)").matches("[\\w ]+ .?@\\d{3}+.? .beats".toRegex())
}
@Test(groups = ["modules"])
@Test
fun testZones() {
COUNTRIES_MAP.filter { it.value != BEATS_KEYWORD }.forEach {
assertThat(ZoneId.of(it.value))

Some files were not shown because too many files have changed in this diff Show more