Files
Ultroid-fork/plugins/polls.py
1Danish-00 386eff647c v0.0.9 18/07/2021
Co-authored-by: New-dev0 <New-dev0@users.noreply.github.com>
Co-authored-by: Aditya <me@xditya.me>
Co-authored-by: Amit Sharma <48654350+buddhhu@users.noreply.github.com>
Co-authored-by: sppidy <sppidy@users.noreply.github.com>
Co-authored-by: Arnab Paryali <Arnabxd@users.noreply.github.com>
Co-authored-by: divkix <divkix@users.noreply.github.com>
Co-authored-by: hellboi_atul <hellboi-atul@users.noreply.github.com>
Co-authored-by: Programming Error <error@notavailable.live>
2021-07-18 17:47:15 +05:30

70 lines
2.1 KiB
Python

# Ultroid - UserBot
# Copyright (C) 2021 TeamUltroid
#
# This file is a part of < https://github.com/TeamUltroid/Ultroid/ >
# PLease read the GNU Affero General Public License in
# <https://www.github.com/TeamUltroid/Ultroid/blob/main/LICENSE/>.
"""
✘ Commands Available -
• `{i}poll <question> ; <option> ; <option>`
Get the Anonymous Poll with Given Options
• `{i}poll <question> ; <option> ; <option> | <type>`
Get the poll specified with desired type!
type should be any of `public`, `multiple` or `quiz`
• `{i}poll <question> ; <option> ; <option> | quiz_<answerno>`
Get the quiz poll where answerno is the number of option which is correct
"""
from telethon.tl.types import InputMediaPoll, Poll, PollAnswer
from . import *
@ultroid_cmd(
pattern="poll ?(.*)",
groups_only=True,
)
async def uri_poll(e):
match = e.pattern_match.group(1)
if not match:
return await eod(e, "`Give Proper Input...`")
if ";" not in match:
return await eod(e, "`Unable to Determine Options.`.")
ques = match.split(";")[0]
option = match.split(";")[1::]
publ = None
quizo = None
karzo = None
mpp = None
if "|" in match:
ptype = match.split(" | ")[1]
option = match.split("|")[0].split(";")[1::]
if "_" in ptype:
karzo = [str(int(ptype.split("_")[1]) - 1).encode()]
ptype = ptype.split("_")[0]
if ptype not in ["public", "quiz", "multiple"]:
return await eod(e, "`Invalid Poll Type...`")
if ptype == "public":
publ = True
if ptype == "quiz":
quizo = True
if ptype == "multiple":
mpp = True
if len(option) <= 1:
return await eod(e, "`Options Should be More than 1..`")
m = await eor(e, "`Processing... `")
OUT = []
for on in range(len(option)):
OUT.append(PollAnswer(option[on], str(on).encode()))
await e.client.send_file(
e.chat_id,
InputMediaPoll(
Poll(20, ques, OUT, multiple_choice=mpp, public_voters=publ, quiz=quizo),
correct_answers=karzo,
),
)
await m.delete()