def add_blackliststicker(bot: Bot, update: Update): 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) spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return 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(set(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, tl(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, tl(update.effective_message, "Sticker <code>{}</code> added to blacklist sticker on <b>{}</b>!").format(html.escape(to_blacklist[0]), chat_name), parse_mode=ParseMode.HTML) else: send_message(update.effective_message, tl(update.effective_message, "<code>{}</code> sticker added to the sticker blacklist on <b>{}</b>!").format(added, chat_name), parse_mode=ParseMode.HTML) elif msg.reply_to_message: added = 0 trigger = msg.reply_to_message.sticker.set_name if trigger == None: send_message(update.effective_message, tl(update.effective_message, "Invalid sticker!")) return try: get = bot.getStickerSet(trigger) sql.add_to_stickers(chat_id, trigger.lower()) added += 1 except BadRequest: send_message(update.effective_message, tl(update.effective_message, "Sticker `{}` can not be found!").format(trigger), parse_mode="markdown") if added == 0: return send_message(update.effective_message, tl(update.effective_message, "Sticker <code>{}</code> added to blacklist sticker on <b>{}</b>!").format(trigger, chat_name), parse_mode=ParseMode.HTML) else: send_message(update.effective_message, tl(update.effective_message, "Tell me what stickers you want to add to the sticker blacklist."))
def blackliststicker(bot: Bot, update: Update, args: List[str]): msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return conn = connected(bot, update, chat, user.id, need_admin=False) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if chat.type == "private": return else: chat_id = update.effective_chat.id chat_name = chat.title sticker_list = tl(update.effective_message, "<b>Blacklist of stickers currently at {}:</b>\n").format(chat_name) all_stickerlist = sql.get_chat_stickers(chat_id) if len(args) > 0 and args[0].lower() == 'copy': for trigger in all_stickerlist: sticker_list += "<code>{}</code>\n".format(html.escape(trigger)) elif len(args) == 0: for trigger in all_stickerlist: sticker_list += " - <code>{}</code>\n".format(html.escape(trigger)) split_text = split_message(sticker_list) for text in split_text: if sticker_list == tl(update.effective_message, "<b>Blacklist of stickers currently at{}:</b>\n").format(chat_name).format(chat_name): send_message(update.effective_message, tl(update.effective_message, "No sticker blacklist sticker on<b>{}</b>!").format(chat_name), parse_mode=ParseMode.HTML) return send_message(update.effective_message, text, parse_mode=ParseMode.HTML)
def del_blackliststicker(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] message = update.effective_message # type: Optional[Message] user = update.effective_user to_match = message.sticker if not to_match: return getmode, value = sql.get_blacklist_setting(chat.id) chat_filters = sql.get_chat_stickers(chat.id) for trigger in chat_filters: if to_match.set_name.lower() == trigger.lower(): try: if getmode == 0: return elif getmode == 1: message.delete() elif getmode == 2: message.delete() warn(update.effective_user, chat, tl(update.effective_message, "Use stickers '{}' on the sticker blacklist").format(trigger), message, update.effective_user, conn=False) return elif getmode == 3: message.delete() bot.restrict_chat_member(chat.id, update.effective_user.id, can_send_messages=False) bot.sendMessage(chat.id, tl(update.effective_message, "{} muted for using stickers '{}' on the sticker blacklist").format(mention_markdown(user.id, user.first_name), trigger), parse_mode="markdown") return elif getmode == 4: message.delete() res = chat.unban_member(update.effective_user.id) if res: bot.sendMessage(chat.id, tl(update.effective_message, "{} kicked for using stickers '{}' on the sticker blacklist").format(mention_markdown(user.id, user.first_name), trigger), parse_mode="markdown") return elif getmode == 5: message.delete() chat.kick_member(user.id) bot.sendMessage(chat.id, tl(update.effective_message, "{} blocked for using stickers'{}' on the sticker blacklist").format(mention_markdown(user.id, user.first_name), trigger), parse_mode="markdown") return elif getmode == 6: message.delete() bantime = extract_time(message, value) chat.kick_member(user.id, until_date=bantime) bot.sendMessage(chat.id, tl(update.effective_message, "{} blocked for {} because of using stickers '{}' on the sticker blacklist").format(mention_markdown(user.id, user.first_name), value, trigger), parse_mode="markdown") return elif getmode == 7: message.delete() mutetime = extract_time(message, value) bot.restrict_chat_member(chat.id, user.id, until_date=mutetime, can_send_messages=False) bot.sendMessage(chat.id, tl(update.effective_message, "{} blocked for {} because of using stickers '{}' on the sticker blacklist").format(mention_markdown(user.id, user.first_name), value, trigger), parse_mode="markdown") return except BadRequest as excp: if excp.message == "Message to delete not found": pass else: LOGGER.exception("Error while deleting blacklist message.") break
def __stats__(): return tl(OWNER_ID, "{} trigger blacklist sticker, all over {} chat.").format(sql.num_stickers_filters(), sql.num_stickers_filter_chats())
def __chat_settings__(chat_id, user_id): blacklisted = sql.num_stickers_chat_filters(chat_id) return tl(user_id, "There is `{}` blacklist of stickers.").format(blacklisted)
def blacklist_mode(bot: Bot, update: Update, args: List[str]): spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat = dispatcher.bot.getChat(conn) chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if update.effective_message.chat.type == "private": send_message(update.effective_message, tl(update.effective_message, "You can do this command in the group, not the PM")) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title if args: if args[0].lower() == 'off' or args[0].lower() == 'nothing' or args[0].lower() == 'no': settypeblacklist = tl(update.effective_message, 'turn off') sql.set_blacklist_strength(chat_id, 0, "0") elif args[0].lower() == 'del' or args[0].lower() == 'delete': settypeblacklist = tl(update.effective_message, 'left, the message will be deleted') sql.set_blacklist_strength(chat_id, 1, "0") elif args[0].lower() == 'warn': settypeblacklist = tl(update.effective_message, 'warn') sql.set_blacklist_strength(chat_id, 2, "0") elif args[0].lower() == 'mute': settypeblacklist = tl(update.effective_message, 'mute') sql.set_blacklist_strength(chat_id, 3, "0") elif args[0].lower() == 'kick': settypeblacklist = tl(update.effective_message, 'kick') sql.set_blacklist_strength(chat_id, 4, "0") elif args[0].lower() == 'ban': settypeblacklist = tl(update.effective_message, 'ban') sql.set_blacklist_strength(chat_id, 5, "0") elif args[0].lower() == 'tban': if len(args) == 1: teks = tl(update.effective_message, """It looks like you are trying to set a temporary value for the sticker blacklist, but have not determined the time yet; Use `/blstickermode tban <timevalue>`. Example time value: 4m = 4 minute, 3h = 3 hour, 6d = 6 day, 5w = 5 Sunday.""") send_message(update.effective_message, teks, parse_mode="markdown") return settypeblacklist = tl(update.effective_message, 'temporarily blocked for {}').format(args[1]) sql.set_blacklist_strength(chat_id, 6, str(args[1])) elif args[0].lower() == 'tmute': if len(args) == 1: teks = tl(update.effective_message, """It looks like you are trying to set a temporary value for the sticker blacklist, but have not determined the time yet; Use `/blstickermode tmute <timevalue>`. Example time value: 4m = 4 minute, 3h = 3 hour, 6d = 6 day, 5w = 5 sunday.""") send_message(update.effective_message, teks, parse_mode="markdown") return settypeblacklist = tl(update.effective_message, 'temporarily blocked for {}').format(args[1]) sql.set_blacklist_strength(chat_id, 7, str(args[1])) else: send_message(update.effective_message, tl(update.effective_message, "I only understood off/del/warn/ban/kick/mute/tban/tmute!")) return if conn: text = tl(update.effective_message, "The blacklist sticker mode is changed, User will `{}` on *{}*!").format(settypeblacklist, chat_name) else: text = tl(update.effective_message, "The blacklist sticker mode is changed, User will `{}`!").format(settypeblacklist) send_message(update.effective_message, text, parse_mode="markdown") return "<b>{}:</b>\n" \ "<b>Admin:</b> {}\n" \ "Changed sticker blacklist mode. Will {}.".format(html.escape(chat.title), mention_html(user.id, user.first_name), settypeblacklist) else: getmode, getvalue = sql.get_blacklist_setting(chat.id) if getmode == 0: settypeblacklist = tl(update.effective_message, "not active") elif getmode == 1: settypeblacklist = tl(update.effective_message, "hapus") elif getmode == 2: settypeblacklist = tl(update.effective_message, "warn") elif getmode == 3: settypeblacklist = tl(update.effective_message, "mute") elif getmode == 4: settypeblacklist = tl(update.effective_message, "kick") elif getmode == 5: settypeblacklist = tl(update.effective_message, "ban") elif getmode == 6: settypeblacklist = tl(update.effective_message, "temporarily banned for {}").format(getvalue) elif getmode == 7: settypeblacklist = tl(update.effective_message, "temporary mute for {}").format(getvalue) if conn: text = tl(update.effective_message, "The blacklist sticker mode is currently set to *{}* on *{}*.").format(settypeblacklist, chat_name) else: text = tl(update.effective_message, "The blacklist mode is currently set to *{}*.").format(settypeblacklist) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) return ""
def unblackliststicker(bot: Bot, update: Update): 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) spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return 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_unblacklist = list(set(trigger.strip() for trigger in text.split("\n") if trigger.strip())) successful = 0 for trigger in to_unblacklist: success = sql.rm_from_stickers(chat_id, trigger.lower()) if success: successful += 1 if len(to_unblacklist) == 1: if successful: send_message(update.effective_message, tl(update.effective_message, "Sticker <code>{}</code> removed from the blacklist at <b>{}</b>!").format(html.escape(to_unblacklist[0]), chat_name), parse_mode=ParseMode.HTML) else: send_message(update.effective_message, tl(update.effective_message, "This isn't on the sticker blacklist ...!")) elif successful == len(to_unblacklist): send_message(update.effective_message, tl(update.effective_message, "Sticker <code>{}</code> I removed it from the blacklist at <b>{}</b>!").format( successful, chat_name), parse_mode=ParseMode.HTML) elif not successful: send_message(update.effective_message, tl(update.effective_message, "None of these stickers exist, so they cannot be removed.").format( successful, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML) else: send_message(update.effective_message, tl(update.effective_message, "Sticker <code>{}</code> removed from the blacklist. {} There is no, " "so it's not deleted.").format(successful, len(to_unblacklist) - successful), parse_mode=ParseMode.HTML) elif msg.reply_to_message: trigger = msg.reply_to_message.sticker.set_name if trigger == None: send_message(update.effective_message, tl(update.effective_message, "Invalid sticker!")) return success = sql.rm_from_stickers(chat_id, trigger.lower()) if success: send_message(update.effective_message, tl(update.effective_message, "Sticker <code>{}</code> removed from the blacklist at <b>{}</b>!").format(trigger, chat_name), parse_mode=ParseMode.HTML) else: send_message(update.effective_message, tl(update.effective_message, "{} not on the sticker blacklist ...!").format(trigger)) else: send_message(update.effective_message, tl(update.effective_message, "Tell me what stickers you want to add to the sticker blacklist."))