-
Notifications
You must be signed in to change notification settings - Fork 82
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
Add Auto Moderation #647
Add Auto Moderation #647
Conversation
a1bb076
to
1e6718a
Compare
# Conflicts: # core/src/main/kotlin/event/Event.kt # core/src/main/kotlin/gateway/handler/BaseGatewayEventHandler.kt # core/src/main/kotlin/gateway/handler/DefaultGatewayEventInterceptor.kt # core/src/main/kotlin/gateway/handler/InteractionEventHandler.kt # core/src/main/kotlin/gateway/handler/ThreadEventHandler.kt
|
||
public class AuditLogService(requestHandler: RequestHandler) : RestService(requestHandler) { | ||
|
||
public suspend inline fun getAuditLogs( | ||
guildId: Snowflake, | ||
builder: AuditLogGetRequestBuilder.() -> Unit, | ||
): DiscordAuditLog { | ||
contract { callsInPlace(builder, EXACTLY_ONCE) } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't have anything to do with automod but contract was missing
@@ -32,7 +32,7 @@ public interface Gateway : CoroutineScope { | |||
public val events: SharedFlow<Event> | |||
|
|||
/** | |||
* The duration between the last [Heartbeat] and [HeartbeatACK]. | |||
* The duration between the last [Heartbeat][Command.Heartbeat] and [HeartbeatACK]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't have anything to do with automod but link was wrong
"Identify(token=hunter2,properties=$properties,compress=$compress,largeThreshold=$largeThreshold," + | ||
"shard=$shard,presence=$presence" | ||
"Identify(token=hunter2, properties=$properties, compress=$compress, largeThreshold=$largeThreshold, " + | ||
"shard=$shard, presence=$presence, intents=$intents)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't have anything to do with automod
override fun toString(): String = "Resume(token=hunter2,sessionId=$sessionId,sequenceNumber:$sequenceNumber)" | ||
override fun toString(): String = "Resume(token=hunter2, sessionId=$sessionId, sequenceNumber=$sequenceNumber)" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
doesn't have anything to do with automod
public abstract interface class dev/kord/rest/builder/AuditRequestBuilder : dev/kord/rest/builder/RequestBuilder { | ||
public abstract interface class dev/kord/rest/builder/AuditBuilder { | ||
public abstract fun getReason ()Ljava/lang/String; | ||
public abstract fun setReason (Ljava/lang/String;)V | ||
} | ||
|
||
public abstract interface class dev/kord/rest/builder/AuditRequestBuilder : dev/kord/rest/builder/AuditBuilder, dev/kord/rest/builder/RequestBuilder { | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a binary compatible change, AuditRequestBuilder
doesn't lose or get new members (they are just inherited now).
@KordDsl | ||
public interface RequestBuilder<T> { | ||
public fun toRequest(): T | ||
} | ||
|
||
@KordDsl | ||
public interface AuditRequestBuilder<T> : RequestBuilder<T> { | ||
public interface AuditBuilder { | ||
/** | ||
* The reason for this request, this will be displayed in the audit log. | ||
*/ | ||
public var reason: String? | ||
} | ||
|
||
@KordDsl | ||
public interface RequestBuilder<out T : Any> { | ||
public fun toRequest(): T | ||
} | ||
|
||
@KordDsl | ||
public interface AuditRequestBuilder<out T : Any> : AuditBuilder, RequestBuilder<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows supertypes of create and modify builders to implement AuditBuilder
. They can't implement AuditRequestBuilder
since create and modify builders usually have different return types for toRequest
.
public val description: DataDescription<UserData, Snowflake> | ||
get() = description(UserData::id) { | ||
link(UserData::id to MemberData::userId) | ||
link(UserData::id to WebhookData::nullableUserId) | ||
link(UserData::id to VoiceStateData::userId) | ||
link(UserData::id to PresenceData::userId) | ||
} | ||
public val description: DataDescription<UserData, Snowflake> = description(UserData::id) { | ||
link(UserData::id to MemberData::userId) | ||
link(UserData::id to WebhookData::nullableUserId) | ||
link(UserData::id to VoiceStateData::userId) | ||
link(UserData::id to PresenceData::userId) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the getter and replaced it with an initializer
query<ThreadMemberData>().remove() | ||
query<MessageData>().remove() | ||
query<EmojiData>().remove() | ||
query<WebhookData>().remove() | ||
query<PresenceData>().remove() | ||
query<VoiceStateData>().remove() | ||
query<ApplicationCommandData>().remove() | ||
query<GuildApplicationCommandPermissionsData>().remove() | ||
query<StickerPackData>().remove() | ||
query<StickerData>().remove() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added these because they were missing, is this right?
override fun equals(other: Any?): Boolean | ||
override fun hashCode(): Int | ||
override fun toString(): String |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this forces overrides in subtypes
/** | ||
* The Gateway that spawned this event. | ||
*/ | ||
public val gateway: Gateway get() = kord.gateway.gateways.getValue(shard) | ||
|
||
public val kord: Kord |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
KordObject
has this property too
@OptIn(FlowPreview::class) | ||
override val events: Flow<ShardEvent> = gateways.entries.asFlow() | ||
override val events: Flow<ShardEvent> = gateways.entries | ||
.map { (shard, gateway) -> gateway.events.map { ShardEvent(it, gateway, shard) } } | ||
.flattenMerge(gateways.size.coerceAtLeast(1)) | ||
.merge() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
merge()
has no limit on concurrency (we used the max with flattenMerge
before anyway) and isn't marked with @FlowPreview
core/src/main/kotlin/event/automoderation/AutoModerationActionExecutionEvent.kt
Outdated
Show resolved
Hide resolved
public abstract interface class dev/kord/core/event/Event { | ||
public abstract interface class dev/kord/core/event/Event : dev/kord/core/KordObject { | ||
public abstract fun getCustomContext ()Ljava/lang/Object; | ||
public abstract fun getGateway ()Ldev/kord/gateway/Gateway; | ||
public abstract fun getKord ()Ldev/kord/core/Kord; | ||
public abstract fun getShard ()I | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a binary compatible change, Event
doesn't lose or get new members (getKord()
is just inherited now).
This should now be ready for review 🥳 |
The overall PR looks good; tho it could've been easier if we used smaller PRs this would've helped splitting tasks to contributors as well Great job tho 👍 |
Yeah, didn't anticipate that it would be this big. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have some tests before we merge this
What kind of tests are you thinking of? Automated tests with the api are hard in this case as automod is only available in community guilds (I did some manual api tests). |
This is enough then |
This PR adds support for Discord's Auto Moderation feature.
The DSL for creating and editing
AutoModerationRule
s looks like this:relevant doc commits / PRs / pages: