Example #1
0
async def echo(event):
    if event.fwd_from:
        return
    if event.sender_id == OWNER_ID:
        pass
    elif sudo(event.sender_id):
        pass
    elif is_admin(event, event.sender_id):
        pass
    else:
        return
    if event.reply_to_msg_id:
        previous_message = await event.get_reply_message()
        try:
            await event.delete()
        except Exception:
            pass
        k = await tbot.send_message(event.chat_id, previous_message)
    else:
        ok = event.pattern_match.group(1)
        try:
            await event.delete()
        except Exception:
            pass
        await tbot.send_message(event.chat_id, ok)
async def _(event):
    if event.is_private:
        return
    if event.is_group:
        if not is_admin(event, event.sender_id):
            await event.reply("You need to be an admin to do this.")
            return
        if not await can_change_info(message=event):
            return
    chat = event.chat_id
    args = event.pattern_match.group(1)
    if args:
        if args == "on" or args == "yes":
            sql.set_chat_setting(chat, True)
            await event.reply(
                "Users will now be able to report messages."
            )

        elif args == "off" or args == "no":
            sql.set_chat_setting(chat, False)
            await event.reply(
                "Users will no longer be able to report via @admin or /report."
            )
        else:
            await event.reply("Your input was not recognised as one of: yes/no/on/off")
            return
    else:
        await event.reply(
            f"Reports are currently {sql.chat_should_report(chat)} in this chat. Users can use the /report command, or mention @admin, to tag all admins.\n\nTo change this setting, try this command again, with one of the following args: yes/no/on/off",
            parse_mode="markdown",
        )
Example #3
0
async def log(event):
    chat = event.chat_id
    if not is_admin(event, event.sender_id):
        return await event.reply("You need to be an admin to do this")
    args = event.pattern_match.group(1)
    if not args:
        fedowner = sql.get_user_owner_fed_full(event.sender_id)
        if not fedowner:
            return await event.reply(
                "Only fed creators can set a fed log - but you don't have a federation!"
            )
        for f in fedowner:
            args = "{}".format(f["fed_id"])
            name = f["fed"]["fname"]
    else:
        if len(args) < 8:
            return await event.reply("This isn't a valid FedID format!")
        getfed = sql.search_fed_by_id(args)
        name = getfed["fname"]
        if not getfed:
            return await event.reply(
                "This FedID does not refer to an existing federation.")
    setlog = sql.set_fed_log(args, chat)
    await event.reply(
        f"This has been set as the fed log for {name} - all fed related actions will be logged here."
    )
Example #4
0
async def stop(event):
    if not is_admin(event, event.chat_id):
        return
    allpoll = poll_id.find({})
    for c in allpoll:
        if event.sender_id == c["user"]:
            try:
                poll_id.delete_one({"user": event.sender_id})
                await event.reply("Done you can now create a new poll.")
            except Exception:
                await event.reply(
                    "Seems like you haven't created any poll yet !")
Example #5
0
async def stop(event):
    secret = event.pattern_match.group(1)
    if not is_admin(event, event.sender_id):
        return
    if not event.reply_to_msg_id:
        await event.reply("Please reply to a poll to stop it")
        return
    if input is None:
        await event.reply("Where is the poll id ?")
        return
    try:
        secret = str(secret)
    except ValueError:
        await event.reply("Poll id should contain only numbers")
        return
    if len(secret) != 5:
        await event.reply("Poll id should be an integer of 5 digits")
        return
    msg = await event.get_reply_message()
    if str(msg.sender_id) != str(BOT_ID):
        await event.reply(
            "I can't do this operation on this poll.\nProbably it's not created by me"
        )
        return
    print(secret)
    if msg.poll:
        allpoll = poll_id.find({})
        for c in allpoll:
            if not event.sender_id == c["user"] and not secret == c["pollid"]:
                await event.reply(
                    "Oops, either you haven't created this poll or you have given wrong poll id"
                )
                return
        if msg.poll.poll.closed:
            await event.reply("Oops, the poll is already closed.")
            return
        poll_id.delete_one({"user": event.sender_id})
        pollid = msg.poll.poll.id
        await msg.edit(file=types.InputMediaPoll(
            poll=types.Poll(id=pollid, question="", answers=[], closed=True)))
        await event.reply("Successfully stopped the poll")
    else:
        await event.reply("This isn't a poll")
Example #6
0
async def _(event):
    if not is_admin(event, event.sender_id):
        return
    try:
        quew = event.pattern_match.group(1)
    except Exception:
        await event.reply("Where is the question ?")
        return
    if "|" in quew:
        secrets, quess, options = quew.split("|")
    secret = secrets.strip()

    if not secret:
        await event.reply("I need a poll id of 5 digits to make a poll")
        return

    try:
        secret = str(secret)
    except ValueError:
        await event.reply("Poll id should contain only numbers")
        return

    # print(secret)

    if len(secret) != 5:
        await event.reply("Poll id should be an integer of 5 digits")
        return

    allpoll = poll_id.find({})
    # print(secret)
    for c in allpoll:
        if event.sender_id == c["user"]:
            await event.reply(
                "Please stop the previous poll before creating a new one !")
            return
    poll_id.insert_one({"user": event.sender_id, "pollid": secret})

    ques = quess.strip()
    option = options.strip()
    quiz = option.split(" ")[1 - 1]
    if "True" in quiz:
        quizy = True
        if "@" in quiz:
            one, two = quiz.split("@")
            rightone = two.strip()
        else:
            await event.reply(
                "You need to select the right answer with question number like True@1, True@3 etc.."
            )
            return

        quizoptionss = []
        try:
            ab = option.split(" ")[4 - 1]
            cd = option.split(" ")[5 - 1]
            quizoptionss.append(types.PollAnswer(ab, b"1"))
            quizoptionss.append(types.PollAnswer(cd, b"2"))
        except Exception:
            await event.reply("At least need two options to create a poll")
            return
        try:
            ef = option.split(" ")[6 - 1]
            quizoptionss.append(types.PollAnswer(ef, b"3"))
        except Exception:
            ef = None
        try:
            gh = option.split(" ")[7 - 1]
            quizoptionss.append(types.PollAnswer(gh, b"4"))
        except Exception:
            gh = None
        try:
            ij = option.split(" ")[8 - 1]
            quizoptionss.append(types.PollAnswer(ij, b"5"))
        except Exception:
            ij = None
        try:
            kl = option.split(" ")[9 - 1]
            quizoptionss.append(types.PollAnswer(kl, b"6"))
        except Exception:
            kl = None
        try:
            mn = option.split(" ")[10 - 1]
            quizoptionss.append(types.PollAnswer(mn, b"7"))
        except Exception:
            mn = None
        try:
            op = option.split(" ")[11 - 1]
            quizoptionss.append(types.PollAnswer(op, b"8"))
        except Exception:
            op = None
        try:
            qr = option.split(" ")[12 - 1]
            quizoptionss.append(types.PollAnswer(qr, b"9"))
        except Exception:
            qr = None
        try:
            st = option.split(" ")[13 - 1]
            quizoptionss.append(types.PollAnswer(st, b"10"))
        except Exception:
            st = None

    elif "False" in quiz:
        quizy = False
    else:
        await event.reply("Wrong arguments provided !")
        return

    pvote = option.split(" ")[2 - 1]
    if "True" in pvote:
        pvoty = True
    elif "False" in pvote:
        pvoty = False
    else:
        await event.reply("Wrong arguments provided !")
        return
    mchoice = option.split(" ")[3 - 1]
    if "True" in mchoice:
        mchoicee = True
    elif "False" in mchoice:
        mchoicee = False
    else:
        await event.reply("Wrong arguments provided !")
        return
    optionss = []
    try:
        ab = option.split(" ")[4 - 1]
        cd = option.split(" ")[5 - 1]
        optionss.append(types.PollAnswer(ab, b"1"))
        optionss.append(types.PollAnswer(cd, b"2"))
    except Exception:
        await event.reply("At least need two options to create a poll")
        return
    try:
        ef = option.split(" ")[6 - 1]
        optionss.append(types.PollAnswer(ef, b"3"))
    except Exception:
        ef = None
    try:
        gh = option.split(" ")[7 - 1]
        optionss.append(types.PollAnswer(gh, b"4"))
    except Exception:
        gh = None
    try:
        ij = option.split(" ")[8 - 1]
        optionss.append(types.PollAnswer(ij, b"5"))
    except Exception:
        ij = None
    try:
        kl = option.split(" ")[9 - 1]
        optionss.append(types.PollAnswer(kl, b"6"))
    except Exception:
        kl = None
    try:
        mn = option.split(" ")[10 - 1]
        optionss.append(types.PollAnswer(mn, b"7"))
    except Exception:
        mn = None
    try:
        op = option.split(" ")[11 - 1]
        optionss.append(types.PollAnswer(op, b"8"))
    except Exception:
        op = None
    try:
        qr = option.split(" ")[12 - 1]
        optionss.append(types.PollAnswer(qr, b"9"))
    except Exception:
        qr = None
    try:
        st = option.split(" ")[13 - 1]
        optionss.append(types.PollAnswer(st, b"10"))
    except Exception:
        st = None

    if pvoty is False and quizy is False and mchoicee is False:
        await tbot.send_file(
            event.chat_id,
            types.InputMediaPoll(poll=types.Poll(
                id=12345, question=ques, answers=optionss, quiz=False)),
        )

    if pvoty is True and quizy is False and mchoicee is True:
        await tbot.send_file(
            event.chat_id,
            types.InputMediaPoll(poll=types.Poll(
                id=12345,
                question=ques,
                answers=optionss,
                quiz=False,
                multiple_choice=True,
                public_voters=True,
            )),
        )

    if pvoty is False and quizy is False and mchoicee is True:
        await tbot.send_file(
            event.chat_id,
            types.InputMediaPoll(poll=types.Poll(
                id=12345,
                question=ques,
                answers=optionss,
                quiz=False,
                multiple_choice=True,
                public_voters=False,
            )),
        )

    if pvoty is True and quizy is False and mchoicee is False:
        await tbot.send_file(
            event.chat_id,
            types.InputMediaPoll(poll=types.Poll(
                id=12345,
                question=ques,
                answers=optionss,
                quiz=False,
                multiple_choice=False,
                public_voters=True,
            )),
        )

    if pvoty is False and quizy is True and mchoicee is False:
        await tbot.send_file(
            event.chat_id,
            types.InputMediaPoll(
                poll=types.Poll(id=12345,
                                question=ques,
                                answers=quizoptionss,
                                quiz=True),
                correct_answers=[f"{rightone}"],
            ),
        )

    if pvoty is True and quizy is True and mchoicee is False:
        await tbot.send_file(
            event.chat_id,
            types.InputMediaPoll(
                poll=types.Poll(
                    id=12345,
                    question=ques,
                    answers=quizoptionss,
                    quiz=True,
                    public_voters=True,
                ),
                correct_answers=[f"{rightone}"],
            ),
        )

    if pvoty is True and quizy is True and mchoicee is True:
        await event.reply("You can't use multiple voting with quiz mode")
        return
    if pvoty is False and quizy is True and mchoicee is True:
        await event.reply("You can't use multiple voting with quiz mode")
        return