Skip to content

Commit

Permalink
Implement temporary bans
Browse files Browse the repository at this point in the history
  • Loading branch information
NoComment1105 committed Apr 2, 2024
1 parent 85cce80 commit 1c66209
Show file tree
Hide file tree
Showing 7 changed files with 476 additions and 46 deletions.
122 changes: 77 additions & 45 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,49 @@ None
* **Arguments**:
* `channel` - The channel to view the auto-threading settings for. - Channel

---
### Command name: `clear count`
**Description**: Clear a specific count of messages

**Required Member Permissions**: Manage Messages

* **Arguments**:
* `messages` - Number of messages to delete - Int
* `author` - The author of the messages to clear - Optional User

---
### Command name: `clear before`
**Description**: Clear messages before a given message ID

**Required Member Permissions**: Manage Messages

* **Arguments**:
* `before` - The ID of the message to clear before - Snowflake
* `message-count` - The number of messages to clear - Optional Int/Long
* `author` - The author of the messages to clear - Optional User

---
### Command name: `clear after`
**Description**: Clear messages before a given message ID

**Required Member Permissions**: Manage Messages

* **Arguments**:
* `after` - The ID of the message to clear after - Snowflake
* `message-count` - The number of messages to clear - Optional Int/Long
* `author` - The author of the messages to clear - Optional User

---
### Command name: `clear between`
**Description**: Clear messages between 2 message IDs

**Required Member Permissions**: Manage Messages

* **Arguments**:
* `after` - The ID of the message to clear after - Snowflake
* `before` - The ID of the message to clear before - Snowflake
* `author` - The author of the messages to clear - Optional User

---
### Command name: `config moderation`
**Description**: Configure Lily's moderation system
Expand Down Expand Up @@ -297,69 +340,58 @@ None
* `image` - An image you'd like to provide as extra context for the action - Optional Attachment

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

**Required Member Permissions**: Ban Members

* Arguments:
* `user` - Person to un-ban - User
* `reason` - The reason for the un-ban - Defaulting String

---
### Command name: `kick`
**Description**: Kicks a user.

**Required Member Permissions**: Kick Members

* Arguments:
* `user` - Person to kick - User
* `reason` - The reason for the Kick - Defaulting String
* `dm` - Whether to send a direct message to the user about the kick - Defaulting Boolean
* **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 ban - Defaulting Boolean
* `image` - An image you'd like to provide as extra context for the action - Optional Attachment

---
### Command name: `clear count`
**Description**: Clear a specific count of messages
### Command name: `temp-ban remove`
**Description**: Removes a temporary ban

**Required Member Permissions**: Manage Messages
**Required Member Permissions**: Ban Members

* **Arguments**:
* `messages` - Number of messages to delete - Int
* `author` - The author of the messages to clear - Optional User
* `user` - Person to un-ban - User
* `reason` - The reason for the un-ban - Defaulting String

---
### Command name: `clear before`
**Description**: Clear messages before a given message ID
### Command name: `temp-ban view-all`
**Description**: View all temporary bans for this guild

**Required Member Permissions**: Manage Messages
**Required Member Permissions**: Ban Members

* **Arguments**:
* `before` - The ID of the message to clear before - Snowflake
* `message-count` - The number of messages to clear - Optional Int/Long
* `author` - The author of the messages to clear - Optional User

None
---
### Command name: `clear after`
**Description**: Clear messages before a given message ID
### Command name: `unban`
**Description**: Unbans a user.

**Required Member Permissions**: Manage Messages
**Required Member Permissions**: Ban Members

* **Arguments**:
* `after` - The ID of the message to clear after - Snowflake
* `message-count` - The number of messages to clear - Optional Int/Long
* `author` - The author of the messages to clear - Optional User
* Arguments:
* `user` - Person to un-ban - User
* `reason` - The reason for the un-ban - Defaulting String

---
### Command name: `clear between`
**Description**: Clear messages between 2 message IDs
### Command name: `kick`
**Description**: Kicks a user.

**Required Member Permissions**: Manage Messages
**Required Member Permissions**: Kick Members

* **Arguments**:
* `after` - The ID of the message to clear after - Snowflake
* `before` - The ID of the message to clear before - Snowflake
* `author` - The author of the messages to clear - Optional User
* Arguments:
* `user` - Person to kick - User
* `reason` - The reason for the Kick - Defaulting String
* `dm` - Whether to send a direct message to the user about the kick - Defaulting Boolean
* `image` - An image you'd like to provide as extra context for the action - Optional Attachment

---
### Command name: `timeout`
Expand Down Expand Up @@ -717,8 +749,8 @@ None
* `clear` - Whether to clear the channel before repopulating it - Defaulting Boolean

---
### Command name: `phishing-check`
**Description**: Check whether a given domain is a known phishing domain.
### Command name: `url-safety-check`
**Description**: Check whether a given domain is a known unsafe domain.

* Arguments:
* `domain` - Domain to check - String
Expand Down Expand Up @@ -767,7 +799,7 @@ None
### Message Command: `Report`

---
### Message Command: `Phishing Check`
### Message Command: `URL Safety Check`

---
## User Commands
Expand Down
Original file line number Diff line number Diff line change
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
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)
}
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
)
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import org.hyacinthbots.lilybot.database.migrations.config.configV5
import org.hyacinthbots.lilybot.database.migrations.config.configV6
import org.hyacinthbots.lilybot.database.migrations.config.configV7
import org.hyacinthbots.lilybot.database.migrations.main.mainV1
import org.hyacinthbots.lilybot.database.migrations.main.mainV10
import org.hyacinthbots.lilybot.database.migrations.main.mainV2
import org.hyacinthbots.lilybot.database.migrations.main.mainV3
import org.hyacinthbots.lilybot.database.migrations.main.mainV4
Expand Down Expand Up @@ -73,6 +74,7 @@ object Migrator : KordExKoinComponent {
7 -> ::mainV7
8 -> ::mainV8
9 -> ::mainV9
10 -> ::mainV10
else -> break
}(db.mainDatabase)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.hyacinthbots.lilybot.database.migrations.main

import org.litote.kmongo.coroutine.CoroutineDatabase

suspend fun mainV10(db: CoroutineDatabase) {
db.createCollection("temporaryBanData")
}

0 comments on commit 1c66209

Please sign in to comment.