Skip to content

Commit

Permalink
Removing rivescript, fixing twitter url parsing, cleaning up compilat…
Browse files Browse the repository at this point in the history
…ion (#422)
  • Loading branch information
jottinger authored Nov 7, 2023
1 parent b276bb5 commit 5ca69f8
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 46 deletions.
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,6 @@
</dependency>
<!-- Unit testing dependencies -->

<!-- rivescript -->
<dependency>
<groupId>com.rivescript</groupId>
<artifactId>rivescript-core</artifactId>
<version>${rivescript.version}</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
Expand Down Expand Up @@ -561,7 +555,6 @@
<logback.version>1.4.11</logback.version>
<morphia.version>2.3.1</morphia.version>
<okhttp.version>4.10.0</okhttp.version>
<rivescript.version>0.11.0</rivescript.version>
<slf4j.version>2.0.9</slf4j.version>
<sofia.version>0.25</sofia.version>

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/javabot/JavabotModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ open class JavabotModule : AbstractModule() {
install(FactoryModuleBuilder().build(ViewFactory::class.java))
}

open fun client(): MongoClient? {
open fun client(): MongoClient {
return mongoClient
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/javabot/javadoc/JavadocAsmParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ constructor(private val apiDao: ApiDao, private val config: JavabotConfig) {

if ("JDK" == api.name) {
File(System.getProperty("java.home"), "jmods")
.listFiles { file, s -> s.startsWith("java") }
.listFiles { _, s -> s.startsWith("java") }
.forEach { scanJar(api, type, it) }
} else {
scanJar(api, type, api.classesUri().download())
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/javabot/operations/LinksOperation.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package javabot.operations

import com.antwerkz.sofia.Sofia
import java.net.URL
import java.net.URI
import java.util.Locale
import javabot.Javabot
import javabot.Message
Expand Down Expand Up @@ -118,7 +118,7 @@ constructor(
tokens
.mapNotNull {
try {
URL(it)
URI(it).toURL()
} catch (e: Exception) {
null
}
Expand Down
13 changes: 10 additions & 3 deletions src/main/kotlin/javabot/operations/URLTitleOperation.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package javabot.operations

import java.io.IOException
import java.net.URL
import java.net.URI
import javabot.Javabot
import javabot.Message
import javabot.dao.AdminDao
Expand Down Expand Up @@ -74,12 +74,18 @@ constructor(
)
}

fun hostBasename(host: String, sections: Int = 2): String {
return host.split(".").takeLast(sections).joinToString(".").lowercase()
}

private fun findTitle(url: String, loop: Boolean): String? {
val twitterUrls = listOf("twitter.com", "x.com")
if (analyzer.precheck(url)) {
@Suppress("GrazieInspection")
try {
val typedUrl = URL(url)
val typedUrl = URI(url).toURL()
// there used to be parsing here for youtube but they use <title> now
if (typedUrl.host.contains("twitter.com", true)) {
if (twitterUrls.contains(typedUrl.host.lowercase())) {
return findTwitterTitle(url)
}
val document = Jsoup.parse(httpService.get(url))
Expand All @@ -102,6 +108,7 @@ constructor(
}

private fun findTwitterTitle(url: String): String {
@Suppress("GrazieInspection")
if (twitterService.isEnabled()) {
if (url.contains("status")) {
val regex = Regex("status/\\d++")
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/javabot/operations/time/DateUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DateUtils {
val date = Date().time
val formattedDate = dateFormatter.withZone(DateTimeZone.forID(timezone)).print(date)
val formattedTime =
timeFormatter.withZone(DateTimeZone.forID(timezone)).print(date).toLowerCase()
timeFormatter.withZone(DateTimeZone.forID(timezone)).print(date).lowercase()
return formattedDate + " @ " + formattedTime
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/javabot/operations/time/TimezonesAustralia.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ class TimezonesAustralia : Timezones {
init {
for (states in AustralianState.values()) {
val timezone = states.timezone
timezones.insert(states.name.toLowerCase(), timezone)
timezones.insert(states.abbreviation.toLowerCase(), timezone)
timezones.insert(states.name.lowercase(), timezone)
timezones.insert(states.abbreviation.lowercase(), timezone)
timezones.insert(states.capital, timezone)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/javabot/operations/time/TimezonesCanada.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class TimezonesCanada : Timezones {
init {
for (province in CanadianProvince.values()) {
val timezone = province.timezone
timezones.insert(province.name.toLowerCase(), timezone)
timezones.insert(province.abbreviation.toLowerCase(), timezone)
timezones.insert(province.name.lowercase(), timezone)
timezones.insert(province.abbreviation.lowercase(), timezone)
timezones.insert(province.capital, timezone)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/javabot/operations/time/TimezonesUS.kt
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class TimezonesUS : Timezones {
init {
for (state in UsState.values()) {
val timezone = state.timezone
timezones.insert(state.name.toLowerCase(), timezone)
timezones.insert(state.abbreviation.toLowerCase(), timezone)
timezones.insert(state.name.lowercase(), timezone)
timezones.insert(state.abbreviation.lowercase(), timezone)
timezones.insert(state.capital, timezone)
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/javabot/operations/time/Tri.kt
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class Tri<T> {
}

private fun clean(key: String): String {
return key.toLowerCase().replace("[^a-z]".toRegex(), "")
return key.lowercase().replace("[^a-z]".toRegex(), "")
}

private fun hash(c: Char): Int {
return c.toInt() - OFFSET
return c.code - OFFSET
}

private inner class Node<T> {
Expand All @@ -56,6 +56,6 @@ class Tri<T> {
}

companion object {
private val OFFSET = 'a'.toInt()
private val OFFSET = 'a'.code
}
}
22 changes: 0 additions & 22 deletions src/main/kotlin/javabot/service/RiveScriptService.kt

This file was deleted.

17 changes: 17 additions & 0 deletions src/test/kotlin/javabot/operations/URLTitleOperationTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package javabot.operations

import java.net.URI
import javabot.BaseTest
import javabot.JavabotConfig
import javabot.Message
Expand All @@ -18,6 +19,22 @@ class URLTitleOperationTest : BaseTest() {
@Inject private lateinit var config: JavabotConfig
private val analyzer = URLContentAnalyzer()

@DataProvider(name = "longUrls")
fun longUrls(): Array<Array<String>> =
arrayOf(
arrayOf("https://twitter.com", "twitter.com"),
arrayOf("http://www.twitter.com", "twitter.com"),
arrayOf("http://x.com", "x.com"),
arrayOf("https://foo.www.x.com", "x.com"),
arrayOf("https://twitter", "twitter"), // ew
)

@Test(dataProvider = "longUrls")
fun testHostBasename(url: String, basenamed: String) {
var host = URI(url).toURL().host
assertEquals(operation.hostBasename(host), basenamed.lowercase())
}

@Test(dataProvider = "urls")
fun testSimpleUrl(url: String, content: String?) {
val results = operation.handleChannelMessage(Message(TEST_CHANNEL, TEST_USER, url))
Expand Down

0 comments on commit 5ca69f8

Please sign in to comment.