Skip to content

Commit 80c8ce8

Browse files
committed
Fix queries with booleans (postgres is a bit more sassy than sqlite)
1 parent a08e9ac commit 80c8ce8

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

ioibot/bot_commands.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,10 +324,10 @@ def _get_poll_display(self, poll_id, question, status, display, anonymous, multi
324324
text += f'anonymous: {"Yes" if anonymous else "No"} \n'
325325
text += f'multiple choice: {"Yes" if multiple_choice else "No"} \n'
326326

327-
if status is not None:
327+
if status:
328328
text += f'status: {["inactive", "active", "closed"][status]} \n'
329329

330-
if display is not None:
330+
if display:
331331
text += f'{"Results are shown" if display else "Results are hidden"} \n'
332332

333333
text += '\n'
@@ -400,10 +400,10 @@ def _get_options(args):
400400
else:
401401
arguments.append(arg.strip())
402402

403-
anonymous = int(bool(options & ANONYM))
404-
multiple_choice = int(bool(options & MULTIPLE))
405-
display = int(bool(options & DISPLAY))
406-
start = int(bool(options & START))
403+
anonymous = bool(options & ANONYM)
404+
multiple_choice = bool(options & MULTIPLE)
405+
display = bool(options & DISPLAY)
406+
start = bool(options & START)
407407

408408
return (arguments, err, (anonymous, multiple_choice, display, start))
409409

@@ -436,7 +436,7 @@ async def _new(args):
436436
status = 1 if poll_id is None else 0
437437

438438
if display:
439-
await self.store.conn.execute('UPDATE polls SET display = 0')
439+
await self.store.conn.execute('UPDATE polls SET display = false')
440440

441441
poll_id = await self.store.conn.fetchval(
442442
'''INSERT INTO polls (question, status, display, anonymous, multiple_choice)
@@ -486,7 +486,7 @@ async def _update(poll_id, args):
486486
await send_text_to_room(self.client, self.room.room_id, f"Format Error: {err_message}")
487487
return
488488

489-
if anonymous == 0 and multiple_choice == 0 and start == 0 and len(arguments) == 0 and display == 1: # only the display is changed
489+
if not anonymous and not multiple_choice and not start and len(arguments) == 0 and display == 1: # only the display is changed
490490
await self.store.conn.execute('UPDATE polls SET display = CASE WHEN poll_id = $1 THEN 1 ELSE 0 END', poll_id)
491491
await send_text_to_room(self.client, self.room.room_id, f'Poll {poll_id} is now displayed. \n')
492492
return
@@ -495,7 +495,7 @@ async def _update(poll_id, args):
495495

496496
if len(arguments) <= 1: # only update the question
497497
if display:
498-
await self.store.conn.execute('UPDATE polls SET display = 0', poll_id)
498+
await self.store.conn.execute('UPDATE polls SET display = false', poll_id)
499499

500500
question = arguments[0] if len(arguments) == 1 else question_db
501501

@@ -749,7 +749,7 @@ async def _close():
749749
await _close()
750750

751751
elif self.args[0] == 'clear-display':
752-
await self.store.conn.execute('UPDATE polls SET display = 0')
752+
await self.store.conn.execute('UPDATE polls SET display = false')
753753
await send_text_to_room(self.client, self.room.room_id, "Display cleared.")
754754

755755
else:

0 commit comments

Comments
 (0)