-
-
Notifications
You must be signed in to change notification settings - Fork 24
/
ConfigCollection.kt
157 lines (141 loc) · 5.16 KB
/
ConfigCollection.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package org.hyacinthbots.lilybot.database.collections
import com.kotlindiscord.kord.extensions.koin.KordExKoinComponent
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.koin.core.component.inject
import org.litote.kmongo.eq
/**
* This class contains the functions for interacting with the [Logging Config Database][LoggingConfigData]. This class
* contains functions for getting, setting and removing logging config.
*
* @since 4.0.0
* @see getConfig
* @see setConfig
* @see clearConfig
*/
class LoggingConfigCollection : KordExKoinComponent {
private val configDb: Database by inject()
@PublishedApi
internal val collection = configDb.configDatabase.getCollection<LoggingConfigData>()
/**
* Gets the logging config for the given guild using the [guildId][inputGuildId].
*
* @param inputGuildId The guild id to get the config for.
* @return The logging config for the given guild.
* @author NoComment1105
* @since 4.0.0
*/
suspend inline fun getConfig(inputGuildId: Snowflake): LoggingConfigData? =
collection.findOne(LoggingConfigData::guildId eq inputGuildId)
/**
* Adds the given [loggingConfig] to the database.
*
* @param loggingConfig The new config values for the logging config you want to set.
* @author NoComment1105
* @since 4.0.0
*/
suspend inline fun setConfig(loggingConfig: LoggingConfigData) {
collection.deleteOne(LoggingConfigData::guildId eq loggingConfig.guildId)
collection.insertOne(loggingConfig)
}
/**
* Clears the logging config for the given guild using the [guildId][inputGuildId].
*
* @param inputGuildId The guild id to clear the config for.
* @author NoComment1105
* @since 4.0.0
*/
suspend inline fun clearConfig(inputGuildId: Snowflake) =
collection.deleteOne(LoggingConfigData::guildId eq inputGuildId)
}
/**
* This class contains the functions for interacting with the [Moderation Config Database][ModerationConfigData]. This
* class contains functions for getting, setting and removing logging config.
*
* @since 4.0.0
* @see getConfig
* @see setConfig
* @see clearConfig
*/
class ModerationConfigCollection : KordExKoinComponent {
private val configDb: Database by inject()
@PublishedApi
internal val collection = configDb.configDatabase.getCollection<ModerationConfigData>()
/**
* Gets the Moderation config for the given guild using the [guildId][inputGuildId].
*
* @param inputGuildId The guild id to get the config for.
* @return The moderation config for the given guild.
* @author NoComment1105
* @since 4.0.0
*/
suspend inline fun getConfig(inputGuildId: Snowflake): ModerationConfigData? =
collection.findOne(ModerationConfigData::guildId eq inputGuildId)
/**
* Adds the given [moderationConfig] to the database.
*
* @param moderationConfig The new config values for the moderation config you want to set.
* @author NoComment1105
* @since 4.0.0
*/
suspend inline fun setConfig(moderationConfig: ModerationConfigData) {
collection.deleteOne(ModerationConfigData::guildId eq moderationConfig.guildId)
collection.insertOne(moderationConfig)
}
/**
* Clears the moderation config for the given guild using the [guildId][inputGuildId].
*
* @param inputGuildId The guild id to clear the config for.
* @author NoComment1105
* @since 4.0.0
*/
suspend inline fun clearConfig(inputGuildId: Snowflake) =
collection.deleteOne(ModerationConfigData::guildId eq inputGuildId)
}
/**
* This class contains the functions for interacting with the [Utility Config Database][UtilityConfigData].
* This class contains functions for getting, setting and removing Utility config.
*
* @since 4.0.0
* @see getConfig
* @see setConfig
* @see clearConfig
*/
class UtilityConfigCollection : KordExKoinComponent {
private val configDb: Database by inject()
@PublishedApi
internal val collection = configDb.configDatabase.getCollection<UtilityConfigData>()
/**
* Gets the Utility config for the given guild using the [guildId][inputGuildId].
*
* @param inputGuildId The guild id to get the config for.
* @return The Utility config for the given guild.
* @author NoComment1105
* @since 4.0.0
*/
suspend inline fun getConfig(inputGuildId: Snowflake): UtilityConfigData? =
collection.findOne(UtilityConfigData::guildId eq inputGuildId)
/**
* Adds the given [utilityConfig] to the database.
*
* @param utilityConfig The new config values for the Utility config you want to set.
* @author NoComment1105
* @since 4.0.0
*/
suspend inline fun setConfig(utilityConfig: UtilityConfigData) {
collection.deleteOne(UtilityConfigData::guildId eq utilityConfig.guildId)
collection.insertOne(utilityConfig)
}
/**
* Clears the Utility config for the given guild using the [guildId][inputGuildId].
*
* @param inputGuildId The guild id to clear the config for.
* @author NoComment1105
* @since 4.0.0
*/
suspend inline fun clearConfig(inputGuildId: Snowflake) =
collection.deleteOne(UtilityConfigData::guildId eq inputGuildId)
}