You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Check if the command contains a valid number of arguments
387
+
iflen(inputs) <3:
388
+
awaitsend_message(
389
+
"Please enter a question and at least two options to create a poll",
390
+
bot_chat,
391
+
)
392
+
eliflen(inputs) > (len(poll_reactions) +1):
393
+
awaitsend_message(
394
+
f"Your poll contained too many options, limit is {len(poll_reactions)} options",
395
+
bot_chat,
396
+
)
397
+
else:
398
+
console.log(
399
+
f'Creating poll "{inputs[0]}" for {user.get_username()}'
400
+
)
401
+
402
+
# Create formatted poll text
403
+
poll_txt="# {0}\n".format(inputs[0])
404
+
foriinrange(1, len(inputs)):
405
+
poll_txt+=":{0}: {1}\n".format(
406
+
poll_reactions[i-1], inputs[i]
407
+
)
408
+
409
+
ifdue_dateisnotNone:
410
+
poll_txt+="\n\n**Poll will end on {0} at {1} ({2})**".format(
411
+
due_date.date(),
412
+
due_date.time(),
413
+
due_date.tzname(),
414
+
)
415
+
poll_id=awaitsend_message(
416
+
poll_txt,
417
+
bot_chat,
418
+
f"This poll was created by {user.get_username()}",
419
+
)
420
+
421
+
# Get the poll message
422
+
message=awaitretry_until_available(
423
+
bot_chat.get_message,
424
+
poll_id,
425
+
timeout=5.0,
426
+
retry_delay=0.5,
427
+
)
428
+
429
+
# Add reaction options
430
+
foriinrange(0, (len(inputs)) -1):
431
+
awaitmessage.react(poll_reactions[i])
432
+
433
+
# Set ending timer using tasks
434
+
ifdue_dateisnotNone:
435
+
task_body="{0}".format(inputs[0])
436
+
# Add options to task message for later parsing
437
+
foriininputs[1:]:
438
+
task_body+=";{0}".format(i)
439
+
# Add reactions used for later parsing
440
+
task_body+=";"
441
+
foriinpoll_reactions[: (len(inputs) -1)]:
442
+
task_body+=";{0}".format(i)
443
+
poll_task=awaitbot_task_board.create_task(
444
+
f"BrainBotPoll#{poll_id}",
445
+
task_body,
446
+
due_date=datetime_to_iso8601(due_date),
447
+
)
448
+
# Create task reminder
449
+
awaitremind_task(
450
+
ryver,
451
+
poll_task,
452
+
int(
453
+
(
454
+
due_date-current_date
455
+
).total_seconds()
456
+
/60
457
+
),
458
+
)
459
+
else:
460
+
awaitsend_message(
461
+
"Ending time entered is already in the past or too short",
462
+
bot_chat,
463
+
)
464
+
else:
465
+
awaitsend_message(
466
+
"Ending time entered is not valid. You can any of these formats:\n `t=hh:mm;`\n `d=mm/dd/yyyy hh:mm;`\n`m=<minutes>;`\n**~Don't~ ~forget~ ~to~ ~use~ ~';'!~**",
467
+
bot_chat,
468
+
)
469
+
else:
470
+
console.log("Cancelled due to cooldown")
471
+
472
+
# Get the invoking message
473
+
message=awaitretry_until_available(
474
+
bot_chat.get_message,
475
+
msg.message_id,
476
+
timeout=5.0,
477
+
retry_delay=0.5,
478
+
)
479
+
480
+
# React to show the command is on cooldown
481
+
awaitmessage.react("timer_clock")
240
482
# Give a list of commands
241
483
elifmsg.text.lower().startswith("!commands"):
242
484
console.log(f"Telling {user.get_username()} my commands")
0 commit comments