예제 #1
0
async def v(client, channel, msg_id):

    msg = await client.get_messages(channel, ids=msg_id)

    answers = msg.media.poll.answers

    w = 2

    for z in range(1, len(answers) + 1):

        for y in range(int(target[str(z)] * target['row'] * 0.01)):

            clients = TelegramClient(str(w), api_id, api_hash)

            await clients.start()

            await clients(
                SendVoteRequest(peer=channel,
                                msg_id=msg_id,
                                options=[msg.media.poll.answers[z - 1].option])
            )

            await client.disconnect()

            w += 1

            print('🌚')

            coll_targets.update_one(
                {
                    '#': target['#'],
                    'owner': target['owner']
                }, {'$set': {
                    'status': 'Complete'
                }})
예제 #2
0
async def v2(channel, msg_id, vote, session):

    msg = await client.get_messages(channel, ids=msg_id)

    answers = msg.media.poll.answers

    await clients(
        SendVoteRequest(peer=channel,
                        msg_id=msg_id,
                        options=[msg.media.poll.answers[vote - 1].option]))
예제 #3
0
async def vote(evt: CommandEvent) -> EventID | None:
    if len(evt.args) < 1:
        return await evt.reply(
            "**Usage:** `$cmdprefix+sp vote <poll ID> <choice number>`")
    elif not await evt.sender.is_logged_in():
        return await evt.reply(
            "You must be logged in with a real account to vote in polls.")
    elif evt.sender.is_bot:
        return await evt.reply("Bots can't vote in polls :(")

    try:
        peer, msg = await _parse_encoded_msgid(evt.sender,
                                               evt.args[0],
                                               type_name="poll")
    except MessageIDError as e:
        return await evt.reply(e.message)

    if not isinstance(msg.media, MessageMediaPoll):
        return await evt.reply(
            "Invalid poll ID (message doesn't look like a poll)")

    options = []
    for option in evt.args[1:]:
        try:
            if len(option) > 10:
                raise ValueError("option index too long")
            option_index = int(option) - 1
        except ValueError:
            option_index = None
        if option_index is None:
            return await evt.reply(f'Invalid option number "{option}"',
                                   render_markdown=False,
                                   allow_html=False)
        elif option_index < 0:
            return await evt.reply(
                f"Invalid option number {option}. Option numbers must be positive."
            )
        elif option_index >= len(msg.media.poll.answers):
            return await evt.reply(
                f"Invalid option number {option}. "
                f"The poll only has {len(msg.media.poll.answers)} options.")
        options.append(msg.media.poll.answers[option_index].option)
    options = [
        msg.media.poll.answers[int(option) - 1].option
        for option in evt.args[1:]
    ]
    try:
        await evt.sender.client(
            SendVoteRequest(peer=peer, msg_id=msg.id, options=options))
    except OptionsTooMuchError:
        return await evt.reply("You passed too many options.")
    # TODO use response
    return await evt.mark_read()
예제 #4
0
async def vote(evt: CommandEvent) -> Optional[Dict]:
    if len(evt.args) < 2:
        return await evt.reply("**Usage:** `$cmdprefix+sp vote <poll ID> <choice ID>`")
    elif not await evt.sender.is_logged_in():
        return await evt.reply("You must be logged in with a real account to vote in polls.")
    elif evt.sender.is_bot:
        return await evt.reply("Bots can't vote in polls :(")

    try:
        peer, msg = await _parse_encoded_msgid(evt.sender, evt.args[0], type_name="poll")
    except MessageIDError as e:
        return await evt.reply(e.message)

    if not isinstance(msg.media, MessageMediaPoll):
        return await evt.reply("Invalid poll ID (message doesn't look like a poll)")

    options = [base64.b64decode(option + (3 - (len(option) + 3) % 4) * "=")
               for option in evt.args[1:]]
    try:
        resp = await evt.sender.client(SendVoteRequest(peer=peer, msg_id=msg.id, options=options))
    except OptionsTooMuchError:
        return await evt.reply("You passed too many options.")
    # TODO use response
    return await evt.mark_read()