Vote#54
Conversation
|
|
||
| def compute_result( | ||
| options: list[str], totals: list[int], minimum: int | ||
| ) -> tuple[str, str, Optional[int]]: |
There was a problem hiding this comment.
suggestion: namedtuples or objects are usually cleaner vs returning tuples for when this function grows in the future, also more explanatory in terms of the return type
There was a problem hiding this comment.
suggestion: first item looks like it should be an enum.StrEnum btw
| self.bot = bot | ||
| self.vote = vote | ||
| self.message = message | ||
| self._task: Optional[asyncio.Task] = None | ||
| self._lock = asyncio.Lock() | ||
| self.view: Optional["VoteButtons"] = None |
There was a problem hiding this comment.
question: why are some of these typed and some not?
aside: usually i like if all the init declarations are typed, makes it easier for collaborators
| self.cache.register(message.id, vote_entry) | ||
|
|
||
| @staticmethod | ||
| def parse_duration(duration: str) -> int: |
There was a problem hiding this comment.
nit: you can employ timedelta(days=5).total_seconds() etc. for a lot of this to prevent manual multiplication
| channel_id=ctx.channel.id, | ||
| threshold=9999, | ||
| minimum=0, | ||
| timeout=24 * 7 * 3600, |
There was a problem hiding this comment.
praise: always like when people do this instead of raw seconds
| """ | ||
| raise NotImplementedError("Command requires implementation and permission set-up.") | ||
| async def vote(self, ctx: commands.Context, ladder_name: str, *, text: str): | ||
| # start a new yes/no vote on a ladder. use `voteoptions` to chnage to custom options |
| # Replace options | ||
| vote.options = list(options) | ||
| vote.totals = [0] * len(options) | ||
| vote.voters = {} | ||
| vote.expiry = int(datetime.utcnow().timestamp()) + ladder.timeout | ||
| vote.finished = False |
No description provided.