~bmp/dortune

7e8d495c51e73233420805063a0393cdc52a9774 — Benjamin Pollack 2 years ago f63fb2b
make this work remotely too
1 files changed, 7 insertions(+), 4 deletions(-)

M dortune.ts
M dortune.ts => dortune.ts +7 -4
@@ 1,11 1,14 @@
#!/usr/bin/env deno run --allow-read=.

const cleanFortunes = Deno.readTextFileSync("freebsd.fortunes");
const fortunes = cleanFortunes.split("%").slice(1);
async function fileFortunes(name: string): Promise<string[]> {
  const resp = await fetch(new URL(`./${name}`, import.meta.url));
  return (await resp.text()).split("%").slice(1);
}

const fortunes = await fileFortunes("freebsd.fortunes");

if (Deno.args.some((a) => a == "-o" || a == "--offensive")) {
  const dirtyFortunes = Deno.readTextFileSync("offensive.fortunes");
  fortunes.push(...dirtyFortunes.split("%").slice(1));
  fortunes.push(...await fileFortunes("offensive.fortunes"));
}

console.log(fortunes[Math.floor(Math.random() * fortunes.length)].trim());