def log_user(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] fed_id = fedsql.get_fed_id(chat.id) if fed_id: user = update.effective_user if user: fban, fbanreason, fbantime = fedsql.get_fban_user(fed_id, user.id) if fban: update.effective_message.reply_text(languages.tl(update.effective_message, "Pengguna ini dilarang di federasi saat ini!\nAlasan: `{}`").format(fbanreason), parse_mode="markdown") try: bot.kick_chat_member(chat.id, user.id) except: print("Fban: cannot banned this user") sql.update_user(msg.from_user.id, msg.from_user.username, chat.id, chat.title) if msg.reply_to_message: sql.update_user(msg.reply_to_message.from_user.id, msg.reply_to_message.from_user.username, chat.id, chat.title) if msg.forward_from: sql.update_user(msg.forward_from.id, msg.forward_from.username)
def log_user(update, context): chat = update.effective_chat # type: Optional[Chat] msg = update.effective_message # type: Optional[Message] """text = msg.text if msg.text else "" uid = msg.from_user.id uname = msg.from_user.name print("{} | {} | {} | {}".format(text, uname, uid, chat.title))""" fed_id = fedsql.get_fed_id(chat.id) if fed_id: user = update.effective_user if user: fban, fbanreason, fbantime = fedsql.get_fban_user(fed_id, user.id) if fban: send_message( update.effective_message, languages.tl( update.effective_message, "Pengguna ini dilarang di federasi saat ini!\nAlasan: `{}`" ).format(fbanreason), parse_mode="markdown") try: context.bot.kick_chat_member(chat.id, user.id) except: print("Fban: cannot banned this user") sql.update_user(msg.from_user.id, msg.from_user.username, chat.id, chat.title) if msg.reply_to_message: sql.update_user(msg.reply_to_message.from_user.id, msg.reply_to_message.from_user.username, chat.id, chat.title) if msg.forward_from: sql.update_user(msg.forward_from.id, msg.forward_from.username)
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()