MCPcopy
hub / github.com/erictik/midjourney-api / waitImageMessage

Method waitImageMessage

src/discord.ws.ts:618–668  ·  view source on GitHub ↗
({
    nonce,
    prompt,
    onmodal,
    messageId,
    loading,
  }: {
    nonce: string;
    prompt?: string;
    messageId?: string;
    onmodal?: OnModal;
    loading?: LoadingHandler;
  })

Source from the content-addressed store, hash-verified

616 }
617
618 async waitImageMessage({
619 nonce,
620 prompt,
621 onmodal,
622 messageId,
623 loading,
624 }: {
625 nonce: string;
626 prompt?: string;
627 messageId?: string;
628 onmodal?: OnModal;
629 loading?: LoadingHandler;
630 }) {
631 if (messageId) this.skipMessageId.push(messageId);
632 return new Promise<MJMessage | null>((resolve, reject) => {
633 const handleImageMessage = ({ message, error }: MJEmit) => {
634 if (error) {
635 this.removeWaitMjEvent(nonce);
636 reject(error);
637 return;
638 }
639 if (message && message.progress === "done") {
640 this.removeWaitMjEvent(nonce);
641 messageId && this.removeSkipMessageId(messageId);
642 resolve(message);
643 return;
644 }
645 message && loading && loading(message.uri, message.progress || "");
646 };
647 this.waitMjEvents.set(nonce, {
648 nonce,
649 prompt,
650 onmodal: async (oldnonce, id) => {
651 if (onmodal === undefined) {
652 // reject(new Error("onmodal is not defined"))
653 return "";
654 }
655 var nonce = await onmodal(oldnonce, id);
656 if (nonce === "") {
657 // reject(new Error("onmodal return empty nonce"))
658 return "";
659 }
660 this.removeWaitMjEvent(oldnonce);
661 this.waitMjEvents.set(nonce, { nonce });
662 this.onceImage(nonce, handleImageMessage);
663 return nonce;
664 },
665 });
666 this.onceImage(nonce, handleImageMessage);
667 });
668 }
669 async waitDescribe(nonce: string) {
670 return new Promise<MJDescribe | null>((resolve) => {
671 this.onceMJ(nonce, (message) => {

Callers 2

ImagineMethod · 0.80
CustomMethod · 0.80

Calls 2

removeWaitMjEventMethod · 0.95
onceImageMethod · 0.95

Tested by

no test coverage detected