diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 00000000..7e6e322b --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,17 @@ +version: 2 +enable-beta-ecosystems: true + +updates: + - package-ecosystem: "gradle" + target-branch: "develop" + directory: "/" + + schedule: + interval: "weekly" + + - package-ecosystem: "github-actions" + target-branch: "develop" + directory: "/" + + schedule: + interval: "weekly" diff --git a/README.md b/README.md index 14ce77be..d94dd38d 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ Lily makes use of the following tools and frameworks. * [Kord](https://github.com/kordlib/kord), the Kotlin API for Discord. * [KordEx](https://github.com/Kord-Extensions/kord-extensions), an integrated commands and extensions framework for Kord. * KordEx's [Phishing](https://github.com/Kord-Extensions/kord-extensions/tree/develop/extra-modules/extra-phishing), [PluralKit](https://github.com/Kord-Extensions/kord-extensions/tree/develop/extra-modules/extra-pluralkit) and [Unsafe](https://github.com/Kord-Extensions/kord-extensions/tree/develop/modules/unsafe) modules. -* [MongoDB](https://www.mongodb.com/) and [KMongo](https://litote.org/kmongo/) +* [MongoDB](https://www.mongodb.com/)'s [Kotlin Driver](https://www.mongodb.com/docs/drivers/kotlin/) to manage the database. * [Logback](https://github.com/qos-ch/logback), a library that makes logging prettier * [Kotlin Logging](https://github.com/MicroUtils/kotlin-logging), a lightweight logging that wraps SLF4J with kotlin extensions diff --git a/build.gradle.kts b/build.gradle.kts index fa430ee0..0ab16aad 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,6 @@ import org.jetbrains.kotlin.gradle.dsl.JvmTarget import org.jetbrains.kotlin.gradle.dsl.KotlinVersion import org.jetbrains.kotlin.gradle.tasks.KotlinCompile -@Suppress("DSL_SCOPE_VIOLATION") plugins { application @@ -16,7 +15,7 @@ plugins { } group = "org.hyacinthbots.lilybot" -version = "4.8.5" +version = "4.9.0" repositories { mavenCentral() @@ -54,6 +53,7 @@ dependencies { implementation(libs.kord.extensions.phishing) implementation(libs.kord.extensions.pluralkit) implementation(libs.kord.extensions.unsafe) + implementation(libs.kord.extensions.mongodb) implementation(libs.kotlin.stdlib) @@ -65,7 +65,7 @@ dependencies { implementation(libs.github.api) // KMongo - implementation(libs.kmongo) + implementation(libs.mongo.driver) // Cozy's welcome module implementation(libs.cozy.welcome) @@ -108,12 +108,18 @@ tasks { detekt { buildUponDefaultConfig = true - config = files("$rootDir/detekt.yml") + config.setFrom("$rootDir/detekt.yml") autoCorrect = true } -blossom { - replaceToken("@build_id@", grgit.head().abbreviatedId) - replaceToken("@version@", project.version.toString()) +sourceSets { + main { + blossom { + kotlinSources { + property("build_id", grgit.head().abbreviatedId) + property("version", project.version.toString()) + } + } + } } diff --git a/detekt.yml b/detekt.yml index e49473b0..4fa127fc 100644 --- a/detekt.yml +++ b/detekt.yml @@ -313,8 +313,6 @@ style: active: true OptionalUnit: active: false - OptionalWhenBraces: - active: true PreferToOverPairSyntax: active: true RedundantExplicitType: diff --git a/docs/changelogs/4.x.x/4.9.0.md b/docs/changelogs/4.x.x/4.9.0.md new file mode 100644 index 00000000..dd0c5a38 --- /dev/null +++ b/docs/changelogs/4.x.x/4.9.0.md @@ -0,0 +1,19 @@ +# LilyBot 4.9.0 + +This release removes th deprecated log uploading, expands the capabilities of the clear command and fixes many bugs +You can find the full changelog below + +New: +* Allow custom messages to be sent with bans, intended for adding Appeals Servers. This is part of the moderation config + +Change: +* The clear command can now clear different ranges of messages based on certain parameters. #348 +* Lily now uses the official Kotlin MongoDB driver, rather than KMongo. #351 +* Upgradle to 8.3 and update other dependencies + +Fix: +* Remove usage of deprecated username tags, making use of the new username system +* Fix bulk delete now working properly +* The permission checks on Auto-threading roles + +You can find a list of all the commits in this update [here](https://github.com/hyacinthbots/LilyBot/compare/v4.8.5...v4.9.0) diff --git a/docs/commands.md b/docs/commands.md index 6ab5f523..53e00423 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -46,6 +46,7 @@ Required Member Permissions: Manage Server * `quick-timeout-length` - The length of timeouts to use for quick timeouts - Coalescing Optional Duration * `warn-auto-punishments` - Whether to automatically punish users for reach a certain threshold on warns - Optional Boolean * `log-publicly` - Whether to log moderation publicly or not. - Optional Boolean + * `ban-dm-message` - A custom message to send to users when they are banned. - Optional String --- #### Command name: `config logging` @@ -291,12 +292,43 @@ Description: Kicks a user. * `image` - An image you'd like to provide as extra context for the action - Optional Attachment --- -### Command name: `clear` -Description: Clears messages from a channel. -**Required Member Permissions**: Manage Messages +#### Command name: `clear count` +**Description**: Clear a specific count of messages +Required Member Permissions: Manage Messages -* Arguments: +* **Arguments**: * `messages` - Number of messages to delete - Int + * `author` - The author of the messages to clear - Optional User + +--- +#### Command name: `clear before` +**Description**: Clear messages before a given message ID +Required Member Permissions: Manage Messages + +* **Arguments**: + * `before` - The ID of the message to clear before - Snowflake + * `message-count` - The number of messages to clear - Optional Int/Long + * `author` - The author of the messages to clear - Optional User + +--- +#### Command name: `clear after` +**Description**: Clear messages before a given message ID +Required Member Permissions: Manage Messages + +* **Arguments**: + * `after` - The ID of the message to clear after - Snowflake + * `message-count` - The number of messages to clear - Optional Int/Long + * `author` - The author of the messages to clear - Optional User + +--- +#### Command name: `clear between` +**Description**: Clear messages between 2 message IDs +Required Member Permissions: Manage Messages + +* **Arguments**: + * `after` - The ID of the message to clear after - Snowflake + * `before` - The ID of the message to clear before - Snowflake + * `author` - The author of the messages to clear - Optional User --- ### Command name: `timeout` @@ -645,7 +677,7 @@ Description: Check whether a given domain is a known phishing domain. **Description**: Set a custom API URL, "reset" to reset * **Arguments**: - * `api-url` - Set an alternative API url, or "reset" to use the default - Optional String + * `api-url` - Set an alternative API URL, or "reset" to use the default - Optional String --- #### Command name: `pluralkit bot` diff --git a/libs.versions.toml b/gradle/libs.versions.toml similarity index 77% rename from libs.versions.toml rename to gradle/libs.versions.toml index 0049acde..c1bce581 100644 --- a/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,18 +1,19 @@ [versions] # Plugins -kotlin = "1.8.21" +kotlin = "1.9.10" shadow = "8.1.1" -detekt = "1.23.0" +detekt = "1.23.1" git-hooks = "0.0.2" grgit = "5.2.0" -blossom = "1.3.1" +blossom = "2.0.1" # Libraries -kord-extensions = "1.5.8-20230618.092018-1" -logging = "3.0.5" -logback = "1.4.7" -github-api = "1.314" -kmongo = "4.9.0" +#kord-extensions = "1.5.9-20230820.204324-8" +kord-extensions = "1.5.9-SNAPSHOT" +logging = "5.1.0" +logback = "1.4.11" +github-api = "1.316" +mongo-driver = "4.10.2" cozy-welcome = "1.0.1-SNAPSHOT" dma = "v0.2.1" docgenerator = "0.1.2-SNAPSHOT" @@ -22,11 +23,12 @@ kord-extensions-core = { module = "com.kotlindiscord.kord.extensions:kord-extens kord-extensions-phishing = { module = "com.kotlindiscord.kord.extensions:extra-phishing", version.ref = "kord-extensions" } kord-extensions-pluralkit = { module = "com.kotlindiscord.kord.extensions:extra-pluralkit", version.ref = "kord-extensions"} kord-extensions-unsafe = { module = "com.kotlindiscord.kord.extensions:unsafe", version.ref = "kord-extensions"} +kord-extensions-mongodb = { module = "com.kotlindiscord.kord.extensions:adapter-mongodb", version.ref = "kord-extensions" } kotlin-stdlib = { module = "org.jetbrains.kotlin:kotlin-stdlib" } logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback" } -logging = { module = "io.github.microutils:kotlin-logging", version.ref = "logging" } +logging = { module = "io.github.oshai:kotlin-logging", version.ref = "logging" } github-api = { module = "org.kohsuke:github-api", version.ref = "github-api" } -kmongo = { module = "org.litote.kmongo:kmongo-coroutine-serialization", version.ref = "kmongo" } +mongo-driver = { module = "org.mongodb:mongodb-driver-kotlin-coroutine", version.ref = "mongo-driver" } detekt = { module = "io.gitlab.arturbosch.detekt:detekt-formatting", version.ref = "detekt"} cozy-welcome = {module = "org.quiltmc.community:module-welcome", version.ref = "cozy-welcome"} dma = { module = "org.hyacinthbots:discord-moderation-actions", version.ref = "dma"} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index c1962a79..7f93135c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 37aef8d3..ac72c34e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.1.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index aeb74cbb..0adc8e1a 100755 --- a/gradlew +++ b/gradlew @@ -83,7 +83,8 @@ done # This is normally unused # shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -130,10 +131,13 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. diff --git a/settings.gradle.kts b/settings.gradle.kts index 5746ff1b..9e813ec3 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1,9 +1 @@ rootProject.name = "LilyBot" - -dependencyResolutionManagement { - versionCatalogs { - create("libs") { - from(files("libs.versions.toml")) - } - } -} diff --git a/src/main/kotlin-templates/org/hyacinthbots/lilybot/internal/BuildInfo.kt b/src/main/kotlin-templates/org/hyacinthbots/lilybot/internal/BuildInfo.kt new file mode 100644 index 00000000..838c9b20 --- /dev/null +++ b/src/main/kotlin-templates/org/hyacinthbots/lilybot/internal/BuildInfo.kt @@ -0,0 +1,12 @@ +package org.hyacinthbots.lilybot.internal + +/** + * This object stores the constants for the Build ID and version of Lily in her current state + */ +object BuildInfo { + /** The short commit hash of this build of Lily. */ + const val BUILD_ID: String = "{{ build_id }}" + + /** The current version of LilyBot. */ + const val LILY_VERSION: String = "{{ version }}" +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/LilyBot.kt b/src/main/kotlin/org/hyacinthbots/lilybot/LilyBot.kt index e62330d5..321fd211 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/LilyBot.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/LilyBot.kt @@ -3,6 +3,7 @@ package org.hyacinthbots.lilybot import com.kotlindiscord.kord.extensions.ExtensibleBot +import com.kotlindiscord.kord.extensions.adapters.mongodb.mongoDB import com.kotlindiscord.kord.extensions.checks.hasPermission import com.kotlindiscord.kord.extensions.modules.extra.phishing.DetectionAction import com.kotlindiscord.kord.extensions.modules.extra.phishing.extPhishing @@ -10,12 +11,11 @@ import com.kotlindiscord.kord.extensions.modules.extra.pluralkit.extPluralKit import dev.kord.common.entity.Permission import dev.kord.gateway.Intent import dev.kord.gateway.PrivilegedIntent -import mu.KotlinLogging +import io.github.oshai.kotlinlogging.KotlinLogging import org.hyacinthbots.docgenerator.docsGenerator import org.hyacinthbots.docgenerator.enums.CommandTypes import org.hyacinthbots.docgenerator.enums.SupportedFileFormat import org.hyacinthbots.lilybot.database.collections.WelcomeChannelCollection -import org.hyacinthbots.lilybot.database.storage.MongoDBDataAdapter import org.hyacinthbots.lilybot.extensions.config.Config import org.hyacinthbots.lilybot.extensions.config.ConfigOptions import org.hyacinthbots.lilybot.extensions.config.GuildLogging @@ -60,7 +60,7 @@ val docFile = Path("./docs/commands.md") suspend fun main() { val bot = ExtensibleBot(BOT_TOKEN) { database(true) - dataAdapter(::MongoDBDataAdapter) + mongoDB() members { lockMemberRequests = true // Collect members one at a time to avoid hitting rate limits @@ -146,10 +146,10 @@ suspend fun main() { // Connect to GitHub to allow the GitHub commands to function try { github = GitHubBuilder().build() - gitHubLogger.info("Connected to GitHub!") + gitHubLogger.info { "Connected to GitHub!" } } catch (exception: IOException) { exception.printStackTrace() - gitHubLogger.error("Failed to connect to GitHub!") + gitHubLogger.error { "Failed to connect to GitHub!" } } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/Cleanups.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/Cleanups.kt index 7d5671ac..a9975248 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/Cleanups.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/Cleanups.kt @@ -1,10 +1,12 @@ package org.hyacinthbots.lilybot.database import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import dev.kord.core.Kord import dev.kord.core.behavior.getChannelOfOrNull import dev.kord.core.entity.channel.thread.ThreadChannel import dev.kord.rest.request.KtorRequestException +import kotlinx.coroutines.flow.toList import kotlinx.datetime.Clock import mu.KotlinLogging import org.hyacinthbots.lilybot.database.Cleanups.cleanupGuildData @@ -24,7 +26,6 @@ import org.hyacinthbots.lilybot.database.collections.WelcomeChannelCollection import org.hyacinthbots.lilybot.database.entities.GuildLeaveTimeData import org.hyacinthbots.lilybot.database.entities.ThreadData import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This object contains the Database clean up functions, for removing old data from the database that Lily no longer @@ -38,10 +39,10 @@ object Cleanups : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val guildLeaveTimeCollection = db.mainDatabase.getCollection() + internal val guildLeaveTimeCollection = db.mainDatabase.getCollection(GuildLeaveTimeData.name) @PublishedApi - internal val threadDataCollection = db.mainDatabase.getCollection() + internal val threadDataCollection = db.mainDatabase.getCollection(ThreadData.name) @PublishedApi internal val cleanupsLogger = KotlinLogging.logger("Database Cleanups") @@ -75,7 +76,7 @@ object Cleanups : KordExKoinComponent { UtilityConfigCollection().clearConfig(it.guildId) WarnCollection().clearWarns(it.guildId) WelcomeChannelCollection().removeWelcomeChannelsForGuild(it.guildId, kord) - guildLeaveTimeCollection.deleteOne(GuildLeaveTimeData::guildId eq it.guildId) + guildLeaveTimeCollection.deleteOne(eq(GuildLeaveTimeData::guildId.name, it.guildId)) deletedGuildData += 1 // Increment the counter for logging } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/Collection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/Collection.kt new file mode 100644 index 00000000..41413e0e --- /dev/null +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/Collection.kt @@ -0,0 +1,22 @@ +package org.hyacinthbots.lilybot.database + +/** + * This class stores the name of a collection, so it can be referenced easily, avoiding string duplication + * + * An example of how it should be used can be found below. The name property used in the get collection line comes from + * this class + * ```kt + * class MagicCollection : KordExKoinComponent { + * private val db: Database by inject() + * + * val collection = db.mainDatabase.getCollection(name) + * + * suspend fun get(): List = collection.find().toList() + * + * companion object : Collection("magicCollection") + * } + * ``` + * + * @property name The name of the collection + */ +abstract class Collection(val name: String) diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/Database.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/Database.kt index 01e2d82c..dd3c19ea 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/Database.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/Database.kt @@ -1,22 +1,29 @@ package org.hyacinthbots.lilybot.database +import com.kotlindiscord.kord.extensions.adapters.mongodb.kordExCodecRegistry import com.mongodb.ConnectionString import com.mongodb.MongoClientSettings +import com.mongodb.kotlin.client.coroutine.MongoClient import org.bson.UuidRepresentation +import org.bson.codecs.configuration.CodecRegistries import org.hyacinthbots.lilybot.database.migrations.Migrator import org.hyacinthbots.lilybot.utils.MONGO_URI -import org.litote.kmongo.coroutine.coroutine -import org.litote.kmongo.reactivestreams.KMongo class Database { + private val codecRegistries = CodecRegistries.fromRegistries( + kordExCodecRegistry, + MongoClientSettings.getDefaultCodecRegistry() + ) + // Connect to the database using the provided connection URL private val settings = MongoClientSettings .builder() .uuidRepresentation(UuidRepresentation.STANDARD) .applyConnectionString(ConnectionString(MONGO_URI)) + .codecRegistry(codecRegistries) .build() - private val client = KMongo.createClient(settings).coroutine + private val client = MongoClient.create(settings) /** The main database for storing data. */ val mainDatabase get() = client.getDatabase("LilyBot") @@ -24,6 +31,8 @@ class Database { /** The database for storing per guild configuration data. */ val configDatabase get() = client.getDatabase("LilyBotConfig") + val tempKordExDatabase get() = client.getDatabase("kordex-data") + /** * Runs the migrations for both databases. * diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/_DatabaseUtils.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/_DatabaseUtils.kt new file mode 100644 index 00000000..188d7453 --- /dev/null +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/_DatabaseUtils.kt @@ -0,0 +1,18 @@ +package org.hyacinthbots.lilybot.database + +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Filters.and +import com.mongodb.kotlin.client.coroutine.FindFlow +import com.mongodb.kotlin.client.coroutine.MongoCollection +import kotlinx.coroutines.flow.firstOrNull +import org.bson.conversions.Bson + +private fun MongoCollection.find(vararg filters: Bson?): FindFlow = find(and(*filters)) + +suspend fun MongoCollection.findOne(filter: Bson): T? = find(filter).firstOrNull() + +suspend fun MongoCollection.findOne(vararg filters: Bson?): T? = find(*filters).firstOrNull() + +suspend fun MongoCollection.deleteOne() = deleteOne(Filters.empty()) + +// TODO Make more cool useful functions diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/AutoThreadingCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/AutoThreadingCollection.kt index db1c6104..071204e1 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/AutoThreadingCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/AutoThreadingCollection.kt @@ -1,11 +1,13 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake +import kotlinx.coroutines.flow.toList import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.AutoThreadingData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [AutoThreading Database][AutoThreadingData]. This @@ -22,7 +24,7 @@ class AutoThreadingCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(AutoThreadingData.name) /** * Gets all auto threads for a given [inputGuildId]. @@ -33,7 +35,7 @@ class AutoThreadingCollection : KordExKoinComponent { * @since 4.6.0 */ suspend inline fun getAllAutoThreads(inputGuildId: Snowflake): List = - collection.find(AutoThreadingData::guildId eq inputGuildId).toList() + collection.find(eq(AutoThreadingData::guildId.name, inputGuildId)).toList() /** * Gets a single auto thread based off the channel ID. @@ -44,7 +46,7 @@ class AutoThreadingCollection : KordExKoinComponent { * @since 4.6.0 */ suspend inline fun getSingleAutoThread(inputChannelId: Snowflake): AutoThreadingData? = - collection.findOne(AutoThreadingData::channelId eq inputChannelId) + collection.findOne(eq(AutoThreadingData::channelId.name, inputChannelId)) /** * Sets a new auto thread. @@ -54,7 +56,7 @@ class AutoThreadingCollection : KordExKoinComponent { * @since 4.6.0 */ suspend inline fun setAutoThread(inputAutoThreadData: AutoThreadingData) { - collection.deleteOne(AutoThreadingData::channelId eq inputAutoThreadData.channelId) + collection.deleteOne(eq(AutoThreadingData::channelId.name, inputAutoThreadData.channelId)) collection.insertOne(inputAutoThreadData) } @@ -66,7 +68,7 @@ class AutoThreadingCollection : KordExKoinComponent { * @since 4.6.0 */ suspend inline fun deleteAutoThread(inputChannelId: Snowflake) = - collection.deleteOne(AutoThreadingData::channelId eq inputChannelId) + collection.deleteOne(eq(AutoThreadingData::channelId.name, inputChannelId)) /** * Deletes auto threads for a given guild. @@ -76,5 +78,5 @@ class AutoThreadingCollection : KordExKoinComponent { * @since 4.6.0 */ suspend inline fun deleteGuildAutoThreads(inputGuildId: Snowflake) = - collection.deleteMany(AutoThreadingData::guildId eq inputGuildId) + collection.deleteMany(eq(AutoThreadingData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ConfigCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ConfigCollection.kt index 61752bca..df428d1a 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ConfigCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ConfigCollection.kt @@ -1,13 +1,14 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.LoggingConfigData import org.hyacinthbots.lilybot.database.entities.ModerationConfigData import org.hyacinthbots.lilybot.database.entities.UtilityConfigData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [Logging Config Database][LoggingConfigData]. This class @@ -22,7 +23,7 @@ class LoggingConfigCollection : KordExKoinComponent { private val configDb: Database by inject() @PublishedApi - internal val collection = configDb.configDatabase.getCollection() + internal val collection = configDb.configDatabase.getCollection(LoggingConfigData.name) /** * Gets the logging config for the given guild using the [guildId][inputGuildId]. @@ -33,7 +34,7 @@ class LoggingConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun getConfig(inputGuildId: Snowflake): LoggingConfigData? = - collection.findOne(LoggingConfigData::guildId eq inputGuildId) + collection.findOne(eq(LoggingConfigData::guildId.name, inputGuildId)) /** * Adds the given [loggingConfig] to the database. @@ -43,7 +44,7 @@ class LoggingConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun setConfig(loggingConfig: LoggingConfigData) { - collection.deleteOne(LoggingConfigData::guildId eq loggingConfig.guildId) + collection.deleteOne(eq(LoggingConfigData::guildId.name, loggingConfig.guildId)) collection.insertOne(loggingConfig) } @@ -55,7 +56,7 @@ class LoggingConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun clearConfig(inputGuildId: Snowflake) = - collection.deleteOne(LoggingConfigData::guildId eq inputGuildId) + collection.deleteOne(eq(LoggingConfigData::guildId.name, inputGuildId)) } /** @@ -71,7 +72,7 @@ class ModerationConfigCollection : KordExKoinComponent { private val configDb: Database by inject() @PublishedApi - internal val collection = configDb.configDatabase.getCollection() + internal val collection = configDb.configDatabase.getCollection(ModerationConfigData.name) /** * Gets the Moderation config for the given guild using the [guildId][inputGuildId]. @@ -82,7 +83,7 @@ class ModerationConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun getConfig(inputGuildId: Snowflake): ModerationConfigData? = - collection.findOne(ModerationConfigData::guildId eq inputGuildId) + collection.findOne(eq(ModerationConfigData::guildId.name, inputGuildId)) /** * Adds the given [moderationConfig] to the database. @@ -92,7 +93,7 @@ class ModerationConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun setConfig(moderationConfig: ModerationConfigData) { - collection.deleteOne(ModerationConfigData::guildId eq moderationConfig.guildId) + collection.deleteOne(eq(ModerationConfigData::guildId.name, moderationConfig.guildId)) collection.insertOne(moderationConfig) } @@ -104,7 +105,7 @@ class ModerationConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun clearConfig(inputGuildId: Snowflake) = - collection.deleteOne(ModerationConfigData::guildId eq inputGuildId) + collection.deleteOne(eq(ModerationConfigData::guildId.name, inputGuildId)) } /** @@ -120,7 +121,7 @@ class UtilityConfigCollection : KordExKoinComponent { private val configDb: Database by inject() @PublishedApi - internal val collection = configDb.configDatabase.getCollection() + internal val collection = configDb.configDatabase.getCollection(UtilityConfigData.name) /** * Gets the Utility config for the given guild using the [guildId][inputGuildId]. @@ -131,7 +132,7 @@ class UtilityConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun getConfig(inputGuildId: Snowflake): UtilityConfigData? = - collection.findOne(UtilityConfigData::guildId eq inputGuildId) + collection.findOne(eq(UtilityConfigData::guildId.name, inputGuildId)) /** * Adds the given [utilityConfig] to the database. @@ -141,7 +142,7 @@ class UtilityConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun setConfig(utilityConfig: UtilityConfigData) { - collection.deleteOne(UtilityConfigData::guildId eq utilityConfig.guildId) + collection.deleteOne(eq(UtilityConfigData::guildId.name, utilityConfig.guildId)) collection.insertOne(utilityConfig) } @@ -153,5 +154,5 @@ class UtilityConfigCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun clearConfig(inputGuildId: Snowflake) = - collection.deleteOne(UtilityConfigData::guildId eq inputGuildId) + collection.deleteOne(eq(UtilityConfigData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GalleryChannelCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GalleryChannelCollection.kt index c9b75e79..d647eba5 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GalleryChannelCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GalleryChannelCollection.kt @@ -1,12 +1,13 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.and +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake +import kotlinx.coroutines.flow.toList import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.GalleryChannelData import org.koin.core.component.inject -import org.litote.kmongo.coroutine.CoroutineCollection -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [Gallery Channel Database][GalleryChannelData]. This @@ -22,17 +23,17 @@ class GalleryChannelCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(GalleryChannelData.name) /** * Collects every gallery channel in the database into a [List]. * - * @return The [CoroutineCollection] of [GalleryChannelData] for all the gallery channels in the database + * @return The [MongoCollection] of [GalleryChannelData] for all the gallery channels in the database * @author NoComment1105 * @since 3.3.0 */ suspend inline fun getChannels(inputGuildId: Snowflake): List = - collection.find(GalleryChannelData::guildId eq inputGuildId).toList() + collection.find(eq(GalleryChannelData::guildId.name, inputGuildId)).toList() /** * Stores a channel ID as input by the user, in the database, with it's corresponding guild, allowing us to find @@ -56,8 +57,10 @@ class GalleryChannelCollection : KordExKoinComponent { */ suspend inline fun removeChannel(inputGuildId: Snowflake, inputChannelId: Snowflake) = collection.deleteOne( - GalleryChannelData::channelId eq inputChannelId, - GalleryChannelData::guildId eq inputGuildId + and( + eq(GalleryChannelData::channelId.name, inputChannelId), + eq(GalleryChannelData::guildId.name, inputGuildId) + ) ) /** @@ -68,5 +71,5 @@ class GalleryChannelCollection : KordExKoinComponent { * @since 4.1.0 */ suspend inline fun removeAll(inputGuildId: Snowflake) = - collection.deleteMany(GalleryChannelData::guildId eq inputGuildId) + collection.deleteMany(eq(GalleryChannelData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GithubCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GithubCollection.kt index 98732e2f..2a95ea9b 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GithubCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GithubCollection.kt @@ -1,11 +1,12 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.GithubData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [GitHub database][GithubData]. This class contains @@ -20,7 +21,7 @@ class GithubCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(GithubData.name) /** * Gets the default repo for GitHub commands. @@ -31,7 +32,7 @@ class GithubCollection : KordExKoinComponent { * @since 4.3.0 */ suspend inline fun getDefaultRepo(inputGuildId: Snowflake): String? = - collection.findOne(GithubData::guildId eq inputGuildId)?.defaultRepo + collection.findOne(eq(GithubData::guildId.name, inputGuildId))?.defaultRepo /** * Sets the default repo for GitHub commands. @@ -42,7 +43,7 @@ class GithubCollection : KordExKoinComponent { * @since 4.3.0 */ suspend inline fun setDefaultRepo(inputGuildId: Snowflake, url: String) { - collection.deleteOne(GithubData::guildId eq inputGuildId) + collection.deleteOne(eq(GithubData::guildId.name, inputGuildId)) collection.insertOne(GithubData(inputGuildId, url)) } @@ -54,5 +55,5 @@ class GithubCollection : KordExKoinComponent { * @since 4.3.0 */ suspend inline fun removeDefaultRepo(inputGuildId: Snowflake) = - collection.deleteOne(GithubData::guildId eq inputGuildId) + collection.deleteOne(eq(GithubData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GuildLeaveTimeCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GuildLeaveTimeCollection.kt index 60b21c6b..6b1a35ec 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GuildLeaveTimeCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GuildLeaveTimeCollection.kt @@ -1,12 +1,12 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake import kotlinx.datetime.Instant import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.GuildLeaveTimeData import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [Guild Leave Time Database][GuildLeaveTimeData]. This @@ -20,7 +20,7 @@ class GuildLeaveTimeCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(GuildLeaveTimeData.name) /** * Adds the time Lily bot left a guild with a config. @@ -43,5 +43,5 @@ class GuildLeaveTimeCollection : KordExKoinComponent { * @since 3.2.0 */ suspend inline fun removeLeaveTime(inputGuildId: Snowflake) = - collection.deleteOne(GuildLeaveTimeData::guildId eq inputGuildId) + collection.deleteOne(eq(GuildLeaveTimeData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/MetaCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/MetaCollection.kt index 01ae94aa..3eddab80 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/MetaCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/MetaCollection.kt @@ -1,11 +1,12 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.ConfigMetaData import org.hyacinthbots.lilybot.database.entities.MainMetaData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [main meta database][MainMetaData]. This class @@ -20,7 +21,7 @@ class MainMetaCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(MainMetaData.name) /** * Gets the main metadata from the database. @@ -30,7 +31,7 @@ class MainMetaCollection : KordExKoinComponent { * @since 4.0.0 */ suspend fun get(): MainMetaData? = - collection.findOne() + collection.findOne(eq(MainMetaData::id.name, "mainMeta")) /** * Sets the metadata when the table is first created. @@ -49,7 +50,7 @@ class MainMetaCollection : KordExKoinComponent { */ suspend fun update(meta: MainMetaData) = collection.findOneAndReplace( - MainMetaData::id eq "mainMeta", + eq(MainMetaData::id.name, "mainMeta"), meta ) } @@ -67,7 +68,7 @@ class ConfigMetaCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.configDatabase.getCollection() + internal val collection = db.configDatabase.getCollection(ConfigMetaData.name) /** * Gets the config metadata from the database. @@ -77,7 +78,7 @@ class ConfigMetaCollection : KordExKoinComponent { * @since 4.0.0 */ suspend fun get(): ConfigMetaData? = - collection.findOne() + collection.findOne(eq(ConfigMetaData::id.name, "configMeta")) /** * Sets the metadata when the table is first created. @@ -96,7 +97,7 @@ class ConfigMetaCollection : KordExKoinComponent { */ suspend fun update(meta: ConfigMetaData) = collection.findOneAndReplace( - ConfigMetaData::id eq "configMeta", + eq(ConfigMetaData::id.name, "configMeta"), meta ) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/NewsChannelPublishingCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/NewsChannelPublishingCollection.kt index 2851da56..1bf10b8c 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/NewsChannelPublishingCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/NewsChannelPublishingCollection.kt @@ -1,11 +1,14 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.and +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake +import kotlinx.coroutines.flow.toList import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.NewsChannelPublishingData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains functions for interacting with the [news channel publishing database][NewsChannelPublishingData]. @@ -22,7 +25,7 @@ class NewsChannelPublishingCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(NewsChannelPublishingData.name) /** * Adds a channel for auto-publishing. @@ -47,8 +50,10 @@ class NewsChannelPublishingCollection : KordExKoinComponent { */ suspend inline fun removeAutoPublishingChannel(inputGuildId: Snowflake, inputChannelId: Snowflake) = collection.deleteOne( - NewsChannelPublishingData::guildId eq inputGuildId, - NewsChannelPublishingData::channelId eq inputChannelId + and( + eq(NewsChannelPublishingData::guildId.name, inputGuildId), + eq(NewsChannelPublishingData::channelId.name, inputChannelId) + ) ) /** @@ -66,8 +71,8 @@ class NewsChannelPublishingCollection : KordExKoinComponent { inputChannelId: Snowflake ): NewsChannelPublishingData? = collection.findOne( - NewsChannelPublishingData::guildId eq inputGuildId, - NewsChannelPublishingData::channelId eq inputChannelId + eq(NewsChannelPublishingData::guildId.name, inputGuildId), + eq(NewsChannelPublishingData::channelId.name, inputChannelId) ) /** @@ -80,7 +85,7 @@ class NewsChannelPublishingCollection : KordExKoinComponent { * @since 4.7.0 */ suspend inline fun getAutoPublishingChannels(inputGuildId: Snowflake): List = - collection.find(NewsChannelPublishingData::guildId eq inputGuildId).toList() + collection.find(eq(NewsChannelPublishingData::guildId.name, inputGuildId)).toList() /** * Clears all the auto-publishing channels from a guild. @@ -91,6 +96,6 @@ class NewsChannelPublishingCollection : KordExKoinComponent { * @since 4.7.0 */ suspend inline fun clearAutoPublishingForGuild(inputGuildId: Snowflake) { - collection.deleteMany(NewsChannelPublishingData::guildId eq inputGuildId) + collection.deleteMany(eq(NewsChannelPublishingData::guildId.name, inputGuildId)) } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ReminderCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ReminderCollection.kt index 90e719d2..f4a066d9 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ReminderCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ReminderCollection.kt @@ -1,14 +1,16 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.and +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake +import kotlinx.coroutines.flow.toList import kotlinx.datetime.DateTimePeriod import kotlinx.datetime.TimeZone import kotlinx.datetime.plus import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.ReminderData import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with []the reminder database][ReminderData]. This @@ -28,7 +30,7 @@ class ReminderCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(ReminderData.name) /** * Gets all the reminders currently in the database. @@ -48,7 +50,7 @@ class ReminderCollection : KordExKoinComponent { * @since 4.2.0 */ suspend fun getRemindersForUser(userId: Snowflake): List = - collection.find(ReminderData::userId eq userId).toList() + collection.find(eq(ReminderData::userId.name, userId)).toList() /** * Gets all the reminders in the database for a specific user, in a specific guild. @@ -80,7 +82,7 @@ class ReminderCollection : KordExKoinComponent { * @since 4.2.0 */ suspend fun removeReminder(userId: Snowflake, number: Long) = - collection.deleteOne(ReminderData::userId eq userId, ReminderData::id eq number) + collection.deleteOne(and(eq(ReminderData::userId.name, userId), eq(ReminderData::id.name, number))) /** * Removes all the reminders for a given guild. @@ -89,7 +91,7 @@ class ReminderCollection : KordExKoinComponent { * @author NoComment1105 * @since 4.2.0 */ - suspend fun removeGuildReminders(guildId: Snowflake) = collection.deleteMany(ReminderData::guildId eq guildId) + suspend fun removeGuildReminders(guildId: Snowflake) = collection.deleteMany(eq(ReminderData::guildId.name, guildId)) /** * Updates a repeating reminder to be extended by the given [repeatingInterval]. diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleMenuCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleMenuCollection.kt index f8319ee5..1999ab21 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleMenuCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleMenuCollection.kt @@ -1,11 +1,12 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.RoleMenuData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [Role Menu Database][RoleMenuData]. This class contains @@ -21,7 +22,7 @@ class RoleMenuCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(RoleMenuData.name) /** * Using the provided [inputMessageId] the associated [RoleMenuData] will be returned from the database. @@ -32,7 +33,7 @@ class RoleMenuCollection : KordExKoinComponent { * @since 3.4.0 */ suspend inline fun getRoleData(inputMessageId: Snowflake): RoleMenuData? = - collection.findOne(RoleMenuData::messageId eq inputMessageId) + collection.findOne(eq(RoleMenuData::messageId.name, inputMessageId)) /** * Add the given [inputRoles] to the database entry for the role menu for the provided [inputMessageId], @@ -52,7 +53,7 @@ class RoleMenuCollection : KordExKoinComponent { inputRoles: MutableList ) { val newRoleMenu = RoleMenuData(inputMessageId, inputChannelId, inputGuildId, inputRoles) - collection.deleteOne(RoleMenuData::messageId eq inputMessageId) + collection.deleteOne(eq(RoleMenuData::messageId.name, inputMessageId)) collection.insertOne(newRoleMenu) } @@ -65,11 +66,11 @@ class RoleMenuCollection : KordExKoinComponent { * @since 3.4.0 */ suspend inline fun removeRoleFromMenu(inputMessageId: Snowflake, inputRoleId: Snowflake) { - val roleMenu = collection.findOne(RoleMenuData::messageId eq inputMessageId) ?: return + val roleMenu = collection.findOne(eq(RoleMenuData::messageId.name, inputMessageId)) ?: return roleMenu.roles.remove(inputRoleId) - collection.deleteOne(RoleMenuData::messageId eq inputMessageId) + collection.deleteOne(eq(RoleMenuData::messageId.name, inputMessageId)) collection.insertOne(roleMenu) } @@ -81,5 +82,5 @@ class RoleMenuCollection : KordExKoinComponent { * @since 4.0.0 */ suspend inline fun removeAllRoleMenus(inputGuildId: Snowflake) = - collection.deleteMany(RoleMenuData::guildId eq inputGuildId) + collection.deleteMany(eq(RoleMenuData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleSubscriptionCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleSubscriptionCollection.kt index 027e5272..17523a39 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleSubscriptionCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleSubscriptionCollection.kt @@ -1,11 +1,13 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq +import com.mongodb.client.model.Updates import dev.kord.common.entity.Snowflake import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.RoleSubscriptionData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [Role Subscription database][RoleSubscriptionData]. This @@ -22,7 +24,7 @@ class RoleSubscriptionCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(RoleSubscriptionData.name) /** * Gets the roles that are subscribable for a given guild. @@ -34,7 +36,7 @@ class RoleSubscriptionCollection : KordExKoinComponent { * @since 4.9.0 */ suspend inline fun getSubscribableRoles(inputGuildId: Snowflake): RoleSubscriptionData? = - collection.findOne(RoleSubscriptionData::guildId eq inputGuildId) + collection.findOne(eq(RoleSubscriptionData::guildId.name, inputGuildId)) /** * Creates a subscribable role record in the database. This should only be used if a record does not already exist. @@ -58,12 +60,12 @@ class RoleSubscriptionCollection : KordExKoinComponent { * @since 4.9.0 */ suspend inline fun addSubscribableRole(inputGuildId: Snowflake, inputRoleId: Snowflake): Boolean? { - val col = collection.findOne(RoleSubscriptionData::guildId eq inputGuildId) ?: return null + val col = collection.findOne(eq(RoleSubscriptionData::guildId.name, inputGuildId)) ?: return null val newRoleList = col.subscribableRoles if (newRoleList.contains(inputRoleId)) return false else newRoleList.add(inputRoleId) collection.updateOne( - RoleSubscriptionData::guildId eq inputGuildId, - RoleSubscriptionData(inputGuildId, newRoleList) + eq(RoleSubscriptionData::guildId.name, inputGuildId), + Updates.set(RoleSubscriptionData::guildId.name, newRoleList) ) return true } @@ -79,7 +81,7 @@ class RoleSubscriptionCollection : KordExKoinComponent { * @since 4.9.0 */ suspend inline fun removeSubscribableRole(inputGuildId: Snowflake, inputRoleId: Snowflake): Boolean? { - val col = collection.findOne(RoleSubscriptionData::guildId eq inputGuildId) ?: return null + val col = collection.findOne(eq(RoleSubscriptionData::guildId.name, inputGuildId)) ?: return null val newRoleList = col.subscribableRoles if (!newRoleList.contains(inputRoleId)) { return false @@ -88,8 +90,8 @@ class RoleSubscriptionCollection : KordExKoinComponent { if (!removal) return false } collection.updateOne( - RoleSubscriptionData::guildId eq inputGuildId, - RoleSubscriptionData(inputGuildId, newRoleList) + eq(RoleSubscriptionData::guildId.name, inputGuildId), + Updates.set(RoleSubscriptionData::guildId.name, newRoleList) ) return true } @@ -103,5 +105,5 @@ class RoleSubscriptionCollection : KordExKoinComponent { * @since 4.9.0 */ suspend inline fun removeAllSubscribableRoles(inputGuildId: Snowflake) = - collection.deleteOne(RoleSubscriptionData::guildId eq inputGuildId) + collection.deleteOne(eq(RoleSubscriptionData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/StatusCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/StatusCollection.kt index aaccbba8..5ae84085 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/StatusCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/StatusCollection.kt @@ -1,7 +1,9 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import kotlinx.coroutines.flow.firstOrNull import org.hyacinthbots.lilybot.database.Database +import org.hyacinthbots.lilybot.database.deleteOne import org.hyacinthbots.lilybot.database.entities.StatusData import org.koin.core.component.inject @@ -17,7 +19,7 @@ class StatusCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(StatusData.name) /** * Gets Lily's status from the database. @@ -27,7 +29,7 @@ class StatusCollection : KordExKoinComponent { * @since 3.0.0 */ suspend inline fun getStatus(): String? = - collection.findOne()?.status + collection.find().firstOrNull()?.status /** * Add the given [newStatus] to the database. diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/TagsCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/TagsCollection.kt index 89584046..21476ee5 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/TagsCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/TagsCollection.kt @@ -1,11 +1,14 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.and +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake +import kotlinx.coroutines.flow.toList import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.TagsData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class contains the functions for interacting with the [Tags Database][TagsData]. This class has functions for @@ -22,7 +25,7 @@ class TagsCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(TagsData.name) /** * Gets the given tag using it's [name] and returns its [TagsData]. If the tag does not exist. @@ -35,7 +38,7 @@ class TagsCollection : KordExKoinComponent { * @since 3.1.0 */ suspend inline fun getTag(inputGuildId: Snowflake, name: String): TagsData? = - collection.findOne(TagsData::guildId eq inputGuildId, TagsData::name eq name) + collection.findOne(and(eq(TagsData::guildId.name, inputGuildId), eq(TagsData::name.name, name))) /** * Gets all tags in the given [inputGuildId]. @@ -46,7 +49,7 @@ class TagsCollection : KordExKoinComponent { * @since 3.1.0 */ suspend inline fun getAllTags(inputGuildId: Snowflake): List = - collection.find(TagsData::guildId eq inputGuildId).toList() + collection.find(eq(TagsData::guildId.name, inputGuildId)).toList() /** * Adds a tag to the database, using the provided parameters. @@ -59,12 +62,12 @@ class TagsCollection : KordExKoinComponent { * @since 3.1.0 */ suspend inline fun setTag( - inputGuildId: Snowflake, - name: String, - tagTitle: String, - tagValue: String, - tagAppearance: String - ) = + inputGuildId: Snowflake, + name: String, + tagTitle: String, + tagValue: String, + tagAppearance: String + ) = collection.insertOne(TagsData(inputGuildId, name, tagTitle, tagValue, tagAppearance)) /** @@ -76,7 +79,7 @@ class TagsCollection : KordExKoinComponent { * @since 3.1.0 */ suspend inline fun removeTag(inputGuildId: Snowflake, name: String) = - collection.deleteOne(TagsData::guildId eq inputGuildId, TagsData::name eq name) + collection.deleteOne(and(eq(TagsData::guildId.name, inputGuildId), eq(TagsData::name.name, name))) /** * Clears all tags for the provided [inputGuildId]. @@ -86,5 +89,5 @@ class TagsCollection : KordExKoinComponent { * @since 3.1.0 */ suspend inline fun clearTags(inputGuildId: Snowflake) = - collection.deleteMany(TagsData::guildId eq inputGuildId) + collection.deleteMany(eq(TagsData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ThreadsCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ThreadsCollection.kt index c65ad4ee..0b86be07 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ThreadsCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ThreadsCollection.kt @@ -1,11 +1,13 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake +import kotlinx.coroutines.flow.toList import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.ThreadData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class stores all the functions for interacting with the [Threads Database][ThreadData]. This class contains @@ -23,7 +25,7 @@ class ThreadsCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(ThreadData.name) /** * Using the provided [inputThreadId] the thread is returned. @@ -35,7 +37,7 @@ class ThreadsCollection : KordExKoinComponent { * @since 3.2.0 */ suspend inline fun getThread(inputThreadId: Snowflake): ThreadData? = - collection.findOne(ThreadData::threadId eq inputThreadId) + collection.findOne(eq(ThreadData::threadId.name, inputThreadId)) /** * Gets all threads into a list and return them to the user. @@ -56,7 +58,7 @@ class ThreadsCollection : KordExKoinComponent { * @since 3.2.0 */ suspend inline fun getOwnerThreads(inputOwnerId: Snowflake): List = - collection.find(ThreadData::ownerId eq inputOwnerId).toList() + collection.find(eq(ThreadData::ownerId.name, inputOwnerId)).toList() /** * Add or update the ownership of the given [inputThreadId] to the given [newOwnerId]. @@ -78,7 +80,7 @@ class ThreadsCollection : KordExKoinComponent { parentChannelId: Snowflake?, preventArchiving: Boolean = false ) { - collection.deleteOne(ThreadData::threadId eq inputThreadId) + collection.deleteOne(eq(ThreadData::threadId.name, inputThreadId)) collection.insertOne(ThreadData(inputGuildId, inputThreadId, newOwnerId, parentChannelId, preventArchiving)) } @@ -91,7 +93,7 @@ class ThreadsCollection : KordExKoinComponent { * @since 3.2.2 */ suspend inline fun removeThread(inputThreadId: Snowflake) = - collection.deleteOne(ThreadData::threadId eq inputThreadId) + collection.deleteOne(eq(ThreadData::threadId.name, inputThreadId)) /** * This function deletes the ownership data stored in database for the given [inputGuildId]. @@ -102,5 +104,5 @@ class ThreadsCollection : KordExKoinComponent { * @since 4.1.0 */ suspend inline fun removeGuildThreads(inputGuildId: Snowflake) = - collection.deleteMany(ThreadData::guildId eq inputGuildId) + collection.deleteMany(eq(ThreadData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/UptimeCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/UptimeCollection.kt index f7f4057e..f96babc2 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/UptimeCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/UptimeCollection.kt @@ -1,6 +1,7 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import kotlinx.coroutines.flow.firstOrNull import kotlinx.datetime.Instant import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.UptimeData @@ -18,7 +19,7 @@ class UptimeCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(UptimeData.name) /** * Gets the uptime data from the database. @@ -28,7 +29,7 @@ class UptimeCollection : KordExKoinComponent { * @since 4.2.0 */ suspend fun get(): UptimeData? = - collection.findOne() + collection.find().firstOrNull() /** * Sets the on time. diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WarnCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WarnCollection.kt index cb64da4d..2f8da8bc 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WarnCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WarnCollection.kt @@ -1,11 +1,13 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters.and +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.WarnData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq /** * This class stores all the functions for interacting with the [Warn Database][WarnData]. The class contains the @@ -20,7 +22,7 @@ class WarnCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(WarnData.name) /** * Gets the number of points the provided [inputUserId] has in the provided [inputGuildId] from the database. @@ -33,8 +35,10 @@ class WarnCollection : KordExKoinComponent { */ suspend inline fun getWarn(inputUserId: Snowflake, inputGuildId: Snowflake): WarnData? = collection.findOne( - WarnData::userId eq inputUserId, - WarnData::guildId eq inputGuildId + and( + eq(WarnData::userId.name, inputUserId), + eq(WarnData::guildId.name, inputGuildId) + ) ) /** @@ -48,7 +52,7 @@ class WarnCollection : KordExKoinComponent { */ suspend inline fun setWarn(inputUserId: Snowflake, inputGuildId: Snowflake, remove: Boolean) { val currentStrikes = getWarn(inputUserId, inputGuildId)?.strikes ?: 0 - collection.deleteOne(WarnData::userId eq inputUserId, WarnData::guildId eq inputGuildId) + collection.deleteOne(and(eq(WarnData::userId.name, inputUserId), eq(WarnData::guildId.name, inputGuildId))) collection.insertOne( WarnData( inputUserId, @@ -66,5 +70,5 @@ class WarnCollection : KordExKoinComponent { * @since 3.0.0 */ suspend inline fun clearWarns(inputGuildId: Snowflake) = - collection.deleteMany(WarnData::guildId eq inputGuildId) + collection.deleteMany(eq(WarnData::guildId.name, inputGuildId)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WelcomeChannelCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WelcomeChannelCollection.kt index adc9e613..463bff04 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WelcomeChannelCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WelcomeChannelCollection.kt @@ -8,12 +8,15 @@ package org.hyacinthbots.lilybot.database.collections import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Filters.eq import dev.kord.common.entity.Snowflake import dev.kord.core.Kord +import kotlinx.coroutines.flow.toList import org.hyacinthbots.lilybot.database.Database import org.hyacinthbots.lilybot.database.entities.WelcomeChannelData +import org.hyacinthbots.lilybot.database.findOne import org.koin.core.component.inject -import org.litote.kmongo.eq import org.quiltmc.community.cozy.modules.welcome.data.WelcomeChannelData as CozyWelcomeChannelData /** @@ -30,25 +33,25 @@ class WelcomeChannelCollection : KordExKoinComponent, CozyWelcomeChannelData { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection() + internal val collection = db.mainDatabase.getCollection(WelcomeChannelData.name) override suspend fun getChannelURLs(): Map = collection.find() .toList().associate { it.channelId to it.url } override suspend fun getUrlForChannel(channelId: Snowflake): String? = - collection.findOne(WelcomeChannelData::channelId eq channelId) + collection.findOne(eq(WelcomeChannelData::channelId.name, channelId)) ?.url override suspend fun setUrlForChannel(channelId: Snowflake, url: String) { - collection.save(WelcomeChannelData(channelId, url)) + collection.replaceOne(Filters.empty(), WelcomeChannelData(channelId, url)) } override suspend fun removeChannel(channelId: Snowflake): String? { val url = getUrlForChannel(channelId) ?: return null - collection.deleteOne(WelcomeChannelData::channelId eq channelId) + collection.deleteOne(eq(WelcomeChannelData::channelId.name, channelId)) return url } @@ -56,7 +59,7 @@ class WelcomeChannelCollection : KordExKoinComponent, CozyWelcomeChannelData { suspend fun removeWelcomeChannelsForGuild(guildId: Snowflake, kord: Kord) { val guild = kord.getGuildOrNull(guildId) ?: return guild.channels.collect { - collection.deleteOne(WelcomeChannelData::channelId eq it.id) + collection.deleteOne(eq(WelcomeChannelData::channelId.name, it.id)) } } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/AdaptedData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/AdaptedData.kt index c41a4716..4eda9635 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/AdaptedData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/AdaptedData.kt @@ -10,8 +10,9 @@ import dev.kord.common.entity.Snowflake import kotlinx.serialization.Serializable @Serializable -@Suppress("DataClassShouldBeImmutable") +@Suppress("DataClassShouldBeImmutable", "PropertyName", "ConstructorParameterNaming") data class AdaptedData( + val _id: String, val identifier: String, val type: StorageType? = null, diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/AutoThreadingData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/AutoThreadingData.kt index c736f76a..546b7743 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/AutoThreadingData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/AutoThreadingData.kt @@ -2,6 +2,7 @@ package org.hyacinthbots.lilybot.database.entities import dev.kord.common.entity.Snowflake import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data for auto-threaded channels. @@ -29,4 +30,6 @@ data class AutoThreadingData( val mention: Boolean, val creationMessage: String?, val addModsAndRole: Boolean -) +) { + companion object : Collection("autoThreadingData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/Config.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/Config.kt index 07cdef37..66ce1941 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/Config.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/Config.kt @@ -3,6 +3,7 @@ package org.hyacinthbots.lilybot.database.entities import dev.kord.common.entity.Snowflake import kotlinx.datetime.DateTimePeriod import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data for moderation configuration. The logging config stores where logs are sent to, and whether to enable or @@ -30,7 +31,9 @@ data class LoggingConfigData( val enablePublicMemberLogs: Boolean, val publicMemberLog: Snowflake?, val publicMemberLogData: PublicMemberLogData? -) +) { + companion object : Collection("loggingConfigData") +} /** * The data for moderation configuration. The moderation config is what stores the data for moderation actions. The @@ -43,6 +46,7 @@ data class LoggingConfigData( * @property quickTimeoutLength The length of timeout to apply when using the moderate menu * @property autoPunishOnWarn Whether to automatically apply punishments for reaching certain warn strike counts * @property publicLogging Whether to log moderation actions publicly in the channel the command was run in + * @property banDmMessage The message to send in a DM to a user when they are banned. * @since 4.0.0 */ @Serializable @@ -54,28 +58,10 @@ data class ModerationConfigData( val quickTimeoutLength: DateTimePeriod?, val autoPunishOnWarn: Boolean?, val publicLogging: Boolean?, -) - -/** - * The data for miscellaneous configuration. The miscellaneous config stores the data for enabling or disabling log - * uploading. - * - * @property guildId The ID of the guild the config is for - * @property disableLogUploading If log uploading is enabled or not - * @property utilityLogChannel The channel to log various utility actions too - * @since 4.0.0 - */ -@Deprecated( - "Replaced by org.hyacinthbots.database.entities.UtilityConfigData", - ReplaceWith("UtilityConfigData", "import org.hyacinthbots.lilybot.database.entities.UtilityConfigData"), - DeprecationLevel.ERROR -) -@Serializable -data class UtilityConfigDataOld( - val guildId: Snowflake, - val disableLogUploading: Boolean, - val utilityLogChannel: Snowflake? -) + val banDmMessage: String?, +) { + companion object : Collection("moderationConfigData") +} /** * The data for miscellaneous configuration. The miscellaneous config stores the data for enabling or disabling log @@ -89,4 +75,6 @@ data class UtilityConfigDataOld( data class UtilityConfigData( val guildId: Snowflake, val utilityLogChannel: Snowflake? -) +) { + companion object : Collection("utilityConfigData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/GalleryChannelData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/GalleryChannelData.kt index 5c7944c8..1c7433da 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/GalleryChannelData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/GalleryChannelData.kt @@ -2,6 +2,7 @@ package org.hyacinthbots.lilybot.database.entities import dev.kord.common.entity.Snowflake import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data for image channels in a guild. @@ -14,4 +15,6 @@ import kotlinx.serialization.Serializable data class GalleryChannelData( val guildId: Snowflake, val channelId: Snowflake -) +) { + companion object : Collection("galleryChannelData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/GithubData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/GithubData.kt index c1c3d011..4438ee49 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/GithubData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/GithubData.kt @@ -2,6 +2,7 @@ package org.hyacinthbots.lilybot.database.entities import dev.kord.common.entity.Snowflake import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data for GitHub commands. @@ -15,4 +16,6 @@ import kotlinx.serialization.Serializable data class GithubData( val guildId: Snowflake, val defaultRepo: String -) +) { + companion object : Collection("githubData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/GuildLeaveTimeData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/GuildLeaveTimeData.kt index 53cf35c2..cdf1a197 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/GuildLeaveTimeData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/GuildLeaveTimeData.kt @@ -3,6 +3,7 @@ package org.hyacinthbots.lilybot.database.entities import dev.kord.common.entity.Snowflake import kotlinx.datetime.Instant import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data for when Lily leaves a guild. @@ -15,4 +16,6 @@ import kotlinx.serialization.Serializable data class GuildLeaveTimeData( val guildId: Snowflake, val guildLeaveTime: Instant -) +) { + companion object : Collection("guildLeaveTimeData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/MetaData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/MetaData.kt index c7769389..53db865e 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/MetaData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/MetaData.kt @@ -1,6 +1,7 @@ package org.hyacinthbots.lilybot.database.entities import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data for the metadata of the main database. @@ -14,7 +15,9 @@ import kotlinx.serialization.Serializable data class MainMetaData( val version: Int, val id: String = "mainMeta" -) +) { + companion object : Collection("mainMetaData") +} /** * The data for the metadata of the config database. @@ -28,4 +31,6 @@ data class MainMetaData( data class ConfigMetaData( val version: Int, val id: String = "configMeta" -) +) { + companion object : Collection("configMetaData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/NewsChannelPublishingData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/NewsChannelPublishingData.kt index 0bf01b37..258245ef 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/NewsChannelPublishingData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/NewsChannelPublishingData.kt @@ -2,6 +2,7 @@ package org.hyacinthbots.lilybot.database.entities import dev.kord.common.entity.Snowflake import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data for the news channel publishing database. @@ -15,4 +16,6 @@ import kotlinx.serialization.Serializable data class NewsChannelPublishingData( val guildId: Snowflake, val channelId: Snowflake -) +) { + companion object : Collection("newsChannelPublishingData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/PublicMemberLogData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/PublicMemberLogData.kt index 573d6b61..f3d6f1a1 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/PublicMemberLogData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/PublicMemberLogData.kt @@ -1,6 +1,7 @@ package org.hyacinthbots.lilybot.database.entities import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data for public member logging. @@ -14,4 +15,6 @@ data class PublicMemberLogData( val pingNewUsers: Boolean, val joinMessage: String?, val leaveMessage: String? -) +) { + companion object : Collection("publicMemberLogData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/ReminderData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/ReminderData.kt index b7ca91c2..3bd03f56 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/ReminderData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/ReminderData.kt @@ -4,6 +4,7 @@ import dev.kord.common.entity.Snowflake import kotlinx.datetime.DateTimePeriod import kotlinx.datetime.Instant import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * THe data for reminders in a guild. @@ -35,4 +36,6 @@ data class ReminderData( val repeating: Boolean, val repeatingInterval: DateTimePeriod?, val id: Long -) +) { + companion object : Collection("reminderData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/RoleMenuData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/RoleMenuData.kt index 0673bd2e..de5a944b 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/RoleMenuData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/RoleMenuData.kt @@ -2,6 +2,7 @@ package org.hyacinthbots.lilybot.database.entities import dev.kord.common.entity.Snowflake import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data for role menus. @@ -18,4 +19,6 @@ data class RoleMenuData( val channelId: Snowflake, val guildId: Snowflake, val roles: MutableList -) +) { + companion object : Collection("roleMenuData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/RoleSubscriptionData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/RoleSubscriptionData.kt index 59290937..ed1e47b1 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/RoleSubscriptionData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/RoleSubscriptionData.kt @@ -2,6 +2,7 @@ package org.hyacinthbots.lilybot.database.entities import dev.kord.common.entity.Snowflake import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data for role subscriptions. @@ -14,4 +15,6 @@ import kotlinx.serialization.Serializable data class RoleSubscriptionData( val guildId: Snowflake, val subscribableRoles: MutableList -) +) { + companion object : Collection("roleSubscriptionData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/StatusData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/StatusData.kt index 090244d0..a199aa0d 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/StatusData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/StatusData.kt @@ -1,6 +1,7 @@ package org.hyacinthbots.lilybot.database.entities import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data for the bot status. @@ -11,4 +12,6 @@ import kotlinx.serialization.Serializable @Serializable data class StatusData( val status: String? -) +) { + companion object : Collection("statusData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/TagsData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/TagsData.kt index 78b00ffb..4ee92e9c 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/TagsData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/TagsData.kt @@ -2,6 +2,7 @@ package org.hyacinthbots.lilybot.database.entities import dev.kord.common.entity.Snowflake import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data of guild tags, which are stored in the database. @@ -20,4 +21,6 @@ data class TagsData( val tagTitle: String, val tagValue: String, val tagAppearance: String -) +) { + companion object : Collection("tagsData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/ThreadData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/ThreadData.kt index 1e60fc9e..2bd5fd1c 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/ThreadData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/ThreadData.kt @@ -2,6 +2,7 @@ package org.hyacinthbots.lilybot.database.entities import dev.kord.common.entity.Snowflake import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data for threads. @@ -21,4 +22,6 @@ data class ThreadData( val ownerId: Snowflake, val parentChannelId: Snowflake?, var preventArchiving: Boolean = false -) +) { + companion object : Collection("threadData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/UptimeData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/UptimeData.kt index 45503f83..93c6d945 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/UptimeData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/UptimeData.kt @@ -2,6 +2,7 @@ package org.hyacinthbots.lilybot.database.entities import kotlinx.datetime.Instant import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data to help calculate bot uptime. @@ -12,4 +13,6 @@ import kotlinx.serialization.Serializable @Serializable data class UptimeData( val onTime: Instant -) +) { + companion object : Collection("uptimeData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/WarnData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/WarnData.kt index db5a79be..bac600c9 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/WarnData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/WarnData.kt @@ -2,6 +2,7 @@ package org.hyacinthbots.lilybot.database.entities import dev.kord.common.entity.Snowflake import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data for warnings in guilds. @@ -16,4 +17,6 @@ data class WarnData( val userId: Snowflake, val guildId: Snowflake, val strikes: Int -) +) { + companion object : Collection("warnData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/WelcomeChannelData.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/WelcomeChannelData.kt index 796c75ec..383c5d2c 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/WelcomeChannelData.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/entities/WelcomeChannelData.kt @@ -2,6 +2,7 @@ package org.hyacinthbots.lilybot.database.entities import dev.kord.common.entity.Snowflake import kotlinx.serialization.Serializable +import org.hyacinthbots.lilybot.database.Collection /** * The data for Welcome channels. @@ -14,4 +15,6 @@ import kotlinx.serialization.Serializable data class WelcomeChannelData( val channelId: Snowflake, val url: String -) +) { + companion object : Collection("welcomeChannelData") +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/Migrator.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/Migrator.kt index c02838bd..8497b07d 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/Migrator.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/Migrator.kt @@ -23,6 +23,8 @@ import org.hyacinthbots.lilybot.database.migrations.config.configV2 import org.hyacinthbots.lilybot.database.migrations.config.configV3 import org.hyacinthbots.lilybot.database.migrations.config.configV4 import org.hyacinthbots.lilybot.database.migrations.config.configV5 +import org.hyacinthbots.lilybot.database.migrations.config.configV6 +import org.hyacinthbots.lilybot.database.migrations.config.configV7 import org.hyacinthbots.lilybot.database.migrations.main.mainV1 import org.hyacinthbots.lilybot.database.migrations.main.mainV2 import org.hyacinthbots.lilybot.database.migrations.main.mainV3 @@ -119,6 +121,8 @@ object Migrator : KordExKoinComponent { 3 -> ::configV3 4 -> ::configV4 5 -> ::configV5 + 6 -> ::configV6 + 7 -> ::configV7 else -> break }(db.configDatabase) diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV1.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV1.kt index d63e0460..87f42e59 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV1.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV1.kt @@ -1,20 +1,20 @@ package org.hyacinthbots.lilybot.database.migrations.config +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.LoggingConfigData -import org.litote.kmongo.coroutine.CoroutineDatabase -import org.litote.kmongo.exists -import org.litote.kmongo.setValue -suspend fun configV1(configDb: CoroutineDatabase) { - with(configDb.getCollection("loggingConfigData")) { +suspend fun configV1(configDb: MongoDatabase) { + with(configDb.getCollection(LoggingConfigData.name)) { updateMany( - LoggingConfigData::enableMessageEditLogs exists false, - setValue(LoggingConfigData::enableMessageEditLogs, false) + Filters.exists(LoggingConfigData::enableMessageEditLogs.name, false), + Updates.set(LoggingConfigData::enableMessageEditLogs.name, false) ) } - configDb.getCollection("loggingConfigData").updateMany( - "{}", - "{\$rename: {enableMessageLogs: \"enableMessageDeleteLogs\"}}" + configDb.getCollection(LoggingConfigData.name).updateMany( + Filters.empty(), + Updates.rename("enableMessageLogs", "enableMessageDeleteLogs") ) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV2.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV2.kt index fa6afca6..7fb69f2a 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV2.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV2.kt @@ -1,20 +1,20 @@ package org.hyacinthbots.lilybot.database.migrations.config +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.ModerationConfigData -import org.litote.kmongo.coroutine.CoroutineDatabase -import org.litote.kmongo.exists -import org.litote.kmongo.setValue -suspend fun configV2(db: CoroutineDatabase) { - with(db.getCollection("moderationConfigData")) { +suspend fun configV2(db: MongoDatabase) { + with(db.getCollection(ModerationConfigData.name)) { updateMany( - ModerationConfigData::quickTimeoutLength exists false, - setValue(ModerationConfigData::quickTimeoutLength, null) + Filters.exists(ModerationConfigData::quickTimeoutLength.name, false), + Updates.set(ModerationConfigData::quickTimeoutLength.name, null) ) updateMany( - ModerationConfigData::autoPunishOnWarn exists false, - setValue(ModerationConfigData::autoPunishOnWarn, null) + Filters.exists(ModerationConfigData::autoPunishOnWarn.name, false), + Updates.set(ModerationConfigData::autoPunishOnWarn.name, null) ) } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV3.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV3.kt index 857d8022..5881fa76 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV3.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV3.kt @@ -1,23 +1,23 @@ package org.hyacinthbots.lilybot.database.migrations.config +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.LoggingConfigData -import org.litote.kmongo.coroutine.CoroutineDatabase -import org.litote.kmongo.exists -import org.litote.kmongo.setValue -suspend fun configV3(db: CoroutineDatabase) { - with(db.getCollection("loggingConfigData")) { +suspend fun configV3(db: MongoDatabase) { + with(db.getCollection(LoggingConfigData.name)) { updateMany( - LoggingConfigData::enablePublicMemberLogs exists false, - setValue(LoggingConfigData::enablePublicMemberLogs, false) + Filters.exists(LoggingConfigData::enablePublicMemberLogs.name, false), + Updates.set(LoggingConfigData::enablePublicMemberLogs.name, false) ) updateMany( - LoggingConfigData::publicMemberLog exists false, - setValue(LoggingConfigData::publicMemberLog, null) + Filters.exists(LoggingConfigData::publicMemberLog.name, false), + Updates.set(LoggingConfigData::publicMemberLog.name, null) ) updateMany( - LoggingConfigData::publicMemberLogData exists false, - setValue(LoggingConfigData::publicMemberLogData, null) + Filters.exists(LoggingConfigData::publicMemberLogData.name, false), + Updates.set(LoggingConfigData::publicMemberLogData.name, null) ) } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV4.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV4.kt index 3c214b91..99ef32ce 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV4.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV4.kt @@ -1,9 +1,9 @@ package org.hyacinthbots.lilybot.database.migrations.config -import org.litote.kmongo.coroutine.CoroutineDatabase +import com.mongodb.kotlin.client.coroutine.MongoDatabase @Suppress("UnusedPrivateMember", "UNUSED_PARAMETER", "RedundantSuspendModifier") -suspend fun configV4(db: CoroutineDatabase) { +suspend fun configV4(db: MongoDatabase) { // Support config has been removed. // if (db.getCollection().find().toList().isEmpty()) { // db.dropCollection("supportConfigData") diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV5.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV5.kt index 35d0b4e8..edd5e203 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV5.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV5.kt @@ -1,24 +1,22 @@ -@file:Suppress("DEPRECATION_ERROR") +@file:Suppress("DEPRECATION_ERROR", "UnusedPrivateMember", "UNUSED_PARAMETER", "RedundantSuspendModifier") package org.hyacinthbots.lilybot.database.migrations.config -import org.hyacinthbots.lilybot.database.entities.UtilityConfigData -import org.hyacinthbots.lilybot.database.entities.UtilityConfigDataOld -import org.litote.kmongo.coroutine.CoroutineDatabase +import com.mongodb.kotlin.client.coroutine.MongoDatabase -suspend fun configV5(db: CoroutineDatabase) { - val collection = db.getCollection("utilityConfigData") - val oldConfigs = collection.find().toList() - val newConfigs = mutableListOf() - - oldConfigs.forEach { - newConfigs.add(UtilityConfigData(it.guildId, it.utilityLogChannel)) - } - - db.dropCollection("utilityConfigData") - db.createCollection("utilityConfigData") - - with(db.getCollection("utilityConfigData")) { - insertMany(newConfigs) - } +suspend fun configV5(db: MongoDatabase) { +// val collection = db.getCollection("utilityConfigData") +// val oldConfigs = collection.find().toList() +// val newConfigs = mutableListOf() +// +// oldConfigs.forEach { +// newConfigs.add(UtilityConfigData(it.guildId, it.utilityLogChannel)) +// } +// +// db.dropCollection("utilityConfigData") +// db.createCollection("utilityConfigData") +// +// with(db.getCollection("utilityConfigData")) { +// insertMany(newConfigs) +// } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV6.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV6.kt new file mode 100644 index 00000000..073accdb --- /dev/null +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV6.kt @@ -0,0 +1,15 @@ +package org.hyacinthbots.lilybot.database.migrations.config + +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoDatabase +import org.hyacinthbots.lilybot.database.entities.ModerationConfigData + +suspend fun configV6(db: MongoDatabase) { + with(db.getCollection(ModerationConfigData.name)) { + updateMany( + Filters.exists(ModerationConfigData::banDmMessage.name, false), + Updates.set(ModerationConfigData::banDmMessage.name, null) + ) + } +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV7.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV7.kt new file mode 100644 index 00000000..ea4c3eeb --- /dev/null +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV7.kt @@ -0,0 +1,9 @@ +package org.hyacinthbots.lilybot.database.migrations.config + +import com.mongodb.kotlin.client.coroutine.MongoDatabase +import org.hyacinthbots.lilybot.database.entities.AdaptedData + +suspend fun configV7(db: MongoDatabase) { + db.getCollection("ext-pluralkit").drop() + db.getCollection("data-ext-pluralkit").drop() +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV1.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV1.kt index cbeb8940..bf774eb7 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV1.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV1.kt @@ -1,10 +1,10 @@ package org.hyacinthbots.lilybot.database.migrations.main +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.StatusData -import org.litote.kmongo.coroutine.CoroutineDatabase // This was commented out due to the remindme data class being removed -suspend fun mainV1(db: CoroutineDatabase) { +suspend fun mainV1(db: MongoDatabase) { // val reminders = db.getCollection("remindMeData") // // val repeating = mutableListOf>() @@ -63,7 +63,7 @@ suspend fun mainV1(db: CoroutineDatabase) { // reminders.bulkWrite(requests = nonRepeating, BulkWriteOptions().ordered(true)) // } - db.dropCollection("statusData") - db.createCollection("statusData") - db.getCollection("statusData").insertOne(StatusData(null)) + db.getCollection(StatusData.name).drop() + db.createCollection(StatusData.name) + db.getCollection(StatusData.name).insertOne(StatusData(null)) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV2.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV2.kt index cb8682fc..bfbf954d 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV2.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV2.kt @@ -1,12 +1,12 @@ package org.hyacinthbots.lilybot.database.migrations.main +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.ThreadData -import org.litote.kmongo.coroutine.CoroutineDatabase -import org.litote.kmongo.exists -import org.litote.kmongo.setValue -suspend fun mainV2(db: CoroutineDatabase) { - with(db.getCollection()) { - updateMany(ThreadData::guildId exists false, setValue(ThreadData::guildId, null)) +suspend fun mainV2(db: MongoDatabase) { + with(db.getCollection(ThreadData.name)) { + updateMany(Filters.exists(ThreadData::guildId.name, false), Updates.set(ThreadData::guildId.name, null)) } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV3.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV3.kt index 3b775ed7..28b4815b 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV3.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV3.kt @@ -1,8 +1,9 @@ package org.hyacinthbots.lilybot.database.migrations.main -import org.litote.kmongo.coroutine.CoroutineDatabase +import com.mongodb.kotlin.client.coroutine.MongoDatabase +import org.hyacinthbots.lilybot.database.entities.ReminderData -suspend fun mainV3(db: CoroutineDatabase) { - db.dropCollection("remindMeData") - db.createCollection("reminderData") +suspend fun mainV3(db: MongoDatabase) { + // db.getCollection("remindMeData") + db.createCollection(ReminderData.name) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV4.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV4.kt index 4c5dc577..16b1c1a4 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV4.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV4.kt @@ -1,8 +1,10 @@ package org.hyacinthbots.lilybot.database.migrations.main -import org.litote.kmongo.coroutine.CoroutineDatabase +import com.mongodb.kotlin.client.coroutine.MongoDatabase +import org.hyacinthbots.lilybot.database.entities.GithubData +import org.hyacinthbots.lilybot.database.entities.WelcomeChannelData -suspend fun mainV4(db: CoroutineDatabase) { - db.createCollection("welcomeChannelData") - db.createCollection("githubData") +suspend fun mainV4(db: MongoDatabase) { + db.createCollection(WelcomeChannelData.name) + db.createCollection(GithubData.name) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV5.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV5.kt index 9d1f5d87..e27f2bf0 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV5.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV5.kt @@ -1,15 +1,18 @@ package org.hyacinthbots.lilybot.database.migrations.main +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.ThreadData -import org.litote.kmongo.coroutine.CoroutineDatabase -import org.litote.kmongo.exists -import org.litote.kmongo.setValue -suspend fun mainV5(db: CoroutineDatabase) { +suspend fun mainV5(db: MongoDatabase) { // db.createCollection("autoThreadingData") - with(db.getCollection()) { - updateMany(ThreadData::parentChannelId exists false, setValue(ThreadData::parentChannelId, null)) + with(db.getCollection(ThreadData.name)) { + updateMany( + Filters.exists(ThreadData::parentChannelId.name, false), + Updates.set(ThreadData::parentChannelId.name, null) + ) } // with(configDb.getCollection()) { diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV6.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV6.kt index ac8b0e21..08b85186 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV6.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV6.kt @@ -1,12 +1,15 @@ package org.hyacinthbots.lilybot.database.migrations.main +import com.mongodb.client.model.Filters +import com.mongodb.client.model.Updates +import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.AutoThreadingData -import org.litote.kmongo.coroutine.CoroutineDatabase -import org.litote.kmongo.exists -import org.litote.kmongo.setValue -suspend fun mainV6(db: CoroutineDatabase) { - with(db.getCollection()) { - updateMany(AutoThreadingData::addModsAndRole exists false, setValue(AutoThreadingData::addModsAndRole, false)) +suspend fun mainV6(db: MongoDatabase) { + with(db.getCollection(AutoThreadingData.name)) { + updateMany( + Filters.exists(AutoThreadingData::addModsAndRole.name, false), + Updates.set(AutoThreadingData::addModsAndRole.name, false) + ) } } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV7.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV7.kt index 6c14d1de..9bc111fe 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV7.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV7.kt @@ -1,7 +1,8 @@ package org.hyacinthbots.lilybot.database.migrations.main -import org.litote.kmongo.coroutine.CoroutineDatabase +import com.mongodb.kotlin.client.coroutine.MongoDatabase +import org.hyacinthbots.lilybot.database.entities.NewsChannelPublishingData -suspend fun mainV7(db: CoroutineDatabase) { - db.createCollection("newsChannelPublishingData") +suspend fun mainV7(db: MongoDatabase) { + db.createCollection(NewsChannelPublishingData.name) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV8.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV8.kt index 0995230d..311db03d 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV8.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV8.kt @@ -1,7 +1,8 @@ package org.hyacinthbots.lilybot.database.migrations.main -import org.litote.kmongo.coroutine.CoroutineDatabase +import com.mongodb.kotlin.client.coroutine.MongoDatabase +import org.hyacinthbots.lilybot.database.entities.RoleSubscriptionData -suspend fun mainV8(db: CoroutineDatabase) { - db.createCollection("roleSubscriptionData") +suspend fun mainV8(db: MongoDatabase) { + db.createCollection(RoleSubscriptionData.name) } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV9.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV9.kt index 0ac485e1..d2e99172 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV9.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV9.kt @@ -1,7 +1,8 @@ package org.hyacinthbots.lilybot.database.migrations.main -import org.litote.kmongo.coroutine.CoroutineDatabase +import com.mongodb.kotlin.client.coroutine.MongoDatabase -suspend fun mainV9(db: CoroutineDatabase) { - db.dropCollection("logUploadingBlacklistData") +@Suppress("UnusedPrivateMember", "UNUSED_PARAMETER", "RedundantSuspendModifier") +suspend fun mainV9(db: MongoDatabase) { + // db.getCollection<>("logUploadingBlacklistData") } diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/database/storage/MongoDBDataAdapter.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/storage/MongoDBDataAdapter.kt deleted file mode 100644 index 6790aa07..00000000 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/storage/MongoDBDataAdapter.kt +++ /dev/null @@ -1,146 +0,0 @@ -/* -* This code was utilized from [cozy](https://github.com/QuiltMC/cozy-discord) by QuiltMC -* and hence is subject to the terms of the Mozilla Public License V. 2.0 -* A copy of this license can be found at https://mozilla.org/MPL/2.0/. -*/ - -package org.hyacinthbots.lilybot.database.storage - -import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent -import com.kotlindiscord.kord.extensions.storage.Data -import com.kotlindiscord.kord.extensions.storage.DataAdapter -import com.kotlindiscord.kord.extensions.storage.StorageUnit -import com.mongodb.client.model.Filters.and -import kotlinx.serialization.InternalSerializationApi -import kotlinx.serialization.json.Json -import kotlinx.serialization.serializer -import org.bson.conversions.Bson -import org.hyacinthbots.lilybot.database.Database -import org.hyacinthbots.lilybot.database.entities.AdaptedData -import org.koin.core.component.inject -import org.litote.kmongo.coroutine.CoroutineCollection -import org.litote.kmongo.eq - -@OptIn(InternalSerializationApi::class) -class MongoDBDataAdapter : DataAdapter(), KordExKoinComponent { - private val database: Database by inject() - private val collectionCache: MutableMap> = mutableMapOf() - - private fun StorageUnit<*>.getIdentifier(): String = - buildString { - append("${storageType.type}/") - - if (guild != null) append("guild-$guild/") - if (channel != null) append("channel-$channel/") - if (user != null) append("user-$user/") - if (message != null) append("message-$message/") - - append(identifier) - } - - private fun getCollection(namespace: String): CoroutineCollection { - var collection = collectionCache[namespace] - - if (collection == null) { - collection = database.configDatabase.getCollection(namespace) - - collectionCache[namespace] = collection - } - - return collection - } - - private fun constructQuery(unit: StorageUnit<*>): Bson { - var query = AdaptedData::identifier eq unit.identifier - - query = and(query, AdaptedData::type eq unit.storageType) - - query = and(query, AdaptedData::channel eq unit.channel) - query = and(query, AdaptedData::guild eq unit.guild) - query = and(query, AdaptedData::message eq unit.message) - query = and(query, AdaptedData::user eq unit.user) - - return query - } - - override suspend fun delete(unit: StorageUnit): Boolean { - removeFromCache(unit) - - val result = getCollection(unit.namespace) - .deleteOne(constructQuery(unit)) - - return result.deletedCount > 0 - } - - override suspend fun get(unit: StorageUnit): R? { - val dataId = unitCache[unit] - - if (dataId != null) { - val data = dataCache[dataId] - - if (data != null) { - return data as R - } - } - - return reload(unit) - } - - override suspend fun reload(unit: StorageUnit): R? { - val dataId = unit.getIdentifier() - val result = getCollection(unit.namespace) - .findOne(constructQuery(unit))?.data - - if (result != null) { - dataCache[dataId] = Json.decodeFromString(unit.dataType.serializer(), result) - unitCache[unit] = dataId - } - - return dataCache[dataId] as R? - } - - override suspend fun save(unit: StorageUnit): R? { - val data = get(unit) ?: return null - - getCollection(unit.namespace).save( - AdaptedData( - identifier = unit.identifier, - - type = unit.storageType, - - channel = unit.channel, - guild = unit.guild, - message = unit.message, - user = unit.user, - - data = Json.encodeToString(unit.dataType.serializer(), data) - ) - ) - - return data - } - - override suspend fun save(unit: StorageUnit, data: R): R { - val dataId = unit.getIdentifier() - - dataCache[dataId] = data - unitCache[unit] = dataId - - getCollection(unit.namespace).save( - AdaptedData( - identifier = unit.identifier, - - type = unit.storageType, - - channel = unit.channel, - guild = unit.guild, - message = unit.message, - user = unit.user, - - data = Json.encodeToString(unit.dataType.serializer(), data) - ) - ) - - return data - } -} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/extensions/config/Config.kt b/src/main/kotlin/org/hyacinthbots/lilybot/extensions/config/Config.kt index 818eb1fb..20bef24f 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/extensions/config/Config.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/extensions/config/Config.kt @@ -10,6 +10,7 @@ import com.kotlindiscord.kord.extensions.commands.converters.impl.coalescingOpti import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalBoolean import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalChannel import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalRole +import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalString import com.kotlindiscord.kord.extensions.components.forms.ModalForm import com.kotlindiscord.kord.extensions.extensions.Extension import com.kotlindiscord.kord.extensions.extensions.ephemeralSlashCommand @@ -79,6 +80,7 @@ class Config : Extension() { null, null, null, + null, null ) ) @@ -150,6 +152,10 @@ class Config : Extension() { null -> "Disabled" } } + field { + name = "Ban DM Message" + value = arguments.banDmMessage ?: "No custom Ban DM message set" + } footer { text = "Configured by ${user.asUserOrNull()?.username}" } @@ -169,7 +175,8 @@ class Config : Extension() { arguments.moderatorRole?.id, arguments.quickTimeoutLength, arguments.warnAutoPunishments, - arguments.logPublicly + arguments.logPublicly, + arguments.banDmMessage ) ) @@ -637,6 +644,10 @@ class Config : Extension() { null -> "Disabled" } } + field { + name = "Ban DM Message" + value = config.banDmMessage ?: "None" + } timestamp = Clock.System.now() } } @@ -750,6 +761,11 @@ class Config : Extension() { name = "log-publicly" description = "Whether to log moderation publicly or not." } + + val banDmMessage by optionalString { + name = "ban-dm-message" + description = "A custom message to send to users when they are banned." + } } inner class LoggingArgs : Arguments() { diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/extensions/moderation/ModerationCommands.kt b/src/main/kotlin/org/hyacinthbots/lilybot/extensions/moderation/ModerationCommands.kt index a4113226..6e69d773 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/extensions/moderation/ModerationCommands.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/extensions/moderation/ModerationCommands.kt @@ -9,12 +9,16 @@ import com.kotlindiscord.kord.extensions.checks.hasPermission import com.kotlindiscord.kord.extensions.checks.hasPermissions import com.kotlindiscord.kord.extensions.checks.types.CheckContextWithCache import com.kotlindiscord.kord.extensions.commands.Arguments +import com.kotlindiscord.kord.extensions.commands.application.slash.EphemeralSlashCommandContext +import com.kotlindiscord.kord.extensions.commands.application.slash.ephemeralSubCommand import com.kotlindiscord.kord.extensions.commands.converters.impl.coalescingOptionalDuration import com.kotlindiscord.kord.extensions.commands.converters.impl.defaultingBoolean import com.kotlindiscord.kord.extensions.commands.converters.impl.defaultingString import com.kotlindiscord.kord.extensions.commands.converters.impl.int import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalAttachment import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalInt +import com.kotlindiscord.kord.extensions.commands.converters.impl.optionalUser +import com.kotlindiscord.kord.extensions.commands.converters.impl.snowflake import com.kotlindiscord.kord.extensions.commands.converters.impl.user import com.kotlindiscord.kord.extensions.components.components import com.kotlindiscord.kord.extensions.components.ephemeralSelectMenu @@ -47,8 +51,10 @@ import dev.kord.core.supplier.EntitySupplyStrategy import dev.kord.rest.builder.message.EmbedBuilder import dev.kord.rest.builder.message.create.embed import dev.kord.rest.request.KtorRequestException +import kotlinx.coroutines.flow.filter +import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map -import kotlinx.coroutines.flow.toList +import kotlinx.coroutines.flow.toSet import kotlinx.datetime.Clock import kotlinx.datetime.DateTimePeriod import kotlinx.datetime.TimeZone @@ -79,8 +85,8 @@ class ModerationCommands : Extension() { override val name = "moderation" private val warnSuffix = "Please consider your actions carefully.\n\n" + - "For more information about the warn system, please see [this document]" + - "($HYACINTH_GITHUB/LilyBot/blob/main/docs/commands.md#name-warn)" + "For more information about the warn system, please see [this document]" + + "($HYACINTH_GITHUB/LilyBot/blob/main/docs/commands.md#name-warn)" @OptIn(DoNotChain::class) override suspend fun setup() { @@ -109,13 +115,19 @@ class ModerationCommands : Extension() { val senderId: Snowflake if (targetMessage.author.isNullOrBot()) { val proxiedMessage = PluralKit().getMessageOrNull(targetMessage.id) - proxiedMessage ?: run { respond { content = "Unable to find user" }; return@action } + proxiedMessage ?: run { + respond { content = "Unable to find user" } + return@action + } senderId = proxiedMessage.sender } else { senderId = targetMessage.author!!.id } val sender = guild!!.getMemberOrNull(senderId) - ?: run { respond { content = "Unable to find user" }; return@action } + ?: run { + respond { content = "Unable to find user" } + return@action + } isBotOrModerator(event.kord, sender.asUserOrNull(), guild, "moderate") ?: return@action @@ -162,8 +174,8 @@ class ModerationCommands : Extension() { val dm = sender.dm { embed { title = "You have been banned from ${guild?.asGuildOrNull()?.name}" - description = - "Quick banned $reasonSuffix" + description = modConfig?.banDmMessage ?: "Quick banned $reasonSuffix" + color = DISCORD_GREEN } } @@ -181,14 +193,14 @@ class ModerationCommands : Extension() { embed { title = "Banned." description = "${sender.mention} user was banned " + - "for sending this message." + "for sending this message." } } } catch (e: KtorRequestException) { channel.createEmbed { title = "Banned." description = "${sender.mention} user was banned " + - "for sending a deleted message." + "for sending a deleted message." } } } @@ -219,7 +231,7 @@ class ModerationCommands : Extension() { title = "You have been soft-banned from ${guild?.asGuildOrNull()?.name}" description = "Quick soft-banned $reasonSuffix. This is a soft-ban, you are " + - "free to rejoin at any time" + "free to rejoin at any time" } } @@ -238,14 +250,14 @@ class ModerationCommands : Extension() { embed { title = "Soft-banned." description = "${sender.mention} user was soft-banned " + - "for sending this message." + "for sending this message." } } } catch (e: KtorRequestException) { channel.createEmbed { title = "Soft-Banned." description = "${sender.mention} user was soft-banned " + - "for sending a deleted message." + "for sending a deleted message." } } } @@ -288,14 +300,14 @@ class ModerationCommands : Extension() { embed { title = "Kicked." description = "${sender.mention} user was kicked " + - "for sending this message." + "for sending this message." } } } catch (e: KtorRequestException) { channel.createEmbed { title = "Kicked." description = "${sender.mention} user was kicked " + - "for sending a deleted message." + "for sending a deleted message." } } } @@ -350,14 +362,14 @@ class ModerationCommands : Extension() { embed { title = "Timed-out." description = "${sender.mention} user was timed-out for " + - "${timeoutTime.interval()} for sending this message." + "${timeoutTime.interval()} for sending this message." } } } catch (e: KtorRequestException) { channel.createEmbed { title = "Timed-out." description = "${sender.mention} user was timed-out for " + - "${timeoutTime.interval()} for sending a deleted message." + "${timeoutTime.interval()} for sending a deleted message." } } } @@ -450,14 +462,14 @@ class ModerationCommands : Extension() { embed { title = "Warned." description = "${sender.mention} user was warned " + - "for sending this message." + "for sending this message." } } } catch (e: KtorRequestException) { channel.createEmbed { title = "Warned." description = "${sender.mention} user was warned " + - "for sending a deleted message." + "for sending a deleted message." } } } @@ -490,9 +502,11 @@ class ModerationCommands : Extension() { return@action } + val modConfig = ModerationConfigCollection().getConfig(guild!!.id) + val action = ban(arguments.userArgument) { reason = arguments.reason - logPublicly = ModerationConfigCollection().getConfig(guild!!.id)?.publicLogging + logPublicly = modConfig?.publicLogging sendActionLog = true sendDm = arguments.dm removeTimeout = true @@ -525,7 +539,13 @@ class ModerationCommands : Extension() { dmEmbed { title = "You have been banned from ${guild?.asGuildOrNull()?.name}" - description = "**Reason:**\n${arguments.reason}" + description = "**Reason:**\n${arguments.reason} ${ + if (modConfig?.banDmMessage != null) { + "\n${modConfig.banDmMessage}" + } else { + "" + } + }" } } @@ -596,7 +616,7 @@ class ModerationCommands : Extension() { dmEmbed { title = "You have been soft-banned from ${guild?.fetchGuild()?.name}" description = "**Reason:**\n${arguments.reason}\n\n" + - "You are free to rejoin without the need to be unbanned" + "You are free to rejoin without the need to be unbanned" } } @@ -719,57 +739,80 @@ class ModerationCommands : Extension() { } } - ephemeralSlashCommand(::ClearArgs) { + ephemeralSlashCommand { name = "clear" - description = "Clears messages from a channel." + description = "Parent command for clear commands" - requirePermission(Permission.ManageMessages) + ephemeralSubCommand(ClearCommandArgs::Count) { + name = "count" + description = "Clear a specific count of messages" - check { - modCommandChecks(Permission.ManageMessages) - requireBotPermissions(Permission.ManageMessages) - botHasChannelPerms(Permissions(Permission.ManageMessages)) + requirePermission(Permission.ManageMessages) + + check { + modCommandChecks(Permission.ManageMessages) + requireBotPermissions(Permission.ManageMessages) + botHasChannelPerms(Permissions(Permission.ManageMessages)) + } + + action { + clearMessages(arguments.count, null, null, arguments.author) + } } - action { - val config = ModerationConfigCollection().getConfig(guild!!.id)!! - val messageAmount = arguments.messages - val textChannel = channel.asChannelOfOrNull() + ephemeralSubCommand(ClearCommandArgs::Before) { + name = "before" + description = "Clear messages before a given message ID" - if (textChannel == null) { - respond { - content = "Could not get the channel to clear messages from." - } - return@action + requirePermission(Permission.ManageMessages) + + check { + modCommandChecks(Permission.ManageMessages) + requireBotPermissions(Permission.ManageMessages) + botHasChannelPerms(Permissions(Permission.ManageMessages)) } - // Get the specified amount of messages into an array list of Snowflakes and delete them - val messages = channel.withStrategy(EntitySupplyStrategy.rest).getMessagesBefore( - Snowflake.max, min(messageAmount, 100) - ).map { it.id }.toList() + action { + clearMessages(arguments.count, Snowflake(arguments.before.value + 1u), null, arguments.author) + } + } - textChannel.bulkDelete(messages) + ephemeralSubCommand(ClearCommandArgs::After) { + name = "after" + description = "Clear messages before a given message ID" - respond { - content = "Messages cleared." + requirePermission(Permission.ManageMessages) + + check { + modCommandChecks(Permission.ManageMessages) + requireBotPermissions(Permission.ManageMessages) + botHasChannelPerms(Permissions(Permission.ManageMessages)) } - if (config.publicLogging != null && config.publicLogging == true) { - channel.createEmbed { - title = "$messageAmount messages have been cleared." - color = DISCORD_BLACK - } + action { + clearMessages(arguments.count, null, Snowflake(arguments.after.value - 1u), arguments.author) } + } - val actionLog = getLoggingChannelWithPerms(ConfigOptions.ACTION_LOG, this.getGuild()!!) ?: return@action - actionLog.createEmbed { - title = "$messageAmount messages have been cleared." - description = "Action occurred in ${textChannel.mention}" - footer { - text = user.asUserOrNull()?.username ?: "Unable to get user username" - icon = user.asUserOrNull()?.avatar?.cdnUrl?.toUrl() - } - color = DISCORD_BLACK + ephemeralSubCommand(ClearCommandArgs::Between) { + name = "between" + description = "Clear messages between 2 message IDs" + + requirePermission(Permission.ManageMessages) + + check { + modCommandChecks(Permission.ManageMessages) + requireBotPermissions(Permission.ManageMessages) + botHasChannelPerms(Permissions(Permission.ManageMessages)) + } + + action { + clearMessages( + null, + Snowflake(arguments.before.value - 1u), + Snowflake(arguments.after.value + 1u), + arguments.author + ) } } } @@ -1171,14 +1214,6 @@ class ModerationCommands : Extension() { } } - inner class ClearArgs : Arguments() { - /** The number of messages the user wants to remove. */ - val messages by int { - name = "messages" - description = "Number of messages to delete" - } - } - inner class TimeoutArgs : Arguments() { /** The requested user to timeout. */ val userArgument by user { @@ -1285,22 +1320,29 @@ private suspend fun CheckContextWithCache<*>.modCommandChecks(actionPermission: hasPermission(actionPermission) } -private fun EmbedBuilder.warnTimeoutLog(timeoutNumber: Int, moderator: User, targetUser: User, reason: String) { - when (timeoutNumber) { +/** + * Creates a log for timeouts produced by a number of warnings. + * + * @param warningNumber The number of warning strikes the user has + * @param moderator The moderator that actioned the warning + * @param targetUser The User that was warned + * @param reason The reason for the warning + * @author NoComment1105 + * @since 4.4.0 + */ +private fun EmbedBuilder.warnTimeoutLog(warningNumber: Int, moderator: User, targetUser: User, reason: String) { + when (warningNumber) { 1 -> {} - 2 -> - description = "${targetUser.mention} has been timed-out for 3 hours due to 2 warn strikes" + 2 -> description = "${targetUser.mention} has been timed-out for 3 hours due to 2 warn strikes" - 3 -> - description = "${targetUser.mention} has been timed-out for 12 hours due to 3 warn strikes" + 3 -> description = "${targetUser.mention} has been timed-out for 12 hours due to 3 warn strikes" else -> - description = "${targetUser.mention} has been timed-out for 3 days due to $timeoutNumber warn " + - "strikes\nIt might be time to consider other " + - "action." + description = "${targetUser.mention} has been timed-out for 3 days due to $warningNumber warn " + + "strikes\nIt might be time to consider other action." } - if (timeoutNumber != 1) { + if (warningNumber != 1) { title = "Timeout" field { name = "User" @@ -1318,3 +1360,169 @@ private fun EmbedBuilder.warnTimeoutLog(timeoutNumber: Int, moderator: User, tar timestamp = Clock.System.now() } } + +/** + * A function to use clear messages based on the count, before and after, as well as a user. + * + * @param count The number of messages to clear, or null + * @param before The ID of the message to clear messages before + * @param after The ID of the message to clear messages after + * @param author The author of the messages that should be cleared + * @author NoComment1105 + * @since 4.8.6 + */ +private suspend fun EphemeralSlashCommandContext<*, *>.clearMessages( + count: Int?, + before: Snowflake?, + after: Snowflake?, + author: User? +) { + val config = ModerationConfigCollection().getConfig(guild!!.id)!! + val textChannel = channel.asChannelOfOrNull() + + if (textChannel == null) { + respond { + content = "Could not get the channel to clear messages from." + } + return + } + + if ((before != null && after != null) && (before < after)) { + respond { + content = "Before cannot be more recent than after!" + } + return + } + + // Get the specified amount of messages into an array list of Snowflakes and delete them + // Send help + val messageFlow = if (before == null && after == null) { + channel.withStrategy(EntitySupplyStrategy.rest).getMessagesBefore(Snowflake.max, count?.let { min(it, 100) }) + } else if (after != null && before == null) { + channel.withStrategy(EntitySupplyStrategy.rest).getMessagesAfter(after, count?.let { min(it, 100) }) + } else if (after == null && before != null) { + channel.withStrategy(EntitySupplyStrategy.rest).getMessagesBefore(before, count?.let { min(it, 100) }) + } else if (after != null && before != null) { + channel.withStrategy(EntitySupplyStrategy.rest).getMessagesBefore(before, count?.let { min(it, 100) }) + .filter { it.id > after } + } else { + flowOf() + } + + val messages = if (author == null) { + messageFlow.map { it.id }.toSet() + } else { + messageFlow.filter { it.author == author }.map { it.id }.toSet() + } + + textChannel.bulkDelete(messages) + + respond { + content = "Messages cleared." + } + + if (config.publicLogging != null && config.publicLogging == true) { + channel.createEmbed { + title = "$count messages have been cleared." + color = DISCORD_BLACK + } + } + + val actionLog = + getLoggingChannelWithPerms(ConfigOptions.ACTION_LOG, this.getGuild()!!) ?: return + actionLog.createEmbed { + title = "${count ?: messages.size} messages have been cleared." + description = "Action occurred in ${textChannel.mention}" + footer { + text = user.asUserOrNull()?.username ?: "Unable to get username" + icon = user.asUserOrNull()?.avatar?.cdnUrl?.toUrl() + } + color = DISCORD_BLACK + } +} + +/** + * An object containing the arguments for clear commands. + * + * @since 4.8.6 + */ +@Suppress("MemberNameEqualsClassName") // Cope +object ClearCommandArgs { + /** Clear a specific count of messages. */ + class Count : Arguments() { + /** The number of messages the user wants to remove. */ + val count by int { + name = "messages" + description = "Number of messages to delete" + } + + /** The author of the messages that need clearing. */ + val author by optionalUser { + name = "author" + description = "The author of the messages to clear" + } + } + + /** Clear messages after a specific one. */ + class After : Arguments() { + /** The ID of the message to start clearing from. */ + val after by snowflake { + name = "after" + description = "The ID of the message to clear after" + } + + /** The number of messages the user wants to remove. */ + val count by optionalInt { + name = "message-count" + description = "The number of messages to clear" + } + + /** The author of the messages that need clearing. */ + val author by optionalUser { + name = "author" + description = "The author of the messages to clear" + } + } + + /** Clear messages before a specific one. */ + class Before : Arguments() { + /** The ID of the message to start clearing before. */ + val before by snowflake { + name = "before" + description = "The ID of the message to clear before" + } + + /** The number of messages the user wants to remove. */ + val count by optionalInt { + name = "message-count" + description = "The number of messages to clear" + } + + /** The author of the messages that need clearing. */ + val author by optionalUser { + name = "author" + description = "The author of the messages to clear" + } + } + + /** Clear messages between 2 specific ones. */ + class Between : Arguments() { + /** The ID of the message to start clearing from. */ + val after by snowflake { + name = "after" + description = "The ID of the message to clear after" + } + + /** The ID of the message to start clearing before. */ + val before by snowflake { + name = "before" + description = "The ID of the message to clear before" + } + + /** The author of the messages that need clearing. */ + val author by optionalUser { + name = "author" + description = "The author of the messages to clear" + } + } +} diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/extensions/util/InfoCommands.kt b/src/main/kotlin/org/hyacinthbots/lilybot/extensions/util/InfoCommands.kt index 6f47de43..b01d2f2c 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/extensions/util/InfoCommands.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/extensions/util/InfoCommands.kt @@ -13,9 +13,8 @@ import dev.kord.rest.builder.message.create.embed import kotlinx.datetime.TimeZone import kotlinx.datetime.toLocalDateTime import org.hyacinthbots.lilybot.database.collections.UptimeCollection -import org.hyacinthbots.lilybot.utils.BUILD_ID +import org.hyacinthbots.lilybot.internal.BuildInfo import org.hyacinthbots.lilybot.utils.HYACINTH_GITHUB -import org.hyacinthbots.lilybot.utils.LILY_VERSION /** * This class contains the info commands that allow users to get a better idea of how to use the bot. @@ -127,8 +126,9 @@ class InfoCommands : Extension() { } field { name = "Version" + // To avoid IntelliJ shouting about build errors, use https://plugins.jetbrains.com/plugin/9407-pebble value = - "$LILY_VERSION ($BUILD_ID)" + "${BuildInfo.LILY_VERSION} (${BuildInfo.BUILD_ID})" inline = true } field { diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/utils/_Constants.kt b/src/main/kotlin/org/hyacinthbots/lilybot/utils/_Constants.kt index 4bebc87d..0bcc99a4 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/utils/_Constants.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/utils/_Constants.kt @@ -24,8 +24,4 @@ val ENVIRONMENT = env("ENVIRONMENT") val ENV = envOrNull("STATUS_URL") -const val BUILD_ID: String = "@build_id@" - -const val LILY_VERSION: String = "@version@" - const val HYACINTH_GITHUB: String = "https://github.com/HyacinthBots" diff --git a/src/main/kotlin/org/hyacinthbots/lilybot/utils/_PermissionUtils.kt b/src/main/kotlin/org/hyacinthbots/lilybot/utils/_PermissionUtils.kt index 20af83b3..ca2af49a 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/utils/_PermissionUtils.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/utils/_PermissionUtils.kt @@ -135,9 +135,7 @@ suspend inline fun CheckContext<*>.botHasChannelPerms(permissions: Permissions) permissionsSet.add( permissions.values.toString() .split(",")[count] - .split(".")[4] - .split("$")[1] - .split("@")[0] + .split(".")[1] .replace("[", "`") .replace("]", "`") )