Skip to content

Commit

Permalink
Revert "Use a constant to determine the collection name"
Browse files Browse the repository at this point in the history
This reverts commit f61306c.
  • Loading branch information
NoComment1105 committed Sep 5, 2023
1 parent f61306c commit 472f1b2
Show file tree
Hide file tree
Showing 30 changed files with 37 additions and 128 deletions.
6 changes: 2 additions & 4 deletions src/main/kotlin/org/hyacinthbots/lilybot/database/Cleanups.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import mu.KotlinLogging
import org.hyacinthbots.lilybot.database.Cleanups.cleanupGuildData
import org.hyacinthbots.lilybot.database.Cleanups.cleanupThreadData
import org.hyacinthbots.lilybot.database.collections.GithubCollection
import org.hyacinthbots.lilybot.database.collections.GuildLeaveTimeCollection
import org.hyacinthbots.lilybot.database.collections.LoggingConfigCollection
import org.hyacinthbots.lilybot.database.collections.ModerationConfigCollection
import org.hyacinthbots.lilybot.database.collections.NewsChannelPublishingCollection
Expand Down Expand Up @@ -40,11 +39,10 @@ object Cleanups : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val guildLeaveTimeCollection =
db.mainDatabase.getCollection<GuildLeaveTimeData>(GuildLeaveTimeCollection.name)
internal val guildLeaveTimeCollection = db.mainDatabase.getCollection<GuildLeaveTimeData>("guildLeaveTimeData")

@PublishedApi
internal val threadDataCollection = db.mainDatabase.getCollection<ThreadData>(ThreadsCollection.name)
internal val threadDataCollection = db.mainDatabase.getCollection<ThreadData>("threadData")

@PublishedApi
internal val cleanupsLogger = KotlinLogging.logger("Database Cleanups")
Expand Down
22 changes: 0 additions & 22 deletions src/main/kotlin/org/hyacinthbots/lilybot/database/Collection.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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.Collection
import org.hyacinthbots.lilybot.database.Database
import org.hyacinthbots.lilybot.database.entities.AutoThreadingData
import org.hyacinthbots.lilybot.database.findOne
Expand All @@ -25,7 +24,7 @@ class AutoThreadingCollection : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val collection = db.mainDatabase.getCollection<AutoThreadingData>(name)
internal val collection = db.mainDatabase.getCollection<AutoThreadingData>("autoThreadingData")

/**
* Gets all auto threads for a given [inputGuildId].
Expand Down Expand Up @@ -80,6 +79,4 @@ class AutoThreadingCollection : KordExKoinComponent {
*/
suspend inline fun deleteGuildAutoThreads(inputGuildId: Snowflake) =
collection.deleteMany(eq(AutoThreadingData::guildId.name, inputGuildId))

companion object : Collection("autoThreadingData")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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.Collection
import org.hyacinthbots.lilybot.database.Database
import org.hyacinthbots.lilybot.database.entities.LoggingConfigData
import org.hyacinthbots.lilybot.database.entities.ModerationConfigData
Expand All @@ -24,7 +23,7 @@ class LoggingConfigCollection : KordExKoinComponent {
private val configDb: Database by inject()

@PublishedApi
internal val collection = configDb.configDatabase.getCollection<LoggingConfigData>(name)
internal val collection = configDb.configDatabase.getCollection<LoggingConfigData>("loggingConfigData")

/**
* Gets the logging config for the given guild using the [guildId][inputGuildId].
Expand Down Expand Up @@ -58,8 +57,6 @@ class LoggingConfigCollection : KordExKoinComponent {
*/
suspend inline fun clearConfig(inputGuildId: Snowflake) =
collection.deleteOne(eq(LoggingConfigData::guildId.name, inputGuildId))

companion object : Collection("loggingConfigData")
}

/**
Expand All @@ -75,7 +72,7 @@ class ModerationConfigCollection : KordExKoinComponent {
private val configDb: Database by inject()

@PublishedApi
internal val collection = configDb.configDatabase.getCollection<ModerationConfigData>(name)
internal val collection = configDb.configDatabase.getCollection<ModerationConfigData>("moderationConfigData")

/**
* Gets the Moderation config for the given guild using the [guildId][inputGuildId].
Expand Down Expand Up @@ -109,8 +106,6 @@ class ModerationConfigCollection : KordExKoinComponent {
*/
suspend inline fun clearConfig(inputGuildId: Snowflake) =
collection.deleteOne(eq(ModerationConfigData::guildId.name, inputGuildId))

companion object : Collection("moderationConfigData")
}

/**
Expand All @@ -126,7 +121,7 @@ class UtilityConfigCollection : KordExKoinComponent {
private val configDb: Database by inject()

@PublishedApi
internal val collection = configDb.configDatabase.getCollection<UtilityConfigData>(name)
internal val collection = configDb.configDatabase.getCollection<UtilityConfigData>("utilityConfigData")

/**
* Gets the Utility config for the given guild using the [guildId][inputGuildId].
Expand Down Expand Up @@ -160,6 +155,4 @@ class UtilityConfigCollection : KordExKoinComponent {
*/
suspend inline fun clearConfig(inputGuildId: Snowflake) =
collection.deleteOne(eq(UtilityConfigData::guildId.name, inputGuildId))

companion object : Collection("utilityConfigData")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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.Collection
import org.hyacinthbots.lilybot.database.Database
import org.hyacinthbots.lilybot.database.entities.GalleryChannelData
import org.koin.core.component.inject
Expand All @@ -24,7 +23,7 @@ class GalleryChannelCollection : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val collection = db.mainDatabase.getCollection<GalleryChannelData>(name)
internal val collection = db.mainDatabase.getCollection<GalleryChannelData>("galleryChannelData")

/**
* Collects every gallery channel in the database into a [List].
Expand Down Expand Up @@ -73,6 +72,4 @@ class GalleryChannelCollection : KordExKoinComponent {
*/
suspend inline fun removeAll(inputGuildId: Snowflake) =
collection.deleteMany(eq(GalleryChannelData::guildId.name, inputGuildId))

companion object : Collection("galleryChannelData")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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.Collection
import org.hyacinthbots.lilybot.database.Database
import org.hyacinthbots.lilybot.database.entities.GithubData
import org.hyacinthbots.lilybot.database.findOne
Expand All @@ -22,7 +21,7 @@ class GithubCollection : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val collection = db.mainDatabase.getCollection<GithubData>(name)
internal val collection = db.mainDatabase.getCollection<GithubData>("githubData")

/**
* Gets the default repo for GitHub commands.
Expand Down Expand Up @@ -57,6 +56,4 @@ class GithubCollection : KordExKoinComponent {
*/
suspend inline fun removeDefaultRepo(inputGuildId: Snowflake) =
collection.deleteOne(eq(GithubData::guildId.name, inputGuildId))

companion object : Collection("githubData")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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.Collection
import org.hyacinthbots.lilybot.database.Database
import org.hyacinthbots.lilybot.database.entities.GuildLeaveTimeData
import org.koin.core.component.inject
Expand All @@ -21,7 +20,7 @@ class GuildLeaveTimeCollection : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val collection = db.mainDatabase.getCollection<GuildLeaveTimeData>(name)
internal val collection = db.mainDatabase.getCollection<GuildLeaveTimeData>("guildLeaveTimeData")

/**
* Adds the time Lily bot left a guild with a config.
Expand All @@ -45,6 +44,4 @@ class GuildLeaveTimeCollection : KordExKoinComponent {
*/
suspend inline fun removeLeaveTime(inputGuildId: Snowflake) =
collection.deleteOne(eq(GuildLeaveTimeData::guildId.name, inputGuildId))

companion object : Collection("guildLeaveTimeData")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ 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.Collection
import org.hyacinthbots.lilybot.database.Database
import org.hyacinthbots.lilybot.database.entities.ConfigMetaData
import org.hyacinthbots.lilybot.database.entities.MainMetaData
Expand All @@ -22,7 +21,7 @@ class MainMetaCollection : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val collection = db.mainDatabase.getCollection<MainMetaData>(name)
internal val collection = db.mainDatabase.getCollection<MainMetaData>("mainMetaData")

/**
* Gets the main metadata from the database.
Expand Down Expand Up @@ -54,8 +53,6 @@ class MainMetaCollection : KordExKoinComponent {
eq(MainMetaData::id.name, "mainMeta"),
meta
)

companion object : Collection("mainMetaData")
}

/**
Expand All @@ -71,7 +68,7 @@ class ConfigMetaCollection : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val collection = db.configDatabase.getCollection<ConfigMetaData>(name)
internal val collection = db.configDatabase.getCollection<ConfigMetaData>("configMetaData")

/**
* Gets the config metadata from the database.
Expand Down Expand Up @@ -103,6 +100,4 @@ class ConfigMetaCollection : KordExKoinComponent {
eq(ConfigMetaData::id.name, "configMeta"),
meta
)

companion object : Collection("configMetaData")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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.Collection
import org.hyacinthbots.lilybot.database.Database
import org.hyacinthbots.lilybot.database.entities.NewsChannelPublishingData
import org.hyacinthbots.lilybot.database.findOne
Expand All @@ -26,7 +25,7 @@ class NewsChannelPublishingCollection : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val collection = db.mainDatabase.getCollection<NewsChannelPublishingData>(name)
internal val collection = db.mainDatabase.getCollection<NewsChannelPublishingData>("newsChannelPublishingData")

/**
* Adds a channel for auto-publishing.
Expand Down Expand Up @@ -99,6 +98,4 @@ class NewsChannelPublishingCollection : KordExKoinComponent {
suspend inline fun clearAutoPublishingForGuild(inputGuildId: Snowflake) {
collection.deleteMany(eq(NewsChannelPublishingData::guildId.name, inputGuildId))
}

companion object : Collection("newsChannelPublishingData")
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import kotlinx.coroutines.flow.toList
import kotlinx.datetime.DateTimePeriod
import kotlinx.datetime.TimeZone
import kotlinx.datetime.plus
import org.hyacinthbots.lilybot.database.Collection
import org.hyacinthbots.lilybot.database.Database
import org.hyacinthbots.lilybot.database.entities.ReminderData
import org.koin.core.component.inject
Expand All @@ -31,7 +30,7 @@ class ReminderCollection : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val collection = db.mainDatabase.getCollection<ReminderData>(name)
internal val collection = db.mainDatabase.getCollection<ReminderData>("reminderData")

/**
* Gets all the reminders currently in the database.
Expand Down Expand Up @@ -121,6 +120,4 @@ class ReminderCollection : KordExKoinComponent {
)
)
}

companion object : Collection("reminderData")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ 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.Collection
import org.hyacinthbots.lilybot.database.Database
import org.hyacinthbots.lilybot.database.entities.RoleMenuData
import org.hyacinthbots.lilybot.database.findOne
Expand All @@ -23,7 +22,7 @@ class RoleMenuCollection : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val collection = db.mainDatabase.getCollection<RoleMenuData>(name)
internal val collection = db.mainDatabase.getCollection<RoleMenuData>("roleMenuData")

/**
* Using the provided [inputMessageId] the associated [RoleMenuData] will be returned from the database.
Expand Down Expand Up @@ -84,6 +83,4 @@ class RoleMenuCollection : KordExKoinComponent {
*/
suspend inline fun removeAllRoleMenus(inputGuildId: Snowflake) =
collection.deleteMany(eq(RoleMenuData::guildId.name, inputGuildId))

companion object : Collection("roleMenuData")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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.Collection
import org.hyacinthbots.lilybot.database.Database
import org.hyacinthbots.lilybot.database.entities.RoleSubscriptionData
import org.hyacinthbots.lilybot.database.findOne
Expand All @@ -25,7 +24,7 @@ class RoleSubscriptionCollection : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val collection = db.mainDatabase.getCollection<RoleSubscriptionData>(name)
internal val collection = db.mainDatabase.getCollection<RoleSubscriptionData>("roleSubscriptionData")

/**
* Gets the roles that are subscribable for a given guild.
Expand Down Expand Up @@ -107,6 +106,4 @@ class RoleSubscriptionCollection : KordExKoinComponent {
*/
suspend inline fun removeAllSubscribableRoles(inputGuildId: Snowflake) =
collection.deleteOne(eq(RoleSubscriptionData::guildId.name, inputGuildId))

companion object : Collection("roleSubscriptionData")
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.hyacinthbots.lilybot.database.collections

import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent
import org.hyacinthbots.lilybot.database.Collection
import org.hyacinthbots.lilybot.database.Database
import org.hyacinthbots.lilybot.database.deleteOne
import org.hyacinthbots.lilybot.database.entities.StatusData
Expand All @@ -20,7 +19,7 @@ class StatusCollection : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val collection = db.mainDatabase.getCollection<StatusData>(name)
internal val collection = db.mainDatabase.getCollection<StatusData>("statusData")

/**
* Gets Lily's status from the database.
Expand All @@ -43,6 +42,4 @@ class StatusCollection : KordExKoinComponent {
collection.deleteOne()
collection.insertOne(StatusData(newStatus))
}

companion object : Collection("statusData")
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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.Collection
import org.hyacinthbots.lilybot.database.Database
import org.hyacinthbots.lilybot.database.entities.TagsData
import org.hyacinthbots.lilybot.database.findOne
Expand All @@ -26,7 +25,7 @@ class TagsCollection : KordExKoinComponent {
private val db: Database by inject()

@PublishedApi
internal val collection = db.mainDatabase.getCollection<TagsData>(name)
internal val collection = db.mainDatabase.getCollection<TagsData>("tagsData")

/**
* Gets the given tag using it's [name] and returns its [TagsData]. If the tag does not exist.
Expand Down Expand Up @@ -91,6 +90,4 @@ class TagsCollection : KordExKoinComponent {
*/
suspend inline fun clearTags(inputGuildId: Snowflake) =
collection.deleteMany(eq(TagsData::guildId.name, inputGuildId))

companion object : Collection("tagsData")
}
Loading

0 comments on commit 472f1b2

Please sign in to comment.