Removed twitter module
This commit is contained in:
parent
c2c5f8beae
commit
207c1b7e02
29 changed files with 360 additions and 416 deletions
|
@ -59,6 +59,12 @@ object Constants {
|
|||
*/
|
||||
const val CLI_CMD = "java -jar ${ReleaseInfo.PROJECT}.jar"
|
||||
|
||||
/**
|
||||
* User-Agent
|
||||
*/
|
||||
const val USER_AGENT =
|
||||
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36"
|
||||
|
||||
/**
|
||||
* The help command.
|
||||
*/
|
||||
|
|
|
@ -74,7 +74,7 @@ class FeedReader(private val url: String, val event: GenericMessageEvent) : Runn
|
|||
fun readFeed(url: String, maxItems: Int = 5): List<Message> {
|
||||
val messages = mutableListOf<Message>()
|
||||
val input = SyndFeedInput()
|
||||
XmlReader(URL(url)).use { reader ->
|
||||
XmlReader(URL(url).openStream()).use { reader ->
|
||||
val feed = input.build(reader)
|
||||
val items = feed.entries
|
||||
if (items.isEmpty()) {
|
||||
|
|
|
@ -78,7 +78,6 @@ import net.thauvin.erik.mobibot.modules.Mastodon
|
|||
import net.thauvin.erik.mobibot.modules.Ping
|
||||
import net.thauvin.erik.mobibot.modules.RockPaperScissors
|
||||
import net.thauvin.erik.mobibot.modules.StockQuote
|
||||
import net.thauvin.erik.mobibot.modules.Twitter
|
||||
import net.thauvin.erik.mobibot.modules.War
|
||||
import net.thauvin.erik.mobibot.modules.Weather2
|
||||
import net.thauvin.erik.mobibot.modules.WolframAlpha
|
||||
|
@ -438,7 +437,7 @@ class Mobibot(nickname: String, val channel: String, logsDirPath: String, p: Pro
|
|||
addons.add(View())
|
||||
|
||||
// Load social modules
|
||||
LinksManager.socialManager.add(addons, Twitter(), Mastodon())
|
||||
LinksManager.socialManager.add(addons, Mastodon())
|
||||
|
||||
// Load the modules
|
||||
addons.add(Calc())
|
||||
|
|
|
@ -1,118 +0,0 @@
|
|||
/*
|
||||
* TwitterOAuth.kt
|
||||
*
|
||||
* 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
|
||||
|
||||
import twitter4j.AccessToken
|
||||
import twitter4j.OAuthAuthorization
|
||||
import twitter4j.TwitterException
|
||||
import java.io.BufferedReader
|
||||
import java.io.IOException
|
||||
import java.io.InputStreamReader
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
|
||||
/**
|
||||
* The `TwitterOAuth` class.
|
||||
*
|
||||
* Go to [https://developer.twitter.com/en/apps](https://developer.twitter.com/en/apps) to register your bot.
|
||||
*
|
||||
* Then execute:
|
||||
*
|
||||
* `java -cp mobibot.jar net.thauvin.erik.mobibot.TwitterOAuth <consumerKey> <consumerSecret>`
|
||||
*
|
||||
* and follow the prompts/instructions.
|
||||
*
|
||||
* @author [Erik C. Thauvin](https://erik.thauvin.net)
|
||||
* @author [Yusuke Yamamoto](https://github.com/Twitter4J/Twitter4J/blob/main/twitter4j-examples/src/main/java/examples/oauth/GetAccessToken.java)
|
||||
*/
|
||||
object TwitterOAuth {
|
||||
/**
|
||||
* Twitter OAuth Client Registration.
|
||||
*
|
||||
* @param args The consumerKey and consumerSecret should be passed as arguments.
|
||||
*/
|
||||
@JvmStatic
|
||||
fun main(args: Array<String>) {
|
||||
if (args.size == 2) {
|
||||
try {
|
||||
val oAuthAuthorization = OAuthAuthorization.getInstance(args[0], args[1])
|
||||
val requestToken = oAuthAuthorization.oAuthRequestToken
|
||||
var accessToken: AccessToken? = null
|
||||
val br = BufferedReader(InputStreamReader(System.`in`))
|
||||
while (null == accessToken) {
|
||||
print(
|
||||
"""
|
||||
Open the following URL and grant access to your account:
|
||||
|
||||
${requestToken.authorizationURL}
|
||||
|
||||
Enter the PIN (if available) or just hit enter. [PIN]: """.trimIndent()
|
||||
)
|
||||
val pin = br.readLine()
|
||||
try {
|
||||
accessToken = if (!pin.isNullOrEmpty()) {
|
||||
oAuthAuthorization.getOAuthAccessToken(requestToken, pin)
|
||||
} else {
|
||||
oAuthAuthorization.getOAuthAccessToken(requestToken)
|
||||
}
|
||||
} catch (te: TwitterException) {
|
||||
if (401 == te.statusCode) {
|
||||
println("Unable to get the access token.")
|
||||
} else {
|
||||
te.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
println(
|
||||
"""
|
||||
Please add the following to the bot's property file:
|
||||
|
||||
twitter-consumerKey=${args[0]}
|
||||
twitter-consumerSecret=${args[1]}
|
||||
twitter-token=${accessToken.token}
|
||||
twitter-tokenSecret=${accessToken.tokenSecret}
|
||||
""".trimIndent()
|
||||
)
|
||||
} catch (te: TwitterException) {
|
||||
te.printStackTrace()
|
||||
println("Failed to get accessToken: " + te.message)
|
||||
exitProcess(-1)
|
||||
} catch (ioe: IOException) {
|
||||
ioe.printStackTrace()
|
||||
println("Failed to read the system input.")
|
||||
exitProcess(-1)
|
||||
}
|
||||
} else {
|
||||
println("Usage: ${TwitterOAuth::class.java.name} <consumerKey> <consumerSecret>")
|
||||
}
|
||||
exitProcess(0)
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
import net.thauvin.erik.mobibot.Constants
|
||||
import net.thauvin.erik.mobibot.Utils
|
||||
import net.thauvin.erik.mobibot.Utils.sendMessage
|
||||
import org.apache.commons.text.WordUtils
|
||||
|
@ -106,6 +107,7 @@ class ChatGpt : AbstractModule() {
|
|||
.uri(URI.create(API_URL))
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Authorization", "Bearer $apiKey")
|
||||
.header("User-Agent", Constants.USER_AGENT)
|
||||
.POST(
|
||||
HttpRequest.BodyPublishers.ofString(
|
||||
"""{
|
||||
|
@ -136,8 +138,10 @@ class ChatGpt : AbstractModule() {
|
|||
}
|
||||
} else {
|
||||
if (response.statusCode() == 429) {
|
||||
throw ModuleException("$CHATGPT_CMD($query): Rate limit reached",
|
||||
"Rate limit reached. Please try again later.")
|
||||
throw ModuleException(
|
||||
"$CHATGPT_CMD($query): Rate limit reached",
|
||||
"Rate limit reached. Please try again later."
|
||||
)
|
||||
} else {
|
||||
throw IOException("HTTP Status Code: " + response.statusCode())
|
||||
}
|
||||
|
|
|
@ -1,133 +0,0 @@
|
|||
/*
|
||||
* Twitter.kt
|
||||
*
|
||||
* 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.helpFormat
|
||||
import net.thauvin.erik.mobibot.entries.EntryLink
|
||||
import net.thauvin.erik.mobibot.social.SocialModule
|
||||
import twitter4j.TwitterException
|
||||
|
||||
/**
|
||||
* The Twitter module.
|
||||
*/
|
||||
class Twitter : SocialModule() {
|
||||
override val name = "Twitter"
|
||||
|
||||
override val handle: String?
|
||||
get() = properties[HANDLE_PROP]
|
||||
|
||||
override val isAutoPost: Boolean
|
||||
get() = isEnabled && properties[AUTO_POST_PROP].toBoolean()
|
||||
|
||||
override val isValidProperties: Boolean
|
||||
get() = !(properties[CONSUMER_KEY_PROP].isNullOrBlank() || properties[CONSUMER_SECRET_PROP].isNullOrBlank()
|
||||
|| properties[TOKEN_PROP].isNullOrBlank() || properties[TOKEN_SECRET_PROP].isNullOrBlank())
|
||||
|
||||
/**
|
||||
* Formats the entry for posting.
|
||||
*/
|
||||
override fun formatEntry(entry: EntryLink): String {
|
||||
return "${entry.title} ${entry.link} via ${entry.nick} on ${entry.channel}"
|
||||
}
|
||||
|
||||
/**
|
||||
* Posts on Twitter.
|
||||
*/
|
||||
@Throws(ModuleException::class)
|
||||
override fun post(message: String, isDm: Boolean): String {
|
||||
return tweet(
|
||||
consumerKey = properties[CONSUMER_KEY_PROP],
|
||||
consumerSecret = properties[CONSUMER_SECRET_PROP],
|
||||
token = properties[TOKEN_PROP],
|
||||
tokenSecret = properties[TOKEN_SECRET_PROP],
|
||||
handle = handle,
|
||||
message = message,
|
||||
isDm = isDm
|
||||
)
|
||||
}
|
||||
|
||||
companion object {
|
||||
// Property keys
|
||||
const val AUTO_POST_PROP = "twitter-auto-post"
|
||||
const val CONSUMER_KEY_PROP = "twitter-consumerKey"
|
||||
const val CONSUMER_SECRET_PROP = "twitter-consumerSecret"
|
||||
const val HANDLE_PROP = "twitter-handle"
|
||||
const val TOKEN_PROP = "twitter-token"
|
||||
const val TOKEN_SECRET_PROP = "twitter-tokenSecret"
|
||||
|
||||
// Twitter commands
|
||||
private const val TWITTER_CMD = "twitter"
|
||||
private const val TWEET_CMD = "tweet"
|
||||
|
||||
/**
|
||||
* Post on Twitter.
|
||||
*/
|
||||
@JvmStatic
|
||||
@Throws(ModuleException::class)
|
||||
fun tweet(
|
||||
consumerKey: String?,
|
||||
consumerSecret: String?,
|
||||
token: String?,
|
||||
tokenSecret: String?,
|
||||
handle: String?,
|
||||
message: String,
|
||||
isDm: Boolean
|
||||
): String {
|
||||
return try {
|
||||
val twitter = twitter4j.Twitter.newBuilder()
|
||||
.prettyDebugEnabled(true)
|
||||
.oAuthConsumer(consumerKey, consumerSecret)
|
||||
.oAuthAccessToken(token, tokenSecret)
|
||||
.build()
|
||||
if (!isDm) {
|
||||
val status = twitter.v1().tweets().updateStatus(message)
|
||||
"Your message was posted to https://twitter.com/${
|
||||
twitter.v1().users().accountSettings.screenName
|
||||
}/statuses/${status.id}"
|
||||
} else {
|
||||
val dm = twitter.v1().directMessages().sendDirectMessage(handle, message)
|
||||
dm.text
|
||||
}
|
||||
} catch (e: TwitterException) {
|
||||
throw ModuleException("tweet($message)", "An error has occurred: ${e.message}", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
init {
|
||||
commands.add(TWITTER_CMD)
|
||||
commands.add(TWEET_CMD)
|
||||
help.add("To $TWEET_CMD on $name:")
|
||||
help.add(helpFormat("%c $TWEET_CMD <message>"))
|
||||
properties[AUTO_POST_PROP] = "false"
|
||||
initProperties(CONSUMER_KEY_PROP, CONSUMER_SECRET_PROP, HANDLE_PROP, TOKEN_PROP, TOKEN_SECRET_PROP)
|
||||
}
|
||||
}
|
|
@ -45,7 +45,6 @@ import net.thauvin.erik.mobibot.modules.Dice
|
|||
import net.thauvin.erik.mobibot.modules.Joke
|
||||
import net.thauvin.erik.mobibot.modules.Lookup
|
||||
import net.thauvin.erik.mobibot.modules.RockPaperScissors
|
||||
import net.thauvin.erik.mobibot.modules.Twitter
|
||||
import net.thauvin.erik.mobibot.modules.War
|
||||
import org.testng.annotations.Test
|
||||
import java.util.Properties
|
||||
|
@ -62,7 +61,6 @@ class AddonsTest {
|
|||
// Modules
|
||||
addons.add(Joke())
|
||||
addons.add(RockPaperScissors())
|
||||
addons.add(Twitter()) // no properties, disabled.
|
||||
addons.add(War())
|
||||
addons.add(Dice())
|
||||
addons.add(Lookup())
|
||||
|
|
|
@ -31,14 +31,9 @@
|
|||
package net.thauvin.erik.mobibot
|
||||
|
||||
import assertk.all
|
||||
import assertk.assertFailure
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.contains
|
||||
import assertk.assertions.index
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isFailure
|
||||
import assertk.assertions.isInstanceOf
|
||||
import assertk.assertions.prop
|
||||
import assertk.assertions.size
|
||||
import assertk.assertions.*
|
||||
import com.rometools.rome.io.FeedException
|
||||
import net.thauvin.erik.mobibot.FeedReader.Companion.readFeed
|
||||
import net.thauvin.erik.mobibot.msg.Message
|
||||
|
@ -66,13 +61,13 @@ class FeedReaderTest {
|
|||
assertThat(messages, "messages").size().isEqualTo(84)
|
||||
assertThat(messages.last(), "messages.last").prop(Message::msg).contains("techdigest.tv")
|
||||
|
||||
assertThat { readFeed("blah") }.isFailure().isInstanceOf(MalformedURLException::class.java)
|
||||
assertFailure { readFeed("blah") }.isInstanceOf(MalformedURLException::class.java)
|
||||
|
||||
assertThat { readFeed("https://www.example.com") }.isFailure().isInstanceOf(FeedException::class.java)
|
||||
assertFailure { readFeed("https://www.example.com") }.isInstanceOf(FeedException::class.java)
|
||||
|
||||
assertThat { readFeed("https://www.thauvin.net/foo") }.isFailure().isInstanceOf(IOException::class.java)
|
||||
assertFailure { readFeed("https://www.thauvin.net/foo") }.isInstanceOf(IOException::class.java)
|
||||
|
||||
assertThat { readFeed("https://www.examplesfoo.com/") }.isFailure()
|
||||
assertFailure { readFeed("https://www.examplesfoo.com/") }
|
||||
.isInstanceOf(UnknownHostException::class.java)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
*/
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
import assertk.assertFailure
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isFailure
|
||||
|
@ -48,6 +49,6 @@ class CalcTest {
|
|||
assertThat(calculate("1 + 1"), "calculate(1+1)").isEqualTo("1+1 = ${2.bold()}")
|
||||
assertThat(calculate("1 -3"), "calculate(1-3)").isEqualTo("1-3 = ${(-2).bold()}")
|
||||
assertThat(calculate("pi+π+e+φ"), "calculate(pi+π+e+φ)").isEqualTo("pi+π+e+φ = ${"10.62".bold()}")
|
||||
assertThat { calculate("one + one") }.isFailure().isInstanceOf(UnknownFunctionOrVariableException::class.java)
|
||||
assertFailure { calculate("one + one") }.isInstanceOf(UnknownFunctionOrVariableException::class.java)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
*/
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
import assertk.assertFailure
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.contains
|
||||
import assertk.assertions.hasNoCause
|
||||
|
@ -41,8 +42,7 @@ import org.testng.annotations.Test
|
|||
class ChatGptTest : LocalProperties() {
|
||||
@Test(groups = ["modules"])
|
||||
fun testApiKey() {
|
||||
assertThat { ChatGpt.chat("1 gallon to liter", "", 0) }
|
||||
.isFailure()
|
||||
assertFailure { ChatGpt.chat("1 gallon to liter", "", 0) }
|
||||
.isInstanceOf(ModuleException::class.java)
|
||||
.hasNoCause()
|
||||
}
|
||||
|
@ -57,8 +57,7 @@ class ChatGptTest : LocalProperties() {
|
|||
ChatGpt.chat("how do I encode a URL in java?", apiKey, 60)
|
||||
).contains("URLEncoder")
|
||||
|
||||
assertThat { ChatGpt.chat("1 liter to gallon", apiKey, 0) }
|
||||
.isFailure()
|
||||
assertFailure { ChatGpt.chat("1 liter to gallon", apiKey, 0) }
|
||||
.isInstanceOf(ModuleException::class.java)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
import assertk.all
|
||||
import assertk.assertFailure
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.contains
|
||||
import assertk.assertions.hasMessage
|
||||
|
@ -59,14 +60,13 @@ class GoogleSearchTest : LocalProperties() {
|
|||
"searchGoogle(empty)"
|
||||
).isInstanceOf(ErrorMessage::class.java)
|
||||
|
||||
assertThat { searchGoogle("test", "", "apiKey") }.isFailure()
|
||||
assertFailure { searchGoogle("test", "", "apiKey") }
|
||||
.isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||
|
||||
assertThat { searchGoogle("test", "apiKey", "") }.isFailure()
|
||||
assertFailure { searchGoogle("test", "apiKey", "") }
|
||||
.isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||
|
||||
assertThat { searchGoogle("test", "apiKey", "cssKey") }
|
||||
.isFailure()
|
||||
assertFailure { searchGoogle("test", "apiKey", "cssKey") }
|
||||
.isInstanceOf(ModuleException::class.java)
|
||||
.hasMessage("API key not valid. Please pass a valid API key.")
|
||||
}
|
||||
|
|
|
@ -32,7 +32,6 @@ package net.thauvin.erik.mobibot.modules
|
|||
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.contains
|
||||
import assertk.assertions.isSuccess
|
||||
import net.thauvin.erik.mobibot.LocalProperties
|
||||
import net.thauvin.erik.mobibot.modules.Mastodon.Companion.toot
|
||||
import org.testng.annotations.Test
|
||||
|
@ -42,7 +41,7 @@ class MastodonTest : LocalProperties() {
|
|||
@Throws(ModuleException::class)
|
||||
fun testToot() {
|
||||
val msg = "Testing Mastodon API from ${getHostName()}"
|
||||
assertThat {
|
||||
assertThat(
|
||||
toot(
|
||||
getProperty(Mastodon.ACCESS_TOKEN_PROP),
|
||||
getProperty(Mastodon.INSTANCE_PROP),
|
||||
|
@ -50,6 +49,6 @@ class MastodonTest : LocalProperties() {
|
|||
msg,
|
||||
true
|
||||
)
|
||||
}.isSuccess().contains(msg)
|
||||
).contains(msg)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@
|
|||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
import assertk.all
|
||||
import assertk.assertFailure
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.hasNoCause
|
||||
import assertk.assertions.index
|
||||
|
@ -78,7 +79,7 @@ class StockQuoteTest : LocalProperties() {
|
|||
isInstanceOf(ErrorMessage::class.java)
|
||||
prop(Message::msg).isEqualTo(StockQuote.INVALID_SYMBOL)
|
||||
}
|
||||
assertThat { getQuote("test", "") }.isFailure().isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||
assertFailure { getQuote("test", "") }.isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||
} catch (e: ModuleException) {
|
||||
// Avoid displaying api keys in CI logs
|
||||
if ("true" == System.getenv("CI")) {
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* TwitterTest.kt
|
||||
*
|
||||
* 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 assertk.assertThat
|
||||
import assertk.assertions.isEqualTo
|
||||
import assertk.assertions.isSuccess
|
||||
import net.thauvin.erik.mobibot.LocalProperties
|
||||
import net.thauvin.erik.mobibot.modules.Twitter.Companion.tweet
|
||||
import org.testng.annotations.Test
|
||||
|
||||
/**
|
||||
* The `TwitterTest` class.
|
||||
*/
|
||||
class TwitterTest : LocalProperties() {
|
||||
@Test(groups = ["modules", "twitter"])
|
||||
@Throws(ModuleException::class)
|
||||
fun testTweet() {
|
||||
val msg = "Testing Twitter API from ${getHostName()}"
|
||||
assertThat {
|
||||
tweet(
|
||||
getProperty(Twitter.CONSUMER_KEY_PROP),
|
||||
getProperty(Twitter.CONSUMER_SECRET_PROP),
|
||||
getProperty(Twitter.TOKEN_PROP),
|
||||
getProperty(Twitter.TOKEN_SECRET_PROP),
|
||||
getProperty(Twitter.HANDLE_PROP),
|
||||
msg,
|
||||
true
|
||||
)
|
||||
}.isSuccess().isEqualTo(msg)
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@
|
|||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
import assertk.all
|
||||
import assertk.assertFailure
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.contains
|
||||
import assertk.assertions.endsWith
|
||||
|
@ -116,8 +117,8 @@ class Weather2Test : LocalProperties() {
|
|||
}
|
||||
|
||||
query = "test"
|
||||
assertThat { getWeather(query, "") }.isFailure().isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||
assertThat { getWeather(query, null) }.isFailure().isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||
assertFailure { getWeather(query, "") }.isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||
assertFailure { getWeather(query, null) }.isInstanceOf(ModuleException::class.java).hasNoCause()
|
||||
|
||||
messages = getWeather("", "apikey")
|
||||
assertThat(messages, "getWeather(empty)").index(0).prop(Message::isError).isTrue()
|
||||
|
|
|
@ -31,10 +31,10 @@
|
|||
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
import assertk.assertFailure
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.contains
|
||||
import assertk.assertions.hasMessage
|
||||
import assertk.assertions.isFailure
|
||||
import assertk.assertions.isInstanceOf
|
||||
import net.thauvin.erik.mobibot.ExceptionSanitizer.sanitize
|
||||
import net.thauvin.erik.mobibot.LocalProperties
|
||||
|
@ -44,13 +44,11 @@ import org.testng.annotations.Test
|
|||
class WolframAlphaTest : LocalProperties() {
|
||||
@Test(groups = ["modules"])
|
||||
fun testAppId() {
|
||||
assertThat { queryWolfram("1 gallon to liter", appId = "DEMO") }
|
||||
.isFailure()
|
||||
assertFailure { queryWolfram("1 gallon to liter", appId = "DEMO") }
|
||||
.isInstanceOf(ModuleException::class.java)
|
||||
.hasMessage("Error 1: Invalid appid")
|
||||
|
||||
assertThat { queryWolfram("1 gallon to liter", appId = "") }
|
||||
.isFailure()
|
||||
assertFailure { queryWolfram("1 gallon to liter", appId = "") }
|
||||
.isInstanceOf(ModuleException::class.java)
|
||||
}
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
*/
|
||||
package net.thauvin.erik.mobibot.modules
|
||||
|
||||
import assertk.assertFailure
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.endsWith
|
||||
import assertk.assertions.isSuccess
|
||||
|
@ -65,7 +66,7 @@ class WordTimeTest {
|
|||
@Test(groups = ["modules"])
|
||||
fun testZones() {
|
||||
COUNTRIES_MAP.filter { it.value != BEATS_KEYWORD }.forEach {
|
||||
assertThat { ZoneId.of(it.value) }.isSuccess()
|
||||
assertThat(ZoneId.of(it.value))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue