From 4cb1b12dd7eb25499e0fbe551cc8b451eaa8295b Mon Sep 17 00:00:00 2001 From: Thorsten Date: Sat, 7 Sep 2024 14:22:53 +0200 Subject: [PATCH] universally use str | bytes --- src/distbot/plugins/votepoll.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) 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): -- 2.39.2