From 86f09cd0ee9ed879eb82fbcffda9285676704a87 Mon Sep 17 00:00:00 2001 From: NoComment1105 Date: Tue, 5 Sep 2023 10:23:10 +0100 Subject: [PATCH] Use a constant to determine the collection name but do it better --- .../lilybot/database/Collection.kt | 22 +++++++++++++++++++ .../collections/AutoThreadingCollection.kt | 2 +- .../database/collections/ConfigCollection.kt | 6 ++--- .../collections/GalleryChannelCollection.kt | 2 +- .../database/collections/GithubCollection.kt | 2 +- .../collections/GuildLeaveTimeCollection.kt | 2 +- .../database/collections/MetaCollection.kt | 4 ++-- .../NewsChannelPublishingCollection.kt | 2 +- .../collections/ReminderCollection.kt | 2 +- .../collections/RoleMenuCollection.kt | 2 +- .../collections/RoleSubscriptionCollection.kt | 2 +- .../database/collections/StatusCollection.kt | 2 +- .../database/collections/TagsCollection.kt | 2 +- .../database/collections/ThreadsCollection.kt | 2 +- .../database/collections/UptimeCollection.kt | 2 +- .../database/collections/WarnCollection.kt | 2 +- .../collections/WelcomeChannelCollection.kt | 2 +- .../database/entities/AutoThreadingData.kt | 5 ++++- .../lilybot/database/entities/Config.kt | 13 ++++++++--- .../database/entities/GalleryChannelData.kt | 5 ++++- .../lilybot/database/entities/GithubData.kt | 5 ++++- .../database/entities/GuildLeaveTimeData.kt | 5 ++++- .../lilybot/database/entities/MetaData.kt | 9 ++++++-- .../entities/NewsChannelPublishingData.kt | 5 ++++- .../database/entities/PublicMemberLogData.kt | 5 ++++- .../lilybot/database/entities/ReminderData.kt | 5 ++++- .../lilybot/database/entities/RoleMenuData.kt | 5 ++++- .../database/entities/RoleSubscriptionData.kt | 5 ++++- .../lilybot/database/entities/StatusData.kt | 5 ++++- .../lilybot/database/entities/TagsData.kt | 5 ++++- .../lilybot/database/entities/ThreadData.kt | 5 ++++- .../lilybot/database/entities/UptimeData.kt | 5 ++++- .../lilybot/database/entities/WarnData.kt | 5 ++++- .../database/entities/WelcomeChannelData.kt | 5 ++++- .../database/migrations/config/configV1.kt | 4 ++-- .../database/migrations/config/configV2.kt | 2 +- .../database/migrations/config/configV3.kt | 2 +- .../database/migrations/config/configV6.kt | 2 +- .../database/migrations/main/mainV1.kt | 6 ++--- .../database/migrations/main/mainV2.kt | 2 +- .../database/migrations/main/mainV3.kt | 3 ++- .../database/migrations/main/mainV4.kt | 6 +++-- .../database/migrations/main/mainV5.kt | 2 +- .../database/migrations/main/mainV6.kt | 2 +- .../database/migrations/main/mainV7.kt | 3 ++- .../database/migrations/main/mainV8.kt | 3 ++- 46 files changed, 139 insertions(+), 55 deletions(-) create mode 100644 src/main/kotlin/org/hyacinthbots/lilybot/database/Collection.kt 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/collections/AutoThreadingCollection.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/AutoThreadingCollection.kt index fb65eff4..071204e1 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/AutoThreadingCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/AutoThreadingCollection.kt @@ -24,7 +24,7 @@ class AutoThreadingCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("autoThreadingData") + internal val collection = db.mainDatabase.getCollection(AutoThreadingData.name) /** * Gets all auto threads for a given [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 f83e1e10..df428d1a 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ConfigCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ConfigCollection.kt @@ -23,7 +23,7 @@ class LoggingConfigCollection : KordExKoinComponent { private val configDb: Database by inject() @PublishedApi - internal val collection = configDb.configDatabase.getCollection("loggingConfigData") + internal val collection = configDb.configDatabase.getCollection(LoggingConfigData.name) /** * Gets the logging config for the given guild using the [guildId][inputGuildId]. @@ -72,7 +72,7 @@ class ModerationConfigCollection : KordExKoinComponent { private val configDb: Database by inject() @PublishedApi - internal val collection = configDb.configDatabase.getCollection("moderationConfigData") + internal val collection = configDb.configDatabase.getCollection(ModerationConfigData.name) /** * Gets the Moderation config for the given guild using the [guildId][inputGuildId]. @@ -121,7 +121,7 @@ class UtilityConfigCollection : KordExKoinComponent { private val configDb: Database by inject() @PublishedApi - internal val collection = configDb.configDatabase.getCollection("utilityConfigData") + internal val collection = configDb.configDatabase.getCollection(UtilityConfigData.name) /** * Gets the Utility config for the given guild using the [guildId][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 0784c0b1..d647eba5 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GalleryChannelCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GalleryChannelCollection.kt @@ -23,7 +23,7 @@ class GalleryChannelCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("galleryChannelData") + internal val collection = db.mainDatabase.getCollection(GalleryChannelData.name) /** * Collects every gallery channel in the database into a [List]. 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 88a89bcc..2a95ea9b 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GithubCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GithubCollection.kt @@ -21,7 +21,7 @@ class GithubCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("githubData") + internal val collection = db.mainDatabase.getCollection(GithubData.name) /** * Gets the default repo for GitHub commands. 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 3489de34..6b1a35ec 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GuildLeaveTimeCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/GuildLeaveTimeCollection.kt @@ -20,7 +20,7 @@ class GuildLeaveTimeCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("guildLeaveTimeData") + internal val collection = db.mainDatabase.getCollection(GuildLeaveTimeData.name) /** * Adds the time Lily bot left a guild with a config. 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 488c4231..3eddab80 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/MetaCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/MetaCollection.kt @@ -21,7 +21,7 @@ class MainMetaCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("mainMetaData") + internal val collection = db.mainDatabase.getCollection(MainMetaData.name) /** * Gets the main metadata from the database. @@ -68,7 +68,7 @@ class ConfigMetaCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.configDatabase.getCollection("configMetaData") + internal val collection = db.configDatabase.getCollection(ConfigMetaData.name) /** * Gets the config metadata from the database. 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 df41b9d7..1bf10b8c 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/NewsChannelPublishingCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/NewsChannelPublishingCollection.kt @@ -25,7 +25,7 @@ class NewsChannelPublishingCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("newsChannelPublishingData") + internal val collection = db.mainDatabase.getCollection(NewsChannelPublishingData.name) /** * Adds a channel for auto-publishing. 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 d9074f53..f4a066d9 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ReminderCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ReminderCollection.kt @@ -30,7 +30,7 @@ class ReminderCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("reminderData") + internal val collection = db.mainDatabase.getCollection(ReminderData.name) /** * Gets all the reminders currently in the database. 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 7ef54e50..1999ab21 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleMenuCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleMenuCollection.kt @@ -22,7 +22,7 @@ class RoleMenuCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("roleMenuData") + internal val collection = db.mainDatabase.getCollection(RoleMenuData.name) /** * Using the provided [inputMessageId] the associated [RoleMenuData] will be returned from the database. 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 849ebd9b..17523a39 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleSubscriptionCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/RoleSubscriptionCollection.kt @@ -24,7 +24,7 @@ class RoleSubscriptionCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("roleSubscriptionData") + internal val collection = db.mainDatabase.getCollection(RoleSubscriptionData.name) /** * Gets the roles that are subscribable for a given guild. 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 f6e265f9..4a961feb 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/StatusCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/StatusCollection.kt @@ -19,7 +19,7 @@ class StatusCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("statusData") + internal val collection = db.mainDatabase.getCollection(StatusData.name) /** * Gets Lily's status from 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 1f5d7e6e..21476ee5 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/TagsCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/TagsCollection.kt @@ -25,7 +25,7 @@ class TagsCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("tagsData") + 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. 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 d9acef10..0b86be07 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ThreadsCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ThreadsCollection.kt @@ -25,7 +25,7 @@ class ThreadsCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("threadsData") + internal val collection = db.mainDatabase.getCollection(ThreadData.name) /** * Using the provided [inputThreadId] the thread is returned. 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 0394f7cb..18d1a1e0 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/UptimeCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/UptimeCollection.kt @@ -19,7 +19,7 @@ class UptimeCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("uptimeData") + internal val collection = db.mainDatabase.getCollection(UptimeData.name) /** * Gets the uptime data from the database. 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 5c16e6d9..2f8da8bc 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WarnCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WarnCollection.kt @@ -22,7 +22,7 @@ class WarnCollection : KordExKoinComponent { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("warnData") + internal val collection = db.mainDatabase.getCollection(WarnData.name) /** * Gets the number of points the provided [inputUserId] has in the provided [inputGuildId] from the database. 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 b1930220..463bff04 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WelcomeChannelCollection.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/collections/WelcomeChannelCollection.kt @@ -33,7 +33,7 @@ class WelcomeChannelCollection : KordExKoinComponent, CozyWelcomeChannelData { private val db: Database by inject() @PublishedApi - internal val collection = db.mainDatabase.getCollection("welcomeChannelData") + internal val collection = db.mainDatabase.getCollection(WelcomeChannelData.name) override suspend fun getChannelURLs(): Map = collection.find() 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 84a256af..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 @@ -56,7 +59,9 @@ data class ModerationConfigData( val autoPunishOnWarn: Boolean?, val publicLogging: Boolean?, val banDmMessage: String?, -) +) { + companion object : Collection("moderationConfigData") +} /** * The data for miscellaneous configuration. The miscellaneous config stores the data for enabling or disabling log @@ -70,4 +75,6 @@ data class ModerationConfigData( 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/config/configV1.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV1.kt index 824c26fe..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 @@ -6,14 +6,14 @@ import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.LoggingConfigData suspend fun configV1(configDb: MongoDatabase) { - with(configDb.getCollection("loggingConfigData")) { + with(configDb.getCollection(LoggingConfigData.name)) { updateMany( Filters.exists(LoggingConfigData::enableMessageEditLogs.name, false), Updates.set(LoggingConfigData::enableMessageEditLogs.name, false) ) } - configDb.getCollection("loggingConfigData").updateMany( + 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 1c11e2e3..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 @@ -6,7 +6,7 @@ import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.ModerationConfigData suspend fun configV2(db: MongoDatabase) { - with(db.getCollection("moderationConfigData")) { + with(db.getCollection(ModerationConfigData.name)) { updateMany( Filters.exists(ModerationConfigData::quickTimeoutLength.name, false), Updates.set(ModerationConfigData::quickTimeoutLength.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 011aac7a..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 @@ -6,7 +6,7 @@ import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.LoggingConfigData suspend fun configV3(db: MongoDatabase) { - with(db.getCollection("loggingConfigData")) { + with(db.getCollection(LoggingConfigData.name)) { updateMany( Filters.exists(LoggingConfigData::enablePublicMemberLogs.name, false), Updates.set(LoggingConfigData::enablePublicMemberLogs.name, false) 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 index f69f1606..073accdb 100644 --- a/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV6.kt +++ b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/config/configV6.kt @@ -6,7 +6,7 @@ import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.ModerationConfigData suspend fun configV6(db: MongoDatabase) { - with(db.getCollection("moderationConfigData")) { + 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/main/mainV1.kt b/src/main/kotlin/org/hyacinthbots/lilybot/database/migrations/main/mainV1.kt index 2b3f856a..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 @@ -63,7 +63,7 @@ suspend fun mainV1(db: MongoDatabase) { // reminders.bulkWrite(requests = nonRepeating, BulkWriteOptions().ordered(true)) // } - db.getCollection("statusData").drop() - 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 ea8405b1..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 @@ -6,7 +6,7 @@ import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.ThreadData suspend fun mainV2(db: MongoDatabase) { - with(db.getCollection("threadData")) { + 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 7fc4896e..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 com.mongodb.kotlin.client.coroutine.MongoDatabase +import org.hyacinthbots.lilybot.database.entities.ReminderData suspend fun mainV3(db: MongoDatabase) { // db.getCollection("remindMeData") - db.createCollection("reminderData") + 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 30bedd90..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 com.mongodb.kotlin.client.coroutine.MongoDatabase +import org.hyacinthbots.lilybot.database.entities.GithubData +import org.hyacinthbots.lilybot.database.entities.WelcomeChannelData suspend fun mainV4(db: MongoDatabase) { - db.createCollection("welcomeChannelData") - db.createCollection("githubData") + 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 0c2b9e01..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 @@ -8,7 +8,7 @@ import org.hyacinthbots.lilybot.database.entities.ThreadData suspend fun mainV5(db: MongoDatabase) { // db.createCollection("autoThreadingData") - with(db.getCollection("threadData")) { + with(db.getCollection(ThreadData.name)) { updateMany( Filters.exists(ThreadData::parentChannelId.name, false), Updates.set(ThreadData::parentChannelId.name, null) 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 04ea448a..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 @@ -6,7 +6,7 @@ import com.mongodb.kotlin.client.coroutine.MongoDatabase import org.hyacinthbots.lilybot.database.entities.AutoThreadingData suspend fun mainV6(db: MongoDatabase) { - with(db.getCollection("autoThreadingData")) { + 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 962c8ca6..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 com.mongodb.kotlin.client.coroutine.MongoDatabase +import org.hyacinthbots.lilybot.database.entities.NewsChannelPublishingData suspend fun mainV7(db: MongoDatabase) { - db.createCollection("newsChannelPublishingData") + 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 5bea5345..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 com.mongodb.kotlin.client.coroutine.MongoDatabase +import org.hyacinthbots.lilybot.database.entities.RoleSubscriptionData suspend fun mainV8(db: MongoDatabase) { - db.createCollection("roleSubscriptionData") + db.createCollection(RoleSubscriptionData.name) }