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

@@ -0,0 +1,54 @@
import { SlashCommandBuilder } from "@discordjs";
// import { drop, help, requestWorker } from "./plugin.ts";
import { logMessage } from "@root/logging.ts";
import { defaultString } from "@root/defaultString.ts";
// export async function rule34MessageHandler(message: Message) {
// const command = message.content.trim().split(" ").slice(1).join(" ");
// if (command === "drop") {
// bot.helpers.sendMessage(message.channelId, {
// embeds: [await drop()]
// })
// } else if (command.startsWith("drop [") && command.endsWith("]")) {
// logMessage(message);
// const generatedEmbeds: Embed[] = await requestWorker(command);
// for (const embed of generatedEmbeds) {
// bot.helpers.sendMessage(message.channelId, {
// embeds: [embed],
// });
// }
// } else if (command === "help") {
// logMessage(message);
// bot.helpers.sendMessage(message.channelId, {
// content: defaultString(help()),
// });
// } else {
// drop();
// }
// }
export const commands = [
new SlashCommandBuilder()
.setName("rule")
.setDescription("Drops one or multiple images using the rule34 API.")
.setNSFW(true)
.addSubcommand(subcommand =>
subcommand
.setName("drop")
.setDescription("Drops one or multiple images using the rule34 API.")
),
new SlashCommandBuilder()
.setName('gif')
.setDescription('Sends a random gif!')
.addStringOption(option =>
option.setName('category')
.setDescription('The gif category')
.setRequired(true)
.addChoices(
{ name: 'Funny', value: 'gif_funny' },
{ name: 'Meme', value: 'gif_meme' },
{ name: 'Movie', value: 'gif_movie' },
))
]

View File

@@ -1,30 +0,0 @@
import { Bot, Message } from "@discordeno";
import { drop, help, requestWorker } from "./plugin.ts";
import { logMessage } from "@root/logging.ts";
import { defaultString } from "@root/defaultString.ts";
import { Embed } from "@root/structures/embeds.ts";
export async function rule34MessageHandler(message: Message) {
const command = message.content.trim().split(" ").slice(1).join(" ");
if (command === "drop") {
bot.helpers.sendMessage(message.channelId, {
embeds: [await drop()]
})
} else if (command.startsWith("drop [") && command.endsWith("]")) {
logMessage(message);
const generatedEmbeds: Embed[] = await requestWorker(command);
for (const embed of generatedEmbeds) {
bot.helpers.sendMessage(message.channelId, {
embeds: [embed],
});
}
} else if (command === "help") {
logMessage(message);
bot.helpers.sendMessage(message.channelId, {
content: defaultString(help()),
});
} else {
drop();
}
}

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() {

View File

@@ -0,0 +1,31 @@
import { SlashCommandBuilder} from "@discordjs";
import { logMessage } from "@root/logging.ts";
import { getPosts } from "@root/plugins/yandere/api/api.ts";
// export async function yandereMessageHandler(message: Message) {
// const command = message.content.split(" ").slice(1).join(" ");
// const args = command.match(/(\[.+\])/g)
// if (command === "drop") {
// const embed: DiscordEmbed | undefined = (await getPosts("[limit: 1]"))[0]
// if (embed === undefined) throw Error("undefined embed")
// bot.helpers.sendMessage(message.channelId, {
// embeds: [embed]
// })
// } else if (command.startsWith("drop [") && command.endsWith("]")) {
// logMessage(message);
// if (args === null) throw Error("args is null")
// const generatedEmbeds = await getPosts(args[0]);
// for (const embed of generatedEmbeds) {
// bot.helpers.sendMessage(message.channelId, {
// embeds: [embed],
// });
// }
// }
// }
export const commands = [
new SlashCommandBuilder()
.setName("drop")
.setDescription("Drops one or multiple images using the yande.re API.")
.setNSFW(true)
]

View File

@@ -1,24 +0,0 @@
import { Bot, DiscordEmbed, Message} from "@discordeno";
import { logMessage } from "@root/logging.ts";
import { getPosts } from "@root/plugins/yandere/api/api.ts";
export async function yandereMessageHandler(message: Message) {
const command = message.content.split(" ").slice(1).join(" ");
const args = command.match(/(\[.+\])/g)
if (command === "drop") {
const embed: DiscordEmbed | undefined = (await getPosts("[limit: 1]"))[0]
if (embed === undefined) throw Error("undefined embed")
bot.helpers.sendMessage(message.channelId, {
embeds: [embed]
})
} else if (command.startsWith("drop [") && command.endsWith("]")) {
logMessage(message);
if (args === null) throw Error("args is null")
const generatedEmbeds = await getPosts(args[0]);
for (const embed of generatedEmbeds) {
bot.helpers.sendMessage(message.channelId, {
embeds: [embed],
});
}
}
}