Breaking Changes!!! Changed discordeno to discord.js. Adaptation in progress.
This commit is contained in:
54
src/plugins/rule34/commands.ts
Normal file
54
src/plugins/rule34/commands.ts
Normal 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' },
|
||||
))
|
||||
]
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user