Skip to content

Vote#54

Open
archivehaze wants to merge 2 commits into
rewritefrom
vote
Open

Vote#54
archivehaze wants to merge 2 commits into
rewritefrom
vote

Conversation

@archivehaze

Copy link
Copy Markdown
Contributor

No description provided.

@archivehaze archivehaze requested a review from notkzrt June 29, 2026 18:37
Comment thread src/ib_py/cogs/voting.py

def compute_result(
options: list[str], totals: list[int], minimum: int
) -> tuple[str, str, Optional[int]]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: first item looks like it should be an enum.StrEnum btw

Comment thread src/ib_py/cogs/voting.py
Comment on lines +112 to +117
self.bot = bot
self.vote = vote
self.message = message
self._task: Optional[asyncio.Task] = None
self._lock = asyncio.Lock()
self.view: Optional["VoteButtons"] = None

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread src/ib_py/cogs/voting.py
self.cache.register(message.id, vote_entry)

@staticmethod
def parse_duration(duration: str) -> int:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you can employ timedelta(days=5).total_seconds() etc. for a lot of this to prevent manual multiplication

Comment thread src/ib_py/cogs/voting.py
channel_id=ctx.channel.id,
threshold=9999,
minimum=0,
timeout=24 * 7 * 3600,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

praise: always like when people do this instead of raw seconds

Comment thread src/ib_py/cogs/voting.py
"""
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

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: typo in chnage -> change

Comment thread src/ib_py/cogs/voting.py
Comment on lines +551 to +556
# Replace options
vote.options = list(options)
vote.totals = [0] * len(options)
vote.voters = {}
vote.expiry = int(datetime.utcnow().timestamp()) + ladder.timeout
vote.finished = False

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: types pls 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants