Skip to content

Commit

Permalink
use seed filter messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric committed Jun 14, 2023
1 parent d5369f9 commit 3904a41
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion example/imagine-ws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async function main() {
});
await client.init();
const Imagine = await client.Imagine(
"A little white elephant",
"Red hamster smoking a cigaret, https://media.discordapp.net/attachments/1108515696385720410/1118385339732590682/DanielH_A_giant_hamster_monster._Friendly_in_a_business_suit_si_d4be1836-a4e1-41a8-b1d7-99eebc521220.png?width=1878&height=1878 ",
(uri: string, progress: string) => {
console.log("Imagine.loading", uri, "progress", progress);
}
Expand Down
3 changes: 1 addition & 2 deletions example/imagine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,10 @@ async function main() {
ChannelId: <string>process.env.CHANNEL_ID,
SalaiToken: <string>process.env.SALAI_TOKEN,
Debug: true,
SessionId: process.env.SALAI_TOKEN || "8bb7f5b79c7a49f7d0824ab4b8773a81",
});

const msg = await client.Imagine(
"A little white elephant",
"Red hamster smoking a cigaret, https://media.discordapp.net/attachments/1108515696385720410/1118385339732590682/DanielH_A_giant_hamster_monster._Friendly_in_a_business_suit_si_d4be1836-a4e1-41a8-b1d7-99eebc521220.png?width=1878&height=1878",
(uri: string, progress: string) => {
console.log("loading", uri, "progress", progress);
}
Expand Down
1 change: 1 addition & 0 deletions example/info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ async function main() {
await client.init();
const msg = await client.Info();
console.log({ msg });
client.Close();
}
main()
.then(() => {
Expand Down
9 changes: 3 additions & 6 deletions src/midjourney.message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,14 @@ export class MidjourneyMessage {
options?: string,
index?: number
) {
// remove urls
const regex = /(<)?(https?:\/\/[^\s]*)(>)?/gi;
prompt = prompt.replace(regex, "");
// remove multiple spaces
prompt = prompt.trim();
const seed = prompt.match(/--seed (\d+)/)?.[1];

const data = await this.safeRetrieveMessages(this.config.Limit);
for (let i = 0; i < data.length; i++) {
const item = data[i];
if (
item.author.id === "936929561302675456" &&
item.content.includes(`${prompt}`)
item.content.includes(`${seed}`)
) {
this.log(JSON.stringify(item));
// Upscaled or Variation
Expand All @@ -72,6 +68,7 @@ export class MidjourneyMessage {
}
const imageUrl = item.attachments[0].url;
//waiting
this.log(`waiting.content`, item.content);
if (
item.attachments[0].filename.startsWith("grid") ||
item.components.length === 0
Expand Down
4 changes: 3 additions & 1 deletion src/midjourney.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ export class Midjourney extends MidjourneyMessage {
return new Promise<Midjourney>((resolve) => {
this.wsClient = new WsMessage(this.config, this.MJApi);
this.wsClient.once("ready", () => {
this.log(`ws ready`);
resolve(this);
});
});
}
async Imagine(prompt: string, loading?: LoadingHandler) {
prompt = prompt.trim();
if (!prompt.includes("--seed")) {
const seed = random(10000, 9999999);
const seed = random(10000000, 999999999);
prompt = `${prompt} --seed ${seed}`;
}

Expand Down

0 comments on commit 3904a41

Please sign in to comment.