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, "Exit!") tag = "BANNED" elif getmode == 2: chat.kick_member(user.id) chat.unban_member(user.id) execstrings = tld(update.effective_message, "Exit!") tag = "KICKED" elif getmode == 3: bot.restrict_chat_member(chat.id, user.id, can_send_messages=False) execstrings = tld(update.effective_message, "Now you are silent!") tag = "MUTED" elif getmode == 4: bantime = extract_time(msg, getvalue) chat.kick_member(user.id, until_date=bantime) execstrings = tld(update.effective_message, "Out as long {}!").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, "Now you stay silent for {}!").format(getvalue) tag = "TMUTE" send_message(update.effective_message, tld(update.effective_message, "I don't like people who send successive messages. But you made me " "dissapointed. {}").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: send_message(update.effective_message, tld(update.effective_message, "Does not have kick permission, so automatically disables antiflood.")) sql.set_flood(chat.id, 0) return "<b>{}:</b>" \ "\n#INFO" \ "\n{}".format(chat.title, tld(update.effective_message, "Does not have kick permission, so automatically disables antiflood."))
def fed_stat_user(bot, update, args): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] msg = update.effective_message # type: Optional[Message] if args: if args[0].isdigit(): user_id = args[0] else: user_id = extract_user(msg, args) else: user_id = extract_user(msg, args) if user_id: if len(args) == 2 and args[0].isdigit(): fed_id = args[1] user_name, reason, fbantime = sql.get_user_fban(fed_id, str(user_id)) if fbantime: fbantime = time.strftime("%d/%m/%Y", time.localtime(fbantime)) else: fbantime = "Unavaiable" if user_name == False: send_message(update.effective_message, tld(update.effective_message, "Federation {} not found!").format(fed_id), parse_mode="markdown") return if user_name == "" or user_name == None: user_name = tld(update.effective_message, "Day") if not reason: send_message(update.effective_message, tld(update.effective_message, "{} has not been banned in this federation!").format(user_name)) else: text = tld(update.effective_message, "{} banned in this federation because:\n`{}`\n*Banned on:* `{}`").format(user_name, reason, fbantime) send_message(update.effective_message, text, parse_mode="markdown") return user_name, fbanlist = sql.get_user_fbanlist(str(user_id)) if user_name == "": try: user_name = bot.get_chat(user_id).first_name except BadRequest: user_name = tld(update.effective_message, "Day") if user_name == "" or user_name == None: user_name = tld(update.effective_message, "Day") if len(fbanlist) == 0: send_message(update.effective_message, tld(update.effective_message, "{} not yet banned in any federation!").format(user_name)) return else: text = tld(update.effective_message, "{} has been banned in this federation:\n").format(user_name) for x in fbanlist: text += "- `{}`: {}\n".format(x[0], x[1][:20]) text += tld(update.effective_message, "\nIf you want to find out more about the specific reasons for fedban, use it /fbanstat <FedID>") send_message(update.effective_message, text, parse_mode="markdown") elif not msg.reply_to_message and not args: user_id = msg.from_user.id user_name, fbanlist = sql.get_user_fbanlist(user_id) if user_name == "": user_name = msg.from_user.first_name if len(fbanlist) == 0: send_message(update.effective_message, tld(update.effective_message, "{} not yet banned in any federation!").format(user_name)) else: text = tld(update.effective_message, "{} has been banned in this federation:\n").format(user_name) for x in fbanlist: text += "- `{}`: {}\n".format(x[0], x[1][:20]) text += tld(update.effective_message, "\nIf you want to find out more about the specific reasons for fedban, use it /fbanstat <FedID>") send_message(update.effective_message, text, parse_mode="markdown") else: fed_id = args[0] fedinfo = sql.get_fed_info(fed_id) if not fedinfo: send_message(update.effective_message, tld(update.effective_message, "Federation {} not found!").format(fed_id)) return name, reason, fbantime = sql.get_user_fban(fed_id, msg.from_user.id) if fbantime: fbantime = time.strftime("%d/%m/%Y", time.localtime(fbantime)) else: fbantime = "Unavaiable" if not name: name = msg.from_user.first_name if not reason: send_message(update.effective_message, tld(update.effective_message, "{} not banned in this federation").format(name)) return send_message(update.effective_message, tld(update.effective_message, "{} banned in this federation because:\n`{}`\n*Banned on:* `{}`").format(name, reason, fbantime), parse_mode="markdown")
def set_flood_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, tld(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() == 'ban': settypeflood = tld(update.effective_message, 'block') sql.set_flood_strength(chat_id, 1, "0") elif args[0].lower() == 'kick': settypeflood = tld(update.effective_message, 'kick') sql.set_flood_strength(chat_id, 2, "0") elif args[0].lower() == 'mute': settypeflood = tld(update.effective_message, 'mute') sql.set_flood_strength(chat_id, 3, "0") elif args[0].lower() == 'tban': if len(args) == 1: text = tld( update.effective_message, """It looks like you are trying to set a temporary value for anti-flood, but have not determined the time yet; use `/ setfloodmode tban <timevalue> `. Example time values: 4m = 4 minutes, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks.""" ) send_message(update.effective_message, text, parse_mode="markdown") return settypeflood = tld(update.effective_message, "block while for {}").format(args[1]) sql.set_flood_strength(chat_id, 4, str(args[1])) elif args[0].lower() == 'tmute': if len(args) == 1: text = tld( update.effective_message, """It looks like you are trying to set a temporary value for anti-flood, but have not determined the time yet; use `/ setfloodmode tmute <timevalue>`. Example time values: 4m = 4 minutes, 3h = 3 hours, 6d = 6 days, 5w = 5 weeks.""" ) send_message(update.effective_message, text, parse_mode="markdown") return settypeflood = tld(update.effective_message, 'block while for {}').format(args[1]) sql.set_flood_strength(chat_id, 5, str(args[1])) else: send_message( update.effective_message, tld(update.effective_message, "I only understand ban/kick/mute/tban/tmute!")) return if conn: text = tld( update.effective_message, "Sending too many messages now will result in `{}` in * {} *! " ).format(settypeflood, chat_name) else: text = tld( update.effective_message, "Sending too many messages will now result in `{}`!").format( settypeflood) send_message(update.effective_message, 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, 'block') 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, 'block while for {}').format(getvalue) elif getmode == 5: settypeflood = tld(update.effective_message, 'block while for {}').format(getvalue) if conn: text = tld( update.effective_message, "If a member sends successive messages, he will *{}* in *{}*." ).format(settypeflood, chat_name) else: text = tl( update.effective_message, "If a member sends successive messages, he will be *{}*." ).format(settypeflood) send_message(update.effective_message, text, parse_mode=ParseMode.MARKDOWN) return ""
def export_data(bot: Bot, update: Update, chat_data): msg = update.effective_message # type: Optional[Message] 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 chat_id = update.effective_chat.id chat = update.effective_chat current_chat_id = update.effective_chat.id 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, tld(update.effective_message, "You can use this command in group and not in PM")) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title jam = time.time() new_jam = jam + 43200 cek = get_chat(chat_id, chat_data) if cek.get('status'): if jam <= int(cek.get('value')): waktu = time.strftime("%H:%M:%S %d/%m/%Y", time.localtime(cek.get('value'))) send_message(update.effective_message, tld(update.effective_message, "You can back up your data once in 12 hours!\n[This Person](tg://user?id={}) already backed up.You can back up data again on `{}`").format(cek.get('user'), waktu), parse_mode=ParseMode.MARKDOWN) return else: if user.id != OWNER_ID: put_chat(chat_id, user.id, new_jam, chat_data) else: if user.id != OWNER_ID: put_chat(chat_id, user.id, new_jam, chat_data) # Backup version # Revision: 07/07/2019 backup_ver = 1 bot_base = "Kanna" # Make sure this backup is for this bot bot_id = bot.id # Backuping antiflood flood_mode, flood_duration = antifloodsql.get_flood_setting(chat_id) flood_limit = antifloodsql.get_flood_limit(chat_id) antiflood = {'flood_mode': flood_mode, 'flood_duration': flood_duration, 'flood_limit': flood_limit} # Backuping blacklists all_blacklisted = blacklistsql.get_chat_blacklist(chat_id) blacklist_mode, blacklist_duration = blacklistsql.get_blacklist_setting(chat.id) blacklists = {'blacklist_mode': blacklist_mode, 'blacklist_duration': blacklist_duration, 'blacklists': all_blacklisted} # Backuping blacklists sticker # Backuping disabled cmd_disabled = disabledsql.get_all_disabled(chat_id) disabled = {'disabled': cmd_disabled} # Backuping filters all_filters = filtersql.get_chat_triggers(chat_id) filters_gen = [] for x in all_filters: filt = filtersql.get_filter(chat.id, x) if filt.is_sticker: filt_type = 1 elif filt.is_document: filt_type = 2 elif filt.is_image: filt_type = 3 elif filt.is_audio: filt_type = 4 elif filt.is_voice: filt_type = 5 elif filt.is_video: filt_type = 6 elif filt.has_markdown: filt_type = 0 else: filt_type = 7 filters_gen.append({"name": x, "reply": filt.reply, "type": filt_type}) filters = {'filters': filters_gen} # Backuping greetings msg and config # Backuping locks curr_locks = locksql.get_locks(chat_id) curr_restr = locksql.get_restr(chat_id) if curr_locks: locked_lock = { "sticker": curr_locks.sticker, "audio": curr_locks.audio, "voice": curr_locks.voice, "document": curr_locks.document, "video": curr_locks.video, "contact": curr_locks.contact, "photo": curr_locks.photo, "gif": curr_locks.gif, "url": curr_locks.url, "bots": curr_locks.bots, "forward": curr_locks.forward, "game": curr_locks.game, "location": curr_locks.location, } else: locked_lock = {} if curr_restr: locked_restr = { "messages": curr_restr.messages, "media": curr_restr.media, "other": curr_restr.other, "previews": curr_restr.preview, "all": all([curr_restr.messages, curr_restr.media, curr_restr.other, curr_restr.preview]) } else: locked_restr = {} lock_warn = locksql.get_lockconf(chat_id) locks = {'lock_warn': lock_warn, 'locks': locked_lock, 'restrict': locked_restr} # Backuping notes note_list = notesql.get_all_chat_notes(chat_id) notes = [] for note in note_list: buttonlist = "" note_tag = note.name note_type = note.msgtype getnote = notesql.get_note(chat_id, note.name) if not note.value: note_data = "" else: tombol = notesql.get_buttons(chat_id, note_tag) keyb = [] buttonlist = "" for btn in tombol: if btn.same_line: buttonlist += "[{}](buttonurl:{}:same)\n".format(btn.name, btn.url) else: buttonlist += "[{}](buttonurl:{})\n".format(btn.name, btn.url) note_data = "{}\n\n{}".format(note.value, buttonlist) note_file = note.file if not note_file: note_file = "" notes.append({"note_tag": note_tag, "note_data": note_data, "note_file": note_file, "note_type": note_type}) # Backuping reports get_report = reportsql.user_should_report(chat_id) report = {'report': get_report} # Backuping rules getrules = rulessql.get_rules(chat_id) rules = {"rules": getrules} # Backuping warns config and warn filters # Parsing backups backup = {"bot_id": bot_id, "bot_base": bot_base, "antiflood": antiflood, "blacklists": blacklists, "disabled": disabled, "filters": filters, "locks": locks, "notes": notes, "report": report, "rules": rules, "version": backup_ver} all_backups = json.dumps(backup, indent=4, cls=SetEncoder) f = open("{}-Kanna.backup".format(chat_id), "w") f.write(str(all_backups)) f.close() bot.sendChatAction(current_chat_id, "upload_document") tgl = time.strftime("%H:%M:%S - %d/%m/%Y", time.localtime(time.time())) try: bot.sendMessage(TEMPORARY_DATA, "*Successfully backed up for:*\nChat Name: `{}`\nChat ID: `{}`\nOn: `{}`".format(chat.title, chat_id, tgl), parse_mode=ParseMode.MARKDOWN) except BadRequest: pass send = bot.sendDocument(current_chat_id, document=open('{}-bot.backup'.format(chat_id), 'rb'), caption=tld(update.effective_message, "*Successfully backed up for:*\nChat Name: `{}`\nChat ID: `{}`\nOn: `{}`\n\nNote: This backup is specific to this bot.").format(chat.title, chat_id, tgl), timeout=360, reply_to_message_id=msg.message_id, parse_mode=ParseMode.MARKDOWN) try: # Send to temp data for prevent unexpected issue bot.sendDocument(TEMPORARY_DATA, document=send.document.file_id, caption=tld(update.effective_message, "*Successfully backed up for:*\nChat Name: `{}`\nVhat ID: `{}`\nOn: `{}`\n\nNote: This backup is specific to this bo").format(chat.title, chat_id, tgl), timeout=360, parse_mode=ParseMode.MARKDOWN) except BadRequest: pass os.remove("{}-bot.backup".format(chat_id)) # Cleaning file
def import_data(bot: Bot, update): msg = update.effective_message # type: Optional[Message] chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] # TODO: allow uploading doc with command, not just as reply # only work with a doc 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=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, tld(update.effective_message, "You can use this command in group and not in PM")) return "" chat = update.effective_chat chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title if msg.reply_to_message and msg.reply_to_message.document: filetype = msg.reply_to_message.document.file_name if filetype.split('.')[-1] not in ("backup", "json", "txt"): send_message(update.effective_message, tld(update.effective_message, "Invalid backup file!")) return try: file_info = bot.get_file(msg.reply_to_message.document.file_id) except BadRequest: send_message(update.effective_message, tld(update.effective_message, "Try downloading and re-uploading the file as yourself before importing - this one seems broken!")) return with BytesIO() as file: file_info.download(out=file) file.seek(0) data = json.load(file) try: # If backup is from Emilia if data.get('bot_base') == "Kanna": imp_antiflood = False imp_blacklist = False imp_blacklist_count = 0 imp_disabled_count = 0 imp_filters_count = 0 imp_locks = False imp_notes = 0 imp_report = False imp_rules = False NOT_IMPORTED = "This cannot be imported because from other bot." NOT_IMPORTED_INT = 0 # If backup is from this bot, import all files if data.get('bot_id') == bot.id: is_self = True else: is_self = False # Import antiflood if data.get('antiflood'): imp_antiflood = True flood_limit = data['antiflood'].get('flood_limit') flood_mode = data['antiflood'].get('flood_mode') flood_duration = data['antiflood'].get('flood_duration') # Add to db antifloodsql.set_flood(chat_id, int(flood_limit)) antifloodsql.set_flood_strength(chat_id, flood_mode, flood_duration) # Import blacklist if data.get('blacklists'): imp_blacklist = True blacklist_mode = data['blacklists'].get('blacklist_mode') blacklist_duration = data['blacklists'].get('blacklist_duration') blacklisted = data['blacklists'].get('blacklists') # Add to db blacklistsql.set_blacklist_strength(chat_id, blacklist_mode, blacklist_duration) if blacklisted: for x in blacklisted: blacklistsql.add_to_blacklist(chat_id, x.lower()) imp_blacklist_count += 1 # Import blacklist sticker # Import disabled if data.get('disabled'): candisable = disabledsql.get_disableable() if data['disabled'].get('disabled'): for listdisabled in data['disabled'].get('disabled'): if listdisabled in candisable: disabledsql.disable_command(chat_id, listdisabled) imp_disabled_count += 1 # Import filters if data.get('filters'): NOT_IMPORTED += "\n\nFilters:\n" for x in data['filters'].get('filters'): # If from self, import all if is_self: is_sticker = False is_document = False is_image = False is_audio = False is_voice = False is_video = False has_markdown = False universal = False if x['type'] == 1: is_sticker = True elif x['type'] == 2: is_document = True elif x['type'] == 3: is_image = True elif x['type'] == 4: is_audio = True elif x['type'] == 5: is_voice = True elif x['type'] == 6: is_video = True elif x['type'] == 0: has_markdown = True note_data, buttons = button_markdown_parser(x['reply'], entities=0) filtersql.add_filter(chat_id, x['name'], note_data, is_sticker, is_document, is_image, is_audio, is_voice, is_video, buttons) imp_filters_count += 1 else: if x['has_markdown']: note_data, buttons = button_markdown_parser(x['reply'], entities=0) filtersql.add_filter(chat_id, x['name'], note_data, False, False, False, False, False, False, buttons) imp_filters_count += 1 else: NOT_IMPORTED += "- {}\n".format(x['name']) NOT_IMPORTED_INT += 1 # Import greetings # Import Locks if data.get('locks'): if data['locks'].get('lock_warn'): locksql.set_lockconf(chat_id, True) else: locksql.set_lockconf(chat_id, False) if data['locks'].get('locks'): for x in list(data['locks'].get('locks')): if x in LOCK_TYPES: is_locked = data['locks']['locks'].get('x') locksql.update_lock(chat_id, x, locked=is_locked) imp_locks = True if x in RESTRICTION_TYPES: is_locked = data['locks']['locks'].get('x') locksql.update_restriction(chat_id, x, locked=is_locked) imp_locks = True # Import notes if data.get('notes'): allnotes = data['notes'] NOT_IMPORTED += "\n\nNotes:\n" for x in allnotes: # If from self, import all if is_self: note_data, buttons = button_markdown_parser(x['note_data'], entities=0) note_name = x['note_tag'] note_file = None note_type = x['note_type'] if x['note_file']: note_file = x['note_file'] if note_type == 0: note_type = Types.TEXT elif note_type == 1: note_type = Types.BUTTON_TEXT elif note_type == 2: note_type = Types.STICKER elif note_type == 3: note_type = Types.DOCUMENT elif note_type == 4: note_type = Types.PHOTO elif note_type == 5: note_type = Types.AUDIO elif note_type == 6: note_type = Types.VOICE elif note_type == 7: note_type = Types.VIDEO elif note_type == 8: note_type = Types.VIDEO_NOTE else: note_type = None if note_type <= 8: notesql.add_note_to_db(chat_id, note_name, note_data, note_type, buttons, note_file) imp_notes += 1 else: # If this text if x['note_type'] == 0: note_data, buttons = button_markdown_parser(x['text'].replace("\\", ""), entities=0) note_name = x['name'] notesql.add_note_to_db(chat_id, note_name, note_data, Types.TEXT, buttons, None) imp_notes += 1 else: NOT_IMPORTED += "- {}\n".format(x['name']) NOT_IMPORTED_INT += 1 # Import reports if data.get('report'): reporting = data['report'].get('report') reportsql.set_chat_setting(chat_id, bool(reporting)) imp_report = True # Import rules if data.get('rules'): contrules = data['rules'].get('rules') if contrules: rulessql.set_rules(chat_id, contrules) imp_rules = True # Import warn config if conn: text = tld(update.effective_message, "The backup is fully restored at * {} *. Welcome back! 😀").format(chat_name) else: text = tld(update.effective_message, "The backup is fully restored. Congratulations welcome back! 😀").format(chat_name) text += tld(update.effective_message, "\n\nWhat I return:\n") if imp_antiflood: text += tld(update.effective_message, "- Settings Antiflood\n") if imp_blacklist: text += tld(update.effective_message, "- Settings Blacklist\n") if imp_blacklist_count: text += tld(update.effective_message, "- {} blacklists\n").format(imp_blacklist_count) if imp_disabled_count: text += tld(update.effective_message, "- {} cmd disabled\n").format(imp_disabled_count) if imp_filters_count: text += tld(update.effective_message, "- {} filters\n").format(imp_filters_count) if imp_locks: text += tld(update.effective_message, "- Lockup\n") if imp_notes: text += tld(update.effective_message, "- {} a note\n").format(imp_notes) if imp_report: text += tld(update.effective_message, "- Reporting arrangements\n") if imp_rules: text += tld(update.effective_message, "- Order regulations group\n") try: send_message(update.effective_message, text, parse_mode="markdown") except BadRequest: send_message(update.effective_message, text, parse_mode="markdown", quote=False) if NOT_IMPORTED_INT: f = open("{}-notimported.txt".format(chat_id), "w") f.write(str(NOT_IMPORTED)) f.close() bot.sendDocument(chat_id, document=open('{}-notimported.txt'.format(chat_id), 'rb'), caption=tl(update.effective_message, "*Data yang tidak dapat di import*"), timeout=360, parse_mode=ParseMode.MARKDOWN) os.remove("{}-notimported.txt".format(chat_id)) return except Exception as err: send_message(update.effective_message, tld(update.effective_message, "An error occured in importing backup.Report it in @LucySupportChat"), parse_mode="markdown") LOGGER.exception("An error when importing from Haruka base!") return try: # If backup is from rose # doing manual lol if data.get('bot_id') == 609517172: imp_antiflood = False imp_blacklist = False imp_blacklist_count = 0 imp_disabled_count = 0 imp_filters_count = 0 imp_notes = 0 imp_report = False imp_rules = False NOT_IMPORTED = "This cannot be imported because from other bot." NOT_IMPORTED_INT = 0 if data.get('data'): # Import antiflood if data['data'].get('antiflood'): floodlimit = data['data']['antiflood'].get('flood_limit') action = data['data']['antiflood'].get('action') actionduration = data['data']['antiflood'].get('action_duration') act_dur = make_time(int(actionduration)) antifloodsql.set_flood(chat_id, int(floodlimit)) if action == "ban": antifloodsql.set_flood_strength(chat_id, 1, str(act_dur)) imp_antiflood = True elif action == "kick": antifloodsql.set_flood_strength(chat_id, 2, str(act_dur)) imp_antiflood = True elif action == "mute": antifloodsql.set_flood_strength(chat_id, 3, str(act_dur)) imp_antiflood = True # Import blacklist if data['data'].get('blacklists'): action = data['data']['blacklists'].get('action') actionduration = data['data']['blacklists'].get('action_duration') act_dur = make_time(int(actionduration)) strengthdone = False if action == "del": strengthdone = True blacklistsql.set_blacklist_strength(chat_id, 1, str(act_dur)) imp_blacklist = True elif action == "warn": strengthdone = True blacklistsql.set_blacklist_strength(chat_id, 2, str(act_dur)) imp_blacklist = True elif action == "mute": strengthdone = True blacklistsql.set_blacklist_strength(chat_id, 3, str(act_dur)) imp_blacklist = True elif action == "kick": strengthdone = True blacklistsql.set_blacklist_strength(chat_id, 4, str(act_dur)) imp_blacklist = True elif action == "ban": strengthdone = True blacklistsql.set_blacklist_strength(chat_id, 5, str(act_dur)) imp_blacklist = True else: if not strengthdone: action = data['data']['blacklists'].get('should_delete') if action: blacklistsql.set_blacklist_strength(chat_id, 1, "0") imp_blacklist = True blacklisted = data['data']['blacklists'].get('filters') if blacklisted: for x in blacklisted: blacklistsql.add_to_blacklist(chat_id, x['name'].lower()) imp_blacklist_count += 1 # Import disabled if data['data'].get('disabled'): if data['data']['disabled'].get('disabled'): candisable = disabledsql.get_disableable() for listdisabled in data['data']['disabled'].get('disabled'): if listdisabled in candisable: disabledsql.disable_command(chat_id, listdisabled) imp_disabled_count += 1 # Import filters if data['data'].get('filters'): NOT_IMPORTED += "\n\nFilters:\n" if data['data']['filters'].get('filters'): for x in data['data']['filters'].get('filters'): if x['type'] == 0: note_data, buttons = button_markdown_parser(x['text'].replace("\\", ""), entities=0) filtersql.add_filter(chat_id, x['name'], note_data, False, False, False, False, False, False, buttons) imp_filters_count += 1 else: NOT_IMPORTED += "- {}\n".format(x['name']) NOT_IMPORTED_INT += 1 # Import greetings # Import notes if data['data'].get('notes'): NOT_IMPORTED += "\n\nNotes:\n" allnotes = data['data']['notes']['notes'] for x in allnotes: # If this text if x['type'] == 0: note_data, buttons = button_markdown_parser(x['text'].replace("\\", ""), entities=0) note_name = x['name'] notesql.add_note_to_db(chat_id, note_name, note_data, Types.TEXT, buttons, None) imp_notes += 1 else: NOT_IMPORTED += "- {}\n".format(x['name']) NOT_IMPORTED_INT += 1 # Import reports if data['data'].get('reports'): if data['data']['reports'].get('disable_reports'): reporting = False else: reporting = True reportsql.set_chat_setting(chat_id, reporting) imp_report = True # Import rules if data['data'].get('rules'): contrules = data['data']['rules'].get('content') if contrules: rulessql.set_rules(chat_id, contrules.replace("\\", "")) imp_rules = True # Import warn if conn: text = tld(update.effective_message, "Backup fully restored at *{}*. Congratulations welcome back! 😀").format(chat_name) else: text = tld(update.effective_message, "Backup fully restored. Congratulations welcome back! 😀").format(chat_name) text += tld(update.effective_message, "\n\nI returned:\n") if imp_antiflood: text += tld(update.effective_message, "- Setting Antiflood\n") if imp_blacklist: text += tld(update.effective_message, "- Settings Blacklist\n") if imp_blacklist_count: text += tld(update.effective_message, "- {} blacklists\n").format(imp_blacklist_count) if imp_disabled_count: text += tld(update.effective_message, "- {} cmd disabled\n").format(imp_disabled_count) if imp_filters_count: text += tld(update.effective_message, "- {} filters\n").format(imp_filters_count) if imp_notes: text += tld(update.effective_message, "- {} a note\n").format(imp_notes) if imp_report: text += tld(update.effective_message, "- Reporting arrangements\n") if imp_rules: text += tld(update.effective_message, "- Order group rules\n") try: send_message(update.effective_message, text, parse_mode="markdown") except BadRequest: send_message(update.effective_message, text, parse_mode="markdown", quote=False) if NOT_IMPORTED_INT: f = open("{}-notimported.txt".format(chat_id), "w") f.write(str(NOT_IMPORTED)) f.close() bot.sendDocument(chat_id, document=open('{}-notimported.txt'.format(chat_id), 'rb'), caption=tld(update.effective_message, "*data cannot be imported*"), timeout=360, parse_mode=ParseMode.MARKDOWN) os.remove("{}-notimported.txt".format(chat_id)) return except Exception as err: send_message(update.effective_message, tld(update.effective_message, "An error occured while restoring backup report at @LucySupportChat"), parse_mode="markdown") LOGGER.exception("An error when importing from Rose base!") return # only import one group if len(data) > 1 and str(chat_id) not in data: send_message(update.effective_message, tld(update.effective_message, "There is more than one group in this file, and no one has the same chat id as" "this group - how do you choose what to import?")) return # Check if backup is this chat try: if data.get(str(chat_id)) == None: if conn: text = tld(update.effective_message, "Backup originates from another chat, I can't return another chat to chat *{}*").format(chat_name) else: text = tld(update.effective_message, "Backup originates from another chat") return send_message(update.effective_message, text, parse_mode="markdown") except: return send_message(update.effective_message, tld(update.effective_message, "An error has occurred in checking the data, please report it to my author at @ LucySupportChat! 🙂")) # Check if backup is from self try: if str(bot.id) != str(data[str(chat_id)]['bot']): return send_message(update.effective_message, tld(update.effective_message, "Backup comes from another bot🙂")) except: pass # Select data source if str(chat_id) in data: data = data[str(chat_id)]['hashes'] else: data = data[list(data.keys())[0]]['hashes'] try: for mod in DATA_IMPORT: mod.__import_data__(str(chat_id), data) except Exception: send_message(update.effective_message, tld(update.effective_message, "An error occurred while restoring your data. The process may not be complete🙂")) LOGGER.exception("Impor untuk id chat %s dengan nama %s gagal.", str(chat_id), str(chat.title)) return # TODO: some of that link logic # NOTE: consider default permissions stuff? if conn: text = tld(update.effective_message, "Backup was restored successfully *{}*. Congratulations welcome back! 😀").format(chat_name) else: text = tld(update.effective_message, "Backup was restored successfully. Congratulations welcome back! 😀").format(chat_name) send_message(update.effective_message, text, parse_mode="markdown")
def set_blue_text_must_click(bot: Bot, update: Update, args): 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 conn = connected(bot, update, chat, user.id, need_admin=True) if conn: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title else: if update.effective_message.chat.type == "private": send_message( update.effective_message, tld(update.effective_message, "You can do this command on the group, not on PM")) return "" chat_id = update.effective_chat.id chat_name = update.effective_message.chat.title if len(args) >= 1: val = args[0].lower() if val == "off" or val == "no": sql.set_cleanbt(chat_id, False) if conn: text = tld( update.effective_message, "The blue message eraser has been *deactivated* in *{}*." ).format(chat_name) else: text = tld(update.effective_message, "The blue message eraser has been *deactivated*.") send_message(update.effective_message, text, parse_mode="markdown") elif val == "yes" or val == "ya" or val == "on": sql.set_cleanbt(chat_id, True) if conn: text = tld( update.effective_message, "The blue message eraser has been *activated* in *{}*." ).format(chat_name) else: text = tld(update.effective_message, "The blue message eraser has been *activated*.") send_message(update.effective_message, text, parse_mode="markdown") else: send_message( update.effective_message, tld(update.effective_message, "Unknown argument - please use 'yes', or 'no'.")) else: send_message( update.effective_message, tld( update.effective_message, "The setting for the blue message eraser is currently on {}: *{}*" ).format(chat_name, "Enabled" if sql.is_enable(chat_id) else "Disabled"), parse_mode="markdown")