-
-
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.
* Start work on audit-log event based logging * Refactor it all because yes * Create action transferring database to move important information over to the event action * Log Kicks, send quick actions to db, generalise channel creation logs * Start work on channel updates * Add the rest of the channel update fields * Fully set up channel edit logging * Add scheduled event logging * Invite events and Role events * Thread creates and deletes logging + updated kordex * Log timeouts created by lily * Fix timeout logging, yeehaw actual code is done now * Add docs * Fix package references * Remove the logging, however funny it was to me it is not needed * Complete merge * Add configuration, split down into two event categories * Update migrations for utility config * Reduce code duplication and rename some packages * Fix formatting of applied tags
- Loading branch information
1 parent
7d2b6ff
commit 378f224
Showing
33 changed files
with
1,673 additions
and
426 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ build/ | |
out/ | ||
classes/ | ||
|
||
# kotlin | ||
.kotlin/ | ||
|
||
# eclipse | ||
|
||
*.launch | ||
|
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
117 changes: 117 additions & 0 deletions
117
src/main/kotlin/org/hyacinthbots/lilybot/database/collections/ModerationActionCollection.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,117 @@ | ||
package org.hyacinthbots.lilybot.database.collections | ||
|
||
import dev.kord.common.entity.Snowflake | ||
import dev.kordex.core.koin.KordExKoinComponent | ||
import org.hyacinthbots.lilybot.database.Database | ||
import org.hyacinthbots.lilybot.database.entities.ActionData | ||
import org.hyacinthbots.lilybot.database.entities.ModerationActionData | ||
import org.hyacinthbots.lilybot.extensions.moderation.utils.ModerationAction | ||
import org.koin.core.component.inject | ||
import org.litote.kmongo.eq | ||
|
||
/** | ||
* This class contains the function for interacting with the [Moderation Action Database][ModerationActionData]. This | ||
* class contains functions for getting, setting, removing and ignoring actions | ||
* | ||
* @since 5.0.0 | ||
* @see addAction | ||
* @see removeAction | ||
* @see getAction | ||
* @see declareActionToIgnore | ||
* @see shouldIgnoreAction | ||
*/ | ||
class ModerationActionCollection : KordExKoinComponent { | ||
private val db: Database by inject() | ||
|
||
@PublishedApi | ||
internal val collection = db.mainDatabase.getCollection<ModerationActionData>() | ||
|
||
/** | ||
* Adds an action that occurred. | ||
* | ||
* @param action The type of action you're adding | ||
* @param guildId The ID of the guild the action occurred in | ||
* @param targetUserId The ID of the user this action happened to | ||
* @param data The [ActionData] for the action | ||
* @param ignore Whether to ignore the action or not. Defaults to false | ||
* @author NoComment1105 | ||
* @since 5.0.0 | ||
*/ | ||
suspend inline fun addAction( | ||
action: ModerationAction, | ||
guildId: Snowflake, | ||
targetUserId: Snowflake, | ||
data: ActionData, | ||
ignore: Boolean = false | ||
) = collection.insertOne(ModerationActionData(action, guildId, targetUserId, data, ignore)) | ||
|
||
/** | ||
* Removes an action that occurred. | ||
* | ||
* @param type The type of action you're removing | ||
* @param guildId The ID of the guild the action occurred in | ||
* @param targetUserId The ID of the user this action happened to | ||
* @author NoComment1105 | ||
* @since 5.0.0 | ||
*/ | ||
suspend inline fun removeAction(type: ModerationAction, guildId: Snowflake, targetUserId: Snowflake) = | ||
collection.deleteOne( | ||
ModerationActionData::actionType eq type, | ||
ModerationActionData::guildId eq guildId, | ||
ModerationActionData::targetUserId eq targetUserId | ||
) | ||
|
||
/** | ||
* Gets an action that occurred. | ||
* | ||
* @param type The type of action you're looking for | ||
* @param guildId The ID of the guild the action occurred in | ||
* @param targetUserId The ID of the user this action happened to | ||
* @return The [data][ModerationActionData] for the event. Can be null if there is no action. | ||
* @author NoComment1105 | ||
* @since 5.0.0 | ||
*/ | ||
suspend inline fun getAction( | ||
type: ModerationAction, | ||
guildId: Snowflake, | ||
targetUserId: Snowflake | ||
): ModerationActionData? = | ||
collection.findOne( | ||
ModerationActionData::actionType eq type, | ||
ModerationActionData::guildId eq guildId, | ||
ModerationActionData::targetUserId eq targetUserId | ||
) | ||
|
||
/** | ||
* Sets an action as ignored. Convenience function more than anything | ||
* | ||
* @param type The type of action you're looking for | ||
* @param guildId The ID of the guild the action occurred in | ||
* @param targetUserId The ID of the user this action happened to | ||
* @author NoComment1105 | ||
* @since 5.0.0 | ||
*/ | ||
suspend inline fun declareActionToIgnore(type: ModerationAction, guildId: Snowflake, targetUserId: Snowflake) = | ||
addAction(type, guildId, targetUserId, ActionData(null, null, null, null, null, null, null), true) | ||
|
||
/** | ||
* Checks if an action should be ignored or not. Convenience function more than anything. | ||
* | ||
* @param type The type of action you're looking for | ||
* @param guildId The ID of the guild the action occurred in | ||
* @param targetUserId The ID of the user this action happened to | ||
* @return True if the action should be ignored, false if otherwise | ||
* @author NoComment1105 | ||
* @since 5.0.0 | ||
*/ | ||
suspend inline fun shouldIgnoreAction( | ||
type: ModerationAction, | ||
guildId: Snowflake, | ||
targetUserId: Snowflake | ||
): Boolean? = | ||
collection.findOne( | ||
ModerationActionData::actionType eq type, | ||
ModerationActionData::guildId eq guildId, | ||
ModerationActionData::targetUserId eq targetUserId | ||
)?.ignore | ||
} |
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
66 changes: 66 additions & 0 deletions
66
src/main/kotlin/org/hyacinthbots/lilybot/database/entities/ModerationActionData.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,66 @@ | ||
package org.hyacinthbots.lilybot.database.entities | ||
|
||
import dev.kord.common.entity.Snowflake | ||
import kotlinx.datetime.DateTimePeriod | ||
import kotlinx.datetime.Instant | ||
import kotlinx.serialization.Serializable | ||
import org.hyacinthbots.lilybot.extensions.moderation.utils.ModerationAction | ||
|
||
/** | ||
* The data for Moderation action. | ||
* | ||
* @property actionType The type of action you're adding | ||
* @property guildId The ID of the guild the action occurred in | ||
* @property targetUserId The ID of the user this action happened to | ||
* @property data The [ActionData] for the action | ||
* @property ignore Whether to ignore the action or not. Defaults to false | ||
* @since 5.0.0 | ||
*/ | ||
@Serializable | ||
data class ModerationActionData( | ||
val actionType: ModerationAction, | ||
val guildId: Snowflake, | ||
val targetUserId: Snowflake, | ||
val data: ActionData, | ||
val ignore: Boolean = false | ||
) | ||
|
||
/** | ||
* Further, more in-depth data about a [moderation action][ModerationActionData]. | ||
* | ||
* @property actioner The ID of the user that requested the action | ||
* @property deletedMessages The amount of messages deleted in the action | ||
* @property timeData The [TimeData] for the action | ||
* @property reason The reason for the action | ||
* @property dmOutcome The outcome of trying to send a DM to the user | ||
* @property dmOverride Whether the DM sending function was override | ||
* @property imageUrl The URL for the image attached to the action | ||
* @since 5.0.0 | ||
*/ | ||
@Serializable | ||
data class ActionData( | ||
val actioner: Snowflake?, | ||
val deletedMessages: Int?, | ||
val timeData: TimeData?, | ||
val reason: String?, | ||
val dmOutcome: Boolean?, | ||
val dmOverride: Boolean?, | ||
val imageUrl: String? | ||
) | ||
|
||
/** | ||
* Further, more in-depth data about the [time data for actions][ActionData.timeData]. | ||
* | ||
* @property durationDtp The Duration as a [DateTimePeriod] | ||
* @property durationInst The Duration as an [Instant] | ||
* @property start The start [Instant] of the action | ||
* @property end The end [Instant] of the action | ||
* @since 5.0.0 | ||
*/ | ||
@Serializable | ||
data class TimeData( | ||
val durationDtp: DateTimePeriod?, | ||
val durationInst: Instant?, | ||
val start: Instant? = null, | ||
val end: Instant? = null, | ||
) |
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
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.