diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Joke.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Joke.kt index c2f15b4..bc89d75 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Joke.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Joke.kt @@ -63,7 +63,7 @@ class Joke : ThreadedModule() { } /** - * Returns a random joke from [The Internet Chuck Norris Database](http://www.icndb.com/). + * Returns a random joke from [Geek-Jokes](https://geek-jokes.sameerkumar.website/). */ override fun run(channel: String, cmd: String, args: String, event: GenericMessageEvent) { with(event.bot()) { @@ -84,7 +84,7 @@ class Joke : ThreadedModule() { // ICNDB URL private const val JOKE_URL = - "http://api.icndb.com/jokes/random?escape=javascript&exclude=[explicit]&limitTo=[nerdy]" + "https://geek-jokes.sameerkumar.website/api?format=json" /** * Retrieves a random joke. @@ -94,11 +94,8 @@ class Joke : ThreadedModule() { fun randomJoke(): Message { return try { val url = URL(JOKE_URL) - val json = JSONObject(url.reader()) - PublicMessage( - json.getJSONObject("value")["joke"].toString().replace("\\'", "'") - .replace("\\\"", "\"") - ) + val json = JSONObject(url.reader().body) + PublicMessage(json.getString("joke")) } catch (e: IOException) { throw ModuleException("randomJoke(): IOE", "An IO error has occurred retrieving a random joke.", e) } catch (e: JSONException) { diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/JokeTest.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/JokeTest.kt index 0aea63e..56355a8 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/JokeTest.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/JokeTest.kt @@ -33,7 +33,7 @@ package net.thauvin.erik.mobibot.modules import assertk.all import assertk.assertThat -import assertk.assertions.contains +import assertk.assertions.endsWith import assertk.assertions.isNotEmpty import net.thauvin.erik.mobibot.modules.Joke.Companion.randomJoke import org.testng.annotations.Test @@ -47,7 +47,7 @@ class JokeTest { fun testRandomJoke() { assertThat(randomJoke().msg, "randomJoke() > 0").all { isNotEmpty() - contains("chuck", true) + endsWith(".") } } } diff --git a/website/index.html b/website/index.html index 8b9831f..8637767 100644 --- a/website/index.html +++ b/website/index.html @@ -112,7 +112,7 @@
  • Viewing when a nickname was last seen
    /msg mobibot seen nickname
  • -
  • Random jokes from The Internet Chuck Norris Database +
  • Random jokes from Geek-Jokes
    mobibot: joke
  • Rolling dice or Playing war and rock paper scissors