Use Lettuce instead of Kreds (and optimise the dependencies) #4
No files matched your search
+11
-6
@@ -47,17 +47,21 @@ dependencies {
|
||||
compileOnly("me.clip:placeholderapi:2.11.6")
|
||||
compileOnly("net.essentialsx:EssentialsX:2.21.0")
|
||||
compileOnly(files("libs/AnnouncerPlus-1.4.1.jar"))
|
||||
compileOnly(project(":libs:Utilities-OG"))
|
||||
|
||||
implementation("net.dv8tion:JDA:5.5.1") {
|
||||
exclude(module = "opus-java")
|
||||
}
|
||||
implementation(project(":libs:Utilities-OG"))
|
||||
implementation("net.dv8tion:JDA:5.5.1")
|
||||
implementation("club.minnced:jda-ktx:0.12.0")
|
||||
implementation("club.minnced:discord-webhooks:0.8.4")
|
||||
implementation("com.google.code.gson:gson:2.13.1")
|
||||
implementation("io.github.crackthecodeabhi:kreds:0.9.1")
|
||||
implementation("io.lettuce:lettuce-core:6.7.1.RELEASE")
|
||||
implementation("com.squareup.okhttp3:okhttp:4.12.0")
|
||||
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.10.2")
|
||||
implementation("org.jetbrains.kotlin:kotlin-stdlib")
|
||||
}
|
||||
|
||||
configurations.all {
|
||||
exclude(group = "com.google.crypto.tink", module = "tink")
|
||||
exclude(group = "net.java", module = "opus-java")
|
||||
exclude(group = "io.projectreactor")
|
||||
}
|
||||
|
||||
java {
|
||||
@@ -80,6 +84,7 @@ tasks.jar {
|
||||
tasks.shadowJar {
|
||||
archiveClassifier.set("") // Use empty string instead of null.
|
||||
exclude("io.github.miniplaceholders.*") // Exclude the MiniPlaceholders package from being shadowed.
|
||||
exclude("natives/**")
|
||||
minimize()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package nl.skbotnl.chatog
|
||||
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import java.net.URI
|
||||
@@ -9,7 +8,6 @@ import java.util.concurrent.TimeUnit
|
||||
object BlocklistManager {
|
||||
private var blockList = mutableListOf<String>()
|
||||
|
||||
@OptIn(DelicateCoroutinesApi::class)
|
||||
fun load() {
|
||||
ChatOG.plugin.logger.info("Loading the blocklists...")
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@ class ChatOG : JavaPlugin() {
|
||||
|
||||
lateinit var plugin: JavaPlugin
|
||||
lateinit var chat: Chat
|
||||
lateinit var languageDatabase: LanguageDatabase
|
||||
var translator: OpenAI? = null
|
||||
var essentials = Bukkit.getServer().pluginManager.getPlugin("Essentials") as Essentials
|
||||
|
||||
@@ -62,7 +63,13 @@ class ChatOG : JavaPlugin() {
|
||||
OpenAI()
|
||||
} else null
|
||||
|
||||
LanguageDatabase.init()
|
||||
languageDatabase = LanguageDatabase()
|
||||
if (languageDatabase.testConnection()) {
|
||||
logger.severe("Could not connect to Redis")
|
||||
Bukkit.getPluginManager().disablePlugin(this)
|
||||
return
|
||||
}
|
||||
|
||||
BlocklistManager.load()
|
||||
scope.launch {
|
||||
EmojiConverter.load()
|
||||
|
||||
@@ -1,37 +1,37 @@
|
||||
package nl.skbotnl.chatog
|
||||
|
||||
import io.github.crackthecodeabhi.kreds.connection.Endpoint
|
||||
import io.github.crackthecodeabhi.kreds.connection.KredsClient
|
||||
import io.github.crackthecodeabhi.kreds.connection.newClient
|
||||
import io.lettuce.core.RedisClient
|
||||
import io.lettuce.core.RedisConnectionException
|
||||
import java.util.*
|
||||
import java.util.logging.Level
|
||||
|
||||
object LanguageDatabase {
|
||||
private lateinit var client: KredsClient
|
||||
|
||||
fun init() {
|
||||
client = newClient(Endpoint.from(Config.redisUrl))
|
||||
}
|
||||
|
||||
suspend fun getPlayerLanguage(uuid: UUID): String? {
|
||||
try {
|
||||
return client.get("chatog:language:$uuid")
|
||||
} catch (e: Exception) {
|
||||
ChatOG.plugin.logger.log(Level.SEVERE, "Exception:", e)
|
||||
}
|
||||
return null
|
||||
}
|
||||
class LanguageDatabase {
|
||||
private val redisClient: RedisClient = RedisClient.create(Config.redisUrl)
|
||||
|
||||
/**
|
||||
* @return True if failed
|
||||
*/
|
||||
suspend fun setPlayerLanguage(uuid: UUID, language: String): Boolean {
|
||||
fun testConnection(): Boolean {
|
||||
try {
|
||||
client.set("chatog:language:$uuid", language)
|
||||
val connection = redisClient.connect()
|
||||
connection.close()
|
||||
return false
|
||||
} catch (e: Exception) {
|
||||
ChatOG.plugin.logger.log(Level.SEVERE, "Exception:", e)
|
||||
} catch (_: RedisConnectionException) {
|
||||
return true
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
fun getPlayerLanguage(uuid: UUID): String? {
|
||||
val connection = redisClient.connect()
|
||||
val commands = connection.sync()
|
||||
val value = commands.get("chatog:language:$uuid")
|
||||
connection.close()
|
||||
return value
|
||||
}
|
||||
|
||||
fun setPlayerLanguage(uuid: UUID, language: String) {
|
||||
val connection = redisClient.connect()
|
||||
val commands = connection.sync()
|
||||
commands.set("chatog:language:$uuid", language)
|
||||
connection.close()
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,12 @@ class ChatConfigReload : CommandExecutor {
|
||||
return true
|
||||
}
|
||||
|
||||
LanguageDatabase.init()
|
||||
ChatOG.languageDatabase = LanguageDatabase()
|
||||
if (ChatOG.languageDatabase.testConnection()) {
|
||||
ChatOG.plugin.logger.severe("Could not connect to Redis")
|
||||
Bukkit.getPluginManager().disablePlugin(ChatOG.plugin)
|
||||
return true
|
||||
}
|
||||
|
||||
if (Config.discordEnabled) {
|
||||
DiscordBridge.webhook = WebhookClient.withUrl(Config.webhook)
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package nl.skbotnl.chatog.commands
|
||||
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.launch
|
||||
import me.clip.placeholderapi.PlaceholderAPI
|
||||
import net.kyori.adventure.text.Component
|
||||
import net.kyori.adventure.text.JoinConfiguration
|
||||
import net.kyori.adventure.text.format.NamedTextColor
|
||||
import net.trueog.utilitiesog.UtilitiesOG
|
||||
import nl.skbotnl.chatog.*
|
||||
import nl.skbotnl.chatog.ChatOG
|
||||
import nl.skbotnl.chatog.Config
|
||||
import nl.skbotnl.chatog.Helper
|
||||
import nl.skbotnl.chatog.Helper.legacyToMm
|
||||
import org.bukkit.Bukkit
|
||||
import org.bukkit.command.Command
|
||||
@@ -97,40 +98,27 @@ class TranslateMessage : CommandExecutor {
|
||||
return true
|
||||
}
|
||||
|
||||
ChatOG.scope.launch {
|
||||
val language = LanguageDatabase.getPlayerLanguage(player.uniqueId)
|
||||
val language = ChatOG.languageDatabase.getPlayerLanguage(player.uniqueId)
|
||||
|
||||
if (language == null) {
|
||||
player.sendMessage(
|
||||
UtilitiesOG.trueogColorize("${Config.prefix}<reset>: <red>Something went wrong while trying to get your preferred language.")
|
||||
)
|
||||
return@launch
|
||||
}
|
||||
|
||||
player.sendMessage(UtilitiesOG.trueogColorize("${Config.prefix}<reset>: Translating message (this can take some time)..."))
|
||||
|
||||
val translated = ChatOG.translator!!.translate(sentMessage.message, language)
|
||||
translateCallback(translated, player, messageType, sentMessage, language)
|
||||
if (language == null) {
|
||||
player.sendMessage(
|
||||
UtilitiesOG.trueogColorize("${Config.prefix}<reset>: <red>Something went wrong while trying to get your preferred language.")
|
||||
)
|
||||
return true
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
player.sendMessage(UtilitiesOG.trueogColorize("${Config.prefix}<reset>: Translating message (this can take some time)..."))
|
||||
|
||||
val translated = ChatOG.translator!!.translate(sentMessage.message, language)
|
||||
|
||||
private fun translateCallback(
|
||||
translated: OpenAI.Translated,
|
||||
player: Player,
|
||||
messageType: Int,
|
||||
sentMessage: ISentMessage?,
|
||||
language: String
|
||||
) {
|
||||
if (translated.error != null) {
|
||||
player.sendMessage(translated.error)
|
||||
return
|
||||
return true
|
||||
}
|
||||
|
||||
if (translated.translatedText == null) {
|
||||
player.sendMessage(UtilitiesOG.trueogColorize("${Config.prefix}<reset>: <red>Could not translate that message."))
|
||||
return
|
||||
return true
|
||||
}
|
||||
|
||||
lateinit var translateMessage: Component
|
||||
@@ -198,5 +186,7 @@ class TranslateMessage : CommandExecutor {
|
||||
}
|
||||
}
|
||||
player.sendMessage(translateMessage)
|
||||
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,9 @@
|
||||
package nl.skbotnl.chatog.commands
|
||||
|
||||
import kotlinx.coroutines.DelicateCoroutinesApi
|
||||
import kotlinx.coroutines.launch
|
||||
import net.trueog.utilitiesog.UtilitiesOG
|
||||
import nl.skbotnl.chatog.ChatOG
|
||||
import nl.skbotnl.chatog.Config
|
||||
import nl.skbotnl.chatog.LanguageDatabase
|
||||
import org.bukkit.command.Command
|
||||
import org.bukkit.command.CommandExecutor
|
||||
import org.bukkit.command.CommandSender
|
||||
@@ -79,14 +77,8 @@ class TranslateSettings : CommandExecutor {
|
||||
return true
|
||||
}
|
||||
|
||||
ChatOG.scope.launch {
|
||||
val failed = LanguageDatabase.setPlayerLanguage(sender.uniqueId, language)
|
||||
if (failed) {
|
||||
sender.sendMessage(UtilitiesOG.trueogColorize("${Config.prefix}<reset>: <red>Failed to set your preferred language. Try again later."))
|
||||
return@launch
|
||||
}
|
||||
sender.sendMessage(UtilitiesOG.trueogColorize("${Config.prefix}<reset>: <green>Set language to: <white>$language."))
|
||||
}
|
||||
ChatOG.languageDatabase.setPlayerLanguage(sender.uniqueId, language)
|
||||
sender.sendMessage(UtilitiesOG.trueogColorize("${Config.prefix}<reset>: <green>Set language to: <white>$language."))
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -3,7 +3,8 @@
|
||||
prefix: <dark_gray>[<green>Chat<white>-<dark_red>OG<dark_gray>]
|
||||
|
||||
# ---Redis---
|
||||
redisUrl: 127.0.0.1:6379
|
||||
# Redis URL according to https://redis.github.io/lettuce/user-guide/connecting-redis/#uri-syntax
|
||||
redisUrl: 127.0.0.1:6379/0
|
||||
|
||||
# ---OpenAI API Translation---
|
||||
# Any OpenAI-compatible (OpenAI, ollama, llama.cpp) API will work here
|
||||
|
||||
Reference in new issue
Block a user