Exemple #1
0
def connected(bot, update, chat, user_id, need_admin=True):
    chat = update.effective_chat  # type: Optional[Chat]
    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:
                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(
                        tld(chat.id, "connection_err_no_admin"))
                    return
            else:
                return conn_id
        else:
            update.effective_message.reply_text(
                tld(chat.id, "connection_err_unknown"))
            disconnect_chat(bot, update)
            return
    else:
        return False
Exemple #2
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:
                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
Exemple #3
0
def keyboard(bot, update):
    chat = update.effective_chat  # type: Optional[Chat]
    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 - {}".format(tld(chat.id, "keyboard_disconnect"))
        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 - {}".format(tld(chat.id, "keyboard_connect"))
        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(
        tld(chat.id, "keyboard_updated"),
        reply_markup=ReplyKeyboardMarkup([[
            KeyboardButton("/help - {}".format(tld(chat.id,
                                                   "keyboard_bothelp"))),
            KeyboardButton("/notes - {}".format(tld(chat.id,
                                                    "keyboard_notes")))
        ], [KeyboardButton(btn1)], [KeyboardButton(btn2)],
                                          [KeyboardButton(btn3)]]))