]> git.aero2k.de Git - urlbot-v3.git/commitdiff
universally use str | bytes
authorThorsten <mail@aero2k.de>
Sat, 7 Sep 2024 12:22:53 +0000 (14:22 +0200)
committerThorsten <mail@aero2k.de>
Sat, 7 Sep 2024 12:22:53 +0000 (14:22 +0200)
src/distbot/plugins/votepoll.py

index 3ee0a1ff60545693701030f22c69fcbef99ebef2..63dfecf40c8f45c8bd0b8514898e6cae81476347 100644 (file)
@@ -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):