Пример #1
0
def connected(bot, update, chat, user_id, need_admin=True):
    if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):
        conn_id = sql.get_connected_chat(user_id).chat_id
        if (bot.get_chat_member(
                conn_id, user_id).status in ('administrator', 'creator') or
            (sql.allow_connect_to_chat(connect_chat) == True)
                and bot.get_chat_member(
                    user_id, update.effective_message.from_user.id).status in
            ('member')) or (user_id in SUDO_USERS):
            if need_admin == True:
                if bot.get_chat_member(
                        conn_id,
                        update.effective_message.from_user.id).status in (
                            'administrator',
                            'creator') or user_id in SUDO_USERS:
                    return conn_id
                else:
                    update.effective_message.reply_text(
                        "You need to be a admin in a connected group!")
                    exit(1)
            else:
                return conn_id
        else:
            update.effective_message.reply_text(
                "Group changed rights connection or you are not admin anymore.\nI'll disconnect you."
            )
            disconnect_chat(bot, update)
            exit(1)
    else:
        return False
Пример #2
0
def connected(bot, update, chat, user_id, need_admin=True):
    user = update.effective_user
    msg = update.effective_message

    if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):

        conn_id = sql.get_connected_chat(user_id).chat_id
        getstatusadmin = bot.get_chat_member(conn_id, msg.from_user.id)
        isadmin = getstatusadmin.status in ADMIN_STATUS
        ismember = getstatusadmin.status in MEMBER_STAUS
        isallow = sql.allow_connect_to_chat(conn_id)

        if isadmin or (isallow and ismember) or (user.id in SUDO_USERS) or (
                user.id in DEV_USERS):
            if need_admin is True:
                if getstatusadmin.status in ADMIN_STATUS or user_id in SUDO_USERS or user.id in DEV_USERS:
                    return conn_id
                else:
                    send_message(
                        msg, "You must be an admin in the connected group!")
                    raise Exception("Not admin!")
            else:
                return conn_id
        else:
            send_message(
                msg,
                "The group changed the connection rights or you are no longer an admin.\n"
                "I've disconnected you.")
            disconnect_chat(bot, update)
            raise Exception("Not admin!")
    else:
        return False
Пример #3
0
def connected(bot, update, chat, user_id, need_admin=True):
    user = update.effective_user  # type: Optional[User]
    spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id)
    if spam == True:
        return
        
    if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):
        conn_id = sql.get_connected_chat(user_id).chat_id
        getstatusadmin = bot.get_chat_member(conn_id, update.effective_message.from_user.id)
        isadmin = getstatusadmin.status in ('administrator', 'creator')
        ismember = getstatusadmin.status in ('member')
        isallow = sql.allow_connect_to_chat(conn_id)
        if (isadmin) or (isallow and ismember) or (user.id in SUDO_USERS):
            if need_admin == True:
                if getstatusadmin.status in ('administrator', 'creator') or user_id in SUDO_USERS:
                    return conn_id
                else:
                    send_message(update.effective_message, "You must be an admin in the connected group!")
                    raise Exception("Not admin!")
            else:
                return conn_id
        else:
            send_message(update.effective_message, "The group changed the connection rights or you are no longer an admin.\nI've disconnected you.")
            disconnect_chat(bot, update)
            raise Exception("Not admin!")
    else:
        return False
Пример #4
0
def connected(bot: Bot, update: Update, chat, user_id, need_admin=True):
    user = update.effective_user

    if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):

        conn_id = sql.get_connected_chat(user_id).chat_id
        getstatusadmin = bot.get_chat_member(
            conn_id, update.effective_message.from_user.id)
        isadmin = getstatusadmin.status in ("administrator", "creator")
        ismember = getstatusadmin.status == "member"
        isallow = sql.allow_connect_to_chat(conn_id)

        if ((isadmin) or (isallow and ismember) or (user.id in SUDO_USERS)
                or (user.id in DEV_USERS)):
            if need_admin is not True:
                return conn_id
            if (getstatusadmin.status in ("administrator", "creator")
                    or user_id in SUDO_USERS or user.id in DEV_USERS):
                return conn_id
            else:
                send_message(
                    update.effective_message,
                    "You must be an admin in the connected group!",
                )
        else:
            send_message(
                update.effective_message,
                "The group changed the connection rights or you are no longer an admin.\nI've disconnected you.",
            )
            disconnect_chat(update, bot)
    else:
        return False
Пример #5
0
def connected(bot, update, chat, user_id, need_admin=True):
    if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):
        conn_id = sql.get_connected_chat(user_id).chat_id
        if (bot.get_chat_member(
                conn_id, user_id).status in ('administrator', 'creator') or
            (sql.allow_connect_to_chat(connect_chat) == True)
                and bot.get_chat_member(
                    user_id, update.effective_message.from_user.id).status in
            ('member')) or (user_id in SUDO_USERS):
            if need_admin == True:
                if bot.get_chat_member(
                        conn_id,
                        update.effective_message.from_user.id).status in (
                            'administrator',
                            'creator') or user_id in SUDO_USERS:
                    return conn_id
                else:
                    update.effective_message.reply_text(
                        "आपको एक जुड़े ग्रुप में एक एडमिन होने की जरुरत है!")
                    exit(1)
            else:
                return conn_id
        else:
            update.effective_message.reply_text(
                "ग्रुप ने अधिकारों का कनेक्शन बदल दिया या आप अब एडमिन नहीं हैं। \n मैं आपको डिस्कनेक्ट कर दूंगा।"
            )
            disconnect_chat(bot, update)
            exit(1)
    else:
        return False
Пример #6
0
def connected(bot, update, chat, user_id, need_admin=True):
    if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):
        conn_id = sql.get_connected_chat(user_id).chat_id
        if (bot.get_chat_member(
                conn_id, user_id).status in ('administrator', 'creator') or
            (sql.allow_connect_to_chat(connect_chat) == True)
                and bot.get_chat_member(
                    user_id, update.effective_message.from_user.id).status in
            ('member')) or (user_id in SUDO_USERS):
            if need_admin == True:
                if bot.get_chat_member(
                        conn_id,
                        update.effective_message.from_user.id).status in (
                            'administrator',
                            'creator') or user_id in SUDO_USERS:
                    return conn_id
                else:
                    update.effective_message.reply_text(
                        "Qoşulacaq söhbətdə admin olmalısan!")
                    exit(1)
            else:
                return conn_id
        else:
            update.effective_message.reply_text(
                "Qrup əlaqələrlə bağlı səlahiyyətləri dəyişib və ya sən orada admin deyilsən.\nSəni Disconnect edəcəm."
            )
            disconnect_chat(bot, update)
            exit(1)
    else:
        return False
Пример #7
0
def connected(bot, update, chat, user_id, need_admin=True):
    if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):
        conn_id = sql.get_connected_chat(user_id).chat_id
        if (bot.get_chat_member(
                conn_id, user_id).status in ('administrator', 'creator') or
            (sql.allow_connect_to_chat(connect_chat) == True)
                and bot.get_chat_member(
                    user_id, update.effective_message.from_user.id).status in
            ('member')) or (user_id in SUDO_USERS):
            if need_admin == True:
                if bot.get_chat_member(
                        conn_id,
                        update.effective_message.from_user.id).status in (
                            'administrator',
                            'creator') or user_id in SUDO_USERS:
                    return conn_id
                else:
                    update.effective_message.reply_text(
                        "Musisz być administratorem połączonej grupy!")
                    exit(1)
            else:
                return conn_id
        else:
            update.effective_message.reply_text(
                "Grupa zmieniła swoje połączenie lub nie jesteś już administratorem.\nRozłączam ciebie."
            )
            disconnect_chat(bot, update)
            exit(1)
    else:
        return False
Пример #8
0
def connected(bot, update, chat, user_id, need_admin=True):
    if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):
        conn_id = sql.get_connected_chat(user_id).chat_id
        if (bot.get_chat_member(
                conn_id, user_id).status in ('administrator', 'creator') or
            (sql.allow_connect_to_chat(connect_chat) == True)
                and bot.get_chat_member(
                    user_id, update.effective_message.from_user.id).status in
            ('member')) or (user_id in SUDO_USERS):
            if need_admin == True:
                if bot.get_chat_member(
                        conn_id,
                        update.effective_message.from_user.id).status in (
                            'administrator',
                            'creator') or user_id in SUDO_USERS:
                    return conn_id
                else:
                    update.effective_message.reply_text(
                        "ඔබ සම්බන්ධිත කණ්ඩායමක පරිපාලකයෙකු විය යුතුය!")
                    exit(1)
            else:
                return conn_id
        else:
            update.effective_message.reply_text(
                "කණ්ඩායම් අයිතිවාසිකම් සම්බන්ධතාවය වෙනස් කර හෝ ඔබ තවදුරටත් පරිපාලක නොවේ.\nමම ඔබව විසන්ධි කරන්නම්."
            )
            disconnect_chat(bot, update)
            exit(1)
    else:
        return False
Пример #9
0
def connected(bot, update, chat, user_id, need_admin=True):
    if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):
        conn_id = sql.get_connected_chat(user_id).chat_id
        if (bot.get_chat_member(
                conn_id, user_id).status in ('administrator', 'creator') or
            (sql.allow_connect_to_chat(connect_chat) == True)
                and bot.get_chat_member(
                    user_id, update.effective_message.from_user.id).status in
            ('member')) or (user_id in SUDO_USERS):
            if need_admin == True:
                if bot.get_chat_member(
                        conn_id,
                        update.effective_message.from_user.id).status in (
                            'administrator',
                            'creator') or user_id in SUDO_USERS:
                    return conn_id
                else:
                    update.effective_message.reply_text(
                        "تحتاج إلى أن تكون مسؤول في مجموعة متصلة!")
                    exit(1)
            else:
                return conn_id
        else:
            update.effective_message.reply_text(
                "مجموعة تغيير الحقوق أو أنت غير مسؤول بعد الآن.\nسيتم قطع اتصالك"
            )
            disconnect_chat(bot, update)
            exit(1)
    else:
        return False
Пример #10
0
def connected(bot, update, chat, user_id, need_admin=True):
    if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):
        conn_id = sql.get_connected_chat(user_id).chat_id
        if (bot.get_chat_member(
                conn_id, user_id).status in ('administrator', 'creator') or
            (sql.allow_connect_to_chat(connect_chat) == True)
                and bot.get_chat_member(
                    user_id, update.effective_message.from_user.id).status in
            ('member')) or (user_id in SUDO_USERS):
            if need_admin == True:
                if bot.get_chat_member(
                        conn_id,
                        update.effective_message.from_user.id).status in (
                            'administrator',
                            'creator') or user_id in SUDO_USERS:
                    return conn_id
                else:
                    update.effective_message.reply_text(
                        "Bağlı bir qrupda admin olmalısınız!")
                    exit(1)
            else:
                return conn_id
        else:
            update.effective_message.reply_text(
                "Qrup dəyişikliyi hüquq bağlantısı və ya artıq admin deyilsiniz.\nSəni ayıracağam."
            )
            disconnect_chat(bot, update)
            exit(1)
    else:
        return False
Пример #11
0
def connected(bot, update, chat, user_id, need_admin=True):
    if sql.get_connected_chat(user_id) and chat.type == chat.PRIVATE:
        conn_id = sql.get_connected_chat(user_id).chat_id
        if need_admin == True:
            if bot.get_chat_member(
                    conn_id, update.effective_message.from_user.id).status in (
                        'administrator',
                        'creator'):  #or user_id in SUDO_USERS:
                return conn_id
            else:
                update.effective_message.reply_text(
                    "You need be a admin in connected group!")
                exit(1)
        else:
            return conn_id
    else:
        return False
Пример #12
0
def connected(bot, update, chat, user_id, need_admin=True):
    if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):
        conn_id = sql.get_connected_chat(user_id).chat_id
        if (bot.get_chat_member(conn_id, user_id).status in ('administrator', 'creator') or 
                                     (sql.allow_connect_to_chat(connect_chat) == True) and 
                                     bot.get_chat_member(user_id, update.effective_message.from_user.id).status in ('member')) or (
                                     user_id in SUDO_USERS):
            if need_admin == True:
                if bot.get_chat_member(conn_id, update.effective_message.from_user.id).status in ('administrator', 'creator') or user_id in SUDO_USERS:
                    return conn_id
                else:
                    update.effective_message.reply_text("Bağlı bir grupta yönetici olmanız gerekir!")
                    exit(1)
            else:
                return conn_id
        else:
            update.effective_message.reply_text("Grup değiştirilen hak bağlantısı veya artık yönetici değilsiniz. \ NSizin bağlantısını keseceğim.")
            disconnect_chat(bot, update)
            exit(1)
    else:
        return False
Пример #13
0
def keyboard(bot, update):
    user = update.effective_user  # type: Optional[User]
    conn_id = con_sql.get_connected_chat(user.id)
    if conn_id and not conn_id == False:
        btn1 = "/disconnect - Disconnect from chat"
        btn2 = ""
        btn3 = ""
    else:
        if con_sql.get_history(user.id):
            history = con_sql.get_history(user.id)
        try:
            chat_name1 = dispatcher.bot.getChat(history.chat_id1).title
        except:
            chat_name1 = ""

        try:
            chat_name2 = dispatcher.bot.getChat(history.chat_id2).title
        except:
            chat_name2 = ""

        try:
            chat_name3 = dispatcher.bot.getChat(history.chat_id3).title
        except:
            chat_name3 = ""

        if chat_name1:
            btn1 = "/connect {} - {}".format(history.chat_id1, chat_name1)
        else:
            btn1 = "/connect - Connect to the chat"
        if chat_name2:
            btn2 = "/connect {} - {}".format(history.chat_id2, chat_name2)
        else:
            btn2 = ""
        if chat_name3:
            btn3 = "/connect {} - {}".format(history.chat_id3, chat_name3)
        else:
            btn3 = ""

        #TODO: Remove except garbage

    update.effective_message.reply_text(
        "keyboard updated",
        reply_markup=ReplyKeyboardMarkup([
            [
                KeyboardButton("/help - Bot Help"),
                #KeyboardButton("/donate - Donate"),
                KeyboardButton("/notes - Notes")
            ],
            [KeyboardButton(btn1)],
            [KeyboardButton(btn2)],
            [KeyboardButton(btn3)]
        ]))
Пример #14
0
def connected(bot: Bot, update: Update, chat, user_id, need_admin=True):
    user = update.effective_user
    msg = update.effective_message
    spam = spamfilters(msg.text, msg.from_user.id, update.effective_chat.id)

    if spam is True:
        return

    if chat.type == chat.PRIVATE and sql.get_connected_chat(user_id):

        conn_id = sql.get_connected_chat(user_id).chat_id
        getstatusadmin = bot.get_chat_member(conn_id, msg.from_user.id)
        isadmin = getstatusadmin.status in ADMIN_STATUS
        ismember = getstatusadmin.status in MEMBER_STAUS
        isallow = sql.allow_connect_to_chat(conn_id)

        if (isadmin or (isallow and ismember) or (user.id in SUDO_USERS)
                or (user.id in DEV_USERS)):
            if need_admin is True:
                if (getstatusadmin.status in ADMIN_STATUS
                        or user_id in SUDO_USERS or user.id in DEV_USERS):
                    return conn_id
                else:
                    send_message(
                        msg,
                        "Anda harus menjadi admin di grup yang terhubung!")
                    raise Exception("Bukan admin!")
            else:
                return conn_id
        else:
            send_message(
                msg,
                "Grup mengubah hak koneksi atau Anda bukan lagi admin.\n"
                "Saya telah memutuskan Anda.",
            )
            disconnect_chat(bot, update)
            raise Exception("Bukan admin!")
    else:
        return False
Пример #15
0
def get(bot, update, notename, show_none=True, no_format=False):
    if not get_connected_chat(update.effective_message.from_user.id):
        chat_id = update.effective_chat.id
    else:
        chat_id = get_connected_chat(
            update.effective_message.from_user.id).chat_id
    chat = update.effective_chat  # type: Optional[Chat]
    user = update.effective_user  # type: Optional[User]
    conn = connected(bot, update, chat, user.id, need_admin=False)
    if not conn == False:
        chat_id = conn
        send_id = user.id
    else:
        chat_id = update.effective_chat.id
        send_id = chat_id
    note = sql.get_note(chat_id, notename)
    message = update.effective_message  # type: Optional[Message]

    if note:
        # If we're replying to a message, reply to that message (unless it's an error)
        if message.reply_to_message:
            reply_id = message.reply_to_message.message_id
        else:
            reply_id = message.message_id

        if note.is_reply:
            if MESSAGE_DUMP:
                try:
                    bot.forward_message(chat_id=chat_id,
                                        from_chat_id=MESSAGE_DUMP,
                                        message_id=note.value)
                except BadRequest as excp:
                    if excp.message == "Message to forward not found":
                        message.reply_text(
                            "This message seems to have been lost - I'll remove it "
                            "from your notes list.")
                        sql.rm_note(chat_id, notename)
                    else:
                        raise
            else:
                try:
                    bot.forward_message(chat_id=chat_id,
                                        from_chat_id=chat_id,
                                        message_id=note.value)
                except BadRequest as excp:
                    if excp.message == "Message to forward not found":
                        message.reply_text(
                            "Looks like the original sender of this note has deleted "
                            "their message - sorry! Get your bot admin to start using a "
                            "message dump to avoid this. I'll remove this note from "
                            "your saved notes.")
                        sql.rm_note(chat_id, notename)
                    else:
                        raise
        else:
            text = note.value
            keyb = []
            parseMode = ParseMode.MARKDOWN
            buttons = sql.get_buttons(chat_id, notename)
            if no_format:
                parseMode = None
                text += revert_buttons(buttons)
            else:
                keyb = build_keyboard(buttons)

            keyboard = InlineKeyboardMarkup(keyb)

            try:
                if note.msgtype in (sql.Types.BUTTON_TEXT, sql.Types.TEXT):
                    bot.send_message(send_id,
                                     text,
                                     reply_to_message_id=reply_id,
                                     parse_mode=parseMode,
                                     disable_web_page_preview=True,
                                     reply_markup=keyboard)
                else:
                    ENUM_FUNC_MAP[note.msgtype](send_id,
                                                note.file,
                                                caption=text,
                                                reply_to_message_id=reply_id,
                                                parse_mode=parseMode,
                                                disable_web_page_preview=True,
                                                reply_markup=keyboard)

            except BadRequest as excp:
                print(excp.message)
                if excp.message == "Entity_mention_user_invalid":
                    message.reply_text(
                        "Looks like you tried to mention someone I've never seen before. If you really "
                        "want to mention them, forward one of their messages to me, and I'll be able "
                        "to tag them!")
                elif FILE_MATCHER.match(note.value):
                    message.reply_text(
                        "This note was an incorrectly imported file from another bot - I can't use "
                        "it. If you really need it, you'll have to save it again. In "
                        "the meantime, I'll remove it from your notes list.")
                    sql.rm_note(chat_id, notename)
                else:
                    message.reply_text(
                        "This note could not be sent, as it is incorrectly formatted. "
                        "Please save it again with proper formatting. ")
                    LOGGER.exception("Could not parse message #%s in chat %s",
                                     notename, str(chat_id))
                    LOGGER.warning("Message was: %s", str(note.value))
        return
    elif show_none:
        message.reply_text("This note doesn't exist")