Breaking Changes!!! Changed discordeno to discord.js. Adaptation in progress.

This commit is contained in:
fzzinchemical
2025-04-14 23:18:43 +02:00
parent 59803fabd5
commit 1f3090d799
13 changed files with 251 additions and 307 deletions

View File

@@ -1,6 +1,5 @@
import { assert } from "@std/assert/assert";
import { requestJSON } from "@root/structures/apiRequest.ts";
import { Embed, EmbedAuthor, EmbedImage } from "@root/structures/embeds.ts";
import { ImageResponse, postUrl } from "./api.ts";
const keys = ["limit", "id", "pid", "tags"] as const;
@@ -10,56 +9,56 @@ function isKey(key: string): key is PostKeys {
return keys.includes(key as any);
}
export async function drop() {
try {
const response = await requestJSON<ImageResponse[]>(`${postUrl}&limit=1`);
const img = response[0];
if (img === undefined) throw Error("An undefined Array was given!");
return new Embed(
`ID: ${img.id}`,
img.sample_url,
new EmbedAuthor(img.owner),
// [new EmbedField("Tags", img.tags, true)],
new EmbedImage(img.file_url, img.height, img.width),
);
} catch (e) {
console.error((e as Error).message);
return new Embed(
"Error Message",
"https://gifdb.com/images/thumbnail/nuh-uh-demon-slayer-girl-hm7q3hqa4lnqyl6d.gif",
new EmbedAuthor("fzzinChemical"),
new EmbedImage(
"https://gifdb.com/images/thumbnail/nuh-uh-demon-slayer-girl-hm7q3hqa4lnqyl6d.gif",
250,
250,
),
);
}
}
// export async function drop() {
// try {
// const response = await requestJSON<ImageResponse[]>(`${postUrl}&limit=1`);
// const img = response[0];
// if (img === undefined) throw Error("An undefined Array was given!");
// return new Embed(
// `ID: ${img.id}`,
// img.sample_url,
// new EmbedAuthor(img.owner),
// // [new EmbedField("Tags", img.tags, true)],
// new EmbedImage(img.file_url, img.height, img.width),
// );
// } catch (e) {
// console.error((e as Error).message);
// return new Embed(
// "Error Message",
// "https://gifdb.com/images/thumbnail/nuh-uh-demon-slayer-girl-hm7q3hqa4lnqyl6d.gif",
// new EmbedAuthor("fzzinChemical"),
// new EmbedImage(
// "https://gifdb.com/images/thumbnail/nuh-uh-demon-slayer-girl-hm7q3hqa4lnqyl6d.gif",
// 250,
// 250,
// ),
// );
// }
// }
export async function requestWorker(requestString: string) {
try {
const response = await requestJSON<ImageResponse[]>(
generateRequestURL(requestString),
);
const stack: Embed[] = [];
for (const img of response) {
stack.push(
new Embed(
`ID: ${img.id}`,
img.sample_url,
new EmbedAuthor(img.owner),
// [new EmbedField("Tags", img.tags, true)],
new EmbedImage(img.file_url, img.height, img.width),
),
);
}
return stack;
} catch (e) {
console.error((e as Error).message);
return [];
}
}
// export async function requestWorker(requestString: string) {
// try {
// const response = await requestJSON<ImageResponse[]>(
// generateRequestURL(requestString),
// );
// const stack: Embed[] = [];
// for (const img of response) {
// stack.push(
// new Embed(
// `ID: ${img.id}`,
// img.sample_url,
// new EmbedAuthor(img.owner),
// // [new EmbedField("Tags", img.tags, true)],
// new EmbedImage(img.file_url, img.height, img.width),
// ),
// );
// }
// return stack;
// } catch (e) {
// console.error((e as Error).message);
// return [];
// }
// }
//TODO: get help in form of a nice beautiful format
export function help() {