-
-
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.
Merge branch 'develop' into issue-347
- Loading branch information
Showing
9 changed files
with
391 additions
and
92 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
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
Binary file not shown.
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
79 changes: 79 additions & 0 deletions
79
src/main/kotlin/org/hyacinthbots/lilybot/database/collections/TemporaryBanCollection.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,79 @@ | ||
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.TemporaryBanData | ||
import org.koin.core.component.inject | ||
import org.litote.kmongo.eq | ||
|
||
/** | ||
* This class contains the functions for interacting with [the temporary ban database][TemporaryBanData]. This class | ||
* contains functions for settings temporary bans, getting temporary bans based off of various parameters and removing | ||
* them. | ||
* | ||
* @since 5.0.0 | ||
* @see getAllTempBans | ||
* @see getTempBansForGuild | ||
* @see getUserTempBan | ||
* @see setTempBan | ||
* @see removeTempBan | ||
*/ | ||
class TemporaryBanCollection : KordExKoinComponent { | ||
private val db: Database by inject() | ||
|
||
@PublishedApi | ||
internal val collection = db.mainDatabase.getCollection<TemporaryBanData>() | ||
|
||
/** | ||
* Gets all the temporary bans currently in the database. | ||
* | ||
* @return A list of temporary bans in the database | ||
* @author NoComment1105 | ||
* @since 5.0.0 | ||
*/ | ||
suspend inline fun getAllTempBans(): List<TemporaryBanData> = collection.find().toList() | ||
|
||
/** | ||
* Gets all the temporary bans for a given guild. | ||
* | ||
* @param guildId The ID of the guild to get the bans in | ||
* @return A list of Temporary bans for the given [guildId] | ||
* @author NoComment1105 | ||
* @since 5.0.0 | ||
*/ | ||
suspend inline fun getTempBansForGuild(guildId: Snowflake): List<TemporaryBanData> = | ||
collection.find(TemporaryBanData::guildId eq guildId).toList() | ||
|
||
/** | ||
* Gets a temporary ban for a given user. | ||
* | ||
* @param guildId The ID of the guild the temporary ban occurred in | ||
* @param bannedUserId The ID of the user that was temporarily banned | ||
* @return The [TemporaryBanData] for the [bannedUserId] | ||
* @author NoComment1105 | ||
* @since 5.0.0 | ||
*/ | ||
suspend inline fun getUserTempBan(guildId: Snowflake, bannedUserId: Snowflake): TemporaryBanData? = | ||
collection.findOne(TemporaryBanData::guildId eq guildId, TemporaryBanData::bannedUserId eq bannedUserId) | ||
|
||
/** | ||
* Sets a temporary ban. | ||
* | ||
* @param tempBanData The data for the temporary ban | ||
* @author NoComment1105 | ||
* @since 5.0.0 | ||
*/ | ||
suspend inline fun setTempBan(tempBanData: TemporaryBanData) = collection.insertOne(tempBanData) | ||
|
||
/** | ||
* Removes the temporary ban for a user in a given guild. This is called once a temporary ban is completed. | ||
* | ||
* @param guildId The guild the temporary ban is being removed from | ||
* @param bannedUserId The ID of the user to remove the temporary ban from | ||
* @author NoComment1105 | ||
* @since 5.0.0 | ||
*/ | ||
suspend inline fun removeTempBan(guildId: Snowflake, bannedUserId: Snowflake) = | ||
collection.deleteOne(TemporaryBanData::guildId eq guildId, TemporaryBanData::bannedUserId eq bannedUserId) | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/kotlin/org/hyacinthbots/lilybot/database/entities/TemporaryBanData.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,25 @@ | ||
package org.hyacinthbots.lilybot.database.entities | ||
|
||
import dev.kord.common.entity.Snowflake | ||
import kotlinx.datetime.Instant | ||
import kotlinx.serialization.Serializable | ||
|
||
/** | ||
* The data for temporary bans in a guild. | ||
* | ||
* @property guildId The ID of the guild the ban occurred in | ||
* @property bannedUserId The ID of the user that was banned | ||
* @property moderatorUserId The ID of the moderator that applied the ban | ||
* @property startTime The time the ban was applied | ||
* @property endTime The time the ban will complete | ||
* | ||
* @since 5.0.0 | ||
*/ | ||
@Serializable | ||
data class TemporaryBanData( | ||
val guildId: Snowflake, | ||
val bannedUserId: Snowflake, | ||
val moderatorUserId: Snowflake, | ||
val startTime: Instant, | ||
val endTime: Instant | ||
) |
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
Oops, something went wrong.