From: Thorsten Date: Sat, 7 Sep 2024 12:22:53 +0000 (+0200) Subject: universally use str | bytes X-Git-Url: https://git.aero2k.de/?a=commitdiff_plain;h=4cb1b12dd7eb25499e0fbe551cc8b451eaa8295b;p=urlbot-v3.git universally use str | bytes --- diff --git a/src/distbot/plugins/votepoll.py b/src/distbot/plugins/votepoll.py index 3ee0a1f..63dfecf 100644 --- a/src/distbot/plugins/votepoll.py +++ b/src/distbot/plugins/votepoll.py @@ -154,8 +154,9 @@ class VotePoll(Worker): if active_key: return self.get_poll(active_key) - def get_poll(self, key: str) -> Poll | None: - poll_bin = self.db.get(key.encode()) + def get_poll(self, key: str | bytes) -> Poll | None: + binkey = key if isinstance(key, bytes) else key.encode() + poll_bin = self.db.get(binkey) if poll_bin: poll = json.loads(poll_bin.decode("utf-8")) return Poll.from_json(poll) @@ -168,9 +169,10 @@ class VotePoll(Worker): self.db.put(key, poll.to_json().encode()) self.db.put(self.KEY_ACTIVE, key) - def close_poll(self, key: str): + def close_poll(self, key: str | bytes): + binkey = key if isinstance(key, bytes) else key.encode() active_key = self.db.get(self.KEY_ACTIVE) - if active_key == key.encode(): + if active_key == binkey: self.db.delete(self.KEY_ACTIVE) def check_poll(self):