def disconnect_chat(bot, update): chat = update.effective_chat # type: Optional[Chat] if update.effective_chat.type == 'private': disconnection_status = sql.disconnect( update.effective_message.from_user.id) if disconnection_status: sql.disconnected_chat = update.effective_message.reply_text( tld(chat.id, "connection_dis_success")) # Rebuild user's keyboard keyboard(bot, update) else: update.effective_message.reply_text( tld(chat.id, "connection_dis_fail")) else: update.effective_message.reply_text(tld(chat.id, 'common_cmd_pm_only'))
def disconnect_chat(bot, update): if update.effective_chat.type == 'private': disconnection_status = sql.disconnect( update.effective_message.from_user.id) if disconnection_status: sql.disconnected_chat = update.effective_message.reply_text( "Disconnected from chat!") # Rebuild user's keyboard keyboard(bot, update) else: update.effective_message.reply_text("Disconnection unsuccessfull!") elif update.effective_chat.type == 'supergroup': disconnection_status = sql.disconnect( update.effective_message.from_user.id) if disconnection_status: sql.disconnected_chat = update.effective_message.reply_text( "Disconnected from chat!") # Rebuild user's keyboard keyboard(bot, update) else: update.effective_message.reply_text("Disconnection unsuccessfull!") else: update.effective_message.reply_text("Usage is restricted to PMs only")
def connect_chat(bot, update, args): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] if update.effective_chat.type == 'private': if len(args) >= 1: try: connect_chat = int(args[0]) except ValueError: update.effective_message.reply_text( tld(chat.id, "common_err_invalid_chatid")) return if (bot.get_chat_member( connect_chat, update.effective_message.from_user.id).status in ('administrator', 'creator') or (sql.allow_connect_to_chat(connect_chat) is True) and bot.get_chat_member( connect_chat, update.effective_message.from_user.id).status in ('member')) or (user.id in SUDO_USERS): connection_status = sql.connect( update.effective_message.from_user.id, connect_chat) if connection_status: chat_name = dispatcher.bot.getChat( connected(bot, update, chat, user.id, need_admin=False)).title update.effective_message.reply_text( tld(chat.id, "connection_success").format(chat_name), parse_mode=ParseMode.MARKDOWN) if history := sql.get_history(user.id): # Vars if history.chat_id1: history1 = int(history.chat_id1) if history.chat_id2: history2 = int(history.chat_id2) if history.chat_id3: history3 = int(history.chat_id3) if history.updated: number = history.updated if number == 1 and connect_chat != history2 and connect_chat != history3: history1 = connect_chat number = 2 elif number == 2 and connect_chat != history1 and connect_chat != history3: history2 = connect_chat number = 3 elif number >= 3 and connect_chat != history2 and connect_chat != history1: history3 = connect_chat number = 1 else: print("Error") print(history.updated) print(number) sql.add_history(user.id, history1, history2, history3, number) else: sql.add_history(user.id, connect_chat, "0", "0", 2) # Rebuild user's keyboard keyboard(bot, update) else: update.effective_message.reply_text( tld(chat.id, "connection_fail")) else: update.effective_message.reply_text( tld(chat.id, "connection_err_not_allowed")) else: update.effective_message.reply_text( tld(chat.id, "connection_err_no_chatid")) history = sql.get_history(user.id)
def connect_chat(bot, update, args): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] if update.effective_chat.type == 'private': if len(args) >= 1: try: connect_chat = int(args[0]) except ValueError: update.effective_message.reply_text( tld(chat.id, "Invalid Chat ID provided!")) return if (bot.get_chat_member( connect_chat, update.effective_message.from_user.id).status in ('administrator', 'creator') or (sql.allow_connect_to_chat(connect_chat) == True) and bot.get_chat_member( connect_chat, update.effective_message.from_user.id).status in ('member')) or (user.id in SUDO_USERS): connection_status = sql.connect( update.effective_message.from_user.id, connect_chat) if connection_status: chat_name = dispatcher.bot.getChat( connected(bot, update, chat, user.id, need_admin=False)).title update.effective_message.reply_text( tld(chat.id, "Successfully connected to *{}*").format( chat_name), parse_mode=ParseMode.MARKDOWN) # Add chat to connection history history = sql.get_history(user.id) if history: # Vars if history.chat_id1: history1 = int(history.chat_id1) if history.chat_id2: history2 = int(history.chat_id2) if history.chat_id3: history3 = int(history.chat_id3) if history.updated: number = history.updated if number == 1 and connect_chat != history2 and connect_chat != history3: history1 = connect_chat number = 2 elif number == 2 and connect_chat != history1 and connect_chat != history3: history2 = connect_chat number = 3 elif number >= 3 and connect_chat != history2 and connect_chat != history1: history3 = connect_chat number = 1 else: print("Error") print(history.updated) print(number) sql.add_history(user.id, history1, history2, history3, number) # print(history.user_id, history.chat_id1, history.chat_id2, history.chat_id3, history.updated) else: sql.add_history(user.id, connect_chat, "0", "0", 2) # Rebuild user's keyboard keyboard(bot, update) else: update.effective_message.reply_text( tld(chat.id, "Connection failed!")) else: update.effective_message.reply_text( tld(chat.id, "Connections to this chat not allowed!")) else: update.effective_message.reply_text( tld(chat.id, "Input chat ID to connect!")) history = sql.get_history(user.id) # print(history.user_id, history.chat_id1, history.chat_id2, history.chat_id3, history.updated) elif update.effective_chat.type == 'supergroup': connect_chat = chat.id if (bot.get_chat_member(connect_chat, update.effective_message.from_user.id).status in ('administrator', 'creator') or (sql.allow_connect_to_chat(connect_chat) == True) and bot.get_chat_member( connect_chat, update.effective_message.from_user.id).status in 'member') or (user.id in SUDO_USERS): connection_status = sql.connect( update.effective_message.from_user.id, connect_chat) if connection_status: update.effective_message.reply_text( tld(chat.id, "Succesfully connected to *{}*").format(chat.id), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( tld(chat.id, "Failed to connect to *{}*").format(chat.id), parse_mode=ParseMode.MARKDOWN) else: update.effective_message.reply_text( tld(chat.id, "You are not admin!")) else: update.effective_message.reply_text( tld(chat.id, "Usage is limited to PMs only!"))