def list_notes(bot: Bot, update: Update): chat_id = update.effective_chat.id chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title msg = "*Notes in {}:*\n" else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "" msg = "*Local Notes:*\n" else: chat_name = chat.title msg = "*Notes in {}:*\n" note_list = sql.get_all_chat_notes(chat_id) for note in note_list: note_name = escape_markdown(" - {}\n".format(note.name)) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == "*Notes in chat:*\n": update.effective_message.reply_text("No notes in this chat!") elif len(msg) != 0: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
def clear_notes(update, context): chat = update.effective_chat user = update.effective_user msg = update.effective_message chatmem = chat.get_member(user.id) if chatmem.status == "creator": allnotes = sql.get_all_chat_notes(chat.id) if not allnotes: msg.reply_text("No notes saved here what should i delete?") return else: msg.reply_text( "Do you really wanna delete all of the notes??", reply_markup=InlineKeyboardMarkup( [ [ InlineKeyboardButton( text="Yes I'm sure️", callback_data="rmnotes_true", ) ], [ InlineKeyboardButton( text="⚠️ Cancel", callback_data="rmnotes_cancel", ) ], ] ), ) else: msg.reply_text("This command can be only used by chat OWNER!")
def rmbutton(bot: Bot, update: Update): query = update.callback_query userid = update.effective_user.id match = query.data.split("_")[1] chat = update.effective_chat owner = chat.get_member(userid).status if match == "cancel" and owner == "creator": return query.message.edit_text("Cancelled deletion of notes.") elif match == "true" and owner == "creator": allnotes = sql.get_all_chat_notes(chat.id) count = 0 notelist = [] for notename in allnotes: count += 1 note = notename.name.lower() notelist.append(note) for i in notelist: sql.rm_note(chat.id, i) query.message.edit_text( f"Successfully cleaned {count} notes in {chat.title}.")
def __chat_settings__(chat_id, user_id): notes = sql.get_all_chat_notes(chat_id) timer = sql.get_clearnotes(chat_id) clear = timer > 0 return "There are `{}` notes in this chat.\nClear welcome is set to {}".format( len(notes), clear) + (" with timer set to {}".format(timer) if clear else ".")
def export_notes(bot: Bot, update: Update): chat_id = update.effective_chat.id notes = sql.get_all_chat_notes(chat_id) notes_dict = {} notes_file = "notes_export.json" msg = update.effective_message.reply_text("Exporting chat notes") if os.path.isfile(notes_file): with open(notes_file, 'r') as f: try: notes_dict = json.loads(f.read()) except json.JSONDecodeError: notes_dict = {} exported = [] for note in notes: _dict = note.to_dict() buttons = sql.get_buttons(chat_id, note.name) _dict["value"] += revert_buttons(buttons) exported.append(_dict) notes_dict[chat_id] = exported with open(notes_file, 'w+') as f: f.write(json.dumps(notes_dict)) msg.delete() update.effective_message.reply_text( "All notes exported. You can now import them using the same bot on a separated server or in a separated chat." )
def clearall_btn(update: Update, context: CallbackContext): query = update.callback_query chat = update.effective_chat message = update.effective_message member = chat.get_member(query.from_user.id) if query.data == "notes_rmall": if member.status == "creator" or query.from_user.id in SUDO_USERS: note_list = sql.get_all_chat_notes(chat.id) try: for notename in note_list: note = notename.name.lower() sql.rm_note(chat.id, note) message.edit_text("Deleted all notes.") except BadRequest: return if member.status == "administrator": query.answer("Only owner of the chat can do this.") if member.status == "member": query.answer("You need to be admin to do this.") elif query.data == "notes_cancel": if member.status == "creator" or query.from_user.id in SUDO_USERS: message.edit_text("Clearing of all notes has been cancelled.") return if member.status == "administrator": query.answer("Only owner of the chat can do this.") if member.status == "member": query.answer("You need to be admin to do this.")
def list_notes(update: Update, context: CallbackContext): bot = context.bot chat_id = update.effective_chat.id timer = sql.get_clearnotes(chat_id) chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] note_list = sql.get_all_chat_notes(chat_id) chat_name = chat.title or chat.first or chat.username msg = "*List of notes in {}:*\n" des = "You can get notes by using `/get notename`, or `#notename`.\n" delmsg = "" for note in note_list: note_name = (" • `{}`\n".format(note.name)) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == "*List of notes in {}:*\n": delmsg = update.effective_message.reply_text("No notes in this chat!") elif len(msg) != 0: delmsg = update.effective_message.reply_text( msg.format(chat_name) + des, parse_mode=ParseMode.MARKDOWN) if timer != 0: sleep(int(timer)) try: delmsg.delete() update.effective_message.delete() except: pass
def list_notes(update: Update, context: CallbackContext): chat_id = update.effective_chat.id note_list = sql.get_all_chat_notes(chat_id) is_private, is_delete = sql.get_private_note(chat_id) notes = len(note_list) + 1 msg = "Get note by `/notenumber` or `#notename` \n\n *ID* *Note* \n" for note_id, note in zip(range(1, notes), note_list): if note_id < 10: note_name = f"`{note_id:2}.` `#{(note.name.lower())}`\n" else: note_name = f"`{note_id}.` `#{(note.name.lower())}`\n" if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if not note_list: update.effective_message.reply_text("No notes in this chat!") elif is_private: buttons = InlineKeyboardMarkup([[ InlineKeyboardButton( text="Click me!", url=f"http://t.me/YuiiChanBot?start=allnotes_{chat_id}", ) ]]) update.effective_message.reply_text( f"Tap here to view all notes in this chat.", parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True, reply_markup=buttons, ) return elif len(msg) != 0: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
def slash_get(update: Update, context: CallbackContext): message, chat_id = update.effective_message.text, update.effective_chat.id no_slash = message[1:] note_list = sql.get_all_chat_notes(chat_id) try: noteid = note_list[int(no_slash) - 1] note_name = str(noteid).strip(">").split()[1] get(update, context, note_name, show_none=False) except IndexError: update.effective_message.reply_text("Wrong Note ID 😾")
def list_notes(bot: Bot, update: Update): chat_id = update.effective_chat.id note_list = sql.get_all_chat_notes(chat_id) msg = "*هشتگ های این گپ:*\n" for note in note_list: note_name = escape_markdown(" - {}\n".format(note.name)) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == "*هشتگ های این گپ:*\n": update.effective_message.reply_text("هشتگی داخل این گپ نیس!") elif len(msg) != 0: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
def list_notes(bot: Bot, update: Update): chat_id = update.effective_chat.id note_list = sql.get_all_chat_notes(chat_id) msg = "*Notes in chat:*\n" for note in note_list: note_name = " - `{}`\n".format(escape_markdown(note.name)) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == "*Notes in chat:*\n": update.effective_message.reply_text("No notes in this chat!") elif len(msg) != 0: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
def list_notes(update: Update, context: CallbackContext): chat_id = update.effective_chat.id note_list = sql.get_all_chat_notes(chat_id) msg = "*Notes in chat:*\n" for note in note_list: note_name = escape_markdown(" - {}\n".format(note.name)) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == "*Notes in chat:*\n": update.effective_message.reply_text("이 채팅방에는 노트가 없어요!") elif len(msg) != 0: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
def list_notes(bot: Bot, update: Update): chat_id = update.effective_chat.id note_list = sql.get_all_chat_notes(chat_id) msg = "*Sohbetteki kayıtlı notlar:*\n" for note in note_list: note_name = escape_markdown(" - {}\n".format(note.name)) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == "*Notes in chat:*\n": update.effective_message.reply_text("Sohbette kayıtlı not yok!") elif len(msg) != 0: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
def list_notes(bot: Bot, update: Update): chat_id = update.effective_chat.id note_list = sql.get_all_chat_notes(chat_id) msg = "*Catatan di grup:*\n" for note in note_list: note_name = escape_markdown(f" - {note.name}\n") if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == "*Catatan di grup:*\n": update.effective_message.reply_text("Belum ada catatan di grup ini!") elif len(msg) != 0: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
def list_notes(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] chat_id = update.effective_chat.id note_list = sql.get_all_chat_notes(chat_id) chat_name = update.effective_chat.title chat_name = chat.title msg = "*Notes in {}:*\n" for note in note_list: note_name = " • `{}`\n".format(note.name) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if not note_list: update.effective_message.reply_text("No notes in this chat!") elif len(msg) != 0: update.effective_message.reply_text(msg.format(chat_name), parse_mode=ParseMode.MARKDOWN)
def list_notes(update, context): chat_id = update.effective_chat.id note_list = sql.get_all_chat_notes(chat_id) msg = "*Notes in this chat:*\n" for note in note_list: note_name = " • `#{}`\n".format(note.name) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == "*Notes in this chat:*\n": update.effective_message.reply_text( tld(chat_id, "No notes in this chat!")) elif len(msg) != 0: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
def list_notes(update: Update, context: CallbackContext): bot = context.bot chat_id = update.effective_chat.id timer = sql.get_clearnotes(chat_id) chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] note_list = sql.get_all_chat_notes(chat_id) msg = "*Get notes* available in here\n" msg += "by adding the *ID* or *Name*\n" msg += "after doing `#` or `/get `\n\n" msg += "*ID* *Name*\n" delmsg = msg count = 1 for note in note_list: if count < 10: note_name = "`{}`. ".format(count) + "`{}`\n".format( note.name) if count >= 10 and count < 100: note_name = "`{}`. ".format(count) + "`{}`\n".format(note.name) if count >= 100: note_name = "`{}`. ".format(count) + "`{}`\n".format(note.name) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name count = count + 1 if delmsg == msg: delmsg = update.effective_message.reply_text("No notes in this chat!") elif len(msg) != 0: delmsg = update.effective_message.reply_text( text=msg, parse_mode=ParseMode.MARKDOWN) if timer != 0: sleep(int(timer)) try: delmsg.delete() update.effective_message.delete() except: pass
def list_notes(update: Update, context: CallbackContext): chat_id = update.effective_chat.id note_list = sql.get_all_chat_notes(chat_id) notes = len(note_list) + 1 msg = "Get note by `/notenumber` or `#notename` \n\n *ID* *Note* \n" for note_id, note in zip(range(1, notes), note_list): if note_id < 10: note_name = f"`{note_id:2}.` `#{(note.name.lower())}`\n" else: note_name = f"`{note_id}.` `#{(note.name.lower())}`\n" if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if not note_list: update.effective_message.reply_text("No notes in this chat!") elif len(msg) != 0: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
def list_notes(bot: Bot, update: Update): chat_id = update.effective_chat.id chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] note_list = sql.get_all_chat_notes(chat_id) chat_name = chat.title or chat.first or chat.username msg = "*List of notes in {}:*\n" des = "You can get notes by using `/get notename`, or `#notename`.\n" for note in note_list: note_name = (" • `{}`\n".format(note.name)) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == "*List of notes in {}:*\n": update.effective_message.reply_text("No notes in this chat!") elif len(msg) != 0: update.effective_message.reply_text(msg.format(chat_name) + des, parse_mode=ParseMode.MARKDOWN)
def lst_notes(bot, update, chat_id): chat = bot.getChat(chat_id) msg = f"*List of Notes in {chat.title}:*\n" note_list = sql.get_all_chat_notes(chat_id) for note in note_list: note_name = f"• [{note.name}](http://t.me/YuiiChanBot?start=notes_{chat_id}={note.name})\n" if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True) msg = "" msg += note_name if not note_list: update.effective_message.reply_text("No notes in *{}*!".format( chat.title), parse_mode=ParseMode.MARKDOWN) elif len(msg) != 0: msg += "\nYou can retrieve these notes by tapping on the notename." update.effective_message.reply_text(msg.format(chat.title), parse_mode=ParseMode.MARKDOWN, disable_web_page_preview=True)
def list_notes(update, context): chat_id = update.effective_chat.id chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(context.bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title msg = "*Notes in {}:*\n" else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "" msg = "*Local Notes:*\n" else: chat_name = chat.title msg = "*Notes saved in {}:*\n" note_list = sql.get_all_chat_notes(chat_id) des = "You can get notes by using `/get notename`, or `#notename`.\n" for note in note_list: note_name = " × `{}`\n".format(note.name.lower()) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if not note_list: update.effective_message.reply_text("No notes saved here!") elif len(msg) != 0: try: update.effective_message.reply_text( msg.format(chat_name) + des, parse_mode=ParseMode.MARKDOWN ) except ValueError: update.effective_message.reply_text( "There was a problem in showing notes list, maybe due to some invalid character in note names. Ask in @tg_botbot if you're unable to figure it out!" )
def clear(update: Update, context: CallbackContext): bot, args = context.bot, context.args chat_id = update.effective_chat.id chat = update.effective_chat chat_name = chat.title or chat.first or chat.username count = 0 if len(args) >= 1: notename = args[0] else: update.effective_message.reply_text("I can't clear empty notes!") return if notename.isnumeric(): check = sql.get_note(chat_id, notename) # If check == true, it means that notename and noteid conflicts each other if check: update.effective_message.reply_text( warning.format(notename=notename)) # If check == false, it means that we need to search notename for given noteid else: note_list = sql.get_all_chat_notes(chat_id) for note in note_list: count = count + 1 if str(count) == notename: notename = note.name break # As it can be overwritten later if sql.rm_note(chat_id, notename): update.effective_message.reply_text( "Note for '`{}`' has been deleted!".format(notename), parse_mode=ParseMode.MARKDOWN, ) else: update.effective_message.reply_text( "Unfortunately, There is no such notes saved on {chat_name}!". format(chat_name=chat_name))
def list_notes(bot: Bot, update: Update): chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title msg = "*Notes in {}:*\n" else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "" msg = "*Local Notes:*\n" else: chat_name = chat.title msg = "*Notes in {}:*\n" note_list = sql.get_all_chat_notes(chat_id) for note in note_list: note_name = " • `#{}`\n".format(note.name) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if not note_list: update.effective_message.reply_text( "No notes in *{}*!".format(chat_name), parse_mode=ParseMode.MARKDOWN) elif len(msg) != 0: msg += "\nYou can retrieve these notes by using `/get notename`, or `#notename`" update.effective_message.reply_text(msg.format(chat_name), parse_mode=ParseMode.MARKDOWN)
def list_notes(bot: Bot, update: Update): chat_id = update.effective_chat.id chat = update.effective_chat # type: Optional[Chat] user = update.effective_user # type: Optional[User] conn = connected(bot, update, chat, user.id, need_admin=False) if not conn == False: chat_id = conn chat_name = dispatcher.bot.getChat(conn).title msg = "*Notes in {}:*\n".format(chat_name) else: chat_id = update.effective_chat.id if chat.type == "private": chat_name = "" msg = "*Local Notes:*\n" else: chat_name = chat.title msg = "*Notes in {}:*\n".format(chat_name) pre_check = msg note_list = sql.get_all_chat_notes(chat_id) for note in note_list: note_name = escape_markdown(" - {}\n".format(note.name)) if len(msg) + len(note_name) > MAX_MESSAGE_LENGTH: update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN) msg = "" msg += note_name if msg == pre_check: update.effective_message.reply_text("No notes in this chat!") elif len(msg) != 0: msg += "\n\n**You can retrieve these notes by using /get notename, or #notename**" msg += "\nIt is recommended to use Telegram X, to use this Telegram Bot." update.effective_message.reply_text(msg, parse_mode=ParseMode.MARKDOWN)
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 != 802002142: put_chat(chat_id, new_jam, chat_data) else: if user.id != 802002142: 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) 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("Reaper{}.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('lucifer{}.backup'.format(chat_id), 'rb'), caption= "*Successfully imported backup:*\nChat: `{}`\nChat ID: `{}`\nOn: `{}`\n\nNote: This 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("lucifer{}.backup".format(chat_id)) # Cleaning file
def export_data(update, context): chat_data = context.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(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": 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 if user.id != OWNER_ID: put_chat(chat_id, new_jam, chat_data) else: if user.id != OWNER_ID: 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 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, "rtl": curr_locks.rtl, } 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 = {} locks = {"locks": locked_lock, "restrict": locked_restr} # Warns (TODO) # warns = warnssql.get_warns(chat_id) # Backing up backup[chat_id] = { "bot": context.bot.id, "hashes": { "info": { "rules": rules }, "extra": notes, "blacklist": bl, "disabled": disabledcmd, "locks": locks, }, } baccinfo = json.dumps(backup, indent=4) f = open("{}.backup".format(chat_id), "w") f.write(str(baccinfo)) f.close() context.bot.sendChatAction(current_chat_id, "upload_document") tgl = time.strftime("%H:%M:%S - %d/%m/%Y", time.localtime(time.time())) try: context.bot.sendMessage( JOIN_LOGGER, "*Successfully imported backup:*\nChat: `{}`\nChat ID: `{}`\nOn: `{}`" .format(chat.title, chat_id, tgl), parse_mode=ParseMode.MARKDOWN, ) except BadRequest: pass context.bot.sendDocument( current_chat_id, document=open("{}.backup".format(chat_id), "rb"), caption= "*Successfully imported backup:*\nChat: `{}`\nChat ID: `{}`\nOn: `{}`\n" .format(chat.title, chat_id, tgl), timeout=360, reply_to_message_id=msg.message_id, parse_mode=ParseMode.MARKDOWN, ) os.remove("{}.backup".format(chat_id)) # Cleaning file
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 note_list = sql.get_all_chat_notes(chat_id) backup = {} notes = {} button = "" buttonlist = [] namacat = "" isicat = "" rules = "" count = 0 countbtn = 0 # 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 }) # 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("Ctrl{}.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('Ctrl{}.backup'.format(chat_id), 'rb'), caption= "*Successfully imported backup:*\nChat: `{}`\nChat ID: `{}`\nOn: `{}`\n\nNote: This `Ctrl's Backup` 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("CTRL{}.backup".format(chat_id)) # Cleaning file
def __chat_settings__(chat_id, user_id): notes = sql.get_all_chat_notes(chat_id) return "There are `{}` notes in this chat.".format(len(notes))
def __chat_settings__(chat_id, user_id): notes = sql.get_all_chat_notes(chat_id) return f"Ada `{len(notes)}` catatan dalam obrolan ini."
def __chat_settings__(chat_id, user_id): notes = sql.get_all_chat_notes(chat_id) return f"There are `{len(notes)}` notes in this chat."