Skip to content

Commit

Permalink
Merge branch 'develop' into issue-347
Browse files Browse the repository at this point in the history
  • Loading branch information
NoComment1105 committed Apr 12, 2024
2 parents 6cc8472 + a61c526 commit a757d9d
Show file tree
Hide file tree
Showing 9 changed files with 391 additions and 92 deletions.
22 changes: 16 additions & 6 deletions docs/commands.md
Expand Up @@ -345,22 +345,32 @@ None
* `user` - Person to ban - User
* `delete-message-days` - The number of days worth of messages to delete - Int
* `reason` - The reason for the ban - Defaulting String
* `soft-ban` - Weather to soft-ban this user (unban them once messages are deleted) - Defaulting Boolean
* `dm` - Whether to send a direct message to the user about the ban - Defaulting Boolean
* `image` - An image you'd like to provide as extra context for the action - Optional Attachment

---
### Command name: `soft-ban`
**Description**: Soft-bans a user.
### Command name: `temp-ban add`
**Description**: Temporarily bans a user

**Required Member Permissions**: Ban Members

* Arguments:
* `user` - Person to Soft ban - User
* `delete-message-days` - The number of days worth of messages to delete - Optional Int/Long
* **Arguments**:
* `user` - Person to ban - User
* `delete-message-days` - The number of days worth of messages to delete - Int
* `duration` - The duration of the temporary ban. - Coalescing Duration
* `reason` - The reason for the ban - Defaulting String
* `dm` - Whether to send a direct message to the user about the soft-ban - Defaulting Boolean
* `dm` - Whether to send a direct message to the user about the ban - Defaulting Boolean
* `image` - An image you'd like to provide as extra context for the action - Optional Attachment

---
### Command name: `temp-ban view-all`
**Description**: View all temporary bans for this guild

**Required Member Permissions**: Ban Members

* **Arguments**:
None
---
### Command name: `unban`
**Description**: Unbans a user.
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Expand Up @@ -2,16 +2,16 @@
# Plugins
kotlin = "1.9.23"
shadow = "8.1.1"
detekt = "1.23.5"
detekt = "1.23.6"
git-hooks = "0.0.2"
grgit = "5.2.2"
blossom = "2.1.0"

# Libraries
kord-extensions = "1.8.0-20240319.115836-21"
logging = "6.0.3"
logging = "6.0.4"
logback = "1.5.3"
github-api = "1.319"
github-api = "1.321"
kmongo = "4.11.0"
docgenerator = "0.1.5-SNAPSHOT"

Expand Down
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
Expand Up @@ -11,7 +11,7 @@ import org.koin.core.component.inject
import org.litote.kmongo.eq

/**
* This class contains the functions for interacting with []the reminder database][ReminderData]. This
* This class contains the functions for interacting with [the reminder database][ReminderData]. This
* class contains functions for setting reminders, getting reminders based of various parameters, removing reminders and
* repeating them.
*
Expand Down
@@ -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)
}
@@ -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
)
Expand Up @@ -10,4 +10,5 @@ suspend fun mainV10(db: CoroutineDatabase) {
updateMany(AutoThreadingData::extraRoleIds exists false, setValue(AutoThreadingData::extraRoleIds, emptyList()))
}
db.createCollection("lockedChannelData")
db.createCollection("temporaryBanData")
}

0 comments on commit a757d9d

Please sign in to comment.