From 0c4e48bd3912908497cca061aca6a154f7c4fe7c Mon Sep 17 00:00:00 2001 From: derpystuff <3515180-derpystuff@users.noreply.gitlab.com> Date: Wed, 25 May 2022 21:26:57 +0200 Subject: [PATCH] a bunch of things also deepai --- commands/message/core/help.js | 1 + commands/message/image/deepai/deepdream.js | 39 ++++++++++++ .../message/image/deepai/superresolution.js | 39 ++++++++++++ commands/message/image/deepai/waifu2x.js | 39 ++++++++++++ commands/message/info/avatar.js | 8 +-- commands/message/search/youtube.js | 60 +++++++++++++++++++ labscore/api/endpoints.js | 5 ++ labscore/api/index.js | 25 ++++++++ labscore/utils/statics.js | 9 ++- 9 files changed, 219 insertions(+), 6 deletions(-) create mode 100644 commands/message/image/deepai/deepdream.js create mode 100644 commands/message/image/deepai/superresolution.js create mode 100644 commands/message/image/deepai/waifu2x.js create mode 100644 commands/message/search/youtube.js diff --git a/commands/message/core/help.js b/commands/message/core/help.js index 2fd18ed..1ee1920 100644 --- a/commands/message/core/help.js +++ b/commands/message/core/help.js @@ -51,6 +51,7 @@ function createCommandPage(context, prefix, command){ const categories = { "core": `${icon("house")} Core Commands`, "info": `${icon("info")} Information Commands`, + "image": `${icon("image")} Image Commands`, "mod": `${icon("moderation")} Moderation Commands`, "search": `${icon("search")} Search Commands` } diff --git a/commands/message/image/deepai/deepdream.js b/commands/message/image/deepai/deepdream.js new file mode 100644 index 0000000..55a5b2e --- /dev/null +++ b/commands/message/image/deepai/deepdream.js @@ -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 ' + }, + 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.`)]}) + } + }, +}; \ No newline at end of file diff --git a/commands/message/image/deepai/superresolution.js b/commands/message/image/deepai/superresolution.js new file mode 100644 index 0000000..316a47a --- /dev/null +++ b/commands/message/image/deepai/superresolution.js @@ -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 ' + }, + 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.`)]}) + } + }, +}; \ No newline at end of file diff --git a/commands/message/image/deepai/waifu2x.js b/commands/message/image/deepai/waifu2x.js new file mode 100644 index 0000000..bb7f0cd --- /dev/null +++ b/commands/message/image/deepai/waifu2x.js @@ -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 ' + }, + 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.`)]}) + } + }, +}; \ No newline at end of file diff --git a/commands/message/info/avatar.js b/commands/message/info/avatar.js index 912d176..bd00bd6 100644 --- a/commands/message/info/avatar.js +++ b/commands/message/info/avatar.js @@ -14,12 +14,12 @@ module.exports = { }, run: async (context, args) => { context.triggerTyping(); - let u; - if(!args.user) { u = context.user } else { u = await getUser(context, args.user) } - if(!u) return editOrReply(context, { embeds: [createEmbed("warning", context, "No users found.")] }) + let u = {}; + if(!args.user) { u.user = context.user } else { u = await getUser(context, args.user) } + if(!u.user) return editOrReply(context, { embeds: [createEmbed("warning", context, "No users found.")] }) return editOrReply(context, { embeds: [createEmbed("default", context, { image: { - url: u.avatarUrl + '?size=4096' + url: u.user.avatarUrl + '?size=4096' } })] }) }, diff --git a/commands/message/search/youtube.js b/commands/message/search/youtube.js new file mode 100644 index 0000000..7c234f1 --- /dev/null +++ b/commands/message/search/youtube.js @@ -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 ' + }, + 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.`)]}) + } + }, +}; \ No newline at end of file diff --git a/labscore/api/endpoints.js b/labscore/api/endpoints.js index f2bc20f..13a1e46 100644 --- a/labscore/api/endpoints.js +++ b/labscore/api/endpoints.js @@ -17,10 +17,15 @@ const Api = Object.freeze({ SEARCH_BING: '/search/bing', SEARCH_BING_IMAGES: '/search/bing-images', SEARCH_WOLFRAM_ALPHA: '/search/wolfram-alpha', + SEARCH_YOUTUBE: '/search/youtube', PHOTOFUNIA_YACHT: '/photofunia/yacht', PHOTOFUNIA_RETRO_WAVE: '/photofunia/retro-wave', + IMAGE_DEEPDREAM: '/image/deepdream', + IMAGE_WAIFU2X: '/image/waifu2x', + IMAGE_SUPERRESOLUTION: '/image/superresolution', + INFERKIT: '/utils/inferkit', }) diff --git a/labscore/api/index.js b/labscore/api/index.js index b4a7c4a..bb1b31e 100644 --- a/labscore/api/index.js +++ b/labscore/api/index.js @@ -5,6 +5,7 @@ const { Api, Static, Hosts } = require('./endpoints') async function request(path, type, headers, args, host) { let timing = Date.now(); url = Api.HOST + path + if(process.env.USE_LOCAL_API) url = Hosts.local + path if(host) url = host + path // 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){ return await request(Api.PHOTOFUNIA_YACHT, "GET", {}, { 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){ return await request(Api.INFERKIT, "GET", {}, { input: input diff --git a/labscore/utils/statics.js b/labscore/utils/statics.js index bc0e14b..4e27b31 100644 --- a/labscore/utils/statics.js +++ b/labscore/utils/statics.js @@ -20,11 +20,15 @@ const Statics = Object.freeze({ }, wolframalpha: { file: "brands/wolframalpha.png", - revision: 0 + revision: 1 }, inferkit: { file: "brands/inferkit.png", revision: 0 + }, + youtube: { + file: "brands/youtube.png", + revision: 1 } } }) @@ -39,5 +43,6 @@ module.exports.STATICS = Object.freeze({ bing: staticAsset(Statics.brands.bing), google: staticAsset(Statics.brands.google), wolframalpha: staticAsset(Statics.brands.wolframalpha), - inferkit: staticAsset(Statics.brands.inferkit) + inferkit: staticAsset(Statics.brands.inferkit), + youtube: staticAsset(Statics.brands.youtube) }) \ No newline at end of file