Improved pagination, empty value checks, and bigints
This commit is contained in:
parent
72efad0928
commit
e1cfbff5a8
17 changed files with 51 additions and 41 deletions
|
@ -135,7 +135,7 @@ class ImageConnection {
|
|||
async getOutput(jobid) {
|
||||
const req = await fetch(`${this.httpurl}?id=${jobid}`, {
|
||||
headers: {
|
||||
"Authentication": this.auth && this.auth !== "" ? this.auth : undefined
|
||||
"Authentication": this.auth ? this.auth : undefined
|
||||
}
|
||||
});
|
||||
const contentType = req.headers.get("Content-Type");
|
||||
|
|
|
@ -59,6 +59,7 @@ const getImage = async (image, image2, video, extraReturnTypes, gifv = false) =>
|
|||
}
|
||||
}
|
||||
const json = await data.json();
|
||||
if (json.error) throw Error(json.error);
|
||||
payload.path = json.results[0].media[0].gif.url;
|
||||
} else {
|
||||
const delay = (await execPromise(`ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate ${image}`)).stdout.replace("\n", "");
|
||||
|
@ -121,7 +122,7 @@ const checkImages = async (message, extraReturnTypes, video, sticker) => {
|
|||
}
|
||||
}
|
||||
// if the return value exists then return it
|
||||
return type ? type : false;
|
||||
return type ?? false;
|
||||
};
|
||||
|
||||
// this checks for the latest message containing an image and returns the url of the image
|
||||
|
|
|
@ -77,17 +77,22 @@ export default async (client, message, pages, timeout = 120000) => {
|
|||
if (member === message.author.id) {
|
||||
switch (interaction) {
|
||||
case "back":
|
||||
await fetch(`https://discord.com/api/v8/interactions/${id}/${token}/callback`, ackOptions);
|
||||
await fetch(`https://discord.com/api/v9/interactions/${id}/${token}/callback`, ackOptions);
|
||||
page = page > 0 ? --page : pages.length - 1;
|
||||
currentPage = await currentPage.edit(Object.assign(pages[page], options));
|
||||
break;
|
||||
case "forward":
|
||||
await fetch(`https://discord.com/api/v8/interactions/${id}/${token}/callback`, ackOptions);
|
||||
await fetch(`https://discord.com/api/v9/interactions/${id}/${token}/callback`, ackOptions);
|
||||
page = page + 1 < pages.length ? ++page : 0;
|
||||
currentPage = await currentPage.edit(Object.assign(pages[page], options));
|
||||
break;
|
||||
case "jump":
|
||||
await fetch(`https://discord.com/api/v8/interactions/${id}/${token}/callback`, ackOptions);
|
||||
await fetch(`https://discord.com/api/v9/interactions/${id}/${token}/callback`, ackOptions);
|
||||
const newComponents = JSON.parse(JSON.stringify(components));
|
||||
for (const index of newComponents.components[0].components.keys()) {
|
||||
newComponents.components[0].components[index].disabled = true;
|
||||
}
|
||||
currentPage = await currentPage.edit(newComponents);
|
||||
client.createMessage(message.channel.id, Object.assign({ content: "What page do you want to jump to?" }, {
|
||||
messageReference: {
|
||||
channelID: currentPage.channel.id,
|
||||
|
@ -107,14 +112,14 @@ export default async (client, message, pages, timeout = 120000) => {
|
|||
if (await client.getMessage(askMessage.channel.id, askMessage.id).catch(() => undefined)) await askMessage.delete();
|
||||
if (manageMessages) await response.delete();
|
||||
page = Number(response.content) - 1;
|
||||
currentPage = await currentPage.edit(Object.assign(pages[page], options));
|
||||
currentPage = await currentPage.edit(Object.assign(pages[page], options, components));
|
||||
});
|
||||
}).catch(error => {
|
||||
throw error;
|
||||
});
|
||||
break;
|
||||
case "delete":
|
||||
await fetch(`https://discord.com/api/v8/interactions/${id}/${token}/callback`, ackOptions);
|
||||
await fetch(`https://discord.com/api/v9/interactions/${id}/${token}/callback`, ackOptions);
|
||||
interactionCollector.emit("end");
|
||||
if (await client.getMessage(currentPage.channel.id, currentPage.id).catch(() => undefined)) await currentPage.delete();
|
||||
return;
|
||||
|
@ -123,8 +128,14 @@ export default async (client, message, pages, timeout = 120000) => {
|
|||
}
|
||||
}
|
||||
});
|
||||
interactionCollector.once("end", () => {
|
||||
interactionCollector.once("end", async () => {
|
||||
interactionCollector.removeAllListeners("interaction");
|
||||
if (await client.getMessage(currentPage.channel.id, currentPage.id).catch(() => undefined)) {
|
||||
for (const index of components.components[0].components.keys()) {
|
||||
components.components[0].components[index].disabled = true;
|
||||
}
|
||||
await currentPage.edit(components);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue