mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-08 06:03:04 -04:00
[cmd] r34
This commit is contained in:
parent
35b16e22b1
commit
e97066e112
5 changed files with 98 additions and 1 deletions
76
commands/message/search/rule34.js
Normal file
76
commands/message/search/rule34.js
Normal file
|
@ -0,0 +1,76 @@
|
|||
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
|
||||
const { link, highlight } = require('../../../labscore/utils/markdown')
|
||||
const { editOrReply } = require('../../../labscore/utils/message')
|
||||
const { STATICS } = require('../../../labscore/utils/statics')
|
||||
|
||||
const { paginator } = require('../../../labscore/client');
|
||||
const { rule34 } = require('../../../labscore/api');
|
||||
|
||||
function createRule34Page(context, result){
|
||||
let res = {
|
||||
"embeds": [
|
||||
createEmbed("default", context, {
|
||||
description: `Rating: ${highlight(result.rating)}`,
|
||||
image: {
|
||||
url: result.fileUrl
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
if(result.thumbnail) res.embeds[0].thumbnail = { url: result.thumbnail };
|
||||
return res;
|
||||
}
|
||||
|
||||
const SITES = {
|
||||
"rule34": "rule34.xxx",
|
||||
"e621": "e621.net",
|
||||
"danbooru": "danbooru.donmai.us",
|
||||
"gelbooru": "gelbooru.com",
|
||||
"paheal": "rule34.paheal.net",
|
||||
"xbooru": "xbooru.com",
|
||||
"safebooru": "safebooru.org"
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
name: 'rule32',
|
||||
label: 'query',
|
||||
aliases: ['r34'],
|
||||
metadata: {
|
||||
description: 'rule34 search',
|
||||
examples: ['r34 sex -site rule34'],
|
||||
category: 'search',
|
||||
usage: 'rule34 <query> [-site <service>]'
|
||||
},
|
||||
args: [
|
||||
{name: 'site', default: 'rule34'}
|
||||
],
|
||||
run: async (context, args) => {
|
||||
context.triggerTyping();
|
||||
|
||||
// very important, maybe make this a command option eventually
|
||||
if(!context.channel.nsfw){
|
||||
return editOrReply(context, {embeds:[createEmbed("nsfw", context)]})
|
||||
}
|
||||
|
||||
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
|
||||
if(!Object.keys(SITES).includes(args.site.toLowerCase())) return editOrReply(context, {embeds:[createEmbed("warning", context, `Invalid site type.`)]})
|
||||
try{
|
||||
let search = await rule34(context, args.query, args.site.toLowerCase())
|
||||
search = search.response
|
||||
|
||||
let pages = []
|
||||
for(const res of search.body.data){
|
||||
pages.push(createRule34Page(context, res))
|
||||
}
|
||||
|
||||
pages = formatPaginationEmbeds(pages)
|
||||
const paging = await paginator.createPaginator({
|
||||
context,
|
||||
pages
|
||||
});
|
||||
}catch(e){
|
||||
console.log(e)
|
||||
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform rule34 search.`)]})
|
||||
}
|
||||
},
|
||||
};
|
|
@ -30,6 +30,7 @@ const Api = Object.freeze({
|
|||
SEARCH_GOOGLE: '/search/google',
|
||||
SEARCH_GOOGLE_IMAGES: '/search/google-images',
|
||||
SEARCH_LYRICS: '/search/lyrics',
|
||||
SEARCH_RULE34: '/search/booru',
|
||||
SEARCH_WOLFRAM_ALPHA: '/search/wolfram-alpha',
|
||||
SEARCH_YOUTUBE: '/search/youtube',
|
||||
|
||||
|
|
|
@ -115,6 +115,13 @@ module.exports.googleImages = async function(context, query){
|
|||
})
|
||||
}
|
||||
|
||||
module.exports.rule34 = async function(context, query, site){
|
||||
return await request(Api.SEARCH_RULE34, "GET", {}, {
|
||||
q: query,
|
||||
site: site
|
||||
})
|
||||
}
|
||||
|
||||
module.exports.bing = async function(context, query){
|
||||
return await request(Api.SEARCH_BING, "GET", {}, {
|
||||
q: query
|
||||
|
|
|
@ -3,7 +3,8 @@ module.exports.COLORS = Object.freeze({
|
|||
"success": 6411359,
|
||||
"warning": 16426522,
|
||||
"embed": 3092790,
|
||||
"brand": 6085465
|
||||
"brand": 6085465,
|
||||
"nsfw": 15549056
|
||||
})
|
||||
|
||||
module.exports.ICONS = Object.freeze({
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
const { COLORS } = require('../constants')
|
||||
const { link } = require('./markdown')
|
||||
|
||||
// TODO: make embed icons use the general STATICS system
|
||||
const embedTypes = Object.freeze({
|
||||
"default": (context) => {
|
||||
return {
|
||||
|
@ -27,6 +29,16 @@ const embedTypes = Object.freeze({
|
|||
},
|
||||
color: COLORS.error
|
||||
}
|
||||
},
|
||||
"nsfw": (context) => {
|
||||
return {
|
||||
author: {
|
||||
iconUrl: `https://derpystuff.gitlab.io/webstorage4/v2/assets/icons/ico_nsfw_small.png`,
|
||||
name: `This command is only available in Age Restricted channels.`,
|
||||
url: `https://support.discord.com/hc/en-us/articles/115000084051-Age-Restricted-Channels-and-Content`
|
||||
},
|
||||
color: COLORS.nsfw
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue