Created
February 1, 2022 20:08
-
-
Save michaelkebe/5825ecd36376cd350a19bc74e3f4d65f 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 { Octokit } from "https://cdn.skypack.dev/@octokit/rest"; | |
import { PERSONAL_ACCESS_TOKEN } from "token.js" | |
// Create a token.js with this content | |
// export const PERSONAL_ACCESS_TOKEN = "ghp_abcdef1234567890" | |
/** @param {NS} ns **/ | |
export async function main(ns) { | |
if (ns.args.length == 0) { | |
ns.tprint("Usage: run gists.js file1 file2 file3 ...") | |
} | |
const octokit = new Octokit({ auth: PERSONAL_ACCESS_TOKEN }) | |
//await octokit.rest.users.getAuthenticated() | |
const files = {} | |
for (const filename of ns.args) { | |
const fileContent = await ns.read((filename.indexOf("/") > 0 ? "/" : "") + filename) | |
if (fileContent !== "") { | |
files[filename.replaceAll("/", "_")] = { | |
"content": fileContent | |
} | |
} else { | |
ns.tprint(`ERROR: Could not read ${filename}`) | |
ns.exit() | |
} | |
} | |
ns.tprint(files) | |
ns.tprint("Creating gist...") | |
const response = await octokit.rest.gists.create({ | |
public: true, | |
files: files | |
}) | |
ns.tprintf(`Gist created. URL: ${response.data.html_url}`) | |
} |
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
/** @param {NS} ns **/ | |
export async function main(ns) { | |
const delay = ns.args[1] | |
if (delay) { | |
await ns.sleep(delay) | |
} | |
await ns.hack(ns.args[0]) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment