Moved to Geek-Jokes
This commit is contained in:
parent
951fdaa5f7
commit
94dc07fb4f
3 changed files with 7 additions and 10 deletions
|
@ -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) {
|
||||
|
|
|
@ -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(".")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -112,7 +112,7 @@
|
|||
<li>Viewing when a nickname was last seen
|
||||
<div><code>/msg mobibot seen nickname</code></div>
|
||||
</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>
|
||||
</li>
|
||||
<li>Rolling dice or Playing war and rock paper scissors
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue