def connection_chat(bot: Bot, update: Update):

    chat = update.effective_chat
    user = update.effective_user

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id)
    if spam == True:
        return

    conn = connected(bot, update, chat, user.id, need_admin=True)

    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type != "private":
            return
        chat = update.effective_chat
        chat_name = update.effective_message.chat.title

    if conn:
        message = "Hazırda {} ilə əlaqə qurmusunuz.\n".format(chat_name)
    else:
        message = "Hal-hazırda heç bir qrupa bağlı deyilsiniz.\n"
    send_message(update.effective_message, message, parse_mode="markdown")
Example #2
0
def connection_chat(bot: Bot, update: Update):

    chat = update.effective_chat
    user = update.effective_user

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id)
    if spam == True:
        return

    conn = connected(bot, update, chat, user.id, need_admin=True)

    if conn:
        chat = dispatcher.bot.getChat(conn)
        chat_name = dispatcher.bot.getChat(conn).title
    else:
        if update.effective_message.chat.type != "private":
            return
        chat = update.effective_chat
        chat_name = update.effective_message.chat.title

    if conn:
        message = "You are currently connected with {}.\n".format(chat_name)
    else:
        message = "You are currently not connected in any group.\n"
    send_message(update.effective_message, message, parse_mode="markdown")
Example #3
0
def connected(bot, update, chat, user_id, need_admin=True):

    user = update.effective_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) or (user.id in DEV_USERS):
            if need_admin == True:
                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!")
                    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
Example #4
0
def help_connect_chat(bot: Bot, update: Update):

    spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id)
    if spam == True:
        return

    if update.effective_message.chat.type != "private":
        send_message(update.effective_message, "PM me with that command to get help.")
        return
    else:
        send_message(update.effective_message, "All commands", parse_mode="markdown")
Example #5
0
def disconnect_chat(bot: Bot, update: Update):

    spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id)
    if spam == True:
        return

    if update.effective_chat.type == 'private':
        disconnection_status = sql.disconnect(update.effective_message.from_user.id)
        if disconnection_status:
           sql.disconnected_chat = send_message(update.effective_message, "Disconnected Successfully this from chat!")
        else:
           send_message(update.effective_message, "You're not connected!")
    else:
        send_message(update.effective_message, "This command is only available in PM.")
def help_connect_chat(bot: Bot, update: Update):

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id)
    if spam == True:
        return

    if update.effective_message.chat.type != "private":
        send_message(update.effective_message,
                     "Kömək almaq üçün bu əmrlə mənə PM də yazın.")
        return
    else:
        send_message(update.effective_message,
                     "Bütün əmrlər",
                     parse_mode="markdown")
def disconnect_chat(bot: Bot, update: Update):

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id)
    if spam == True:
        return

    if update.effective_chat.type == 'private':
        disconnection_status = sql.disconnect(
            update.effective_message.from_user.id)
        if disconnection_status:
            sql.disconnected_chat = send_message(
                update.effective_message,
                "Bu söhbətdən müvəffəqiyyətlə ayrıldı!")
        else:
            send_message(update.effective_message, "Bağlı deyilsiniz!")
    else:
        send_message(update.effective_message,
                     "Bu əmr yalnız PM-də mövcuddur.")
def connected(bot, update, chat, user_id, need_admin=True):

    user = update.effective_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) or (
                user.id in DEV_USERS):
            if need_admin == True:
                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,
                                 "Bağlı qrupda bir admin olmalısınız!")
                    raise Exception("Not admin!")
            else:
                return conn_id
        else:
            send_message(
                update.effective_message,
                "Qrup əlaqə hüquqlarını dəyişdirdi, yada artıq idarəçi deyilsiniz.\nSizlə əlaqəni kəsdim."
            )
            disconnect_chat(bot, update)
            raise Exception("Not admin!")
    else:
        return False
Example #9
0
def connect_chat(bot: Bot, update: Update, args: List[str]):

    chat = update.effective_chat
    user = update.effective_user

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id)
    if spam == True:
        return

    if update.effective_chat.type == 'private':
        if len(args) >= 1:
            try:
                connect_chat = int(args[0])
                getstatusadmin = bot.get_chat_member(
                    connect_chat, update.effective_message.from_user.id)
            except ValueError:
                try:
                    connect_chat = str(args[0])
                    get_chat = bot.getChat(connect_chat)
                    connect_chat = get_chat.id
                    getstatusadmin = bot.get_chat_member(
                        connect_chat, update.effective_message.from_user.id)
                except BadRequest:
                    send_message(update.effective_message,
                                 "Please Check Your Chat ID!")
                    return
            except BadRequest:
                send_message(update.effective_message,
                             "Please Check Your Chat ID!")
                return

            isadmin = getstatusadmin.status in ('administrator', 'creator')
            ismember = getstatusadmin.status in ('member')
            isallow = sql.allow_connect_to_chat(connect_chat)

            if (isadmin) or (isallow and ismember) or (
                    user.id in SUDO_USERS) or (user.id in DEV_USERS):
                connection_status = sql.connect(
                    update.effective_message.from_user.id, connect_chat)
                if connection_status:
                    conn_chat = dispatcher.bot.getChat(
                        connected(bot, update, chat, user.id,
                                  need_admin=False))
                    chat_name = conn_chat.title
                    send_message(
                        update.effective_message,
                        "Successfully connected to *{}*. Use /connection for see current available commands."
                        .format(chat_name),
                        parse_mode=ParseMode.MARKDOWN)
                    sql.add_history_conn(user.id, str(conn_chat.id), chat_name)
                else:
                    send_message(update.effective_message,
                                 "_Connection failed!_")
            else:
                send_message(update.effective_message,
                             "Connection to this chat is not allowed!")
        else:
            gethistory = sql.get_history_conn(user.id)
            if gethistory:
                buttons = [
                    InlineKeyboardButton(text="🔐 CLOSE",
                                         callback_data="connect_close"),
                    InlineKeyboardButton(text="CLEAR",
                                         callback_data="connect_clear")
                ]
            else:
                buttons = []
            conn = connected(bot, update, chat, user.id, need_admin=False)
            if conn:
                connectedchat = dispatcher.bot.getChat(conn)
                text = "_You are connected to *{}* (`{}`)_".format(
                    connectedchat.title, conn)
                buttons.append(
                    InlineKeyboardButton(text="DISCONNECT",
                                         callback_data="connect_disconnect"))
            else:
                text = "_Write the chat ID or tag to connect!_"
            if gethistory:
                text += "\n\n*Connection history:*\n"
                text += "╒═══「 *Info* 」\n"
                text += "│  Sorted: `Newest`\n"
                text += "│\n"
                buttons = [buttons]
                for x in sorted(gethistory.keys(), reverse=True):
                    htime = time.strftime("%d/%m/%Y", time.localtime(x))
                    text += "╞═「 *{}* 」\n│   `{}`\n│   `{}`\n".format(
                        gethistory[x]['chat_name'], gethistory[x]['chat_id'],
                        htime)
                    text += "│\n"
                    buttons.append([
                        InlineKeyboardButton(
                            text=gethistory[x]['chat_name'],
                            callback_data="connect({})".format(
                                gethistory[x]['chat_id']))
                    ])
                text += "╘══「 Total {} Chats 」".format(
                    str(len(gethistory)) +
                    " (max)" if len(gethistory) == 5 else str(len(gethistory)))
                conn_hist = InlineKeyboardMarkup(buttons)
            elif buttons:
                conn_hist = InlineKeyboardMarkup([buttons])
            else:
                conn_hist = None
            send_message(update.effective_message,
                         text,
                         parse_mode="markdown",
                         reply_markup=conn_hist)

    else:
        getstatusadmin = bot.get_chat_member(
            chat.id, update.effective_message.from_user.id)
        isadmin = getstatusadmin.status in ('administrator', 'creator')
        ismember = getstatusadmin.status in ('member')
        isallow = sql.allow_connect_to_chat(chat.id)
        if (isadmin) or (isallow and ismember) or (user.id in SUDO_USERS) or (
                user.id in DEV_USERS):
            connection_status = sql.connect(
                update.effective_message.from_user.id, chat.id)
            if connection_status:
                chat_name = dispatcher.bot.getChat(chat.id).title
                send_message(
                    update.effective_message,
                    "Successfully Connected ==> *{}*".format(chat_name),
                    parse_mode=ParseMode.MARKDOWN)
                try:
                    sql.add_history_conn(user.id, str(chat.id), chat_name)
                    bot.send_message(
                        update.effective_message.from_user.id,
                        "You have connected with *{}*. Use /connection for see current available commands."
                        .format(chat_name),
                        parse_mode="markdown")
                except BadRequest:
                    pass
                except Unauthorized:
                    pass
            else:
                send_message(update.effective_message, "Connection failed!")
        else:
            send_message(update.effective_message,
                         "Connection to this chat is not allowed!")
def connect_chat(bot: Bot, update: Update, args: List[str]):

    chat = update.effective_chat
    user = update.effective_user

    spam = spamfilters(update.effective_message.text,
                       update.effective_message.from_user.id,
                       update.effective_chat.id)
    if spam == True:
        return

    if update.effective_chat.type == 'private':
        if len(args) >= 1:
            try:
                connect_chat = int(args[0])
                getstatusadmin = bot.get_chat_member(
                    connect_chat, update.effective_message.from_user.id)
            except ValueError:
                try:
                    connect_chat = str(args[0])
                    get_chat = bot.getChat(connect_chat)
                    connect_chat = get_chat.id
                    getstatusadmin = bot.get_chat_member(
                        connect_chat, update.effective_message.from_user.id)
                except BadRequest:
                    send_message(update.effective_message,
                                 "Zəhmət olmasa Sohbet ID-nizi yoxlayın!")
                    return
            except BadRequest:
                send_message(update.effective_message,
                             "Zəhmət olmasa Sohbet ID-nizi yoxlayın!")
                return

            isadmin = getstatusadmin.status in ('administrator', 'creator')
            ismember = getstatusadmin.status in ('member')
            isallow = sql.allow_connect_to_chat(connect_chat)

            if (isadmin) or (isallow and ismember) or (
                    user.id in SUDO_USERS) or (user.id in DEV_USERS):
                connection_status = sql.connect(
                    update.effective_message.from_user.id, connect_chat)
                if connection_status:
                    conn_chat = dispatcher.bot.getChat(
                        connected(bot, update, chat, user.id,
                                  need_admin=False))
                    chat_name = conn_chat.title
                    send_message(
                        update.effective_message,
                        "*{}* İlə uğurla əlaqələndirildi. Mövcud əmrləri görmək üçün /connection istifadə edin."
                        .format(chat_name),
                        parse_mode=ParseMode.MARKDOWN)
                    sql.add_history_conn(user.id, str(conn_chat.id), chat_name)
                else:
                    send_message(update.effective_message,
                                 "_Bağlantı alınmadı!_")
            else:
                send_message(update.effective_message,
                             "Bu söhbətə qoşulmağa icazə verilmir!")
        else:
            gethistory = sql.get_history_conn(user.id)
            if gethistory:
                buttons = [
                    InlineKeyboardButton(text="✖️ Düyməni bağlayın",
                                         callback_data="connect_close"),
                    InlineKeyboardButton(text="🧹 Tarixçəni silin",
                                         callback_data="connect_clear")
                ]
            else:
                buttons = []
            conn = connected(bot, update, chat, user.id, need_admin=False)
            if conn:
                connectedchat = dispatcher.bot.getChat(conn)
                text = "_*{}* İlə əlaqə qurdunuz (`{}`)_".format(
                    connectedchat.title, conn)
                buttons.append(
                    InlineKeyboardButton(text="🔌 Ayırın",
                                         callback_data="connect_disconnect"))
            else:
                text = "_Qoşulmaq üçün söhbət ID-sini və ya etiketi yazın!_"
            if gethistory:
                text += "\n\n*Connection History:*\n"
                text += "╒═══「 *Məlumat* 」\n"
                text += "│  Çeşidləndi: Ən yeni`\n"
                text += "│\n"
                buttons = [buttons]
                for x in sorted(gethistory.keys(), reverse=True):
                    htime = time.strftime("%d/%m/%Y", time.localtime(x))
                    text += "╞═「 *{}* 」\n│   `{}`\n│   `{}`\n".format(
                        gethistory[x]['chat_name'], gethistory[x]['chat_id'],
                        htime)
                    text += "│\n"
                    buttons.append([
                        InlineKeyboardButton(
                            text=gethistory[x]['chat_name'],
                            callback_data="connect({})".format(
                                gethistory[x]['chat_id']))
                    ])
                text += "╘══「 Cəmi {} söhbət 」".format(
                    str(len(gethistory)) +
                    " (max)" if len(gethistory) == 5 else str(len(gethistory)))
                conn_hist = InlineKeyboardMarkup(buttons)
            elif buttons:
                conn_hist = InlineKeyboardMarkup([buttons])
            else:
                conn_hist = None
            send_message(update.effective_message,
                         text,
                         parse_mode="markdown",
                         reply_markup=conn_hist)

    else:
        getstatusadmin = bot.get_chat_member(
            chat.id, update.effective_message.from_user.id)
        isadmin = getstatusadmin.status in ('administrator', 'creator')
        ismember = getstatusadmin.status in ('member')
        isallow = sql.allow_connect_to_chat(chat.id)
        if (isadmin) or (isallow and ismember) or (user.id in SUDO_USERS) or (
                user.id in DEV_USERS):
            connection_status = sql.connect(
                update.effective_message.from_user.id, chat.id)
            if connection_status:
                chat_name = dispatcher.bot.getChat(chat.id).title
                send_message(
                    update.effective_message,
                    "Uğurla əlaqələndirildi ==> *{}*".format(chat_name),
                    parse_mode=ParseMode.MARKDOWN)
                try:
                    sql.add_history_conn(user.id, str(chat.id), chat_name)
                    bot.send_message(
                        update.effective_message.from_user.id,
                        "*{}* İlə əlaqə qurdunuz. Mövcud əmrləri görmək üçün /connection istifadə edin."
                        .format(chat_name),
                        parse_mode="markdown")
                except BadRequest:
                    pass
                except Unauthorized:
                    pass
            else:
                send_message(update.effective_message, "Bağlantı alınmadı!")
        else:
            send_message(update.effective_message,
                         "Bu söhbətə qoşulmağa icazə verilmir!")