Created
July 28, 2022 17:38
-
-
Save johnlindquist/46ca2de766ce4f7b2b6e11b883512c7a 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
// Name: Midjourney Prompt | |
// Description: Generate a Random Midjourney Prompt | |
// Author: John Lindquist | |
// Twitter: @johnlindquist | |
import "@johnlindquist/kit" | |
let count = parseInt( | |
await arg({ | |
placeholder: "How many prompts to generate and paste?", | |
onInput: input => { | |
submit(input) //auto submit the number on press | |
}, | |
}), | |
10 | |
) | |
let frontmost = await npm("frontmost-app") | |
let exitIfNotDiscord = async () => { | |
let { localizedName: name } = await frontmost() | |
if (name !== "Discord") { | |
exit() | |
} | |
} | |
await exitIfNotDiscord() | |
let n = (x = 0) => | |
`::${Number(_.random(0.2, 2.2) + x).toPrecision(1)}` | |
let iw = (x = 0) => | |
`${Number(_.random(0.2, 2.2) + x).toPrecision(1)}` | |
let parentDir = await env( | |
"MIDJOURNEY_PARENT_DIR", | |
async () => { | |
return await path({ | |
hint: `Select a parent dir to clone the repo: https://github.com/johnlindquist/midjourney`, | |
}) | |
} | |
) | |
let mjDir = path.resolve(parentDir, "midjourney") | |
let mjExists = await isDir(mjDir) | |
if (!mjExists) { | |
cd(parentDir) | |
await exec( | |
`git clone https://github.com/johnlindquist/midjourney` | |
) | |
cd(mjDir) | |
} else { | |
cd(mjDir) | |
await exec(`git pull`) | |
} | |
// await wiki() will pull a random wikipedia title | |
let wiki = await npm("random-word-wikipedia") | |
// Generate functions based on .md files in the repo | |
let files = await readdir(mjDir) | |
files = files.filter(file => file.endsWith("s.md")) | |
for await (let file of files) { | |
let filePath = path.resolve(mjDir, file) | |
let list = await readFile(filePath, "utf-8") | |
let { name } = path.parse(filePath) | |
let fn = name.slice(0, -1) | |
global[fn] = () => _.sample(list.trim().split("\n")) | |
} | |
hide() | |
let go = async () => { | |
await exitIfNotDiscord() | |
// Customize however you want. More old "maybe working" examples here: https://github.com/johnlindquist/midjourney/blob/main/prompts.md | |
let fnsPrompt = `/imagine: ${image()} ${myimage()} Studio photoshoot of ${celeb()} ${animal()} ${hero()} ${await wiki()} in a ${color()} ${climate()} in the style of ${game()} taken by ${photographer()} by ${artist()} stylized like ${style()} and ${rank()} --stylize ${_.random( | |
1000, | |
3000 | |
)} --uplight --aspect 16:9 --iw ${iw()}` | |
let prompt = _.sample([fnsPrompt]) | |
await exitIfNotDiscord() | |
await setSelectedText(prompt) | |
log(prompt) | |
await wait(1000) | |
await exitIfNotDiscord() //I try to be extra careful when scripting the `Enter` key | |
await keyboard.pressKey(Key.Enter) | |
await keyboard.releaseKey(Key.Enter) | |
await wait(500) // Discord needs a sec after paste+enter to recorgnize it as a command | |
await exitIfNotDiscord() | |
await keyboard.pressKey(Key.Enter) | |
await keyboard.releaseKey(Key.Enter) | |
} | |
let i = 0 | |
while (i < count) { | |
i++ | |
await go() | |
await wait(1000) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment