Skip to content

Commit

Permalink
Bump dependencies and a couple of other stuff idk
Browse files Browse the repository at this point in the history
  • Loading branch information
shuuyu committed Oct 5, 2024
1 parent 60b175b commit 6557a4e
Show file tree
Hide file tree
Showing 30 changed files with 164 additions and 172 deletions.
1 change: 0 additions & 1 deletion api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ dependencies {
implementation(project(":common"))
implementation(libs.bundles.kotlin)
implementation(libs.bundles.logger)
implementation(libs.bundles.parsers)
implementation(libs.bundles.ktor)
}
2 changes: 0 additions & 2 deletions bot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ dependencies {
implementation(libs.bundles.discord)
implementation(libs.bundles.database)
implementation(libs.bundles.jackson)
implementation(libs.bundles.parsers)
implementation(libs.bundles.logger)
implementation(libs.bundles.caching)
implementation(libs.kotlin.protobuf)
implementation(libs.bundles.ktor)
}

Expand Down
11 changes: 10 additions & 1 deletion bot/src/main/kotlin/live/shuuyu/nabi/NabiCore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,30 @@ class NabiCore(
1. We cannot register more than 100 slash commands, 5 user commands, and 5 message commands
2. It's better if we do this before initializing to prevent issues from coming up.
*/
fun preInitialization() = runBlocking {
private fun preInitialization() = runBlocking {
val slashCommandCount = interaktions.manager.applicationCommandsDeclarations.filterIsInstance<SlashCommandDeclaration>().size
val messageCommandCount = interaktions.manager.applicationCommandsDeclarations.filterIsInstance<MessageCommandDeclaration>().size

logger.info { "Running pre-initialization tasks, this may take a while..." }

require(slashCommandCount > 100) {
"Registered slash command count is more than 100! Exiting the process.... "
}
}

@OptIn(PrivilegedIntent::class)
fun initialize() = runBlocking {
// Initialize all of our microservices before the bot starts to prevent issues from arrising
preInitialization()
database.initialize()
database.createMissingSchemaAndColumns()
manager.registerGlobalApplicationCommands()
manager.registerGuildApplicationCommands(config.discord.defaultGuildId)
cache.initialize(kord)
metrics.start()

logger.info { "Initializing all Gateway instances of Nabi..." }

gatewayManager.gateways.forEach { (shardId, gateway) ->
gateway.installDiscordInteraKTions(interaktions)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import live.shuuyu.nabi.NabiCore
abstract class AbstractEventModule(val nabi: NabiCore) {
val kord = nabi.kord
val rest = nabi.rest
val cache = nabi.cache
val database = nabi.database
val logger = KotlinLogging.logger {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ class DiscordCacheModule(nabi: NabiCore): AbstractEventModule(nabi) {
is GuildCreate -> {
val guild = event.guild


cache.guilds[guild.id]
}

is GuildDelete -> {
val guildId = event.guild.id

cache.guilds.remove(guildId)
}

is GuildMemberAdd -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package live.shuuyu.nabi.events.impl

import com.github.luben.zstd.Zstd
import dev.kord.common.entity.DiscordUser
import dev.kord.common.entity.Snowflake
import dev.kord.core.behavior.ban
Expand Down Expand Up @@ -89,8 +88,6 @@ class PhishingBlocker(nabi: NabiCore): AbstractEventModule(nabi) {
agent = "Nabi-Phishing-Blocker"
}
}

private val zstd = Zstd()
}

// There may be multiple suspicious links in the same message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import live.shuuyu.nabi.utils.ColorUtils
import live.shuuyu.nabi.utils.MessageUtils
import org.jetbrains.exposed.sql.upsert

class Blacklist(nabi: NabiCore): NabiSlashCommandExecutor(nabi, LanguageManager("./locale/commands/Blacklist.toml")) {
class Blacklist(nabi: NabiCore): NabiSlashCommandExecutor(nabi, LanguageManager("./locale/commands/Blacklist.toml")) {
inner class Options: ApplicationCommandOptions() {
val user = user(i18n.get("userOptionName"), i18n.get("userOptionDescription"))
val reason = optionalString(i18n.get("reasonOptionName"), i18n.get("reasonOptionDescription")) {
Expand Down Expand Up @@ -66,7 +66,7 @@ class Blacklist(nabi: NabiCore): NabiSlashCommandExecutor(nabi, LanguageManager(
}
}.await()

MessageUtils.directMessageUser(target, rest, createBlacklistDirectMessage())
MessageUtils.directMessageUser(target, nabi, createBlacklistDirectMessage())
} catch (e: Exception) {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class BanExecutor(
)
}

MessageUtils.directMessageUser(target, rest, createDirectMessageEmbed(guild, reason))
MessageUtils.directMessageUser(target, nabi, createDirectMessageEmbed(guild, reason))

guild.ban(target.id) {
this.reason = reason
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class KickExecutor(
)
}

MessageUtils.directMessageUser(target, rest, createKickMessage())
MessageUtils.directMessageUser(target, nabi, createKickMessage())

guild.kick(target.id, reason)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class WarnExecutor(

MessageUtils.directMessageUser(
target,
rest,
nabi,
sendModerationLoggingMessage(target, executor, reason, ModerationInteractionWrapper.ModerationType.Warn)
)

Expand Down
21 changes: 15 additions & 6 deletions bot/src/main/kotlin/live/shuuyu/nabi/utils/MessageUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,39 @@ import dev.kord.rest.builder.message.embed
import dev.kord.rest.json.request.DMCreateRequest
import dev.kord.rest.json.request.MultipartMessageCreateRequest
import dev.kord.rest.request.RestRequestException
import dev.kord.rest.service.RestClient
import io.github.oshai.kotlinlogging.KotlinLogging
import kotlinx.datetime.Clock
import live.shuuyu.discordinteraktions.common.builder.message.MessageBuilder
import live.shuuyu.discordinteraktions.common.builder.message.embed
import live.shuuyu.nabi.NabiCore

object MessageUtils {
val logger = KotlinLogging.logger { }

suspend fun directMessageUser(
user: User,
rest: RestClient,
nabi: NabiCore,
builder: MultipartMessageCreateRequest
) {
val rest = nabi.rest
val dmChannelId = nabi.cache.channels[user.getDmChannel().id]?.id ?: nabi.rest.user.createDM(DMCreateRequest(user.id)).id
try {
val dmChannel = rest.user.createDM(DMCreateRequest(user.id))
rest.channel.createMessage(dmChannel.id, builder)
rest.channel.createMessage(dmChannelId, builder)
} catch (e: RestRequestException) {
logger.debug(e) {
"Failed to send direct message to the user, most likely because the user has their direct messages closed"
}

// It most likely is someone who doesn't exist, let's just delete it from the cache.
nabi.cache.channels.remove(dmChannelId)
}
}

suspend fun directMessageUser(
user: User,
rest: RestClient,
nabi: NabiCore,
builder: UserMessageCreateBuilder.() -> (Unit)
) = directMessageUser(user, rest, UserMessageCreateBuilder().apply(builder).toRequest())
) = directMessageUser(user, nabi, UserMessageCreateBuilder().apply(builder).toRequest())

fun createDirectMessageEmbed(
title: String,
Expand Down

This file was deleted.

41 changes: 21 additions & 20 deletions bot/src/main/kotlin/live/shuuyu/nabi/utils/i18n/LanguageManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,48 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory
import live.shuuyu.i18n.I18nContext
import live.shuuyu.i18n.I18nData
import live.shuuyu.i18n.LanguageData
import live.shuuyu.i18n.TextData
import java.io.File

class LanguageManager {
val context = mutableMapOf<String, I18nContext>()
val language = mutableMapOf<String, LanguageData>()

fun associate() = when {
fun getI18nContext(key: String): I18nContext {
return context[key]!!
}

fun associateData(data: TextData?): I18nData {
val strings = data?.strings?.toMutableMap() ?: mutableMapOf()
val lists = data?.lists?.toMutableMap() ?: mutableMapOf()

val textData = TextData(strings, lists)

else -> {}
return I18nData(LanguageData(), textData)
}

private fun load(file: File, i18n: I18nData) {
val files = file.listFiles()!!
val files = file.listFiles()!!.filter { it.isDirectory }.toMutableList()
val lists = i18n.text.lists.toMutableMap()
val strings = i18n.text.strings.toMutableMap()

val data = mapOf<String, LanguageData>()

for (childFile in files) {
if (childFile.isDirectory) {
load(childFile.absoluteFile, i18n)
} else {
val getMap: Map<String, Any> = when {
file.endsWith(".json") -> ObjectMapper().readValue(file, object: TypeReference<Map<String, Any>>() {})
file.endsWith(".yaml") -> ObjectMapper(YAMLFactory()).readValue(file, object: TypeReference<Map<String, Any>>() {})
file.endsWith(".toml") -> ObjectMapper(TomlFactory()).readValue(file, object: TypeReference<Map<String, Any>>() {})
file.endsWith(".json") -> ObjectMapper().readValue(childFile, object: TypeReference<Map<String, Any>>() {})
file.endsWith(".yaml") -> ObjectMapper(YAMLFactory()).readValue(childFile, object: TypeReference<Map<String, Any>>() {})
file.endsWith(".toml") -> ObjectMapper(TomlFactory()).readValue(childFile, object: TypeReference<Map<String, Any>>() {})
else -> throw UnsupportedOperationException("Cannot decode the sequestered file.")
}

getMap.forEach { (key, value) ->
when(value) {
is Map<*, *> -> load(childFile, i18n)

is List<*> -> {
lists[key] = value as List<String>
}

else -> {
strings[key] = (value as String)
}
}
}
}
}
}

private fun loadContext() {

}
}
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ repositories {
}

tasks.wrapper {
gradleVersion = "8.10.1"
gradleVersion = "8.10.2"
distributionType = Wrapper.DistributionType.ALL
}

Expand Down
1 change: 0 additions & 1 deletion common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ kotlin {
}

dependencies {
implementation(libs.bundles.parsers)
implementation(libs.bundles.caching)
implementation(libs.bundles.ktor)
implementation(libs.bundles.i18n)
Expand Down
4 changes: 2 additions & 2 deletions dashboard/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import com.github.gradle.node.pnpm.task.PnpmTask

plugins {
kotlin("jvm")
id("com.github.node-gradle.node") version "7.0.2"
id("com.github.node-gradle.node") version "7.1.0"
}

repositories {
mavenCentral() // BECAUSE APPARENTLY IT DOESN'T APPLY FROM DEPENDENCY RESOLUTION MANAGER
}

node {
version.set("20.16.0")
version.set("22.9.0")
pnpmVersion.set("9.11.0")
download.set(true)
}
Expand Down
Loading

0 comments on commit 6557a4e

Please sign in to comment.