def open_element(chat_id,element_path): storage = literal_eval(users.get_conf_value(chat_id, 'General', 'storage', str(DEFAULT_FOLDER_STRUCTURE))) if element_path[-1] == '..': element_path = element_path[0:-2] element = get_element(storage,element_path) if element: if element['mime_type'] == 'folder': users.update_conf(chat_id, 'General', 'position', element_path) display_folder(chat_id,storage,element_path) elif element['mime_type'] == 'telegram/audio' or element['mime_type'] == 'audio/telegram': methods.send_audio(chat_id, element['file_id']) display_folder(chat_id,storage,element_path[0:-1]) elif element['mime_type'] == 'telegram/contact': profile_photo = methods.get_user_profile_photos(element['user_id'],limit = 1) methods.send_photo(chat_id, profile_photo['result']['photos'][0][0]['file_id'], element['first_name'] + ' ' + element['last_name'] + '\n' +\ '+' + element['phone_number'],) methods.send_message(chat_id, element['first_name'] + ' ' + element['last_name'] + '\n' +\ '+' + element['phone_number'] + '\n' +\ str(element['user_id'])) display_folder(chat_id,storage,element_path[0:-1]) elif element['mime_type'] == 'telegram/location': methods.send_location(chat_id, element['latitude'], element['longitude']) display_folder(chat_id,storage,element_path[0:-1]) elif element['mime_type'] == 'telegram/message': methods.forward_message(chat_id, chat_id, element['message_id']) display_folder(chat_id,storage,element_path[0:-1]) elif element['mime_type'] == 'telegram/photo': methods.send_photo(chat_id, element['file_id']) display_folder(chat_id,storage,element_path[0:-1]) elif element['mime_type'] == 'telegram/url-stickerpack': methods.send_message(chat_id, 'https://telegram.me/addstickers/' + element['stickerpack_name']) display_folder(chat_id,storage,element_path[0:-1]) elif element['mime_type'] == 'telegram/url-chat': methods.send_message(chat_id, 'https://telegram.me/joinchat/' + element['group_name']) display_folder(chat_id,storage,element_path[0:-1]) elif element['mime_type'] == 'telegram/url-contact': methods.send_message(chat_id, 'https://telegram.me/' + element['contact_name']) display_folder(chat_id,storage,element_path[0:-1]) else: methods.send_document(chat_id, element['file_id']) display_folder(chat_id,storage,element_path[0:-1]) else: methods.send_message(chat_id, '⚠ ' + position_to_path(element_path) + ' does not exists') display_folder(chat_id, storage, literal_eval(users.get_conf_value(chat_id, 'General', 'position', '[]')))
def document_sended(chat_id, document): task = users.get_conf_value(chat_id, 'General', 'task', '') if task == '': storage = literal_eval(users.get_conf_value(chat_id, 'General', 'storage', str(DEFAULT_FOLDER_STRUCTURE))) position = literal_eval(users.get_conf_value(chat_id, 'General', 'position', '[]')) file_name = document['file_name'].replace('\'','\\\'') document['icon'] = None if file_name in get_element(storage,position)['content'].keys(): file_name = correct(file_name) storage = set_element(storage,position,{file_name:document},'content') users.update_conf(chat_id, 'General', 'storage', storage) display_folder(chat_id,storage,position)
def perform(chat_id, text): position = literal_eval(users.get_conf_value(chat_id, 'General', 'position', '[]')) task = users.get_conf_value(chat_id, 'General', 'task', '') responses = literal_eval(users.get_conf_value(chat_id, 'General', 'responses', '{}')) try: text = responses[text] except KeyError: pass if text == '/start': storage = literal_eval(users.get_conf_value(chat_id, 'General', 'storage', str(DEFAULT_FOLDER_STRUCTURE))) display_folder(chat_id,storage,position) elif task == '☑': selected = literal_eval(users.get_conf_value(chat_id, 'General', 'selected', '[]')) storage = literal_eval(users.get_conf_value(chat_id, 'General', 'storage', str(DEFAULT_FOLDER_STRUCTURE))) responses =literal_eval(users.get_conf_value(chat_id, 'General', 'responses', '{}')) try: text = responses[text] except KeyError: pass text = text.replace(chr(65039),'') if is_a_emoji(text[0]): code = text[0] else: code = None if code == '✖': users.update_conf(chat_id, 'General', 'task', '') users.update_conf(chat_id, 'General', 'selected', '[]') display_folder(chat_id,storage,position) elif code == '▪': selected = list(get_element(storage,position)['content'].keys()) users.update_conf(chat_id, 'General', 'selected', str(selected)) display_folder(chat_id,storage,position,selected) elif code == '▫': selected = [] users.update_conf(chat_id, 'General', 'selected', '[]') display_folder(chat_id,storage,position,selected) elif code == '❌': for element in selected: element = protect_string(element) del_element(storage,position + [element]) users.update_conf(chat_id, 'General', 'storage', str(storage)) users.update_conf(chat_id, 'General', 'task', '') users.update_conf(chat_id, 'General', 'selected', '[]') display_folder(chat_id,storage,position) elif code == '📑': copy_elements(chat_id, storage, position, selected) users.update_conf(chat_id, 'General', 'task', '') users.update_conf(chat_id, 'General', 'selected', '[]') display_folder(chat_id,storage,position) elif code == '✂': copy_elements(chat_id, storage, position, selected) for element in selected: element = protect_string(element) del_element(storage,position + [element]) users.update_conf(chat_id, 'General', 'storage', str(storage)) users.update_conf(chat_id, 'General', 'task', '') users.update_conf(chat_id, 'General', 'selected', '[]') display_folder(chat_id,storage,position) elif code == '✏' and len(selected) == 1: users.update_conf(chat_id, 'General', 'task', '✏') methods.send_message(chat_id, 'Insert a new name:',reply_markup = {'keyboard': [['✖ Cancel']], 'resize_keyboard':True}) users.update_conf(chat_id, 'General', 'position', position + selected) elif code == '🔵' and len(selected) == 1: users.update_conf(chat_id, 'General', 'task', '🔵') methods.send_message(chat_id, 'Send an emoji:',reply_markup = {'keyboard': [['🔵 Default','✖ Cancel']], 'resize_keyboard':True}) users.update_conf(chat_id, 'General', 'position', position + selected) elif code == 'ℹ' and len(selected) == 1: users.update_conf(chat_id, 'General', 'position', position + selected) methods.send_message(chat_id, '⛔ Not implemented') elif text in get_element(storage,position)['content']: if text in selected: selected.remove(text) else: selected.append(text) users.update_conf(chat_id, 'General', 'selected', selected) display_folder(chat_id,storage,position,selected) else: methods.send_message(chat_id, '⚠ ' + text + ' does not exists') elif task == '✏': if text[0] == '✖': storage = literal_eval(users.get_conf_value(chat_id, 'General', 'storage', str(DEFAULT_FOLDER_STRUCTURE))) users.update_conf(chat_id, 'General', 'position', position[0:-1]) users.update_conf(chat_id, 'General', 'task', '') users.update_conf(chat_id, 'General', 'selected', '[]') display_folder(chat_id,storage,position[0:-1]) elif text == '.' or text == '..': methods.send_message(chat_id, '⛔ Name can not be "." or ".."\nInsert another folder name:') elif has_emojis(text): methods.send_message(chat_id, '⛔ Name can not contain emojis\nInsert another folder name:') else: storage = literal_eval(users.get_conf_value(chat_id, 'General', 'storage', str(DEFAULT_FOLDER_STRUCTURE))) element = get_element(storage,position) if text in get_element(storage,position[0:-1])['content'].keys(): methods.send_message(chat_id, '⛔ There is already a folder named ' + text + '\nInsert another folder name:') else: print(storage,position[0:-1],{text:element}) storage = set_element(storage,position[0:-1],{text:element},'content') del_element(storage,position) users.update_conf(chat_id, 'General', 'storage', str(storage)) users.update_conf(chat_id, 'General', 'position', position[0:-1]) users.update_conf(chat_id, 'General', 'task', '') users.update_conf(chat_id, 'General', 'selected', '[]') display_folder(chat_id,storage,position[0:-1]) elif task == '🔵': if is_a_emoji(text[0]) and len(text) == 1: storage = literal_eval(users.get_conf_value(chat_id, 'General', 'storage', str(DEFAULT_FOLDER_STRUCTURE))) storage = set_element(storage,position,{'icon':text}) users.update_conf(chat_id, 'General', 'storage', str(storage)) users.update_conf(chat_id, 'General', 'position', position[0:-1]) users.update_conf(chat_id, 'General', 'task', '') users.update_conf(chat_id, 'General', 'selected', '[]') display_folder(chat_id,storage,position[0:-1]) elif text == '✖ Cancel': storage = literal_eval(users.get_conf_value(chat_id, 'General', 'storage', str(DEFAULT_FOLDER_STRUCTURE))) users.update_conf(chat_id, 'General', 'position', position[0:-1]) users.update_conf(chat_id, 'General', 'task', '') users.update_conf(chat_id, 'General', 'selected', '[]') display_folder(chat_id,storage,position[0:-1]) elif text == '🔵 Default': storage = literal_eval(users.get_conf_value(chat_id, 'General', 'storage', str(DEFAULT_FOLDER_STRUCTURE))) storage = set_element(storage,position,{'icon':None}) users.update_conf(chat_id, 'General', 'storage', str(storage)) users.update_conf(chat_id, 'General', 'position', position[0:-1]) users.update_conf(chat_id, 'General', 'task', '') users.update_conf(chat_id, 'General', 'selected', '[]') display_folder(chat_id,storage,position[0:-1]) else: methods.send_message(chat_id, '⛔ Icon must be an emoji') elif task == '➕': if text[0] == '✖': storage = literal_eval(users.get_conf_value(chat_id, 'General', 'storage', str(DEFAULT_FOLDER_STRUCTURE))) users.update_conf(chat_id, 'General', 'task', '') display_folder(chat_id,storage,position) elif text == '.' or text == '..': methods.send_message(chat_id, '⛔ Name can not be "." or ".."\nInsert another folder name:') elif has_emojis(text): methods.send_message(chat_id, '⛔ Name can not contain emojis\nInsert another folder name:') else: storage = literal_eval(users.get_conf_value(chat_id, 'General', 'storage', str(DEFAULT_FOLDER_STRUCTURE))) text=protect_string(text) if text in get_element(storage,position)['content'].keys(): methods.send_message(chat_id, '⛔ There is already a folder named ' + text + '\nInsert another folder name:') else: new_folder = {text:DEFAULT_FOLDER} storage = literal_eval(users.get_conf_value(chat_id, 'General', 'storage', str(DEFAULT_FOLDER_STRUCTURE))) storage = set_element(storage,position,new_folder,'content') users.update_conf(chat_id, 'General', 'task', '') users.update_conf(chat_id, 'General', 'storage', storage) display_folder(chat_id,storage,position) elif text[0] == '➕': users.update_conf(chat_id, 'General', 'task', '➕') methods.send_message(chat_id, 'Insert folder name:',reply_markup = {'keyboard': [['✖ Cancel']], 'resize_keyboard':True}) elif text[0] == '☑': storage = literal_eval(users.get_conf_value(chat_id, 'General', 'storage', str(DEFAULT_FOLDER_STRUCTURE))) selected = literal_eval(users.get_conf_value(chat_id, 'General', 'selected', '[]')) users.update_conf(chat_id, 'General', 'task', '☑') display_folder(chat_id,storage,position,selected) elif text[0] == '📋': clipboard = literal_eval(users.get_conf_value(chat_id, 'General', 'clipboard', '{}')) if clipboard == {}: methods.send_message(chat_id,'⚠ There is nothing to paste in the clipboard') else: storage = literal_eval(users.get_conf_value(chat_id, 'General', 'storage', str(DEFAULT_FOLDER_STRUCTURE))) elements = get_element(storage,position)['content'].keys() name_error = False for clipboard_element in clipboard.keys(): if clipboard_element in elements: clipboard[correct(clipboard_element)] = clipboard[clipboard_element] del clipboard[clipboard_element] if name_error: methods.send_message(chat_id, '⛔ There is already a file named ' + name_error + '\nRename the folder before paste') else: storage = set_element(storage,position,clipboard,'content') users.update_conf(chat_id, 'General', 'clipboard', '{}') users.update_conf(chat_id, 'General', 'storage', storage) display_folder(chat_id,storage,position) else: responses =literal_eval(users.get_conf_value(chat_id, 'General', 'responses', '{}')) try: text = responses[text] except KeyError: pass open_element(chat_id,position + [text])
def copy_elements(chat_id, storage, position, selected): clipboard = {} for element in selected: clipboard[element] = get_element(storage,position + [element]) users.update_conf(chat_id, 'General', 'clipboard', clipboard)
def display_folder(chat_id,storage,position,selection = None): storage = get_element(storage,position)['content'] elements = list(storage.keys()) elements = sorted(elements, key=lambda s: s.lower()) folder_elements = [] file_elements = [] for element in elements: if storage[element]['mime_type'] == 'folder': folder_elements.append(element) else: file_elements.append(element) elements = folder_elements + file_elements print(elements) message = position_to_path(position) if selection != None: keyboard = [['✖️End selection','▪ Select all','▫ Unselect all']] if len(selection) > 0: if len(selection) == 1: keyboard.append(['✏ Rename','🔵 Change icon','ℹ Properties','❌ Remove','📑 Copy','✂ Cut']) else: keyboard.append(['❌ Remove','📑 Copy','✂ Cut']) else: keyboard = [['➕ Folder']] if not is_empty(storage): keyboard[0].append('☑ Select') clipboard = literal_eval(users.get_conf_value(chat_id, 'General', 'clipboard', '{}')) if not clipboard == {}: keyboard[0].append('📋 Paste') if position == [] or selection != None: responses = {} else: keyboard.append(['⬆ ..']) responses = {'⬆ ..':'..'} for element in elements: icon = storage[element]['icon'] if icon == None: try: icon = DEFAULT_FULL_MIMETYPE_ICONS[storage[element]['mime_type']] except KeyError: not_full_icons = set(literal_eval(users.get_conf_value('recolection', 'General', 'not-full-icons', '{}'))) not_full_icons.add(storage[element]['mime_type']) users.update_conf('recolection', 'General', 'not-full-icons', not_full_icons) try: icon = DEFAULT_MIMETYPE_ICONS[storage[element]['mime_type'].split('/')[0]] except KeyError: not_icons = set(literal_eval(users.get_conf_value('recolection', 'General', 'not-icons', '{}'))) not_icons.add(storage[element]['mime_type']) users.update_conf('recolection', 'General', 'not-icons', not_icons) icon = DEFAULT_ICON if selection == None: line = icon + ' ' + element elif element in selection: line = '🔳 ' + icon + ' ' + element else: line = '◻ ' + icon + ' ' + element message += '\n' + line responses[line] = element keyboard.append([line]) users.update_conf(chat_id, 'General', 'responses', responses) methods.send_message(chat_id, message, reply_markup = {'keyboard':keyboard, 'resize_keyboard':True})