def check_flood(update, context) -> str: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] if not user: # ignore channels return "" # ignore admins if is_user_admin(chat, user.id): sql.update_flood(chat.id, None) return "" should_ban = sql.update_flood(chat.id, user.id) if not should_ban: return "" try: getmode, getvalue = sql.get_flood_setting(chat.id) if getmode == 1: chat.kick_member(user.id) execstrings = ("Banned") tag = "BANNED" elif getmode == 2: chat.kick_member(user.id) chat.unban_member(user.id) execstrings = ("Kicked") tag = "KICKED" elif getmode == 3: context.bot.restrict_chat_member(chat.id, user.id, permissions=ChatPermissions(can_send_messages=False)) execstrings = ("Muted") tag = "MUTED" elif getmode == 4: bantime = extract_time(msg, getvalue) chat.kick_member(user.id, until_date=bantime) execstrings = ("Banned for {}".format(getvalue)) tag = "TBAN" elif getmode == 5: mutetime = extract_time(msg, getvalue) context.bot.restrict_chat_member(chat.id, user.id, until_date=mutetime, permissions=ChatPermissions(can_send_messages=False)) execstrings = ("Muted for {}".format(getvalue)) tag = "TMUTE" send_message(update.effective_message, "Great, I like to leave flooding to natural disasters but you, " "you were just a disappointment. {}!".format(execstrings)) return "<b>{}:</b>" \ "\n#{}" \ "\n<b>User:</b> {}" \ "\nFlooded the group.".format(tag, html.escape(chat.title), mention_html(user.id, user.first_name)) except BadRequest: msg.reply_text("I can't restrict people here, give me permissions first! Until then, I'll disable anti-flood.") sql.set_flood(chat.id, 0) return "<b>{}:</b>" \ "\n#INFO" \ "\nDon't have enough permission to restrict users so automatically disabled anti-flood".format(chat.title)
def set_flood_mode(bot: Bot, update: Update, args: List[str]) -> str: 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, "This command is meant to use in group not in 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() == 'ban': settypeflood = ('ban') sql.set_flood_strength(chat_id, 1, "0") elif args[0].lower() == 'kick': settypeflood = ('kick') sql.set_flood_strength(chat_id, 2, "0") elif args[0].lower() == 'mute': settypeflood = ('mute') sql.set_flood_strength(chat_id, 3, "0") elif args[0].lower() == 'tban': if len(args) == 1: teks = update.effective_message, """It looks like you tried to set time value for antiflood but you didn't specified time; Try, `/setfloodmode tban <timevalue>`. Examples of time value: 4m = 4 minutes, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks.""" send_message(update.effective_message, teks, parse_mode="markdown") return settypeflood = ("tban for {}".format(args[1])) sql.set_flood_strength(chat_id, 4, str(args[1])) elif args[0].lower() == 'tmute': if len(args) == 1: teks = update.effective_message, """It looks like you tried to set time value for antiflood but you didn't specified time; Try, `/setfloodmode tmute <timevalue>`. Examples of time value: 4m = 4 minutes, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks.""" send_message(update.effective_message, teks, parse_mode="markdown") return settypeflood = ("tmute for {}".format(args[1])) sql.set_flood_strength(chat_id, 5, str(args[1])) else: send_message(update.effective_message, "I only understand ban/kick/mute/tban/tmute!") return if conn: text = msg.reply_text("Exceeding consecutive flood limit will result in {} in {}!".format(settypeflood, chat_name)) else: text = msg.reply_text("Exceeding consecutive flood limit will result in {}!".format(settypeflood)) return "<b>{}:</b>\n" \ "<b>Admin:</b> {}\n" \ "Has changed antiflood mode. User will {}.".format(settypeflood, html.escape(chat.title), mention_html(user.id, user.first_name)) else: getmode, getvalue = sql.get_flood_setting(chat.id) if getmode == 1: settypeflood = ('ban') elif getmode == 2: settypeflood = ('kick') elif getmode == 3: settypeflood = ('mute') elif getmode == 4: settypeflood = ('tban for {}'.format(getvalue)) elif getmode == 5: settypeflood = ('tmute for {}'.format(getvalue)) if conn: text = msg.reply_text("Sending more messages than flood limit will result in {} in {}.".format(settypeflood, chat_name)) else: text = msg.reply_text("Sending more message than flood limit will result in {}.".format(settypeflood)) return ""
def check_flood(update, context) -> str: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] if not user: # ignore channels return "" # ignore admins and whitelists if (is_user_admin(chat, user.id) or user.id in WHITELIST_USERS or user.id in TIGER_USERS): sql.update_flood(chat.id, None) return "" # ignore approved users if is_approved(chat.id, user.id): sql.update_flood(chat.id, None) return should_ban = sql.update_flood(chat.id, user.id) if not should_ban: return "" try: getmode, getvalue = sql.get_flood_setting(chat.id) if getmode == 1: chat.kick_member(user.id) execstrings = "Banned" tag = "BANNED" elif getmode == 2: chat.kick_member(user.id) chat.unban_member(user.id) execstrings = "Kicked" tag = "KICKED" elif getmode == 3: context.bot.restrict_chat_member( chat.id, user.id, permissions=ChatPermissions(can_send_messages=False)) execstrings = "Muted" tag = "MUTED" elif getmode == 4: bantime = extract_time(msg, getvalue) chat.kick_member(user.id, until_date=bantime) execstrings = "Banned for {}".format(getvalue) tag = "TBAN" elif getmode == 5: mutetime = extract_time(msg, getvalue) context.bot.restrict_chat_member( chat.id, user.id, until_date=mutetime, permissions=ChatPermissions(can_send_messages=False), ) execstrings = "Muted for {}".format(getvalue) tag = "TMUTE" send_message(update.effective_message, "Beep Boop! Boop Beep!\n{}!".format(execstrings)) return ("<b>{}:</b>" "\n#{}" "\n<b>User:</b> {}" "\nFlooded the group.".format( tag, html.escape(chat.title), mention_html(user.id, user.first_name))) except BadRequest: msg.reply_text( "I can't restrict people here, give me permissions first! Until then, I'll disable anti-flood." ) sql.set_flood(chat.id, 0) return ( "<b>{}:</b>" "\n#INFO" "\nDon't have enough permission to restrict users so automatically disabled anti-flood" .format(chat.title))
def set_flood_mode(bot: Bot, update: Update, args: List[str]): spam = (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": update.effective_message.reply_text( tl(update.effective_message, "Use This Command in Groups,NOT in 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() == 'ban': settypeflood = (update.effective_message, 'Banned') sql.set_flood_strength(chat_id, 1, "0") elif args[0].lower() == 'kick': settypeflood = (update.effective_message, 'Kicked') sql.set_flood_strength(chat_id, 2, "0") elif args[0].lower() == 'mute': settypeflood = (update.effective_message, 'Muted') sql.set_flood_strength(chat_id, 3, "0") elif args[0].lower() == 'tban': if len(args) == 1: teks = ( update.effective_message, """Sepertinya Anda mencoba menetapkan nilai sementara untuk anti-banjir, tetapi belum menentukan waktu; gunakan `/setfloodmode tban <timevalue>`. Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""") msg.reply_text(teks, parse_mode="markdown") return settypeflood = (update.effective_message, "blokir sementara selama {}").format(args[1]) sql.set_flood_strength(chat_id, 4, str(args[1])) elif args[0].lower() == 'tmute': if len(args) == 1: teks = ( update.effective_message, """Sepertinya Anda mencoba menetapkan nilai sementara untuk anti-banjir, tetapi belum menentukan waktu; gunakan `/setfloodmode tban <timevalue>`. Contoh nilai waktu: 4m = 4 menit, 3h = 3 jam, 6d = 6 hari, 5w = 5 minggu.""") msg.reply_text(teks, parse_mode="markdown") return settypeflood = (update.effective_message, 'bisukan sementara selama {}').format(args[1]) sql.set_flood_strength(chat_id, 5, str(args[1])) else: msg.reply_text((update.effective_message, "I understand only ban/kick/mute/tban/tmute")) return if conn: text = ( update.effective_message, "Terlalu banyak mengirim pesan sekarang akan menghasilkan `{}` pada *{}*!" ).format(settypeflood, chat_name) else: text = ( update.effective_message, "Terlalu banyak mengirim pesan sekarang akan menghasilkan `{}`!" ).format(settypeflood) msg.reply_text(text, parse_mode="markdown") return "<b>{}:</b>\n" \ "<b>Admin:</b> {}\n" \ "Has changed antiflood mode. User will {}.".format(settypeflood, html.escape(chat.title), mention_html(user.id, user.first_name)) else: getmode, getvalue = sql.get_flood_setting(chat.id) if getmode == 1: settypeflood = (update.effective_message, 'blokir') elif getmode == 2: settypeflood = (update.effective_message, 'tendang') elif getmode == 3: settypeflood = (update.effective_message, 'bisukan') elif getmode == 4: settypeflood = (update.effective_message, 'blokir sementara selama {}').format(getvalue) elif getmode == 5: settypeflood = (update.effective_message, 'bisukan sementara selama {}').format(getvalue) if conn: text = ( update.effective_message, "Jika member mengirim pesan beruntun, maka dia akan *di {}* pada *{}*." ).format(settypeflood, chat_name) else: text = ( update.effective_message, "Jika member mengirim pesan beruntun, maka dia akan *di {}*." ).format(settypeflood) msg.reply_text(text, parse_mode=ParseMode.MARKDOWN) return ""
def check_flood(bot: Bot, update: Update) -> str: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] if not user: # ignore channels return "" # ignore admins and whitelists if (is_user_admin(chat, user.id) or user.id in WHITELIST_USERS or user.id in SARDEGNA_USERS): sql.update_flood(chat.id, None) return "" should_ban = sql.update_flood(chat.id, user.id) if not should_ban: return "" try: getmode, getvalue = sql.get_flood_setting(chat.id) if getmode == 1: chat.kick_member(user.id) execstrings = ("Banned") tag = "BANNED" elif getmode == 2: chat.kick_member(user.id) chat.unban_member(user.id) execstrings = ("Ditendang") tag = "DITENDANG" elif getmode == 3: bot.restrict_chat_member(chat.id, user.id, can_send_messages=False) execstrings = ("Dibisukan") tag = "TERBISU" elif getmode == 4: bantime = extract_time(msg, getvalue) chat.kick_member(user.id, until_date=bantime) execstrings = ("Dilarang untuk {}".format(getvalue)) tag = "TBAN" elif getmode == 5: mutetime = extract_time(msg, getvalue) bot.restrict_chat_member(chat.id, user.id, until_date=mutetime, can_send_messages=False) execstrings = ("Dibisukan untuk {}".format(getvalue)) tag = "TMUTE" send_message( update.effective_message, "Hebat, saya suka meninggalkan flood untuk bencana alam tetapi Anda, " "Anda hanya mengecewakan {}!".format(execstrings)) return "<b>{}:</b>" \ "\n#{}" \ "\n<b>Pengguna:</b> {}" \ "\nFlooded ini grup.".format(tag, html.escape(chat.title), mention_html(user.id, user.first_name)) except BadRequest: msg.reply_text( "Saya tidak bisa membatasi orang di sini, beri saya izin dulu! Sampai saat itu, saya akan menonaktifkan anti-flood." ) sql.set_flood(chat.id, 0) return "<b>{}:</b>" \ "\n#INFO" \ "\nTidak memiliki cukup izin untuk membatasi pengguna jadi nonaktifkan secara otomatisd anti-flood".format(chat.title)
def set_flood_mode(bot: Bot, update: Update, args: List[str]) -> str: 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, "Perintah ini dimaksudkan untuk digunakan dalam grup bukan di 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() == 'ban': settypeflood = ('ban') sql.set_flood_strength(chat_id, 1, "0") elif args[0].lower() == 'kick': settypeflood = ('kick') sql.set_flood_strength(chat_id, 2, "0") elif args[0].lower() == 'mute': settypeflood = ('mute') sql.set_flood_strength(chat_id, 3, "0") elif args[0].lower() == 'tban': if len(args) == 1: teks = update.effective_message, """Sepertinya Anda mencoba menyetel nilai waktu untuk antiflood tetapi Anda tidak menentukan waktu; Coba, `/setfloodmode tban <nilai waktu>`. 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 settypeflood = ("tban for {}".format(args[1])) sql.set_flood_strength(chat_id, 4, str(args[1])) elif args[0].lower() == 'tmute': if len(args) == 1: teks = update.effective_message, """Sepertinya Anda mencoba menyetel nilai waktu untuk antiflood tetapi Anda tidak menentukan waktu; Coba, `/setfloodmode 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 settypeflood = ("tmute for {}".format(args[1])) sql.set_flood_strength(chat_id, 5, str(args[1])) else: send_message(update.effective_message, "Saya hanya mengerti ban/kick/mute/tban/tmute!") return if conn: text = msg.reply_text( "Melebihi batas flood yang berurutan akan berakibat {} dalam {}!" .format(settypeflood, chat_name)) else: text = msg.reply_text( "Melebihi batas flood yang berurutan akan berakibat {}!". format(settypeflood)) return "<b>{}:</b>\n" \ "<b>Admin:</b> {}\n" \ "Telah mengubah mode antiflood. Pengguna akan {}.".format(settypeflood, html.escape(chat.title), mention_html(user.id, user.first_name)) else: getmode, getvalue = sql.get_flood_setting(chat.id) if getmode == 1: settypeflood = ('ban') elif getmode == 2: settypeflood = ('kick') elif getmode == 3: settypeflood = ('mute') elif getmode == 4: settypeflood = ('tban for {}'.format(getvalue)) elif getmode == 5: settypeflood = ('tmute for {}'.format(getvalue)) if conn: text = msg.reply_text( "Mengirim lebih banyak pesan daripada batas banjir akan mengakibatkan {} dalam {}." .format(settypeflood, chat_name)) else: text = msg.reply_text( "Mengirim pesan lebih dari batas banjir akan menghasilkan {}.". format(settypeflood)) return ""
def check_flood(bot: Bot, update: Update) -> str: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] if not user: # ignore channels return "" if user.id == 777000: return "" # ignore admins and whitelists if (is_user_admin(chat, user.id) or user.id in WHITELIST_USERS or user.id in SUDO_USERS): sql.update_flood(chat.id, None) return "" should_ban = sql.update_flood(chat.id, user.id) if not should_ban: return "" try: getmode, getvalue = sql.get_flood_setting(chat.id) if getmode == 1: chat.kick_member(user.id) execstrings = ("Banned") tag = "BANNED" elif getmode == 2: chat.kick_member(user.id) chat.unban_member(user.id) execstrings = ("Kicked") tag = "KICKED" elif getmode == 3: bot.restrict_chat_member(chat.id, user.id, can_send_messages=False) execstrings = ("Muted") tag = "MUTED" elif getmode == 4: bantime = extract_time(msg, getvalue) chat.kick_member(user.id, until_date=bantime) execstrings = (f"Banned for {getvalue}") tag = "TBAN" elif getmode == 5: mutetime = extract_time(msg, getvalue) bot.restrict_chat_member(chat.id, user.id, until_date=mutetime, can_send_messages=False) execstrings = (f"Muted for {getvalue}") tag = "TMUTE" send_message( update.effective_message, f"Wonderful, I like to leave flooding to natural disasters but you, you were just a disappointment {execstrings}!" ) return f"<b>{tag}:</b>" \ f"\n#{html.escape(chat.title)}" \ f"\n<b>User:</b> {mention_html(user.id, user.first_name)}" \ f"\nFlooded the group." except BadRequest: msg.reply_text( "I can't restrict people here, give me permissions first! Until then, I'll disable anti-flood." ) sql.set_flood(chat.id, 0) return f"<b>{chat.title}:</b>" \ f"\n#INFO" \ f"\nDon't have enough permission to restrict users so automatically disabled anti-flood"
def check_flood(bot: Bot, update: Update) -> str: user = update.effective_user # type: Optional[User] chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] if not user: # ignore channels return "" # ignore admins if is_user_admin(chat, user.id): sql.update_flood(chat.id, None) return "" should_ban = sql.update_flood(chat.id, user.id) if not should_ban: return "" try: getmode, getvalue = sql.get_flood_setting(chat.id) if getmode == 1: chat.kick_member(user.id) execstrings = tld(update.effective_message, "Get Out!") tag = "BANNED" elif getmode == 2: chat.kick_member(user.id) chat.unban_member(user.id) execstrings = tld(update.effective_message, "Kicked!") tag = "KICKED" elif getmode == 3: bot.restrict_chat_member(chat.id, user.id, can_send_messages=False) execstrings = tld(update.effective_message, "Now you silent!") tag = "MUTED" elif getmode == 4: bantime = extract_time(msg, getvalue) chat.kick_member(user.id, until_date=bantime) execstrings = tld(update.effective_message, "Banned till {}").format(getvalue) tag = "TBAN" elif getmode == 5: mutetime = extract_time(msg, getvalue) bot.restrict_chat_member(chat.id, user.id, until_date=mutetime, can_send_messages=False) execstrings = tld(update.effective_message, "Muted till {}").format(getvalue) tag = "TMUTE" msg.reply_text( tld(update.effective_message, "Don't try to flood in font of me *{}*").format(execstrings)) return "#MUTED" \ "\n<b>Chat:</b> {}" \ "\n<b>User:</b> {}" \ "\nFlooded the group.".format(html.escape(chat.title), mention_html(user.id, user.first_name)) except BadRequest: msg.reply_text( tld( chat.id, "I can't Mute people here, give me permissions first! Until then, I'll disable antiflood." )) sql.set_flood(chat.id, 0) return "#INFO" \ "\n<b>Chat:</b> {}" \ "\nDon't have Mute permissions, so automatically disabled antiflood.".format(chat.title)
def set_flood_mode(bot: Bot, update: Update, args: List[str]): 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": update.effective_message.reply_text( tld(update.effective_message, "Use This Command in Groups,NOT in 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() == 'ban': settypeflood = tld(update.effective_message, 'Banned') sql.set_flood_strength(chat_id, 1, "0") elif args[0].lower() == 'kick': settypeflood = tld(update.effective_message, 'Kicked') sql.set_flood_strength(chat_id, 2, "0") elif args[0].lower() == 'mute': settypeflood = tld(update.effective_message, 'Muted') sql.set_flood_strength(chat_id, 3, "0") elif args[0].lower() == 'tban': if len(args) == 1: teks = tld( update.effective_message, """It looks like you tried to set a time value for the anti-flood, but did not specify a time; use `/setfloodmode tban <timevalue>`. Examples of the value of time: 4m = 4 minute, 3h = 3 Hours, 6d = 6 days, 5w = 5 weeks.""" ) msg.reply_text(teks, parse_mode="markdown") return settypeflood = tld(update.effective_message, "temporarily ban during {}").format(args[1]) sql.set_flood_strength(chat_id, 4, str(args[1])) elif args[0].lower() == 'tmute': if len(args) == 1: teks = tld( update.effective_message, """It looks like you tried to set a time value for the anti-flood, but did not specify a time; use `/setfloodmode tban <timevalue>`. Examples of the value of time: 4m = 4 minute, 3h = 3 Hours, 6d = 6 days, 5w = 5 weeks.""" ) msg.reply_text(teks, parse_mode="markdown") return settypeflood = tld(update.effective_message, 'temporarily mute during {}').format(args[1]) sql.set_flood_strength(chat_id, 5, str(args[1])) else: msg.reply_text( tld(update.effective_message, "I understand only ban/kick/mute/tban/tmute")) return if conn: text = tld( update.effective_message, "Too many sent messages Result Will Be `{}` on *{}*!").format( settypeflood, chat_title) else: text = tld(update.effective_message, "Too many sent messages Result Will Be `{}`!").format( settypeflood) msg.reply_text(text, parse_mode="markdown") return "<b>{}:</b>\n" \ "<b>Admin:</b> {}\n" \ "Has changed antiflood mode. User will {}.".format(settypeflood, html.escape(chat.title), mention_html(user.id, user.first_name)) else: getmode, getvalue = sql.get_flood_setting(chat.id) if getmode == 1: settypeflood = tld(update.effective_message, 'banned') elif getmode == 2: settypeflood = tld(update.effective_message, 'kick') elif getmode == 3: settypeflood = tld(update.effective_message, 'mute') elif getmode == 4: settypeflood = tld(update.effective_message, 'Blocking while during {}'.format(getvalue)) elif getmode == 5: settypeflood = tld(update.effective_message, 'temporarily mute during {}'.format(getvalue)) if conn: text = tld( update.effective_message, "If the member sends a message straight, then he will *di {}* on *{}*." ).format(settypeflood, chat_name) else: text = tld( update.effective_message, "If the member sends a message straight, then he will *di {}*." ).format(settypeflood) msg.reply_text(text, parse_mode=ParseMode.MARKDOWN) return ""