def rmall_filters(update, context): chat = update.effective_chat user = update.effective_user msg = update.effective_message usermem = chat.get_member(user.id) if not usermem.status == "creator": msg.reply_text( "Perintah ini hanya dapat digunakan oleh PEMILIK obrolan!") return allfilters = sql.get_chat_triggers(chat.id) if not allfilters: msg.reply_text( "Tidak ada filter dalam obrolan ini, tidak ada yang bisa dihentikan!" ) return count = 0 filterlist = [] for x in allfilters: count += 1 filterlist.append(x) for i in filterlist: sql.remove_filter(chat.id, i) return msg.reply_text(f"Cleaned {count} filters in {chat.title}")
def addnew_filter(update, chat_id, keyword, text, file_type, file_id, buttons): msg = update.effective_message totalfilt = sql.get_chat_triggers(chat_id) if len(totalfilt) >= 50: # Idk why i made this like function.... msg.reply_text( "Anda tidak dapat memiliki lebih dari lima puluh filter sekaligus! coba hapus beberapa sebelum menambahkan filter baru." ) return False else: sql.new_add_filter(chat_id, keyword, text, file_type, file_id, buttons) return True
def list_handlers(update, context): chat = update.effective_chat user = update.effective_user conn = connected(context.bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title filter_list = "*Filter in {}:*\n" else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "Local filters" filter_list = "*local filters:*\n" else: chat_name = chat.title filter_list = "*Filters in {}*:\n" all_handlers = sql.get_chat_triggers(chat_id) if not all_handlers: send_message( update.effective_message, "Tidak ada filter yang disimpan di {}!".format(chat_name), ) return for keyword in all_handlers: entry = " × `{}`\n".format(escape_markdown(keyword)) if len(entry) + len(filter_list) > telegram.MAX_MESSAGE_LENGTH: send_message( update.effective_message, filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN, ) filter_list = entry else: filter_list += entry send_message( update.effective_message, filter_list.format(chat_name), parse_mode=telegram.ParseMode.MARKDOWN, )
def stop_filter(update, context): chat = update.effective_chat user = update.effective_user args = update.effective_message.text.split(None, 1) conn = connected(context.bot, update, chat, user.id) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "Local filters" else: chat_name = chat.title if len(args) < 2: send_message(update.effective_message, "Apa yang harus saya hentikan?") return chat_filters = sql.get_chat_triggers(chat_id) if not chat_filters: send_message(update.effective_message, "Tidak ada filter yang aktif di sini!") return for keyword in chat_filters: if keyword == args[1]: sql.remove_filter(chat_id, args[1]) send_message( update.effective_message, "Oke, saya akan berhenti membalas filter itu *{}*.".format( chat_name), parse_mode=telegram.ParseMode.MARKDOWN, ) raise DispatcherHandlerStop send_message( update.effective_message, "Itu bukan filter - Klik: /filters untuk mendapatkan filter yang sedang aktif.", )
def __chat_settings__(chat_id, user_id): cust_filters = sql.get_chat_triggers(chat_id) return "Ada `{}` filter ubahsuaian di sini.".format(len(cust_filters))
def reply_filter(update, context): chat = update.effective_chat message = update.effective_message to_match = extract_text(message) if not to_match: return chat_filters = sql.get_chat_triggers(chat.id) for keyword in chat_filters: pattern = r"( |^|[^\w])" + re.escape(keyword) + r"( |$|[^\w])" if re.search(pattern, to_match, flags=re.IGNORECASE): filt = sql.get_filter(chat.id, keyword) if filt.reply == "harus ada balasan baru": buttons = sql.get_buttons(chat.id, filt.keyword) keyb = build_keyboard_parser(context.bot, chat.id, buttons) keyboard = InlineKeyboardMarkup(keyb) VALID_WELCOME_FORMATTERS = [ "first", "last", "fullname", "username", "id", "chatname", "mention", ] if filt.reply_text: valid_format = escape_invalid_curly_brackets( filt.reply_text, VALID_WELCOME_FORMATTERS) if valid_format: filtext = valid_format.format( first=escape(message.from_user.first_name), last=escape(message.from_user.last_name or message.from_user.first_name), fullname=" ".join( [ escape(message.from_user.first_name), escape(message.from_user.last_name), ] if message.from_user.last_name else [escape(message.from_user.first_name)]), username="******" + escape(message.from_user.username) if message.from_user.username else mention_html( message.from_user.id, message.from_user.first_name, ), mention=mention_html( message.from_user.id, message.from_user.first_name, ), chatname=escape(message.chat.title) if message.chat.type != "private" else escape( message.from_user.first_name), id=message.from_user.id, ) else: filtext = "" else: filtext = "" if filt.file_type in (sql.Types.BUTTON_TEXT, sql.Types.TEXT): try: context.bot.send_message( chat.id, markdown_to_html(filtext), reply_to_message_id=message.message_id, parse_mode=ParseMode.HTML, reply_markup=keyboard, ) except BadRequest as excp: error_catch = get_exception(excp, filt, chat) if error_catch == "noreply": try: context.bot.send_message( chat.id, markdown_to_html(filtext), parse_mode=ParseMode.HTML, reply_markup=keyboard, ) except BadRequest as excp: LOGGER.exception("Error in filters: " + excp.message) send_message( update.effective_message, get_exception(excp, filt, chat), ) else: try: send_message( update.effective_message, get_exception(excp, filt, chat), ) except BadRequest as excp: LOGGER.exception("Failed to send message: " + excp.message) else: if (ENUM_FUNC_MAP[filt.file_type] == dispatcher.bot.send_sticker): ENUM_FUNC_MAP[filt.file_type]( chat.id, filt.file_id, reply_to_message_id=message.message_id, reply_markup=keyboard, ) else: ENUM_FUNC_MAP[filt.file_type]( chat.id, filt.file_id, caption=markdown_to_html(filtext), reply_to_message_id=message.message_id, parse_mode=ParseMode.HTML, reply_markup=keyboard, ) break else: if filt.is_sticker: message.reply_sticker(filt.reply) elif filt.is_document: message.reply_document(filt.reply) elif filt.is_image: message.reply_photo(filt.reply) elif filt.is_audio: message.reply_audio(filt.reply) elif filt.is_voice: message.reply_voice(filt.reply) elif filt.is_video: message.reply_video(filt.reply) elif filt.has_markdown: buttons = sql.get_buttons(chat.id, filt.keyword) keyb = build_keyboard_parser(context.bot, chat.id, buttons) keyboard = InlineKeyboardMarkup(keyb) try: send_message( update.effective_message, filt.reply, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard, ) except BadRequest as excp: if excp.message == "Unsupported url protocol": try: send_message( update.effective_message, "Anda tampaknya mencoba menggunakan protokol url yang tidak didukung. " "Telegram tidak mendukung tombol untuk beberapa protokol, seperti tg://. Silakan coba " "lagi...", ) except BadRequest as excp: LOGGER.exception("Error in filters: " + excp.message) elif excp.message == "Pesan balasan tidak ditemukan": try: context.bot.send_message( chat.id, filt.reply, parse_mode=ParseMode.MARKDOWN, reply_markup=keyboard, ) except BadRequest as excp: LOGGER.exception("Error in filters: " + excp.message) else: try: send_message( update.effective_message, "Pesan ini tidak dapat dikirim karena formatnya salah.", ) except BadRequest as excp: LOGGER.exception("Error in filters: " + excp.message) LOGGER.warning( "Message %s could not be parsed", str(filt.reply), ) LOGGER.exception( "Could not parse filter %s in chat %s", str(filt.keyword), str(chat.id), ) else: # LEGACY - all new filters will have has_markdown set to # True. try: send_message(update.effective_message, filt.reply) except BadRequest as excp: LOGGER.exception("Error in filters: " + excp.message) break