Created
February 8, 2023 20:53
-
-
Save zacjones93/edfcc20d57787061393bcdfb81233881 to your computer and use it in GitHub Desktop.
This file contains hidden or 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(".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) | |
global[name] = () => _.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 prompt: ${image()} ${myimage()} Studio photoshoot of ${celeb()} ${animal()} ${hero()}::4 ${await wiki()}${n()} in a ${color()} ${climate()}${n()} in the style of ${game()}${n()} taken by ${photographer()}${n()} by ${artist()}${n()} stylized like ${style()} and ${rank()}${n()} --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(250) // 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