diff --git a/config/emojis.example.json b/config/emojis.example.json index e1c1c77..edcd68b 100644 --- a/config/emojis.example.json +++ b/config/emojis.example.json @@ -1,5 +1,8 @@ { "warning": "<:warning:1293874152150667315>", + "green_arrow_up": "<:green_arrow_up:1293819944399667222>", + "red_arrow_down": "<:red_arrow_down:1293819951764869181>", + "yellow_tilde": "<:yellow_tilde:1293819958643396608>", "booru": { "rating": { "safe": "<:rating_safe:1293819920978804829>", @@ -7,11 +10,6 @@ "questionable": "<:rating_questionable:1293819907099725925>", "explicit": "<:rating_explicit:1293819893795389491>", "unknown": "<:rating_unknown:1293819936845594665>" - }, - "score": { - "green_arrow_up": "<:green_arrow_up:1293819944399667222>", - "red_arrow_down": "<:red_arrow_down:1293819951764869181>", - "yellow_tilde": "<:yellow_tilde:1293819958643396608>" } } } \ No newline at end of file diff --git a/src/commands/fun/gelbooru.js b/src/commands/fun/gelbooru.js index 9331125..b69d2ec 100644 --- a/src/commands/fun/gelbooru.js +++ b/src/commands/fun/gelbooru.js @@ -1,9 +1,9 @@ const { InteractionContextType, ApplicationIntegrationType, SlashCommandBuilder, EmbedBuilder, escapeMarkdown, bold } = require("discord.js"); const { generateImageUrl } = require('@imgproxy/imgproxy-node'); +const { extname, basename } = require("node:path"); const { stringify } = require("node:querystring"); const { readFileSync } = require("node:fs"); const { decode } = require("html-entities"); -const { extname, basename } = require("node:path"); const { knex } = require("../../db.js"); const Booru = require("@himeka/booru"); @@ -82,11 +82,11 @@ function formatRating(rating) { function formatScore(score) { if (score > 0) { - return `${emojis.booru.score.green_arrow_up} ${score}` + return `${emojis.green_arrow_up} ${score}` } else if (score < 0) { - return `${emojis.booru.score.red_arrow_down} ${score}` + return `${emojis.red_arrow_down} ${score}` } else { - return `${emojis.booru.score.yellow_tilde} ${score}` + return `${emojis.yellow_tilde} ${score}` } } diff --git a/src/commands/fun/imagesearch.js b/src/commands/fun/imagesearch.js deleted file mode 100644 index 9eae4bf..0000000 --- a/src/commands/fun/imagesearch.js +++ /dev/null @@ -1,88 +0,0 @@ -const { InteractionContextType, ApplicationIntegrationType, SlashCommandBuilder, EmbedBuilder, escapeMarkdown, bold, ButtonBuilder, ButtonStyle } = require("discord.js"); -const { generateImageUrl } = require('@imgproxy/imgproxy-node'); -const { stringify } = require("node:querystring"); -const { Pagination } = require('pagination.djs'); - -const data = new SlashCommandBuilder() - .setName("isrch") - .setDescription("SearxNG-powered image search") - .addStringOption(builder => - builder // - .setName("query") - .setRequired(true) - .setDescription("What to search for") - ) - .setContexts([ - InteractionContextType.Guild, - InteractionContextType.BotDM, - InteractionContextType.PrivateChannel - ]) - .setIntegrationTypes([ - ApplicationIntegrationType.GuildInstall, - ApplicationIntegrationType.UserInstall - ]); - -function notEmpty(str) { - return str.trim() !== '' -} - -function proxy(url) { - if (!process.env.IMGPROXY_HOST) - return url; - - url = generateImageUrl({ - endpoint: process.env.IMGPROXY_HOST, - url: url, - salt: process.env.IMGPROXY_SALT, - key: process.env.IMGPROXY_KEY - }); - - return url; -} - -module.exports = { - data, - async execute(interaction) { - const query = interaction.options.getString("query"); - await interaction.deferReply(); - - var queryString = stringify({ - "category_images": "", - "format": "json", - "q": "!goi " + query - }); - - const embeds = []; - const data = await (await fetch(`https://s.koda.re/search?${queryString}`)).json(); - for (const result of data.results) { - if (result.img_src == '') continue; - - var description = result.source ?? result.title; - if (description.length > 1024) description = description.slice(0, 1021) + "..."; - - if (result.img_src.startsWith("//")) result.img_src = "http:" + result.img_src - - const embed = new EmbedBuilder() - .setColor("#cba6f7") - .setImage(proxy(result.img_src)) - .setFooter({ - text: result.engines.join(", ") - }); - - if (description.length >= 1) - embed.setDescription(description); - - embeds.push(embed); - } - - const pagination = new Pagination(interaction); - pagination.setEmbeds(embeds, (embed, index, array) => { - const footerText = [ - `${index + 1}/${array.length}`, - embed.data.footer.text - ].filter(notEmpty).join(' · ') - return embed.setFooter({ text: footerText }); - }); - pagination.render(); - } -} diff --git a/src/commands/utility/file.js b/src/commands/utility/file.js new file mode 100644 index 0000000..ee0aa5b --- /dev/null +++ b/src/commands/utility/file.js @@ -0,0 +1,90 @@ +const { InteractionContextType, ApplicationIntegrationType, SlashCommandBuilder, EmbedBuilder, ButtonBuilder, ButtonStyle } = require("discord.js"); +const { readFileSync } = require("node:fs"); +const { stringify } = require("node:querystring"); +const { Pagination } = require("pagination.djs"); + +const data = new SlashCommandBuilder() + .setName("file") + .setDescription("SearxNG-powered file search") + .addStringOption(builder => + builder // + .setName("query") + .setRequired(true) + .setDescription("What to search for") + ) + .setContexts([ + InteractionContextType.Guild, + InteractionContextType.BotDM, + InteractionContextType.PrivateChannel + ]) + .setIntegrationTypes([ + ApplicationIntegrationType.GuildInstall, + ApplicationIntegrationType.UserInstall + ]); + +function notEmpty(str) { + return str && str.trim() !== '' +} + +const emojis = JSON.parse(readFileSync("config/emojis.json")); + +module.exports = { + data, + async execute(interaction) { + const query = interaction.options.getString("query"); + await interaction.deferReply(); + + var queryString = stringify({ + "categories": "files", + "format": "json", + "q": query + }); + + const embeds = []; + const data = await (await fetch(`${process.env.SEARXNG_INSTANCE}/search?${queryString}`)).json(); + for (const result of data.results) { + if (result.magnetlink) result.magnetlink = `[magnet](${process.env.BASE_URL}/magnet/${result.magnetlink})`; + + const footerText = ([ + result.filesize, + `${result.seed} S`, + `${result.leech} L` + ]).filter(notEmpty).join(" • "); + + const site = result.parsed_url.slice(0, 2).join("://"); + + const description = [ + "Downloads:", + result.magnetlink, + result.torrentfile, + result.url + ].filter(notEmpty).join("\n"); + + const embed = new EmbedBuilder() + .setAuthor({ + name: result.engine, + iconURL: `https://vault.incest.world/icons/${result.parsed_url[1]}/icon.png` + }) + .setTitle(result.title) + .setURL(result.url) + .setColor("#cba6f7") + .setDescription(description) + .setFooter({ + text: footerText + }) + .setTimestamp(new Date(result.publishedDate)); + + embeds.push(embed); + } + + const pagination = new Pagination(interaction); + pagination.setEmbeds(embeds, (embed, index, array) => { + const footerText = [ + `${index + 1}/${array.length}`, + embed.data.footer.text + ].filter(notEmpty).join(' • ') + return embed.setFooter({ text: footerText }); + }); + pagination.render(); + } +} diff --git a/src/index.js b/src/index.js index 216b5b0..5328bcc 100644 --- a/src/index.js +++ b/src/index.js @@ -37,6 +37,8 @@ for (const folder of commandFolders) { } client.on(Events.InteractionCreate, async interaction => { + if (!interaction.isAutocomplete() && !interaction.isCommand()) return; + const command = interaction.client.commands.get(interaction.commandName); if (!command) { console.error(`No command matching ${interaction.commandName} was found.`); diff --git a/src/server/index.js b/src/server/index.js index 6fa9703..7f85a71 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -36,7 +36,13 @@ app.get("/view/:paste", async function (req, res) { bot, text }); - return; +}); + +app.get("/magnet/:magnet", function (req, res) { + res.render("magnet", { + bot, + url: (req.params.magnet + (req.originalUrl.includes("?") ? req.originalUrl.slice(req.originalUrl.indexOf("?")) : '')).replaceAll('"', '"') + }); }); app.all('*', function (req, res) { diff --git a/src/server/partials/head.ejs b/src/server/partials/head.ejs index 689c27f..701ae59 100644 --- a/src/server/partials/head.ejs +++ b/src/server/partials/head.ejs @@ -1,8 +1,6 @@ -
<% invite = `https://discord.com/oauth2/authorize?client_id=${bot.user.id}&scope=applications.commands&integration_type=` %> - + <% invite = `https://discord.com/oauth2/authorize?client_id=${bot.user.id}&scope=applications.commands&integration_type=` %> <% for(let i = 16; i <= 512; i*=2) { %> <% } %>You should get redirected within 5 seconds.
+ Not redirected automatically? +