def add_blackliststicker(update: Update, context: CallbackContext): bot = context.bot msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] words = msg.text.split(None, 1) bot = context.bot conn = connected(bot, update, chat, user.id) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: chat_id = update.effective_chat.id if chat.type == "private": return else: chat_name = chat.title if len(words) > 1: text = words[1].replace("https://t.me/addstickers/", "") to_blacklist = list( {trigger.strip() for trigger in text.split("\n") if trigger.strip()} ) added = 0 for trigger in to_blacklist: try: get = bot.getStickerSet(trigger) sql.add_to_stickers(chat_id, trigger.lower()) added += 1 except BadRequest: send_message( update.effective_message, "Sticker `{}` can not be found!".format(trigger), parse_mode="markdown", ) if added == 0: return if len(to_blacklist) == 1: send_message( update.effective_message, "Sticker <code>{}</code> added to blacklist stickers in <b>{}</b>!".format( html.escape(to_blacklist[0]), html.escape(chat_name) ), parse_mode=ParseMode.HTML, ) else: send_message( update.effective_message, "<code>{}</code> stickers added to blacklist sticker in <b>{}</b>!".format( added, html.escape(chat_name) ), parse_mode=ParseMode.HTML, ) elif msg.reply_to_message: added = 0 trigger = msg.reply_to_message.sticker.set_name if trigger is None: send_message(update.effective_message, "Sticker is invalid!") return try: get = bot.getStickerSet(trigger) sql.add_to_stickers(chat_id, trigger.lower()) added += 1 except BadRequest: send_message( update.effective_message, "Sticker `{}` can not be found!".format(trigger), parse_mode="markdown", ) if added == 0: return send_message( update.effective_message, "Sticker <code>{}</code> added to blacklist stickers in <b>{}</b>!".format( trigger, html.escape(chat_name) ), parse_mode=ParseMode.HTML, ) else: send_message( update.effective_message, "Tell me what stickers you want to add to the blacklist.", )
def __import_data__(chat_id, data): # set chat blacklist blacklist = data.get("sticker_blacklist", {}) for trigger in blacklist: sql.add_to_stickers(chat_id, trigger)