Skip to content

Commit

Permalink
improve validation logic
Browse files Browse the repository at this point in the history
  • Loading branch information
MahdiBM committed Feb 23, 2023
1 parent 3e222e5 commit 33474b9
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Sources/DiscordModels/Types/RequestBody.swift
Expand Up @@ -277,6 +277,7 @@ public enum RequestBody {
}

public func validate() throws {
try validateElementCountDoesNotExceed(embeds, max: 10, name: "embeds")
try validateElementCountDoesNotExceed(sticker_ids, max: 3, name: "sticker_ids")
try validateCharacterCountDoesNotExceed(content, max: 2_000, name: "content")
try validateCharacterCountDoesNotExceed(nonce?.asString, max: 25, name: "nonce")
Expand Down Expand Up @@ -339,6 +340,7 @@ public enum RequestBody {
}

public func validate() throws {
try validateElementCountDoesNotExceed(embeds, max: 10, name: "embeds")
try validateCharacterCountDoesNotExceed(content, max: 2_000, name: "content")
try validateCombinedCharacterCountDoesNotExceed(
embeds?.reduce(into: 0, { $0 += $1.contentLength }),
Expand Down Expand Up @@ -500,6 +502,7 @@ public enum RequestBody {
}

public func validate() throws {
try validateElementCountDoesNotExceed(embeds, max: 10, name: "embeds")
try validateCharacterCountDoesNotExceed(content, max: 2_000, name: "content")
try validateCombinedCharacterCountDoesNotExceed(
embeds?.reduce(into: 0, { $0 += $1.contentLength }),
Expand Down Expand Up @@ -609,6 +612,7 @@ public enum RequestBody {
}

public func validate() throws {
try validateElementCountDoesNotExceed(embeds, max: 10, name: "embeds")
try validateElementCountDoesNotExceed(sticker_ids, max: 3, name: "sticker_ids")
try validateCharacterCountDoesNotExceed(content, max: 2_000, name: "content")
try allowed_mentions?.validate()
Expand Down

0 comments on commit 33474b9

Please sign in to comment.