-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix permissions being lost by locked channels when unlocked (#395)
* Begin work on storing original permissions when locking channels * Complete work on storing original permission for locked channels
- Loading branch information
1 parent
a61c526
commit ce9eac2
Showing
5 changed files
with
137 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/kotlin/org/hyacinthbots/lilybot/database/collections/LockedChannelCollection.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
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.LockedChannelData | ||
import org.koin.core.component.inject | ||
import org.litote.kmongo.eq | ||
|
||
/** | ||
* This class contains the function for interacting with the [Locked Channel Database][LockedChannelData]. This class | ||
* contains functions for getting, setting and removing locked channels | ||
* | ||
* @since 5.0.0 | ||
* @see addLockedChannel | ||
* @see removeLockedChannel | ||
* @see removeAllLockedChannels | ||
* @see getLockedChannel | ||
*/ | ||
class LockedChannelCollection : KordExKoinComponent { | ||
private val db: Database by inject() | ||
|
||
@PublishedApi | ||
internal val collection = db.mainDatabase.getCollection<LockedChannelData>() | ||
|
||
/** | ||
* Adds the data about a newly locked channel to the database. | ||
* | ||
* @param data The [LockedChannelData] for the locked channel | ||
* | ||
* @author NoComment1105 | ||
* @since 5.0.0 | ||
*/ | ||
suspend inline fun addLockedChannel(data: LockedChannelData) = collection.insertOne(data) | ||
|
||
/** | ||
* Removes a locked channel from the database. This is usually called when a channel is unlocked. | ||
* | ||
* @param inputGuildId The ID of the guild the locked channel is in | ||
* @param inputChannelId The ID of the locked channel itself | ||
* | ||
* @author NoComment1105 | ||
* @since 5.0.0 | ||
*/ | ||
suspend inline fun removeLockedChannel(inputGuildId: Snowflake, inputChannelId: Snowflake) = | ||
collection.deleteOne(LockedChannelData::guildId eq inputGuildId, LockedChannelData::channelId eq inputChannelId) | ||
|
||
/** | ||
* Removes all locked channels for a given guild from the database. Used in guild cleanups. | ||
* | ||
* @param inputGuildId The ID of the guild to remove the locked channels from | ||
* | ||
* @author NoComment1105 | ||
* @since 5.0.0 | ||
*/ | ||
suspend inline fun removeAllLockedChannels(inputGuildId: Snowflake) = | ||
collection.deleteMany(LockedChannelData::guildId eq inputGuildId) | ||
|
||
/** | ||
* Gets a locked channel based on the input parameters. | ||
* | ||
* @param inputGuildId The ID of the guild the locked channel is in | ||
* @param inputChannelId The ID of the channel to get the locked data for | ||
* @return A [LockedChannelData] object for the given channel | ||
* | ||
* @author NoComment1105 | ||
* @since 5.0.0 | ||
*/ | ||
suspend inline fun getLockedChannel(inputGuildId: Snowflake, inputChannelId: Snowflake): LockedChannelData? = | ||
collection.findOne(LockedChannelData::guildId eq inputGuildId, LockedChannelData::channelId eq inputChannelId) | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/kotlin/org/hyacinthbots/lilybot/database/entities/LockedChannelData.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package org.hyacinthbots.lilybot.database.entities | ||
|
||
import dev.kord.common.entity.Snowflake | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* The data for locked channels. | ||
* | ||
* @property guildId The ID of the guild the locked channel is in | ||
* @property channelId The ID of the channel that is locked | ||
* @property allowed The Discord Bit Set code for the allowed permissions, formatted as a string | ||
* @property denied The Discord Bit Set code for the denied permissions, formatted as a string | ||
* @since 5.0.0 | ||
*/ | ||
@Serializable | ||
data class LockedChannelData( | ||
val guildId: Snowflake, | ||
val channelId: Snowflake, | ||
val allowed: String, | ||
val denied: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters