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 in ("member") isallow = sql.allow_connect_to_chat(conn_id) if ((isadmin) or (isallow and ismember) or (user.id in DRAGONS) or (user.id in DEV_USERS)): if need_admin is True: if (getstatusadmin.status in ("administrator", "creator") or user_id in DRAGONS or user.id in DEV_USERS): return conn_id else: send_message( update.effective_message, "Sən qoşulmuş qrupda admin olmalısan!", ) else: return conn_id else: send_message( update.effective_message, "Qrup əlaqə hüquqlarını dəyişdirdi, və ya artıq admin deyilsən. \nSizlə əlaqəni kəsdim.", ) disconnect_chat(update, bot) else: return False
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 in ("member") isallow = sql.allow_connect_to_chat(conn_id) if ((isadmin) or (isallow and ismember) or (user.id in DRAGONS) or (user.id in DEV_USERS)): if need_admin is True: if (getstatusadmin.status in ("administrator", "creator") or user_id in DRAGONS 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: 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(update, bot) else: return False
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, "Bağlı grupta yönetici olmalısınız!") raise Exception("Yönetici değil!") else: return conn_id else: send_message( msg, "Grup bağlantı haklarını değiştirdi veya artık yönetici değilsiniz.\n" "Seni ayırdım.") disconnect_chat(bot, update) raise Exception("Yönetici değil!") else: return False
def allow_connections(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat if chat.type != chat.PRIVATE: if len(args) >= 1: var = args[0] if var == "no": sql.set_allow_connect_to_chat(chat.id, False) send_message(update.effective_message, "Bu sohbet için bağlantı devre dışı bırakıldı") elif var == "yes": sql.set_allow_connect_to_chat(chat.id, True) send_message(update.effective_message, "Bu sohbet için bağlantı etkinleştirildi") else: send_message(update.effective_message, "Lütfen gir`yes` or `no`!", parse_mode=ParseMode.MARKDOWN) else: get_settings = sql.allow_connect_to_chat(chat.id) if get_settings: send_message( update.effective_message, "Bu gruba bağlantılar üyeler için * İzin verilir *!", parse_mode=ParseMode.MARKDOWN) else: send_message( update.effective_message, "Bu gruba bağlantı üyeler için * İzin verilmez *!", parse_mode=ParseMode.MARKDOWN) else: send_message(update.effective_message, "Bu komut yalnızca grup içindir. PM'de değil!")
def connected(update, context, 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 = context.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(update, context) raise Exception("Not admin!") else: return False
def allow_connections(update: Update, context: CallbackContext): chat = update.effective_chat args = context.args if chat.type != chat.PRIVATE: if len(args) >= 1: var = args[0] if var == "no": sql.set_allow_connect_to_chat(chat.id, False) send_message(update.effective_message, "Connection has been disabled for this chat") elif var == "yes": sql.set_allow_connect_to_chat(chat.id, True) send_message(update.effective_message, "Connection has been enabled for this chat") else: send_message(update.effective_message, "Please enter `yes` or `no`!", parse_mode=ParseMode.MARKDOWN) else: get_settings = sql.allow_connect_to_chat(chat.id) if get_settings: send_message( update.effective_message, "Connections to this group are *Allowed* for members!", parse_mode=ParseMode.MARKDOWN) else: send_message( update.effective_message, "Connection to this group are *Not Allowed* for members!", parse_mode=ParseMode.MARKDOWN) else: send_message(update.effective_message, "This command is for group only. Not in PM!")
def connect_button(update, context): query = update.callback_query chat = update.effective_chat user = update.effective_user connect_match = re.match(r"connect\((.+?)\)", query.data) disconnect_match = query.data == "connect_disconnect" clear_match = query.data == "connect_clear" connect_close = query.data == "connect_close" if connect_match: target_chat = connect_match.group(1) getstatusadmin = context.bot.get_chat_member(target_chat, query.from_user.id) isadmin = getstatusadmin.status in ("administrator", "creator") ismember = getstatusadmin.status in ("member") isallow = sql.allow_connect_to_chat(target_chat) if (isadmin) or (isallow and ismember) or (user.id in DRAGONS): connection_status = sql.connect(query.from_user.id, target_chat) if connection_status: conn_chat = dispatcher.bot.getChat( connected(context.bot, update, chat, user.id, need_admin=False)) chat_name = conn_chat.title query.message.edit_text( "Successfully connected to *{}*. \nUse `/helpconnect` to check available commands." .format(chat_name), parse_mode=ParseMode.MARKDOWN, ) sql.add_history_conn(user.id, str(conn_chat.id), chat_name) else: query.message.edit_text("Connection failed!") else: context.bot.answer_callback_query( query.id, "Connection to this chat is not allowed!", show_alert=True) elif disconnect_match: disconnection_status = sql.disconnect(query.from_user.id) if disconnection_status: sql.disconnected_chat = query.message.edit_text( "Disconnected from chat!") else: context.bot.answer_callback_query(query.id, "You're not connected!", show_alert=True) elif clear_match: sql.clear_history_conn(query.from_user.id) query.message.edit_text("History connected has been cleared!") elif connect_close: query.message.edit_text("Closed.\nTo open again, type /connect") else: connect_chat(update, context)
def connect_button(update, context): query = update.callback_query chat = update.effective_chat user = update.effective_user connect_match = re.match(r"connect\((.+?)\)", query.data) disconnect_match = query.data == "connect_disconnect" clear_match = query.data == "connect_clear" connect_close = query.data == "connect_close" if connect_match: target_chat = connect_match.group(1) getstatusadmin = context.bot.get_chat_member(target_chat, query.from_user.id) isadmin = getstatusadmin.status in ("administrator", "creator") ismember = getstatusadmin.status in ("member") isallow = sql.allow_connect_to_chat(target_chat) if (isadmin) or (isallow and ismember) or (user.id in DRAGONS): connection_status = sql.connect(query.from_user.id, target_chat) if connection_status: conn_chat = dispatcher.bot.getChat( connected(context.bot, update, chat, user.id, need_admin=False)) chat_name = conn_chat.title query.message.edit_text( "*{}* qrupu ilə əlaqə uğurla yaradıldı. \n`/helpconnect` yazaraq mövcud əmrlərə baxa bilərsən." .format(chat_name), parse_mode=ParseMode.MARKDOWN, ) sql.add_history_conn(user.id, str(conn_chat.id), chat_name) else: query.message.edit_text("Əlaqə uğursuz oldu!") else: context.bot.answer_callback_query( query.id, "Bu qrupa qoşulmalar deaktiv edilib!", show_alert=True) elif disconnect_match: disconnection_status = sql.disconnect(query.from_user.id) if disconnection_status: sql.disconnected_chat = query.message.edit_text( "Qrup ilə əlaqə kəsildi!") else: context.bot.answer_callback_query(query.id, "Sən qoşulmamısan!", show_alert=True) elif clear_match: sql.clear_history_conn(query.from_user.id) query.message.edit_text("Qoşulmalarla bağlı tarixçə silindi!") elif connect_close: query.message.edit_text("Bağlandı.\nYenidən qoşulmaq üçün /connect") else: connect_chat(update, context)
def connect_button(update: Update, context: CallbackContext): query = update.callback_query chat = update.effective_chat user = update.effective_user bot = context.bot connect_match = re.match(r"connect\((.+?)\)", query.data) disconnect_match = query.data == "connect_disconnect" clear_match = query.data == "connect_clear" connect_close = query.data == "connect_close" if connect_match: target_chat = connect_match.group(1) getstatusadmin = bot.get_chat_member(target_chat, query.from_user.id) isadmin = getstatusadmin.status in ADMIN_STATUS ismember = getstatusadmin.status in MEMBER_STAUS isallow = sql.allow_connect_to_chat(target_chat) if isadmin or (isallow and ismember) or (user.id in SUDO_USERS) or ( user.id in DEV_USERS): connection_status = sql.connect(query.from_user.id, target_chat) if connection_status: conn_chat = bot.getChat( connected(update, context, chat, user.id, need_admin=False)) chat_name = conn_chat.title query.message.edit_text( f"Successfully connected to *{chat_name}*." f" Use /connection for see current available commands.", parse_mode=ParseMode.MARKDOWN) sql.add_history_conn(user.id, str(conn_chat.id), chat_name) else: query.message.edit_text("Connection failed!") else: bot.answer_callback_query( query.id, "Connection to this chat is not allowed!", show_alert=True) elif disconnect_match: disconnection_status = sql.disconnect(query.from_user.id) if disconnection_status: sql.disconnected_chat = query.message.edit_text( "Disconnected from chat!") else: bot.answer_callback_query(query.id, "You're not connected!", show_alert=True) elif clear_match: sql.clear_history_conn(query.from_user.id) query.message.edit_text("History connected has been cleared!") elif connect_close: query.message.edit_text("Closed.\nTo open again, type /connect") else: connect_chat(update, context, [])
def connect_button(bot: Bot, update: Update): query = update.callback_query chat = update.effective_chat user = update.effective_user connect_match = re.match(r"connect\((.+?)\)", query.data) disconnect_match = query.data == "connect_disconnect" clear_match = query.data == "connect_clear" connect_close = query.data == "connect_close" if connect_match: target_chat = connect_match.group(1) getstatusadmin = bot.get_chat_member(target_chat, query.from_user.id) isadmin = getstatusadmin.status in ADMIN_STATUS ismember = getstatusadmin.status in MEMBER_STAUS isallow = sql.allow_connect_to_chat(target_chat) if isadmin or (isallow and ismember) or (user.id in SUDO_USERS) or ( user.id in DEV_USERS): connection_status = sql.connect(query.from_user.id, target_chat) if connection_status: conn_chat = dispatcher.bot.getChat( connected(bot, update, chat, user.id, need_admin=False)) chat_name = conn_chat.title query.message.edit_text( f"Başarıyla bağlandı *{chat_name}*." f" Mevcut komutları görmek için /connection kullanın.", parse_mode=ParseMode.MARKDOWN) sql.add_history_conn(user.id, str(conn_chat.id), chat_name) else: query.message.edit_text("Bağlantı başarısız!!") else: bot.answer_callback_query(query.id, "Bu sohbete bağlantıya izin verilmiyor!", show_alert=True) elif disconnect_match: disconnection_status = sql.disconnect(query.from_user.id) if disconnection_status: sql.disconnected_chat = query.message.edit_text( "Sohbet bağlantısı kesildi!") else: bot.answer_callback_query(query.id, "Bağlı değilsin!", show_alert=True) elif clear_match: sql.clear_history_conn(query.from_user.id) query.message.edit_text("Bağlı tarih silindi!") elif connect_close: query.message.edit_text("Kapatıldı.\nTekrar açmak için /connect yazın") else: connect_chat(bot, update, [])
def allow_connections(update, context) -> str: chat = update.effective_chat args = context.args if chat.type != chat.PRIVATE: if len(args) >= 1: var = args[0] if var == "no": sql.set_allow_connect_to_chat(chat.id, False) send_message( update.effective_message, "Bu qrup üçün əlaqələr deaktiv edilib", ) elif var == "yes": sql.set_allow_connect_to_chat(chat.id, True) send_message( update.effective_message, "Bu qrup üçün əlaqələr aktiv edilib", ) else: send_message( update.effective_message, "Zəhmət olmasa `yes` və ya `no` istifadə edin!", parse_mode=ParseMode.MARKDOWN, ) else: get_settings = sql.allow_connect_to_chat(chat.id) if get_settings: send_message( update.effective_message, "Bu qrupa qoşulma (Connection) üzvlər üçün *İcazə verilir*!", parse_mode=ParseMode.MARKDOWN, ) else: send_message( update.effective_message, "Bu qrupa qoşulma (Connection) üzvlər üçün *İcazə verilmir*!", parse_mode=ParseMode.MARKDOWN, ) else: send_message(update.effective_message, "Bu əmr qrup üçündür!")
def connect_chat(update, context): chat = update.effective_chat user = update.effective_user args = context.args if update.effective_chat.type == "private": if args and len(args) >= 1: try: connect_chat = int(args[0]) getstatusadmin = context.bot.get_chat_member( connect_chat, update.effective_message.from_user.id) except ValueError: try: connect_chat = str(args[0]) get_chat = context.bot.getChat(connect_chat) connect_chat = get_chat.id getstatusadmin = context.bot.get_chat_member( connect_chat, update.effective_message.from_user.id) except BadRequest: send_message(update.effective_message, "Invalid Chat ID!") return except BadRequest: send_message(update.effective_message, "Invalid 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 DRAGONS): connection_status = sql.connect( update.effective_message.from_user.id, connect_chat) if connection_status: conn_chat = dispatcher.bot.getChat( connected(context.bot, update, chat, user.id, need_admin=False)) chat_name = conn_chat.title send_message( update.effective_message, "Successfully connected to *{}*. \nUse /helpconnect to check 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 button", callback_data="connect_close"), InlineKeyboardButton(text="🧹 Clear history", callback_data="connect_clear"), ] else: buttons = [] conn = connected(context.bot, update, chat, user.id, need_admin=False) if conn: connectedchat = dispatcher.bot.getChat(conn) text = "You are currently 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 = context.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 DRAGONS): 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 to *{}*.".format(chat_name), parse_mode=ParseMode.MARKDOWN, ) try: sql.add_history_conn(user.id, str(chat.id), chat_name) context.bot.send_message( update.effective_message.from_user.id, "You are connected to *{}*. \nUse `/helpconnect` to check 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(update, context): chat = update.effective_chat user = update.effective_user args = context.args if update.effective_chat.type == "private": if args and len(args) >= 1: try: connect_chat = int(args[0]) getstatusadmin = context.bot.get_chat_member( connect_chat, update.effective_message.from_user.id) except ValueError: try: connect_chat = str(args[0]) get_chat = context.bot.getChat(connect_chat) connect_chat = get_chat.id getstatusadmin = context.bot.get_chat_member( connect_chat, update.effective_message.from_user.id) except BadRequest: send_message(update.effective_message, "Yanlış qrup ID!") return except BadRequest: send_message(update.effective_message, "Yanlış qrup 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 DRAGONS): connection_status = sql.connect( update.effective_message.from_user.id, connect_chat) if connection_status: conn_chat = dispatcher.bot.getChat( connected(context.bot, update, chat, user.id, need_admin=False)) chat_name = conn_chat.title send_message( update.effective_message, "Uğurla *{}* qrupuna qoşuldu. \n/helpconnect istifadə edərək mövcud əmrlərə baxa bilərsən." .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, "Qoşulma uğursuz oldu!") else: send_message(update.effective_message, "Bu qrupa qoşulmalar deaktiv edilib!") else: gethistory = sql.get_history_conn(user.id) if gethistory: buttons = [ InlineKeyboardButton(text="❎ Bağla", callback_data="connect_close"), InlineKeyboardButton(text="🧹 Təmizlə", callback_data="connect_clear"), ] else: buttons = [] conn = connected(context.bot, update, chat, user.id, need_admin=False) if conn: connectedchat = dispatcher.bot.getChat(conn) text = "Sən hal hazırda bu qrupla əlaqə qurmusan *{}* (`{}`)".format( connectedchat.title, conn) buttons.append( InlineKeyboardButton(text="🔌 Əlaqəni kəs", callback_data="connect_disconnect")) else: text = "Qoşulmaq üçün qrup ID və ya etiketi yazın!" if gethistory: text += "\n\n*Əlaqə tarixçəsi:*\n" text += "╒═══「 *Info* 」\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 += "╘══「 Ümumi {} qrup 」".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 = context.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 DRAGONS): 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, "*{}* qrupu ilə əlaqə yaradıldı.".format(chat_name), parse_mode=ParseMode.MARKDOWN, ) try: sql.add_history_conn(user.id, str(chat.id), chat_name) context.bot.send_message( update.effective_message.from_user.id, "Sən hazırda *{}* qrupu ilə əlaqə yaratmısan. \n`/helpconnect` yazaraq mövcud əmrlərə baxa bilərsən." .format(chat_name), parse_mode="markdown", ) except BadRequest: pass except Unauthorized: pass else: send_message(update.effective_message, "Əlaqə uğursuz oldu!") else: send_message(update.effective_message, "Bu qrup ilə əlaqələr deaktiv edilib!")
def connect_chat(bot: Bot, update: Update, args: List[str]): chat = update.effective_chat user = update.effective_user msg = update.effective_message if chat.type == 'private': if len(args) >= 1: try: connect_chat = int(args[0]) getstatusadmin = bot.get_chat_member(connect_chat, msg.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, msg.from_user.id) except BadRequest: send_message(msg, "Geçersiz Sohbet Kimliği!") return except BadRequest: send_message(msg, "Geçersiz Sohbet Kimliği!!") return isadmin = getstatusadmin.status in ADMIN_STATUS ismember = getstatusadmin.status in MEMBER_STAUS 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(msg.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( msg, "Başarıyla bağlandı *{chat_name}*." " Mevcut komutları görmek için /connection kullanın.", parse_mode=ParseMode.MARKDOWN) sql.add_history_conn(user.id, str(conn_chat.id), chat_name) else: send_message(msg, "Bağlantı başarısız!") else: send_message(msg, "Bu sohbete bağlantıya izin verilmiyor!") else: gethistory = sql.get_history_conn(user.id) if gethistory: buttons = [ InlineKeyboardButton(text="❎ Close button", callback_data="connect_close"), InlineKeyboardButton(text="🧹 Clear history", callback_data="connect_clear") ] else: buttons = [] conn = connected(bot, update, chat, user.id, need_admin=False) if conn: connectedchat = dispatcher.bot.getChat(conn) text = "Bağlandınız *{}* (`{}`)".format( connectedchat.title, conn) buttons.append( InlineKeyboardButton(text="🔌 Disconnect", callback_data="connect_disconnect")) else: text = "Bağlanmak için sohbet kimliğini veya etiketini yazın!" if gethistory: text += "\n\n*Bağlantı geçmişi:*\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(msg, text, parse_mode="markdown", reply_markup=conn_hist) else: getstatusadmin = bot.get_chat_member(chat.id, msg.from_user.id) isadmin = getstatusadmin.status in ADMIN_STATUS ismember = getstatusadmin.status in MEMBER_STAUS 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(msg.from_user.id, chat.id) if connection_status: chat_name = dispatcher.bot.getChat(chat.id).title send_message(msg, "Başarıyla bağlandı *{}*.".format(chat_name), parse_mode=ParseMode.MARKDOWN) try: sql.add_history_conn(user.id, str(chat.id), chat_name) bot.send_message( msg.from_user.id, f"İle bağlandın *{chat_name}*." f" Mevcut komutları görmek için /connection kullanın.", parse_mode="markdown") except BadRequest: pass except Unauthorized: pass else: send_message(msg, "Bağlantı başarısız!") else: send_message(msg, "Bu sohbete bağlantıya izin verilmiyor!")
def connect_chat(update: Update, context: CallbackContext): chat = update.effective_chat user = update.effective_user msg = update.effective_message bot, args = context.bot, context.args if chat.type == 'private': if len(args) >= 1: try: connect_chat = int(args[0]) getstatusadmin = bot.get_chat_member(connect_chat, msg.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, msg.from_user.id) except BadRequest: send_message(msg, "Invalid Chat ID!") return except BadRequest: send_message(msg, "Invalid Chat ID!") return isadmin = getstatusadmin.status in ADMIN_STATUS ismember = getstatusadmin.status in MEMBER_STAUS 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(msg.from_user.id, connect_chat) if connection_status: conn_chat = dispatcher.bot.getChat( connected(update, context, chat, user.id, need_admin=False)) chat_name = conn_chat.title send_message( msg, "Successfully connected to *{chat_name}*." " Use /connection for see current available commands.", parse_mode=ParseMode.MARKDOWN) sql.add_history_conn(user.id, str(conn_chat.id), chat_name) else: send_message(msg, "Connection failed!") else: send_message(msg, "Connection to this chat is not allowed!") else: gethistory = sql.get_history_conn(user.id) if gethistory: buttons = [ InlineKeyboardButton(text="❎ Close button", callback_data="connect_close"), InlineKeyboardButton(text="🧹 Clear history", callback_data="connect_clear") ] else: buttons = [] conn = connected(update, context, 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(msg, text, parse_mode="markdown", reply_markup=conn_hist) else: getstatusadmin = bot.get_chat_member(chat.id, msg.from_user.id) isadmin = getstatusadmin.status in ADMIN_STATUS ismember = getstatusadmin.status in MEMBER_STAUS 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(msg.from_user.id, chat.id) if connection_status: chat_name = dispatcher.bot.getChat(chat.id).title send_message( msg, "Successfully connected to *{}*.".format(chat_name), parse_mode=ParseMode.MARKDOWN) try: sql.add_history_conn(user.id, str(chat.id), chat_name) bot.send_message( msg.from_user.id, f"You have connected with *{chat_name}*." f" Use /connection for see current available commands.", parse_mode="markdown") except BadRequest: pass except Unauthorized: pass else: send_message(msg, "Connection failed!") else: send_message(msg, "Connection to this chat is not allowed!")