Skip to content

Commit

Permalink
upgrade describetion
Browse files Browse the repository at this point in the history
  • Loading branch information
Eric committed Jun 26, 2023
1 parent 9389df0 commit cd54593
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
4 changes: 2 additions & 2 deletions example/describe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ async function main() {
Ws: true,
});
await client.Connect();
const msg = await client.Describe(
const Describe = await client.Describe(
"https://cdn.discordapp.com/attachments/1107965981839605792/1119977411631652914/Soga_a_cool_cat_blue_ears_yellow_hat_02afd1ed-17eb-4a61-9101-7a99b105e4cc.png"
);
console.log({ msg });
console.log(Describe);
client.Close();
}
main().catch((err) => {
Expand Down
16 changes: 8 additions & 8 deletions src/midjourne.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -204,27 +204,27 @@ export class MidjourneyApi extends Command {
private async attachments(
...files: UploadParam[]
): Promise<{ attachments: UploadSlot[] }> {
const { SalaiToken, DiscordBaseUrl, ChannelId, fetch } = this.config;
const headers = {
Authorization: this.config.SalaiToken,
Authorization: SalaiToken,
"content-type": "application/json",
};
const url = new URL(
`${this.config.DiscordBaseUrl}/api/v9/channels/${this.config.ChannelId}/attachments`
`${DiscordBaseUrl}/api/v9/channels/${ChannelId}/attachments`
);
const body = { files };
const response = await this.config.fetch(url.toString(), {
const response = await this.config.fetch(url, {
headers,
method: "POST",
body: JSON.stringify(body),
});
if (response.status === 200) {
return (await response.json()) as { attachments: UploadSlot[] };
}
throw new Error(
`Attachments return ${response.status} ${
response.statusText
} ${await response.text()}`
);
const error = `Attachments return ${response.status} ${
response.statusText
} ${await response.text()}`;
throw new Error(error);
}
private async uploadImage(
slot: UploadSlot,
Expand Down
23 changes: 18 additions & 5 deletions src/ws.message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
WsEventMsg,
MJInfo,
MJSettings,
MJOptions,
} from "./interfaces";

import { MidjourneyApi } from "./midjourne.api";
Expand Down Expand Up @@ -137,7 +138,14 @@ export class WsMessage {
this.messageUpdate(message);
}
private messageUpdate(message: any) {
const { content, embeds, interaction = {}, nonce, id } = message;
const {
content,
embeds,
interaction = {},
nonce,
id,
components,
} = message;

if (!nonce) {
const { name } = interaction;
Expand All @@ -147,7 +155,10 @@ export class WsMessage {
this.emit("settings", message);
return;
case "describe":
this.emitDescribe(id, embeds?.[0]?.description);
this.emitDescribe(id, {
descriptions: embeds?.[0]?.description.split("\n\n"),
options: formatOptions(components),
});
break;
case "info":
this.emit("info", embeds?.[0]?.description);
Expand Down Expand Up @@ -418,10 +429,12 @@ export class WsMessage {
}

async waitDescribe(nonce: string) {
return new Promise<string[] | null>((resolve) => {
return new Promise<{
options: MJOptions[];
descriptions: string[];
} | null>((resolve) => {
this.onceDescribe(nonce, (message) => {
const data = message.split("\n\n");
resolve(data);
resolve(message);
});
});
}
Expand Down

0 comments on commit cd54593

Please sign in to comment.