a bunch of things also deepai

This commit is contained in:
derpystuff 2022-05-25 21:26:57 +02:00
parent aec828beb5
commit 0c4e48bd39
9 changed files with 219 additions and 6 deletions

View file

@ -51,6 +51,7 @@ function createCommandPage(context, prefix, command){
const categories = { const categories = {
"core": `${icon("house")} Core Commands`, "core": `${icon("house")} Core Commands`,
"info": `${icon("info")} Information Commands`, "info": `${icon("info")} Information Commands`,
"image": `${icon("image")} Image Commands`,
"mod": `${icon("moderation")} Moderation Commands`, "mod": `${icon("moderation")} Moderation Commands`,
"search": `${icon("search")} Search Commands` "search": `${icon("search")} Search Commands`
} }

View file

@ -0,0 +1,39 @@
const { getRecentImage } = require("../../../../labscore/utils/attachment");
const { createEmbed } = require("../../../../labscore/utils/embed");
const { editOrReply } = require("../../../../labscore/utils/message");
const { deepdream } = require('../../../../labscore/api')
module.exports = {
name: 'deepdream',
aliases: ['dd'],
metadata: {
description: 'deepdream',
examples: ['deepdream'],
category: 'image',
usage: 'deepdream <image>'
},
run: async (context, args) => {
context.triggerTyping();
try{
let image = await getRecentImage(context, 50)
if(!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
let res = await deepdream(context, image)
if(res.response.body.status == 1) return editOrReply(context, {embeds:[createEmbed("warning", context, res.response.body.errors[0])]})
return editOrReply(context, {embeds:[createEmbed("default", context, {
image: {
url: res.response.body.image
},
footer: {
iconUrl: `https://cdn.discordapp.com/avatars/${context.application.id}/${context.application.icon}.png?size=256`,
text: `${context.application.name} • Took ${res.timings}s`
}
})]})
}catch(e){
console.log(e)
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to modify image.`)]})
}
},
};

View file

@ -0,0 +1,39 @@
const { getRecentImage } = require("../../../../labscore/utils/attachment");
const { createEmbed } = require("../../../../labscore/utils/embed");
const { editOrReply } = require("../../../../labscore/utils/message");
const { superresolution } = require('../../../../labscore/api')
module.exports = {
name: 'superresolution',
aliases: ['sr'],
metadata: {
description: 'superresolution',
examples: ['superresolution'],
category: 'image',
usage: 'superresolution <image>'
},
run: async (context, args) => {
context.triggerTyping();
try{
let image = await getRecentImage(context, 50)
if(!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
let res = await superresolution(context, image)
if(res.response.body.status == 1) return editOrReply(context, {embeds:[createEmbed("warning", context, res.response.body.errors[0])]})
return editOrReply(context, {embeds:[createEmbed("default", context, {
image: {
url: res.response.body.image
},
footer: {
iconUrl: `https://cdn.discordapp.com/avatars/${context.application.id}/${context.application.icon}.png?size=256`,
text: `${context.application.name} • Took ${res.timings}s`
}
})]})
}catch(e){
console.log(e)
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to modify image.`)]})
}
},
};

View file

@ -0,0 +1,39 @@
const { getRecentImage } = require("../../../../labscore/utils/attachment");
const { createEmbed } = require("../../../../labscore/utils/embed");
const { editOrReply } = require("../../../../labscore/utils/message");
const { waifu2x } = require('../../../../labscore/api')
module.exports = {
name: 'waifu2x',
aliases: ['2x'],
metadata: {
description: 'waifu2x',
examples: ['waifu2x'],
category: 'image',
usage: 'waifu2x <image>'
},
run: async (context, args) => {
context.triggerTyping();
try{
let image = await getRecentImage(context, 50)
if(!image) return editOrReply(context, { embeds: [createEmbed("warning", context, "No images found.")] })
let res = await waifu2x(context, image)
if(res.response.body.status == 1) return editOrReply(context, {embeds:[createEmbed("warning", context, res.response.body.errors[0])]})
return editOrReply(context, {embeds:[createEmbed("default", context, {
image: {
url: res.response.body.image
},
footer: {
iconUrl: `https://cdn.discordapp.com/avatars/${context.application.id}/${context.application.icon}.png?size=256`,
text: `${context.application.name} • Took ${res.timings}s`
}
})]})
}catch(e){
console.log(e)
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to modify image.`)]})
}
},
};

View file

@ -14,12 +14,12 @@ module.exports = {
}, },
run: async (context, args) => { run: async (context, args) => {
context.triggerTyping(); context.triggerTyping();
let u; let u = {};
if(!args.user) { u = context.user } else { u = await getUser(context, args.user) } if(!args.user) { u.user = context.user } else { u = await getUser(context, args.user) }
if(!u) return editOrReply(context, { embeds: [createEmbed("warning", context, "No users found.")] }) if(!u.user) return editOrReply(context, { embeds: [createEmbed("warning", context, "No users found.")] })
return editOrReply(context, { embeds: [createEmbed("default", context, { return editOrReply(context, { embeds: [createEmbed("default", context, {
image: { image: {
url: u.avatarUrl + '?size=4096' url: u.user.avatarUrl + '?size=4096'
} }
})] }) })] })
}, },

View file

@ -0,0 +1,60 @@
const { createEmbed, formatPaginationEmbeds } = require('../../../labscore/utils/embed')
const { link } = require('../../../labscore/utils/markdown')
const { editOrReply } = require('../../../labscore/utils/message')
const { STATICS } = require('../../../labscore/utils/statics')
const { paginator } = require('../../../labscore/client');
const { youtube } = require('../../../labscore/api');
function createYoutubePage(context, result){
let res = {
"embeds": [
createEmbed("default", context, {
description: `**${link(result.url, result.name)}**\n${result.description}`,
thumbnail: {
url: result.image
},
footer: {
iconUrl: STATICS.youtube,
text: `YouTube • ${context.application.name}`
}
})
]
}
return res;
}
module.exports = {
name: 'youtube',
label: 'query',
aliases: ['yt'],
metadata: {
description: 'youtube search',
examples: ['youtube Google'],
category: 'search',
usage: 'youtube <query>'
},
run: async (context, args) => {
context.triggerTyping();
if(!args.query) return editOrReply(context, {embeds:[createEmbed("warning", context, `Missing Parameter (query).`)]})
try{
let search = await youtube(context, args.query)
search = search.response
let pages = []
for(const res of search.body.results){
pages.push(createYoutubePage(context, res))
}
pages = formatPaginationEmbeds(pages)
const message = context.message
const paging = await paginator.createPaginator({
message,
pages
});
}catch(e){
console.log(e)
return editOrReply(context, {embeds:[createEmbed("error", context, `Unable to perform google search.`)]})
}
},
};

View file

@ -17,10 +17,15 @@ const Api = Object.freeze({
SEARCH_BING: '/search/bing', SEARCH_BING: '/search/bing',
SEARCH_BING_IMAGES: '/search/bing-images', SEARCH_BING_IMAGES: '/search/bing-images',
SEARCH_WOLFRAM_ALPHA: '/search/wolfram-alpha', SEARCH_WOLFRAM_ALPHA: '/search/wolfram-alpha',
SEARCH_YOUTUBE: '/search/youtube',
PHOTOFUNIA_YACHT: '/photofunia/yacht', PHOTOFUNIA_YACHT: '/photofunia/yacht',
PHOTOFUNIA_RETRO_WAVE: '/photofunia/retro-wave', PHOTOFUNIA_RETRO_WAVE: '/photofunia/retro-wave',
IMAGE_DEEPDREAM: '/image/deepdream',
IMAGE_WAIFU2X: '/image/waifu2x',
IMAGE_SUPERRESOLUTION: '/image/superresolution',
INFERKIT: '/utils/inferkit', INFERKIT: '/utils/inferkit',
}) })

View file

@ -5,6 +5,7 @@ const { Api, Static, Hosts } = require('./endpoints')
async function request(path, type, headers, args, host) { async function request(path, type, headers, args, host) {
let timing = Date.now(); let timing = Date.now();
url = Api.HOST + path url = Api.HOST + path
if(process.env.USE_LOCAL_API) url = Hosts.local + path
if(host) url = host + path if(host) url = host + path
// apply default headers // apply default headers
@ -82,6 +83,12 @@ module.exports.wolframAlpha = async function(context, query){
}) })
} }
module.exports.youtube = async function(context, query){
return await request(Api.SEARCH_YOUTUBE, "GET", {}, {
q: query
})
}
module.exports.yacht = async function(context, text){ module.exports.yacht = async function(context, text){
return await request(Api.PHOTOFUNIA_YACHT, "GET", {}, { return await request(Api.PHOTOFUNIA_YACHT, "GET", {}, {
text: text text: text
@ -98,6 +105,24 @@ module.exports.retroWave = async function(context, background = 5, textStyle= 4,
}) })
} }
module.exports.deepdream = async function(context, url){
return await request(Api.IMAGE_DEEPDREAM, "GET", {}, {
url: url
})
}
module.exports.waifu2x = async function(context, url){
return await request(Api.IMAGE_WAIFU2X, "GET", {}, {
url: url
})
}
module.exports.superresolution = async function(context, url){
return await request(Api.IMAGE_SUPERRESOLUTION, "GET", {}, {
url: url
})
}
module.exports.inferkit = async function(context, input){ module.exports.inferkit = async function(context, input){
return await request(Api.INFERKIT, "GET", {}, { return await request(Api.INFERKIT, "GET", {}, {
input: input input: input

View file

@ -20,11 +20,15 @@ const Statics = Object.freeze({
}, },
wolframalpha: { wolframalpha: {
file: "brands/wolframalpha.png", file: "brands/wolframalpha.png",
revision: 0 revision: 1
}, },
inferkit: { inferkit: {
file: "brands/inferkit.png", file: "brands/inferkit.png",
revision: 0 revision: 0
},
youtube: {
file: "brands/youtube.png",
revision: 1
} }
} }
}) })
@ -39,5 +43,6 @@ module.exports.STATICS = Object.freeze({
bing: staticAsset(Statics.brands.bing), bing: staticAsset(Statics.brands.bing),
google: staticAsset(Statics.brands.google), google: staticAsset(Statics.brands.google),
wolframalpha: staticAsset(Statics.brands.wolframalpha), wolframalpha: staticAsset(Statics.brands.wolframalpha),
inferkit: staticAsset(Statics.brands.inferkit) inferkit: staticAsset(Statics.brands.inferkit),
youtube: staticAsset(Statics.brands.youtube)
}) })