Ejemplo n.º 1
0
    def check_update(self, update):

        if (isinstance(update, Update) and
            (update.message or update.edited_message and self.allow_edited)):
            message = update.message or update.edited_message

            if sql.is_user_blacklisted(update.effective_user.id):
                return False

            if message.text and len(message.text) > 1:
                fst_word = message.text_html.split(None, 1)[0]

                if len(fst_word) > 1 and any(
                        fst_word.startswith(start) for start in CMD_STARTERS):
                    command = fst_word[1:].split('@')
                    command.append(
                        message.bot.username
                    )  # in case the command was sent without a username

                    if self.filters is None:
                        res = True
                    elif isinstance(self.filters, list):
                        res = any(func(message) for func in self.filters)
                    else:
                        res = self.filters(message)

                    return res and (command[0].lower() in self.command
                                    and command[1].lower()
                                    == message.bot.username.lower())

            return False
Ejemplo n.º 2
0
def __user_info__(user_id):
    is_blacklisted = sql.is_user_blacklisted(user_id)

    text = "Blacklisted: <b>{}</b>"

    if is_blacklisted:
        text = text.format("Yes")
        reason = sql.get_reason(user_id)
        if reason:
            text += f"\nReason: <code>{reason}</code>"
    else:
        text = text.format("No")

    return text
Ejemplo n.º 3
0
def unbl_user(bot: Bot, update: Update, args: List[str]) -> str:
    message = update.effective_message
    user = update.effective_user

    user_id = extract_user(message, args)

    if not user_id:
        message.reply_text("I doubt that's a user.")
        return ""

    if user_id == bot.id:
        message.reply_text("I always notice myself.")
        return ""

    try:
        target_user = bot.get_chat(user_id)
    except BadRequest as excp:
        if excp.message == "User not found":
            message.reply_text("I can't seem to find this user.")
            return ""
        else:
            raise

    if sql.is_user_blacklisted(user_id):

        sql.unblacklist_user(user_id)
        message.reply_text("*notices user*")
        log_message = "#UNBLACKLIST" \
                      "\n<b>Admin:</b> {}" \
                      "\n<b>User:</b> {}".format(mention_html(user.id, user.first_name),
                                                 mention_html(target_user.id, target_user.first_name))

        return log_message

    else:
        message.reply_text("I am not ignoring them at all though!")
        return ""