Skip to content

Commit 6f76907

Browse files
committed
refactor: use constants instead of hardcoded values
1 parent 366ac5f commit 6f76907

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

interactions/models/discord/poll.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import attrs
55

6-
from interactions.client.const import MISSING
6+
from interactions.client.const import MISSING, POLL_MAX_DURATION_HOURS, POLL_MAX_ANSWERS
77
from interactions.client.utils.attr_converters import (
88
optional,
99
timestamp_converter,
@@ -124,13 +124,15 @@ def create(
124124

125125
@answers.validator
126126
def _answers_validation(self, attribute: str, value: Any) -> None:
127-
if len(value) > 10:
128-
raise ValueError("A poll can have at most 10 answers.")
127+
if len(value) > POLL_MAX_ANSWERS:
128+
raise ValueError(f"A poll can have at most {POLL_MAX_ANSWERS} answers.")
129129

130130
@_duration.validator
131131
def _duration_validation(self, attribute: str, value: int) -> None:
132-
if value < 0 or value > 168:
133-
raise ValueError("The duration must be between 0 and 168 hours (7 days).")
132+
if value < 0 or value > POLL_MAX_DURATION_HOURS:
133+
raise ValueError(
134+
f"The duration must be between 0 and {POLL_MAX_DURATION_HOURS} hours ({POLL_MAX_DURATION_HOURS // 24} days)."
135+
)
134136

135137
def add_answer(self, text: Optional[str] = None, emoji: Optional[Union[PartialEmoji, dict, str]] = None) -> None:
136138
"""

0 commit comments

Comments
 (0)