Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More event logging #410

Merged
merged 25 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
73363b1
Start work on audit-log event based logging
NoComment1105 Jun 21, 2024
d0a801c
Refactor it all because yes
NoComment1105 Jun 22, 2024
5338b2a
Create action transferring database to move important information ove…
NoComment1105 Jun 27, 2024
9ebf3b9
Merge branch 'refs/heads/develop' into auditlog-event-logging
NoComment1105 Jul 1, 2024
a7da8de
Log Kicks, send quick actions to db, generalise channel creation logs
NoComment1105 Jul 1, 2024
fa3cf83
Merge branch 'refs/heads/develop' into auditlog-event-logging
NoComment1105 Jul 2, 2024
2e72c64
Start work on channel updates
NoComment1105 Jul 2, 2024
edcb57d
Add the rest of the channel update fields
NoComment1105 Jul 3, 2024
6b7130e
Fully set up channel edit logging
NoComment1105 Jul 6, 2024
4862d8b
Add scheduled event logging
NoComment1105 Jul 7, 2024
7432287
Invite events and Role events
NoComment1105 Jul 8, 2024
4319fa1
Thread creates and deletes logging + updated kordex
NoComment1105 Jul 9, 2024
8038338
Log timeouts created by lily
NoComment1105 Jul 9, 2024
6fbfb1b
Merge branch 'refs/heads/develop' into auditlog-event-logging
NoComment1105 Jul 9, 2024
19e511a
Fix timeout logging, yeehaw actual code is done now
NoComment1105 Jul 9, 2024
f805bb8
Add docs
NoComment1105 Jul 9, 2024
47839a9
Merge branch 'develop' into auditlog-event-logging
NoComment1105 Aug 25, 2024
acd3e55
Fix package references
NoComment1105 Aug 25, 2024
cc11b65
Remove the logging, however funny it was to me it is not needed
NoComment1105 Aug 25, 2024
1442c8e
Merge branch 'develop' into auditlog-event-logging
NoComment1105 Aug 25, 2024
3a02a59
Complete merge
NoComment1105 Aug 25, 2024
cab1292
Add configuration, split down into two event categories
NoComment1105 Aug 28, 2024
3081b45
Update migrations for utility config
NoComment1105 Aug 28, 2024
1af9cbc
Reduce code duplication and rename some packages
NoComment1105 Aug 29, 2024
710e214
Fix formatting of applied tags
NoComment1105 Aug 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ build/
out/
classes/

# kotlin
.kotlin/

# eclipse

*.launch
Expand Down
26 changes: 15 additions & 11 deletions src/main/kotlin/org/hyacinthbots/lilybot/LilyBot.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,22 @@ import org.hyacinthbots.lilybot.extensions.moderation.commands.LockingCommands
import org.hyacinthbots.lilybot.extensions.moderation.commands.ModUtilities
import org.hyacinthbots.lilybot.extensions.moderation.commands.ModerationCommands
import org.hyacinthbots.lilybot.extensions.moderation.commands.Report
import org.hyacinthbots.lilybot.extensions.moderation.events.ModerationEvents
import org.hyacinthbots.lilybot.extensions.threads.AutoThreading
import org.hyacinthbots.lilybot.extensions.threads.ModThreadInviting
import org.hyacinthbots.lilybot.extensions.threads.ThreadControl
import org.hyacinthbots.lilybot.extensions.utils.commands.GalleryChannel
import org.hyacinthbots.lilybot.extensions.utils.commands.Github
import org.hyacinthbots.lilybot.extensions.utils.commands.GuildAnnouncements
import org.hyacinthbots.lilybot.extensions.utils.commands.InfoCommands
import org.hyacinthbots.lilybot.extensions.utils.commands.NewsChannelPublishing
import org.hyacinthbots.lilybot.extensions.utils.commands.PublicUtilities
import org.hyacinthbots.lilybot.extensions.utils.commands.Reminders
import org.hyacinthbots.lilybot.extensions.utils.commands.RoleMenu
import org.hyacinthbots.lilybot.extensions.utils.commands.StartupHooks
import org.hyacinthbots.lilybot.extensions.utils.commands.StatusPing
import org.hyacinthbots.lilybot.extensions.utils.commands.Tags
import org.hyacinthbots.lilybot.extensions.utility.commands.GalleryChannel
import org.hyacinthbots.lilybot.extensions.utility.commands.Github
import org.hyacinthbots.lilybot.extensions.utility.commands.GuildAnnouncements
import org.hyacinthbots.lilybot.extensions.utility.commands.InfoCommands
import org.hyacinthbots.lilybot.extensions.utility.commands.NewsChannelPublishing
import org.hyacinthbots.lilybot.extensions.utility.commands.PublicUtilities
import org.hyacinthbots.lilybot.extensions.utility.commands.Reminders
import org.hyacinthbots.lilybot.extensions.utility.commands.RoleMenu
import org.hyacinthbots.lilybot.extensions.utility.commands.StartupHooks
import org.hyacinthbots.lilybot.extensions.utility.commands.StatusPing
import org.hyacinthbots.lilybot.extensions.utility.commands.Tags
import org.hyacinthbots.lilybot.extensions.utility.events.UtilityEvents
import org.hyacinthbots.lilybot.internal.BuildInfo
import org.hyacinthbots.lilybot.utils.BOT_TOKEN
import org.hyacinthbots.lilybot.utils.ENVIRONMENT
Expand Down Expand Up @@ -177,6 +179,7 @@ suspend fun main() {
add(::MemberLogging)
add(::MessageDelete)
add(::MessageEdit)
add(::ModerationEvents)
add(::ModThreadInviting)
add(::ModUtilities)
add(::ModerationCommands)
Expand All @@ -189,6 +192,7 @@ suspend fun main() {
add(::StatusPing)
add(::Tags)
add(::ThreadControl)
add(::UtilityEvents)

/*
The welcome channel extension allows users to designate a YAML file to create a channel with
Expand Down
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,9 @@ data class ModerationConfigData(
@Serializable
data class UtilityConfigData(
val guildId: Snowflake,
val utilityLogChannel: Snowflake?
val utilityLogChannel: Snowflake?,
val logChannelUpdates: Boolean,
val logEventUpdates: Boolean,
val logInviteUpdates: Boolean,
val logRoleUpdates: Boolean
)
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,
)
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hyacinthbots.lilybot.database.migrations.config

import org.hyacinthbots.lilybot.database.entities.ModerationConfigData
import org.hyacinthbots.lilybot.database.entities.UtilityConfigData
import org.litote.kmongo.coroutine.CoroutineDatabase
import org.litote.kmongo.exists
import org.litote.kmongo.setValue
Expand All @@ -12,4 +13,22 @@ suspend fun configV7(db: CoroutineDatabase) {
setValue(ModerationConfigData::autoInviteModeratorRole, null)
)
}
with(db.getCollection<UtilityConfigData>("utilityConfigData")) {
updateMany(
UtilityConfigData::logChannelUpdates exists false,
setValue(UtilityConfigData::logChannelUpdates, false)
)
updateMany(
UtilityConfigData::logEventUpdates exists false,
setValue(UtilityConfigData::logEventUpdates, false)
)
updateMany(
UtilityConfigData::logInviteUpdates exists false,
setValue(UtilityConfigData::logInviteUpdates, false)
)
updateMany(
UtilityConfigData::logRoleUpdates exists false,
setValue(UtilityConfigData::logRoleUpdates, false)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ suspend fun mainV10(db: CoroutineDatabase) {
}
db.createCollection("lockedChannelData")
db.createCollection("temporaryBanData")
db.createCollection("moderationActionCacheData")
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import org.hyacinthbots.lilybot.extensions.config.commands.configClearCommand
import org.hyacinthbots.lilybot.extensions.config.commands.configViewCommand
import org.hyacinthbots.lilybot.extensions.logging.config.loggingCommand
import org.hyacinthbots.lilybot.extensions.moderation.config.moderationCommand
import org.hyacinthbots.lilybot.extensions.utils.config.utilityCommand
import org.hyacinthbots.lilybot.extensions.utility.config.utilityCommand

class ConfigExtension : Extension() {
override val name: String = "config"
Expand Down
Loading