def kick(bot: Bot, update: Update, args: List[str]) -> str: currentchat = update.effective_chat # type: Optional[Chat] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return user_id, reason = extract_user_and_text(message, args) if not user_id: send_message( update.effective_message, tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna.")) return "" 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, "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 check = bot.getChatMember(chat_id, bot.id) if check.status == 'member': if conn: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru." ).format(chat_name) else: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru." ) send_message(update.effective_message, text, parse_mode="markdown") return "" else: if check['can_restrict_members'] == False: if conn: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di *{}*! Pastikan saya admin dan dapat menunjuk admin baru." ).format(chat_name) else: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru." ) send_message(update.effective_message, text, parse_mode="markdown") return "" if not user_id: return "" try: if conn: member = bot.getChatMember(chat_id, user_id) else: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": send_message( update.effective_message, tl(update.effective_message, "Saya tidak dapat menemukan pengguna ini 😣")) return "" else: raise if user_id == bot.id: send_message( update.effective_message, tl( update.effective_message, "Saya tidak akan menendang diri saya sendiri, apakah kamu gila? 😠" )) return "" if is_user_ban_protected(chat, user_id): send_message( update.effective_message, tl( update.effective_message, "Saya tidak bisa menendang orang ini karena dia adalah admin 😒" )) return "" if user_id == bot.id: send_message( update.effective_message, tl(update.effective_message, "Yahhh aku tidak akan melakukan itu 😝")) return "" check = bot.getChatMember(chat.id, user.id) if check['can_restrict_members'] == False: send_message( update.effective_message, tl(update.effective_message, "Anda tidak punya hak untuk membatasi seseorang.")) return "" if conn: res = bot.unbanChatMember(chat_id, user_id) # unban on current user = kick else: res = chat.unban_member(user_id) # unban on current user = kick if res: if conn: bot.send_sticker(currentchat.id, BAN_STICKER) # banhammer marie sticker text = tl(update.effective_message, "Tertendang pada *{}*! 😝").format(chat_name) send_message(update.effective_message, text, parse_mode="markdown") else: if message.text.split(None, 1)[0][1:] == "skick": update.effective_message.delete() else: bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie sticker text = tl(update.effective_message, "Tertendang! 😝") send_message(update.effective_message, text, parse_mode="markdown") log = "<b>{}:</b>" \ "\n#KICKED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id) log += "\n<b>Reason:</b> {}".format(reason) return log else: send_message( update.effective_message, tl(update.effective_message, "Yah sial, aku tidak bisa menendang pengguna itu 😒")) return ""
def ban(bot: Bot, update: Update, args: List[str]) -> str: currentchat = update.effective_chat # type: Optional[Chat] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return user_id, reason = extract_user_and_text(message, args) 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, "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 check = bot.getChatMember(chat_id, bot.id) if check.status == 'member' or check['can_restrict_members'] == False: if conn: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru." ).format(chat_name) else: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru." ) send_message(update.effective_message, text, parse_mode="markdown") return "" if not user_id: send_message( update.effective_message, tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna.")) return "" try: if conn: member = bot.getChatMember(chat_id, user_id) else: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": if conn: text = tl( update.effective_message, "Saya tidak dapat menemukan pengguna ini pada *{}* 😣" ).format(chat_name) else: text = tl(update.effective_message, "Saya tidak dapat menemukan pengguna ini 😣") send_message(update.effective_message, text, parse_mode="markdown") return "" else: raise if user_id == bot.id: send_message( update.effective_message, tl(update.effective_message, "Saya tidak akan BAN diri saya sendiri, apakah kamu gila? 😠")) return "" if is_user_ban_protected(chat, user_id, member): send_message( update.effective_message, tl(update.effective_message, "Saya tidak bisa banned orang ini karena dia adalah admin 😒")) return "" if member['can_restrict_members'] == False: if conn: text = tl( update.effective_message, "Anda tidak punya hak untuk membatasi seseorang pada *{}*." ).format(chat_name) else: text = tl(update.effective_message, "Anda tidak punya hak untuk membatasi seseorang.") send_message(update.effective_message, text, parse_mode="markdown") return "" log = "<b>{}:</b>" \ "\n#BANNED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id) if reason: log += "\n<b>Reason:</b> {}".format(reason) try: if conn: bot.kickChatMember(chat_id, user_id) bot.send_sticker(currentchat.id, BAN_STICKER) # banhammer marie sticker send_message(update.effective_message, tl(update.effective_message, "Terbanned pada *{}*! 😝").format(chat_name), parse_mode="markdown") else: chat.kick_member(user_id) if message.text.split(None, 1)[0][1:] == "sban": update.effective_message.delete() else: bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie sticker send_message(update.effective_message, tl(update.effective_message, "Terbanned! 😝")) return log except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply send_message(update.effective_message, tl(update.effective_message, "Terbanned! 😝"), quote=False) return log elif excp.message == "Message can't be deleted": pass else: LOGGER.warning(update) LOGGER.exception( "ERROR membanned pengguna %s di obrolan %s (%s) disebabkan oleh %s", user_id, chat.title, chat.id, excp.message) send_message( update.effective_message, tl(update.effective_message, "Yah sial, aku tidak bisa banned pengguna itu 😒")) return ""
def temp_ban(bot: Bot, update: Update, args: List[str]) -> str: currentchat = update.effective_chat # type: Optional[Chat] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] spam = spamfilters(update.effective_message.text, update.effective_message.from_user.id, update.effective_chat.id, update.effective_message) if spam == True: return user_id, reason = extract_user_and_text(message, args) 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, "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 check = bot.getChatMember(chat_id, bot.id) if check.status == 'member': if conn: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di *{}*! Pastikan saya admin dan dapat menunjuk admin baru." ).format(chat_name) else: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru." ) send_message(update.effective_message, text, parse_mode="markdown") return "" else: if check['can_restrict_members'] == False: if conn: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di *{}*! Pastikan saya admin dan dapat menunjuk admin baru." ).format(chat_name) else: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru." ) send_message(update.effective_message, text, parse_mode="markdown") return "" if not user_id: send_message( update.effective_message, tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna.")) return "" try: if conn: member = bot.getChatMember(chat_id, user_id) else: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": send_message( update.effective_message, tl(update.effective_message, "Saya tidak dapat menemukan pengguna ini 😣")) return "" else: raise if user_id == bot.id: send_message( update.effective_message, tl(update.effective_message, "Saya tidak akan BAN diri saya sendiri, apakah kamu gila? 😠")) return "" if is_user_ban_protected(chat, user_id, member): send_message( update.effective_message, tl(update.effective_message, "Saya tidak bisa banned orang ini karena dia adalah admin 😒")) return "" if member['can_restrict_members'] == False: send_message( update.effective_message, tl(update.effective_message, "Anda tidak punya hak untuk membatasi seseorang.")) return "" if not reason: send_message( update.effective_message, tl(update.effective_message, "Anda belum menetapkan waktu untuk banned pengguna ini!")) return "" split_reason = reason.split(None, 1) time_val = split_reason[0].lower() if len(split_reason) > 1: reason = split_reason[1] else: reason = "" bantime = extract_time(message, time_val) if not bantime: return "" log = "<b>{}:</b>" \ "\n#TEMPBAN" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)" \ "\n<b>Time:</b> {}".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id, time_val) if reason: log += "\n<b>Reason:</b> {}".format(reason) try: if conn: bot.kickChatMember(chat_id, user_id, until_date=bantime) bot.send_sticker(currentchat.id, BAN_STICKER) # banhammer marie sticker send_message( update.effective_message, tl(update.effective_message, "Banned! Pengguna diblokir untuk *{}* pada *{}*.").format( time_val, chat_name), parse_mode="markdown") else: chat.kick_member(user_id, until_date=bantime) bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie sticker send_message( update.effective_message, tl(update.effective_message, "Banned! Pengguna diblokir untuk {}.").format(time_val)) return log except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply send_message( update.effective_message, tl(update.effective_message, "Banned! Pengguna diblokir untuk {}.").format(time_val), quote=False) return log else: LOGGER.warning(update) LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) send_message( update.effective_message, tl(update.effective_message, "Yah sial, aku tidak bisa menendang pengguna itu 😒")) return ""
def new_member(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] should_welc, cust_welcome, cust_content, welc_type = sql.get_welc_pref(chat.id) cleanserv = sql.clean_service(chat.id) if cleanserv: new_members = update.effective_message.new_chat_members for new_mem in new_members: try: dispatcher.bot.delete_message(chat.id, update.message.message_id) except BadRequest: pass if should_welc: sent = None new_members = update.effective_message.new_chat_members for new_mem in new_members: # Give the owner a special welcome if OWNER_SPECIAL and new_mem.id == OWNER_ID: if cleanserv: bot.send_message(chat.id, tl(update.effective_message, "Master telah pulang! Mari kita mulai pesta ini! 😆")) else: send_message(update.effective_message, tl(update.effective_message, "Master telah pulang! Mari kita mulai pesta ini! 😆")) continue # Don't welcome yourself elif new_mem.id == bot.id: continue else: # If welcome message is media, send with appropriate function if welc_type != sql.Types.TEXT and welc_type != sql.Types.BUTTON_TEXT: reply = update.message.message_id # Clean service welcome if cleanserv: reply = False # Formatting text first_name = new_mem.first_name or "PersonWithNoName" # edge case of empty name - occurs for some bugs. if new_mem.last_name: fullname = "{} {}".format(first_name, new_mem.last_name) else: fullname = first_name count = chat.get_members_count() mention = mention_markdown(new_mem.id, first_name) if new_mem.username: username = "******" + escape_markdown(new_mem.username) else: username = mention if cust_welcome: formatted_text = cust_welcome.format(first=escape_markdown(first_name), last=escape_markdown(new_mem.last_name or first_name), fullname=escape_markdown(fullname), username=username, mention=mention, count=count, chatname=escape_markdown(chat.title), id=new_mem.id) else: formatted_text = "" # Build keyboard buttons = sql.get_welc_buttons(chat.id) keyb = build_keyboard(buttons) getsec, mutetime, custom_text = sql.welcome_security(chat.id) # If user ban protected don't apply security on him if is_user_ban_protected(chat, new_mem.id, chat.get_member(new_mem.id)): pass elif getsec: # If mute time is turned on if mutetime: if mutetime[:1] == "0": try: bot.restrict_chat_member(chat.id, new_mem.id, can_send_messages=False) canrest = True except BadRequest: canrest = False else: mutetime = extract_time(update.effective_message, mutetime) try: bot.restrict_chat_member(chat.id, new_mem.id, until_date=mutetime, can_send_messages=False) canrest = True except BadRequest: canrest = False # If security welcome is turned on if canrest: sql.add_to_userlist(chat.id, new_mem.id) keyb.append([InlineKeyboardButton(text=str(custom_text), callback_data="check_bot_({})".format(new_mem.id))]) keyboard = InlineKeyboardMarkup(keyb) # Send message try: sent = ENUM_FUNC_MAP[welc_type](chat.id, cust_content, caption=formatted_text, reply_markup=keyboard, parse_mode="markdown", reply_to_message_id=reply) except BadRequest: sent = send_message(update.effective_message, tl(update.effective_message, "Catatan: Terjadi kesalahan saat mengirim pesan kustom. Harap perbarui.")) return else: # else, move on first_name = new_mem.first_name or "PersonWithNoName" # edge case of empty name - occurs for some bugs. if cust_welcome: if new_mem.last_name: fullname = "{} {}".format(first_name, new_mem.last_name) else: fullname = first_name count = chat.get_members_count() mention = mention_markdown(new_mem.id, first_name) if new_mem.username: username = "******" + escape_markdown(new_mem.username) else: username = mention valid_format = escape_invalid_curly_brackets(cust_welcome, VALID_WELCOME_FORMATTERS) if valid_format: res = valid_format.format(first=escape_markdown(first_name), last=escape_markdown(new_mem.last_name or first_name), fullname=escape_markdown(fullname), username=username, mention=mention, count=count, chatname=escape_markdown(chat.title), id=new_mem.id) else: res = "" buttons = sql.get_welc_buttons(chat.id) keyb = build_keyboard(buttons) else: res = sql.DEFAULT_WELCOME.format(first=first_name) keyb = [] getsec, mutetime, custom_text = sql.welcome_security(chat.id) # If user ban protected don't apply security on him if is_user_ban_protected(chat, new_mem.id, chat.get_member(new_mem.id)): pass elif getsec: if mutetime: if mutetime[:1] == "0": try: bot.restrict_chat_member(chat.id, new_mem.id, can_send_messages=False) canrest = True except BadRequest: canrest = False else: mutetime = extract_time(update.effective_message, mutetime) try: bot.restrict_chat_member(chat.id, new_mem.id, until_date=mutetime, can_send_messages=False) canrest = True except BadRequest: canrest = False if canrest: sql.add_to_userlist(chat.id, new_mem.id) keyb.append([InlineKeyboardButton(text=str(custom_text), callback_data="check_bot_({})".format(new_mem.id))]) keyboard = InlineKeyboardMarkup(keyb) sent = send(update, res, keyboard, sql.DEFAULT_WELCOME.format(first=first_name)) # type: Optional[Message] prev_welc = sql.get_clean_pref(chat.id) if prev_welc: try: if int(prev_welc) != 1: bot.delete_message(chat.id, prev_welc) except BadRequest as excp: pass if sent: sql.set_clean_welcome(chat.id, sent.message_id) fed_id = fedsql.get_fed_id(chat.id) if fed_id == "TeamNusantaraDevs": new_members = update.effective_message.new_chat_members for new_mem in new_members: # CAS Security thread t = threading.Thread(target=check_cas, args=(bot, new_mem.id, new_mem, update.effective_message,)) t.start()
def kick(update, context): currentchat = update.effective_chat # type: Optional[Chat] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args user_id, reason = extract_user_and_text(message, args) if user_id == "error": send_message(update.effective_message, tl(update.effective_message, reason)) return "" if not user_id: send_message( update.effective_message, tl(update.effective_message, "Anda sepertinya tidak mengacu pada pengguna.")) return "" 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 check = context.bot.getChatMember(chat_id, context.bot.id) if check.status == 'member': if conn: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di {}! Pastikan saya admin dan dapat menunjuk admin baru." ).format(chat_name) else: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru." ) send_message(update.effective_message, text, parse_mode="markdown") return "" else: if check['can_restrict_members'] == False: if conn: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di *{}*! Pastikan saya admin dan dapat menunjuk admin baru." ).format(chat_name) else: text = tl( update.effective_message, "Saya tidak bisa membatasi orang di sini! Pastikan saya admin dan dapat menunjuk admin baru." ) send_message(update.effective_message, text, parse_mode="markdown") return "" if not user_id: return "" try: if conn: member = context.bot.getChatMember(chat_id, user_id) else: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": send_message( update.effective_message, tl(update.effective_message, "I can not find this user 😣")) return "" else: raise if user_id == context.bot.id: send_message( update.effective_message, tl(update.effective_message, "I'm not going to kick myself, are you crazy? 😠")) return "" if is_user_ban_protected(chat, user_id): send_message( update.effective_message, tl(update.effective_message, "I can not kick this guy because he is admin")) return "" if user_id == context.bot.id: send_message(update.effective_message, tl(update.effective_message, "Yahhh I will not do it 😝")) return "" check = context.bot.getChatMember(chat.id, user.id) if check['can_restrict_members'] == False: send_message( update.effective_message, tl(update.effective_message, "You have no right to restrict a person.")) return "" if conn: res = context.bot.unbanChatMember( chat_id, user_id) # unban on current user = kick else: res = chat.unban_member(user_id) # unban on current user = kick if res: if conn: context.bot.send_sticker(currentchat.id, BAN_STICKER) # banhammer marie sticker text = tl(update.effective_message, "Kicked in *{}*! 😝").format(chat_name) send_message(update.effective_message, text, parse_mode="markdown") else: if message.text.split(None, 1)[0][1:] == "skick": update.effective_message.delete() else: context.bot.send_sticker( chat.id, BAN_STICKER) # banhammer marie sticker text = tl(update.effective_message, "Kicked! 😝") send_message(update.effective_message, text, parse_mode="markdown") log = "<b>{}:</b>" \ "\n#KICKED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id) log += "\n<b>Reason:</b> {}".format(reason) return log else: send_message( update.effective_message, tl(update.effective_message, "Yah sial, aku tidak bisa menendang pengguna itu 😒")) return ""
def ban(update, context): currentchat = update.effective_chat # type: Optional[Chat] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] message = update.effective_message # type: Optional[Message] args = context.args user_id, reason = extract_user_and_text(message, args) if user_id == "error": send_message(update.effective_message, tl(update.effective_message, reason)) return "" 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 check = context.bot.getChatMember(chat_id, context.bot.id) if check.status == 'member' or check['can_restrict_members'] == False: if conn: text = tl( update.effective_message, "I can not restrict people on {}! Make sure that I am the admin and can appoint a new admin." ).format(chat_name) else: text = tl( update.effective_message, "I can not restrict people here! Make sure that I am the admin and can appoint a new admin." ) send_message(update.effective_message, text, parse_mode="markdown") return "" if not user_id: send_message( update.effective_message, tl(update.effective_message, "You don't seem to be referring to a user.")) return "" try: if conn: member = context.bot.getChatMember(chat_id, user_id) else: member = chat.get_member(user_id) except BadRequest as excp: if excp.message == "User not found": if conn: text = tl( update.effective_message, "I can not find this user in *{}* 😣").format(chat_name) else: text = tl(update.effective_message, "I can not find this user 😣") send_message(update.effective_message, text, parse_mode="markdown") return "" else: raise if user_id == context.bot.id: send_message( update.effective_message, tl(update.effective_message, "Saya tidak akan BAN diri saya sendiri, apakah kamu gila? 😠")) return "" if is_user_ban_protected(chat, user_id, member): send_message( update.effective_message, tl(update.effective_message, "Saya tidak bisa banned orang ini karena dia adalah admin 😒")) return "" if member['can_restrict_members'] == False: if conn: text = tl( update.effective_message, "Anda tidak punya hak untuk membatasi seseorang pada *{}*." ).format(chat_name) else: text = tl(update.effective_message, "Anda tidak punya hak untuk membatasi seseorang.") send_message(update.effective_message, text, parse_mode="markdown") return "" log = "<b>{}:</b>" \ "\n#BANNED" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)".format(html.escape(chat.title), mention_html(user.id, user.first_name), mention_html(member.user.id, member.user.first_name), member.user.id) if reason: log += "\n<b>Reason:</b> {}".format(reason) try: if conn: context.bot.kickChatMember(chat_id, user_id) context.bot.send_sticker(currentchat.id, BAN_STICKER) # banhammer marie sticker send_message(update.effective_message, tl(update.effective_message, "Banned on *{}*! 😝").format(chat_name), parse_mode="markdown") else: chat.kick_member(user_id) if message.text.split(None, 1)[0][1:] == "sban": update.effective_message.delete() else: context.bot.send_sticker( chat.id, BAN_STICKER) # banhammer marie sticker send_message(update.effective_message, tl(update.effective_message, "Banned! 😝")) return log except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply send_message(update.effective_message, tl(update.effective_message, "Banned! 😝"), quote=False) return log elif excp.message == "Message can't be deleted": pass else: LOGGER.warning(update) LOGGER.exception("ERROR banning user %s in chat %s (%s) due to %s", user_id, chat.title, chat.id, excp.message) send_message( update.effective_message, tl(update.effective_message, "Well damn, I can't ban that User. 😒")) return ""