Skip to content

Commit

Permalink
spotless apply, such win
Browse files Browse the repository at this point in the history
  • Loading branch information
jottinger committed Feb 5, 2024
1 parent f632e50 commit ddbb4c0
Show file tree
Hide file tree
Showing 20 changed files with 36 additions and 35 deletions.
2 changes: 2 additions & 0 deletions src/main/kotlin/javabot/JavabotModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ open class JavabotModule : AbstractModule() {
lateinit var ircAdapterProvider: Provider<out IrcAdapter>
lateinit var channelDaoProvider: Provider<ChannelDao>
lateinit var configDaoProvider: Provider<ConfigDao>

override fun configure() {
configDaoProvider = binder().getProvider(ConfigDao::class.java)
channelDaoProvider = binder().getProvider(ChannelDao::class.java)
Expand Down Expand Up @@ -124,6 +125,7 @@ open class JavabotModule : AbstractModule() {
}

protected open fun loadConfigProperties(): HashMap<Any, Any> = HashMap()

protected fun validate(config: JavabotConfig): JavabotConfig {
@Suppress("UNCHECKED_CAST")
val configClass = config.javaClass.interfaces[0] as Class<JavabotConfig>
Expand Down
7 changes: 2 additions & 5 deletions src/main/kotlin/javabot/ScriptComparator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ class ScriptComparator : Comparator<UpgradeScript> {
return 1
}
throw RuntimeException(
"%s and %s have the same priority: %d".format(
o1.javaClass.name,
o2.javaClass.name,
o1.id()
)
"%s and %s have the same priority: %d"
.format(o1.javaClass.name, o2.javaClass.name, o1.id())
)
}
}
4 changes: 2 additions & 2 deletions src/main/kotlin/javabot/dao/ChannelDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class ChannelDao @Inject constructor(ds: Datastore) : BaseDao<Channel>(ds, Chann
+ " min(l.updated), (select count(e) from Logs e)) from Logs l "
+ "where l.channel like '#%' group by l.channel order by count(l) desc")
*/
return listOf(
) // (List<Activity>) getEntityManager().createNamedQuery(ChannelDao.STATISTICS)
return listOf() // (List<Activity>)
// getEntityManager().createNamedQuery(ChannelDao.STATISTICS)
// .getResultList();
}

Expand Down
12 changes: 3 additions & 9 deletions src/main/kotlin/javabot/dao/ChatGPTDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ import io.dropwizard.util.Duration
import javabot.JavabotConfig
import javabot.operations.throttle.BotRateLimiter


@Singleton
class ChatGPTDao
@Inject
constructor(val javabotConfig: JavabotConfig) {
class ChatGPTDao @Inject constructor(val javabotConfig: JavabotConfig) {

private var limiter: BotRateLimiter = BotRateLimiter(
javabotConfig.chatGptLimit(),
Duration.days(1).toMilliseconds()
)
private var limiter: BotRateLimiter =
BotRateLimiter(javabotConfig.chatGptLimit(), Duration.days(1).toMilliseconds())

fun sendPromptToChatGPT(prompt: String): String? {
return if (javabotConfig.chatGptKey().isNotEmpty() && limiter.tryAcquire()) {
Expand All @@ -32,5 +27,4 @@ constructor(val javabotConfig: JavabotConfig) {
null
}
}

}
1 change: 1 addition & 0 deletions src/main/kotlin/javabot/dao/JavadocClassDao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class JavadocClassDao @Inject constructor(ds: Datastore) :
}

fun count() = ds.find(JavadocClass::class.java).count()

fun getClass(api: JavadocApi? = null, name: String): List<JavadocClass> {
val strings = calculateNameAndPackage(name)
val pkgName = strings.first
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/javabot/dao/WeatherHandler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import javabot.dao.weather.Weather
interface WeatherHandler {
/**
* Gets weather info, or null if none can be found
*
* @return Current Weather information, null if not found
*/
fun getWeatherFor(place: String): Weather?
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/javabot/dao/util/QueryParam.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import dev.morphia.query.Sort

/**
* Set to return count sorted elements, starting at the first element.
*
* @param first First element to return.
* @param count Number of elements to return.
* @param sort Column to sort on.
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/javabot/javadoc/JavadocAsmParser.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ constructor(private val apiDao: ApiDao, private val config: JavabotConfig) {
.substringBeforeLast(".")
.replace("/", ".")
}

private fun JarEntry.packageName(): String {
return this.name.substringAfter("classes/").substringBeforeLast("/").replace("/", ".")
}
Expand Down Expand Up @@ -139,6 +140,7 @@ constructor(private val apiDao: ApiDao, private val config: JavabotConfig) {
URI(
"https://repo1.maven.org/maven2/${groupId.toPath()}/${artifactId}/${version}/${artifactId}-${version}-javadoc.jar"
)

private fun JavadocApi.classesUri() =
URI(
"https://repo1.maven.org/maven2/${groupId.toPath()}/${artifactId}/${version}/${artifactId}-${version}.jar"
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/javabot/javadoc/JavadocType.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ enum class JavadocType {
fun forVersion(version: String): JavadocType {
return valueOf("JAVA${version}")
}

fun discover(root: File): JavadocType {
val manFile = File(root, "META-INF/MANIFEST.MF")
if (manFile.exists()) {
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/javabot/operations/BotOperation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ abstract class BotOperation constructor(var bot: Javabot, var adminDao: AdminDao
* This method returns where the operation should fall in terms of priority. Lower values
* represent lower priority. Implementations can probably get by with the default implementation
* (which returns a priority of 10) but some commands may want to override this.
*
* @return the priority of the command
*/
open fun getPriority(): Int {
Expand Down
10 changes: 5 additions & 5 deletions src/main/kotlin/javabot/operations/ChatGPTOperation.kt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package javabot.operations

import java.util.*
import javabot.Javabot
import javabot.Message
import javabot.dao.AdminDao
import javabot.dao.ChatGPTDao
import java.util.*
import javax.inject.Inject

/** Gets current weather conditions for a place given as a parameter. */
Expand All @@ -18,12 +18,14 @@ constructor(bot: Javabot, adminDao: AdminDao, var chatGPTDao: ChatGPTDao) :
if (message.lowercase(Locale.getDefault()).startsWith("gpt ")) {
val uuid = UUID.randomUUID()
val query = message.substringAfter("gpt ")
val prompt = """Someone is asking "$query".
val prompt =
"""Someone is asking "$query".
Restrict your answer to being applicable to the Java Virtual Machine,
and limit the response's length as if it were to be posted on Twitter,
but without hashtags or other such twitter-like features;
if the answer does not contain constructive information for Java programming,
respond ONLY with \"$uuid-not applicable\" and no other text""".trimIndent()
respond ONLY with \"$uuid-not applicable\" and no other text"""
.trimIndent()
val result = chatGPTDao.sendPromptToChatGPT(prompt)
if (!result.isNullOrEmpty() && !result.lowercase().contains(uuid.toString())) {
responses.add(Message(event, result.toString()))
Expand All @@ -32,5 +34,3 @@ constructor(bot: Javabot, adminDao: AdminDao, var chatGPTDao: ChatGPTDao) :
return responses
}
}


2 changes: 1 addition & 1 deletion src/main/kotlin/javabot/operations/LinksOperation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ constructor(
* Ugh. Okay, so:
* 1. See if the first token is a channel. If it is, pull it off and retain it internally...
* 2. If we have an internal and external channel, they should match. If not, throw a wrong
* channel message.
* channel message.
* 3. If we NEED a channel, and the internal channel is empty, throw a no channel message.
* 4. return either the internal channel (if present) or the external channel.
*/
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/javabot/operations/time/Timezones.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package javabot.operations.time

interface Timezones {
fun get(province: String): String?

fun getCapital(): String
}
7 changes: 2 additions & 5 deletions src/main/kotlin/javabot/web/auth/OpenIDCredentials.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,16 @@ import java.util.UUID
import javabot.web.model.Authority

/**
*
* Value object to provide the following to [OpenIDAuthenticator]:
*
* * Storage of the necessary credentials for OpenID authentication
*
* @since 0.0.1
*/
class OpenIDCredentials
/**
* @param sessionToken The session token acting as a surrogate for the OpenID token
* *
* @param sessionToken The session token acting as a surrogate for the OpenID token *
* @param requiredAuthorities The authorities required to authenticate (provided by the [Restricted]
* annotation)
* annotation)
*/
(sessionToken: UUID, requiredAuthorities: Set<Authority>) {

Expand Down
3 changes: 1 addition & 2 deletions src/main/kotlin/javabot/web/model/InMemoryUserCache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ enum class InMemoryUserCache {
.build<String, User>()

/**
* @param sessionToken The session token to locate the user (not JSESSIONID)
* *
* @param sessionToken The session token to locate the user (not JSESSIONID) *
* @return The matching User or absent
*/
fun getBySessionToken(sessionToken: String?): User? {
Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/javabot/BaseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ open class BaseTest {
)
)
}

protected fun loadApi(
apiName: String,
groupId: String = "",
Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/javabot/IrcAdapterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.testng.annotations.Test

class IrcAdapterTest : BaseTest() {
companion object {}

@Inject lateinit var ircAdapter: IrcAdapter
@Inject lateinit var factoidDao: FactoidDao

Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/javabot/javadoc/JavadocClassVisitorTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class JavadocClassVisitorTest : BaseTest() {

assertEquals(list, listOf("java/lang/Object", "java/lang/Class"))
}

@Test
fun testMapSignature() {
val visitor = JavadocClassVisitor(apiDao, JavadocApi(), "", "", null, JAVA11)
Expand Down
12 changes: 6 additions & 6 deletions src/test/kotlin/javabot/operations/ChatGPTOperationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@ import org.testng.Assert.assertTrue
import org.testng.annotations.Test

class ChatGPTOperationTest : BaseTest() {
@Inject
protected lateinit var operation: ChatGPTOperation
@Inject protected lateinit var operation: ChatGPTOperation

@Inject
protected lateinit var config: JavabotConfig
@Inject protected lateinit var config: JavabotConfig

@Test
fun testNonJavaQuestion() {
if (config.chatGptKey().isNotEmpty()) {
val response = operation.handleMessage(message("~gpt speed of an african laden swallow"))
val response =
operation.handleMessage(message("~gpt speed of an african laden swallow"))
assertTrue(response.isEmpty())
LOG.info("ChatGPT inappropriate (non-java) content test passed")
} else {
Expand All @@ -28,7 +27,8 @@ class ChatGPTOperationTest : BaseTest() {
@Test
fun testMavenDirectories() {
if (config.chatGptKey().isNotEmpty()) {
val response = operation.handleMessage(message("~gpt what is the maven directory structure"))
val response =
operation.handleMessage(message("~gpt what is the maven directory structure"))
assertTrue(response.isNotEmpty())
assertTrue(response[0].value.contains("src/main/java"))
LOG.info("ChatGPT appropriate content passed: ${response[0].value}")
Expand Down
1 change: 1 addition & 0 deletions src/test/kotlin/javabot/operations/LiteralOperationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import org.testng.annotations.Test
@Test(groups = arrayOf("operations"))
class LiteralOperationTest : BaseTest() {
@Inject private lateinit var operation: LiteralOperation

@Test
fun testMissingFactoid() {
val factoidName = "foo${Date().time}"
Expand Down

0 comments on commit ddbb4c0

Please sign in to comment.