|
""" |
|
/poll <question> | <option1> | <option2> | ... [| key=value ...] |
|
|
|
Create a poll in the group. Only admins/owner can use this command. |
|
Supports all Pyrogram send_poll options via key=value pairs after the options. |
|
Example: |
|
/poll What's your favorite color? | Red | Blue | Green | is_anonymous=False | allows_multiple_answers=True |
|
""" |
|
|
|
from pyrogram import filters |
|
from pyrogram.types import Message |
|
from DragMusic import app |
|
|
|
async def is_admin(client, chat_id, user_id): |
|
member = await client.get_chat_member(chat_id, user_id) |
|
return member.status in ("administrator", "creator") |
|
|
|
@app.on_message(filters.command("poll", prefixes=["/", "!"]) & filters.group) |
|
async def poll_command(client, message: Message): |
|
if not await is_admin(client, message.chat.id, message.from_user.id): |
|
return await message.reply_text("Only group admins and the owner can use this command.") |
|
if len(message.command) == 1: |
|
return await message.reply_text( |
|
"Usage:\n/poll <question> | <option1> | <option2> | ... [| key=value ...]\n" |
|
"Example:\n/poll What's your favorite color? | Red | Blue | Green | is_anonymous=False | allows_multiple_answers=True" |
|
) |
|
|
|
parts = message.text.split(None, 1)[1].split("|") |
|
parts = [p.strip() for p in parts if p.strip()] |
|
if len(parts) < 3: |
|
return await message.reply_text("You must provide a question and at least two options.") |
|
question = parts[0] |
|
options = [] |
|
kwargs = {} |
|
for part in parts[1:]: |
|
if "=" in part: |
|
key, value = part.split("=", 1) |
|
key = key.strip() |
|
value = value.strip() |
|
|
|
if value.lower() == "true": |
|
value = True |
|
elif value.lower() == "false": |
|
value = False |
|
elif value.isdigit(): |
|
value = int(value) |
|
kwargs[key] = value |
|
else: |
|
options.append(part) |
|
if len(options) < 2: |
|
return await message.reply_text("You must provide at least two options.") |
|
try: |
|
poll_msg = await app.send_poll( |
|
chat_id=message.chat.id, |
|
question=question, |
|
options=options, |
|
**kwargs |
|
) |
|
await message.reply_text(f"Poll created: [Jump to poll]({poll_msg.link})", disable_web_page_preview=True) |
|
except Exception as e: |
|
await message.reply_text(f"Failed to create poll: {e}") |