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, "Menggunakan stiker '{}' yang ada di daftar hitam stiker").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, "{} di bisukan karena menggunakan stiker '{}' yang ada di daftar hitam stiker").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, "{} di tendang karena menggunakan stiker '{}' yang ada di daftar hitam stiker").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, "{} di blokir karena menggunakan stiker '{}' yang ada di daftar hitam stiker").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, "{} di blokir selama {} karena menggunakan stiker '{}' yang ada di daftar hitam stiker").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, "{} di bisukan selama {} karena menggunakan stiker '{}' yang ada di daftar hitam stiker").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 blacklist_mode(update, context): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] args = context.args conn = connected(context.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, "Anda bisa lakukan command ini pada grup, bukan pada 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, 'di matikan') sql.set_blacklist_strength(chat_id, 0, "0") elif args[0].lower() == 'del' or args[0].lower() == 'delete': settypeblacklist = tl(update.effective_message, 'di biarkan, pesannya akan dihapus') sql.set_blacklist_strength(chat_id, 1, "0") elif args[0].lower() == 'warn': settypeblacklist = tl(update.effective_message, 'di peringati') sql.set_blacklist_strength(chat_id, 2, "0") elif args[0].lower() == 'mute': settypeblacklist = tl(update.effective_message, 'di bisukan') sql.set_blacklist_strength(chat_id, 3, "0") elif args[0].lower() == 'kick': settypeblacklist = tl(update.effective_message, 'di tendang') sql.set_blacklist_strength(chat_id, 4, "0") elif args[0].lower() == 'ban': settypeblacklist = tl(update.effective_message, 'di blokir') sql.set_blacklist_strength(chat_id, 5, "0") elif args[0].lower() == 'tban': if len(args) == 1: teks = tl( update.effective_message, """Sepertinya Anda mencoba menetapkan nilai sementara untuk blacklist sticker, tetapi belum menentukan waktu; gunakan `/blstickermode tban <timevalue>`. Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""") send_message(update.effective_message, teks, parse_mode="markdown") return settypeblacklist = tl(update.effective_message, 'di blokir sementara selama {}').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, """Sepertinya Anda mencoba menetapkan nilai sementara untuk blacklist sticker, tetapi belum menentukan waktu; gunakan `/blstickermode tmute <timevalue>`. Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""") send_message(update.effective_message, teks, parse_mode="markdown") return settypeblacklist = tl(update.effective_message, 'di bisukan sementara selama {}').format( args[1]) sql.set_blacklist_strength(chat_id, 7, str(args[1])) else: send_message( update.effective_message, tl( update.effective_message, "Saya hanya mengerti off/del/warn/ban/kick/mute/tban/tmute!" )) return if conn: text = tl( update.effective_message, "Mode blacklist sticker diubah, Pengguna akan `{}` pada *{}*!" ).format(settypeblacklist, chat_name) else: text = tl( update.effective_message, "Mode blacklist sticker diubah, Pengguna akan `{}`!").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, "tidak aktif") 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, "banned sementara selama {}").format(getvalue) elif getmode == 7: settypeblacklist = tl(update.effective_message, "mute sementara selama {}").format(getvalue) if conn: text = tl( update.effective_message, "Mode blacklist sticker saat ini disetel ke *{}* pada *{}*." ).format(settypeblacklist, chat_name) else: text = tl(update.effective_message, "Mode blacklist saat ini disetel ke *{}*.").format( settypeblacklist) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) return ""