def send_rules(update, chat_id, from_pm=False): bot = dispatcher.bot chat = update.effective_chat user = update.effective_user # type: Optional[User] try: chat = bot.get_chat(chat_id) except BadRequest as excp: if excp.message == "Chat not found" and from_pm: bot.send_message(user.id, tld(chat.id, "rules_shortcut_not_setup_properly")) return else: raise rules = sql.get_rules(chat_id) text = tld(chat.id, "rules_display").format(escape_markdown(chat.title), rules) if from_pm and rules: bot.send_message(user.id, text, parse_mode=ParseMode.MARKDOWN) elif from_pm: bot.send_message(user.id, tld(chat.id, "rules_not_found")) elif rules: rules_text = tld(chat.id, "rules") update.effective_message.reply_text( tld(chat.id, "rules_button_click"), reply_markup=InlineKeyboardMarkup([[ InlineKeyboardButton(text=rules_text, url="t.me/{}?start={}".format( bot.username, chat_id)) ]])) else: update.effective_message.reply_text(tld(chat.id, "rules_not_found"))
def send_rules(update, chat_id, from_pm=False): bot = dispatcher.bot user = update.effective_user # type: Optional[User] try: chat = bot.get_chat(chat_id) except BadRequest as excp: if excp.message == "Chat not found" and from_pm: bot.send_message(user.id, "The rules shortcut for this chat hasn't been set properly! Ask admins to " "fix this.") return else: raise rules = sql.get_rules(chat_id) text = "The rules for *{}* are:\n\n{}".format(escape_markdown(chat.title), rules) if from_pm and rules: bot.send_message(user.id, text, parse_mode=ParseMode.MARKDOWN) elif from_pm: bot.send_message(user.id, "The group admins haven't set any rules for this chat yet. " "This probably doesn't mean it's lawless though...!") elif rules: update.effective_message.reply_text("Click the button below to get this group's rules.", reply_markup=InlineKeyboardMarkup( [[InlineKeyboardButton(text="Rules", url="t.me/{}?start={}".format(bot.username, chat_id))]])) else: update.effective_message.reply_text("The group admins haven't set any rules for this chat yet. " "This probably doesn't mean it's lawless though...!")
def warn(user: User, chat: Chat, reason: str, message: Message, warner: User = None) -> str: bot = dispatcher.bot if is_user_admin(chat, user.id): message.reply_text(tld(chat.id, 'warns_warn_admin_no_warn')) return "" if warner: warner_tag = mention_html(warner.id, warner.first_name) else: warner_tag = tld(chat.id, 'warns_warn_admin_autofilter') limit, soft_warn = sql.get_warn_setting(chat.id) num_warns, reasons = sql.warn_user(user.id, chat.id, reason) if num_warns >= limit: sql.reset_warns(user.id, chat.id) if soft_warn: # kick chat.unban_member(user.id) reply = tld(chat.id, 'warns_max_warn_kick').format( limit, mention_html(user.id, user.first_name)) else: # ban chat.kick_member(user.id) reply = tld(chat.id, 'warns_max_warn_ban').format( limit, mention_html(user.id, user.first_name)) for warn_reason in reasons: reply += "\n - {}".format(html.escape(warn_reason)) keyboard = [] log_reason = tld(chat.id, 'warns_warn_ban_log_channel').format( html.escape(chat.title), warner_tag, mention_html(user.id, user.first_name), user.id, reason, num_warns, limit) else: keyboard = [[ InlineKeyboardButton(tld(chat.id, 'warns_btn_remove_warn'), callback_data="rm_warn({})".format(user.id)) ]] rules = rules_sql.get_rules(chat.id) if rules: keyboard[0].append( InlineKeyboardButton(tld(chat.id, 'warns_btn_rules'), url="t.me/{}?start={}".format( bot.username, chat.id))) reply = tld(chat.id, 'warns_user_warned').format( mention_html(user.id, user.first_name), num_warns, limit) if reason: reply += tld(chat.id, 'warns_latest_warn_reason').format( html.escape(reason)) log_reason = tld(chat.id, 'warns_warn_log_channel').format( html.escape(chat.title), warner_tag, mention_html(user.id, user.first_name), user.id, reason, num_warns, limit) try: message.reply_text(reply, reply_markup=InlineKeyboardMarkup(keyboard), parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text(reply, reply_markup=InlineKeyboardMarkup(keyboard), parse_mode=ParseMode.HTML, quote=False) else: raise return log_reason
def export_data(bot: Bot, update: Update, chat_data): msg = update.effective_message # type: Optional[Message] user = update.effective_user # type: Optional[User] 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": update.effective_message.reply_text( "This command can only be used on group, not 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 + 10800 checkchat = get_chat(chat_id, chat_data) if checkchat.get('status'): if jam <= int(checkchat.get('value')): timeformatt = time.strftime("%H:%M:%S %d/%m/%Y", time.localtime(checkchat.get('value'))) update.effective_message.reply_text( "You can only backup once a day!\nYou can backup again in about `{}`" .format(timeformatt), parse_mode=ParseMode.MARKDOWN) return else: if user.id != 654839744: put_chat(chat_id, new_jam, chat_data) else: if user.id != 654839744: put_chat(chat_id, new_jam, chat_data) note_list = sql.get_all_chat_notes(chat_id) backup = {} notes = {} button = "" buttonlist = [] namacat = "" isicat = "" rules = "" count = 0 countbtn = 0 # Notes for note in note_list: count += 1 getnote = sql.get_note(chat_id, note.name) namacat += '{}<###splitter###>'.format(note.name) if note.msgtype == 1: tombol = sql.get_buttons(chat_id, note.name) keyb = [] for btn in tombol: countbtn += 1 if btn.same_line: buttonlist.append( ('{}'.format(btn.name), '{}'.format(btn.url), True)) else: buttonlist.append( ('{}'.format(btn.name), '{}'.format(btn.url), False)) isicat += '###button###: {}<###button###>{}<###splitter###>'.format( note.value, str(buttonlist)) buttonlist.clear() elif note.msgtype == 2: isicat += '###sticker###:{}<###splitter###>'.format(note.file) elif note.msgtype == 3: isicat += '###file###:{}<###TYPESPLIT###>{}<###splitter###>'.format( note.file, note.value) elif note.msgtype == 4: isicat += '###photo###:{}<###TYPESPLIT###>{}<###splitter###>'.format( note.file, note.value) elif note.msgtype == 5: isicat += '###audio###:{}<###TYPESPLIT###>{}<###splitter###>'.format( note.file, note.value) elif note.msgtype == 6: isicat += '###voice###:{}<###TYPESPLIT###>{}<###splitter###>'.format( note.file, note.value) elif note.msgtype == 7: isicat += '###video###:{}<###TYPESPLIT###>{}<###splitter###>'.format( note.file, note.value) elif note.msgtype == 8: isicat += '###video_note###:{}<###TYPESPLIT###>{}<###splitter###>'.format( note.file, note.value) else: isicat += '{}<###splitter###>'.format(note.value) for x in range(count): notes['#{}'.format( namacat.split("<###splitter###>")[x])] = '{}'.format( isicat.split("<###splitter###>")[x]) # Rules rules = rulessql.get_rules(chat_id) # Blacklist bl = list(blacklistsql.get_chat_blacklist(chat_id)) # Disabled command disabledcmd = list(disabledsql.get_all_disabled(chat_id)) # Filters (TODO) """ all_filters = list(filtersql.get_chat_triggers(chat_id)) export_filters = {} for filters in all_filters: filt = filtersql.get_filter(chat_id, filters) # print(vars(filt)) if filt.is_sticker: tipefilt = "sticker" elif filt.is_document: tipefilt = "doc" elif filt.is_image: tipefilt = "img" elif filt.is_audio: tipefilt = "audio" elif filt.is_voice: tipefilt = "voice" elif filt.is_video: tipefilt = "video" elif filt.has_buttons: tipefilt = "button" buttons = filtersql.get_buttons(chat.id, filt.keyword) print(vars(buttons)) elif filt.has_markdown: tipefilt = "text" if tipefilt == "button": content = "{}#=#{}|btn|{}".format(tipefilt, filt.reply, buttons) else: content = "{}#=#{}".format(tipefilt, filt.reply) print(content) export_filters[filters] = content print(export_filters) """ # Welcome (TODO) # welc = welcsql.get_welc_pref(chat_id) # Locked locks = locksql.get_locks(chat_id) locked = [] if locks: if locks.sticker: locked.append('sticker') if locks.document: locked.append('document') if locks.contact: locked.append('contact') if locks.audio: locked.append('audio') if locks.game: locked.append('game') if locks.bots: locked.append('bots') if locks.gif: locked.append('gif') if locks.photo: locked.append('photo') if locks.video: locked.append('video') if locks.voice: locked.append('voice') if locks.location: locked.append('location') if locks.forward: locked.append('forward') if locks.url: locked.append('url') restr = locksql.get_restr(chat_id) if restr.other: locked.append('other') if restr.messages: locked.append('messages') if restr.preview: locked.append('preview') if restr.media: locked.append('media') # Warns (TODO) # warns = warnssql.get_warns(chat_id) # Backing up backup[chat_id] = { 'bot': bot.id, 'hashes': { 'info': { 'rules': rules }, 'extra': notes, 'blacklist': bl, 'disabled': disabledcmd, 'locks': locked } } baccinfo = json.dumps(backup, indent=4) f = open("harukab{}.backup".format(chat_id), "w") f.write(str(baccinfo)) 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( MESSAGE_DUMP, "*Successfully imported backup:*\nChat: `{}`\nChat ID: `{}`\nOn: `{}`" .format(chat.title, chat_id, tgl), parse_mode=ParseMode.MARKDOWN) except BadRequest: pass bot.sendDocument( current_chat_id, document=open('harukab{}.backup'.format(chat_id), 'rb'), caption= "*Successfully imported backup:*\nChat: `{}`\nChat ID: `{}`\nOn: `{}`\n\nNote: This `harukab` is specially made for notes." .format(chat.title, chat_id, tgl), timeout=360, reply_to_message_id=msg.message_id, parse_mode=ParseMode.MARKDOWN) os.remove("harukab{}.backup".format(chat_id)) # Cleaning file
def __chat_settings__(bot, update, chat, chatP, user): return "This chat has had it's rules set: `{}`".format( bool(sql.get_rules(chat.id)))
def warn(user: User, chat: Chat, reason: str, message: Message, warner: User = None) -> str: bot = dispatcher.bot if is_user_admin(chat, user.id): message.reply_text("I'm not going to warn an admin!") return "" if warner: warner_tag = mention_html(warner.id, warner.first_name) else: warner_tag = "Automated warn filter." limit, soft_warn = sql.get_warn_setting(chat.id) num_warns, reasons = sql.warn_user(user.id, chat.id, reason) if num_warns >= limit: sql.reset_warns(user.id, chat.id) if soft_warn: # kick chat.unban_member(user.id) reply = "{} warnings, {} has been kicked!".format( limit, mention_html(user.id, user.first_name)) else: # ban chat.kick_member(user.id) reply = "{} warnings, {} has been banned!".format( limit, mention_html(user.id, user.first_name)) for warn_reason in reasons: reply += "\n - {}".format(html.escape(warn_reason)) message.bot.send_sticker(chat.id, BAN_STICKER) # banhammer marie sticker keyboard = [] log_reason = "<b>{}:</b>" \ "\n#WARN_BAN" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)" \ "\n<b>Reason:</b> {}" \ "\n<b>Counts:</b> <code>{}/{}</code>".format(html.escape(chat.title), warner_tag, mention_html(user.id, user.first_name), user.id, reason, num_warns, limit) else: keyboard = [[ InlineKeyboardButton("тЪая╕П Remove warn", callback_data="rm_warn({})".format(user.id)) ]] rules = rules_sql.get_rules(chat.id) if rules: keyboard[0].append( InlineKeyboardButton("ЁЯУЭ Rules", url="t.me/{}?start={}".format( bot.username, chat.id))) reply = "{} <b>has been warned!</b>\nThey have {}/{} warnings.".format( mention_html(user.id, user.first_name), num_warns, limit) if reason: reply += "\nThe latest warning was because:\n<code>{}</code>".format( html.escape(reason)) log_reason = "<b>{}:</b>" \ "\n#WARN" \ "\n<b>Admin:</b> {}" \ "\n<b>User:</b> {} (<code>{}</code>)" \ "\n<b>Reason:</b> {}" \ "\n<b>Counts:</b> <code>{}/{}</code>".format(html.escape(chat.title), warner_tag, mention_html(user.id, user.first_name), user.id, reason, num_warns, limit) try: message.reply_text(reply, reply_markup=InlineKeyboardMarkup(keyboard), parse_mode=ParseMode.HTML) except BadRequest as excp: if excp.message == "Reply message not found": # Do not reply message.reply_text(reply, reply_markup=InlineKeyboardMarkup(keyboard), parse_mode=ParseMode.HTML, quote=False) else: raise return log_reason
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 export_data(bot: Bot, update: Update, chat_data): msg = update.effective_message user = update.effective_user 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 else: if update.effective_message.chat.type == "private": update.effective_message.reply_text( tld(chat.id, "common_cmd_group_only")) return "" chat = update.effective_chat chat_id = update.effective_chat.id jam = time.time() new_jam = jam + 10800 checkchat = get_chat(chat_id, chat_data) if checkchat.get('status'): if jam <= int(checkchat.get('value')): timeformatt = time.strftime("%H:%M:%S %d/%m/%Y", time.localtime(checkchat.get('value'))) update.effective_message.reply_text(tld( chat.id, "backups_err_timelimit").format(timeformatt), parse_mode=ParseMode.MARKDOWN) return else: if user.id != 654839744: put_chat(chat_id, new_jam, chat_data) else: if user.id != 654839744: put_chat(chat_id, new_jam, chat_data) note_list = sql.get_all_chat_notes(chat_id) backup = {} notes = {} buttonlist = [] namacat = "" isicat = "" rules = "" count = 0 countbtn = 0 # Notes for note in note_list: count += 1 namacat += '{}<###splitter###>'.format(note.name) if note.msgtype == 1: tombol = sql.get_buttons(chat_id, note.name) for btn in tombol: countbtn += 1 if btn.same_line: buttonlist.append( ('{}'.format(btn.name), '{}'.format(btn.url), True)) else: buttonlist.append( ('{}'.format(btn.name), '{}'.format(btn.url), False)) isicat += '###button###: {}<###button###>{}<###splitter###>'.format( note.value, str(buttonlist)) buttonlist.clear() elif note.msgtype == 2: isicat += '###sticker###:{}<###splitter###>'.format(note.file) elif note.msgtype == 3: isicat += '###file###:{}<###TYPESPLIT###>{}<###splitter###>'.format( note.file, note.value) elif note.msgtype == 4: isicat += '###photo###:{}<###TYPESPLIT###>{}<###splitter###>'.format( note.file, note.value) elif note.msgtype == 5: isicat += '###audio###:{}<###TYPESPLIT###>{}<###splitter###>'.format( note.file, note.value) elif note.msgtype == 6: isicat += '###voice###:{}<###TYPESPLIT###>{}<###splitter###>'.format( note.file, note.value) elif note.msgtype == 7: isicat += '###video###:{}<###TYPESPLIT###>{}<###splitter###>'.format( note.file, note.value) elif note.msgtype == 8: isicat += '###video_note###:{}<###TYPESPLIT###>{}<###splitter###>'.format( note.file, note.value) else: isicat += '{}<###splitter###>'.format(note.value) for x in range(count): notes['#{}'.format( namacat.split("<###splitter###>")[x])] = '{}'.format( isicat.split("<###splitter###>")[x]) # Rules rules = rulessql.get_rules(chat_id) # Blacklist bl = list(blacklistsql.get_chat_blacklist(chat_id)) # Disabled command disabledcmd = list(disabledsql.get_all_disabled(chat_id)) # Locks locks = locksql.get_locks(chat_id) locked = [] if locks: if locks.sticker: locked.append('sticker') if locks.document: locked.append('document') if locks.contact: locked.append('contact') if locks.audio: locked.append('audio') if locks.game: locked.append('game') if locks.bots: locked.append('bots') if locks.gif: locked.append('gif') if locks.photo: locked.append('photo') if locks.video: locked.append('video') if locks.voice: locked.append('voice') if locks.location: locked.append('location') if locks.forward: locked.append('forward') if locks.url: locked.append('url') restr = locksql.get_restr(chat_id) if restr.other: locked.append('other') if restr.messages: locked.append('messages') if restr.preview: locked.append('preview') if restr.media: locked.append('media') # TODO: Warnings # warns = warnssql.get_warns(chat_id) # Backing up backup[chat_id] = { 'bot': bot.id, 'hashes': { 'info': { 'rules': rules }, 'extra': notes, 'blacklist': bl, 'disabled': disabledcmd, 'locks': locked } } baccinfo = json.dumps(backup, indent=4) f = open("harukab{}.backup".format(chat_id), "w") f.write(str(baccinfo)) 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(MESSAGE_DUMP, tld(chat.id, "backups_success").format(chat.title, chat_id, tgl), parse_mode=ParseMode.MARKDOWN) except BadRequest: pass bot.sendDocument(current_chat_id, document=open('harukab{}.backup'.format(chat_id), 'rb'), caption=tld(chat.id, "backups_success").format( chat.title, chat_id, tgl), timeout=360, reply_to_message_id=msg.message_id, parse_mode=ParseMode.MARKDOWN) os.remove("harukab{}.backup".format(chat_id)) # Cleaning file