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

fix: Implementation for Equals & Hashcode in Builder #968

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
226 changes: 226 additions & 0 deletions rest/api/rest.api

Large diffs are not rendered by default.

243 changes: 243 additions & 0 deletions rest/api/rest.klib.api

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,20 @@ public class ApplicationRoleConnectionMetadataRecordsBuilder :
}

override fun toRequest(): List<DiscordApplicationRoleConnectionMetadata> = records.map { it.toRequest() }

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false

other as ApplicationRoleConnectionMetadataRecordsBuilder

return records == other.records
}

override fun hashCode(): Int {
return records.hashCode()
}

}

@KordDsl
Expand Down Expand Up @@ -69,4 +83,32 @@ public class ApplicationRoleConnectionMetadataBuilder(
description = description,
descriptionLocalizations = _descriptionLocalizations.mapCopy(),
)

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false

other as ApplicationRoleConnectionMetadataBuilder

if (type != other.type) return false
if (key != other.key) return false
if (name != other.name) return false
if (description != other.description) return false
if (nameLocalizations != other.nameLocalizations) return false
if (descriptionLocalizations != other.descriptionLocalizations) return false

return true
}

override fun hashCode(): Int {
var result = type.hashCode()
result = 31 * result + key.hashCode()
result = 31 * result + name.hashCode()
result = 31 * result + description.hashCode()
result = 31 * result + (nameLocalizations?.hashCode() ?: 0)
result = 31 * result + (descriptionLocalizations?.hashCode() ?: 0)
return result
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,29 @@ public class AuditLogGetRequestBuilder : RequestBuilder<AuditLogGetRequest> {
public var limit: Int? = null

override fun toRequest(): AuditLogGetRequest = AuditLogGetRequest(userId, action, before, after, limit)

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false

other as AuditLogGetRequestBuilder

if (userId != other.userId) return false
if (action != other.action) return false
if (before != other.before) return false
if (after != other.after) return false
if (limit != other.limit) return false

return true
}

override fun hashCode(): Int {
var result = userId?.hashCode() ?: 0
result = 31 * result + (action?.hashCode() ?: 0)
result = 31 * result + (before?.hashCode() ?: 0)
result = 31 * result + (after?.hashCode() ?: 0)
result = 31 * result + (limit ?: 0)
return result
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ public sealed class AutoModerationActionBuilder : RequestBuilder<DiscordAutoMode
type = type,
metadata = buildMetadata(),
)

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false

other as AutoModerationActionBuilder

return type == other.type
}

override fun hashCode(): Int {
return type.hashCode()
}

}

/** An [AutoModerationActionBuilder] for building actions with type [BlockMessage]. */
Expand All @@ -53,6 +67,23 @@ public class BlockMessageAutoModerationActionBuilder : AutoModerationActionBuild
Optional.Missing()
}
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false
if (!super.equals(other)) return false

other as BlockMessageAutoModerationActionBuilder

return customMessage == other.customMessage
}

override fun hashCode(): Int {
var result = super.hashCode()
result = 31 * result + (customMessage?.hashCode() ?: 0)
return result
}

}

/** An [AutoModerationActionBuilder] for building actions with type [SendAlertMessage]. */
Expand All @@ -66,6 +97,23 @@ public class SendAlertMessageAutoModerationActionBuilder(

override fun buildMetadata(): Optional.Value<DiscordAutoModerationActionMetadata> =
DiscordAutoModerationActionMetadata(channelId = channelId.optionalSnowflake()).optional()

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false
if (!super.equals(other)) return false

other as SendAlertMessageAutoModerationActionBuilder

return channelId == other.channelId
}

override fun hashCode(): Int {
var result = super.hashCode()
result = 31 * result + channelId.hashCode()
return result
}

}

/** An [AutoModerationActionBuilder] for building actions with type [Timeout]. */
Expand All @@ -79,4 +127,21 @@ public class TimeoutAutoModerationActionBuilder(

override fun buildMetadata(): Optional.Value<DiscordAutoModerationActionMetadata> =
DiscordAutoModerationActionMetadata(durationSeconds = duration.optional()).optional()

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false
if (!super.equals(other)) return false

other as TimeoutAutoModerationActionBuilder

return duration == other.duration
}

override fun hashCode(): Int {
var result = super.hashCode()
result = 31 * result + duration.hashCode()
return result
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,35 @@ public sealed class AutoModerationRuleCreateBuilder(
exemptRoles = _exemptRoles.mapCopy(),
exemptChannels = _exemptChannels.mapCopy(),
)

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false

other as AutoModerationRuleCreateBuilder

if (name != other.name) return false
if (eventType != other.eventType) return false
if (reason != other.reason) return false
if (actions != other.actions) return false
if (enabled != other.enabled) return false
if (exemptRoles != other.exemptRoles) return false
if (exemptChannels != other.exemptChannels) return false

return true
}

override fun hashCode(): Int {
var result = name.hashCode()
result = 31 * result + eventType.hashCode()
result = 31 * result + (reason?.hashCode() ?: 0)
result = 31 * result + actions.hashCode()
result = 31 * result + (enabled?.hashCode() ?: 0)
result = 31 * result + (exemptRoles?.hashCode() ?: 0)
result = 31 * result + (exemptChannels?.hashCode() ?: 0)
return result
}

}

/** A [KeywordAutoModerationRuleBuilder] for building [AutoModerationRuleCreateRequest]s. */
Expand All @@ -81,6 +110,29 @@ public class KeywordAutoModerationRuleCreateBuilder(
regexPatterns = _regexPatterns.mapCopy(),
allowList = _allowedKeywords.mapCopy(),
).optional()

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false
if (!super.equals(other)) return false

other as KeywordAutoModerationRuleCreateBuilder

if (keywords != other.keywords) return false
if (regexPatterns != other.regexPatterns) return false
if (allowedKeywords != other.allowedKeywords) return false

return true
}

override fun hashCode(): Int {
var result = super.hashCode()
result = 31 * result + (keywords?.hashCode() ?: 0)
result = 31 * result + (regexPatterns?.hashCode() ?: 0)
result = 31 * result + (allowedKeywords?.hashCode() ?: 0)
return result
}

}

/** A [SpamAutoModerationRuleBuilder] for building [AutoModerationRuleCreateRequest]s. */
Expand Down Expand Up @@ -112,6 +164,27 @@ public class KeywordPresetAutoModerationRuleCreateBuilder(
presets = presets.toList().optional(),
allowList = _allowedKeywords.mapCopy(),
).optional()

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false
if (!super.equals(other)) return false

other as KeywordPresetAutoModerationRuleCreateBuilder

if (presets != other.presets) return false
if (allowedKeywords != other.allowedKeywords) return false

return true
}

override fun hashCode(): Int {
var result = super.hashCode()
result = 31 * result + presets.hashCode()
result = 31 * result + (allowedKeywords?.hashCode() ?: 0)
return result
}

}

/** A [MentionSpamAutoModerationRuleBuilder] for building [AutoModerationRuleCreateRequest]s. */
Expand All @@ -134,4 +207,25 @@ public class MentionSpamAutoModerationRuleCreateBuilder(
mentionTotalLimit = _mentionLimit,
mentionRaidProtectionEnabled = _mentionRaidProtectionEnabled,
).optional()

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (other == null || this::class != other::class) return false
if (!super.equals(other)) return false

other as MentionSpamAutoModerationRuleCreateBuilder

if (mentionLimit != other.mentionLimit) return false
if (mentionRaidProtectionEnabled != other.mentionRaidProtectionEnabled) return false

return true
}

override fun hashCode(): Int {
var result = super.hashCode()
result = 31 * result + (mentionLimit ?: 0)
result = 31 * result + (mentionRaidProtectionEnabled?.hashCode() ?: 0)
return result
}

}
Loading