Moved to Geek-Jokes

This commit is contained in:
Erik C. Thauvin 2022-09-18 23:32:55 -07:00
parent 951fdaa5f7
commit 94dc07fb4f
3 changed files with 7 additions and 10 deletions

View file

@ -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) { override fun run(channel: String, cmd: String, args: String, event: GenericMessageEvent) {
with(event.bot()) { with(event.bot()) {
@ -84,7 +84,7 @@ class Joke : ThreadedModule() {
// ICNDB URL // ICNDB URL
private const val JOKE_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. * Retrieves a random joke.
@ -94,11 +94,8 @@ class Joke : ThreadedModule() {
fun randomJoke(): Message { fun randomJoke(): Message {
return try { return try {
val url = URL(JOKE_URL) val url = URL(JOKE_URL)
val json = JSONObject(url.reader()) val json = JSONObject(url.reader().body)
PublicMessage( PublicMessage(json.getString("joke"))
json.getJSONObject("value")["joke"].toString().replace("\\'", "'")
.replace("\\\"", "\"")
)
} catch (e: IOException) { } catch (e: IOException) {
throw ModuleException("randomJoke(): IOE", "An IO error has occurred retrieving a random joke.", e) throw ModuleException("randomJoke(): IOE", "An IO error has occurred retrieving a random joke.", e)
} catch (e: JSONException) { } catch (e: JSONException) {

View file

@ -33,7 +33,7 @@ package net.thauvin.erik.mobibot.modules
import assertk.all import assertk.all
import assertk.assertThat import assertk.assertThat
import assertk.assertions.contains import assertk.assertions.endsWith
import assertk.assertions.isNotEmpty import assertk.assertions.isNotEmpty
import net.thauvin.erik.mobibot.modules.Joke.Companion.randomJoke import net.thauvin.erik.mobibot.modules.Joke.Companion.randomJoke
import org.testng.annotations.Test import org.testng.annotations.Test
@ -47,7 +47,7 @@ class JokeTest {
fun testRandomJoke() { fun testRandomJoke() {
assertThat(randomJoke().msg, "randomJoke() > 0").all { assertThat(randomJoke().msg, "randomJoke() > 0").all {
isNotEmpty() isNotEmpty()
contains("chuck", true) endsWith(".")
} }
} }
} }

View file

@ -112,7 +112,7 @@
<li>Viewing when a nickname was last seen <li>Viewing when a nickname was last seen
<div><code>/msg mobibot seen nickname</code></div> <div><code>/msg mobibot seen nickname</code></div>
</li> </li>
<li>Random jokes from <a href="http://www.icndb.com/">The Internet Chuck Norris Database</a> <li>Random jokes from <a href="https://geek-jokes.sameerkumar.website/">Geek-Jokes</a>
<div><code>mobibot: joke</code></div> <div><code>mobibot: joke</code></div>
</li> </li>
<li>Rolling dice or Playing war and rock paper scissors <li>Rolling dice or Playing war and rock paper scissors