mono2: screenshot

This commit is contained in:
bignutty 2024-05-23 22:58:33 +02:00
parent 2d84cddca9
commit eb7a03f971
4 changed files with 23 additions and 19 deletions

View file

@ -1,7 +1,7 @@
const { createEmbed } = require("../../../../labscore/utils/embed"); const { createEmbed } = require("../../../../labscore/utils/embed");
const { editOrReply } = require("../../../../labscore/utils/message"); const { editOrReply } = require("../../../../labscore/utils/message");
const { webshot } = require("../../../../labscore/api/obelisk"); const { WebUtilsWebPageScreenshot} = require("../../../../labscore/api/obelisk");
const { ApplicationCommandOptionTypes, InteractionCallbackTypes } = require('detritus-client/lib/constants'); const { ApplicationCommandOptionTypes, InteractionCallbackTypes } = require('detritus-client/lib/constants');
@ -32,28 +32,26 @@ module.exports = {
try { try {
const t = Date.now(); const t = Date.now();
let ss = await webshot(context, args.url, false) // nsfw sites are always blocked let ss = await WebUtilsWebPageScreenshot(context, args.url, false) // nsfw sites are always blocked
if (ss.response.body.status && ss.response.body.status !== 3) { if (ss.response.body.error) return await editOrReply(context,
if (ss.response.body.image) return await editOrReply(context,
createEmbed("image", context, { createEmbed("image", context, {
url: ss.response.body.image, url: ss.response.body.error.image_url,
time: ((Date.now() - t) / 1000).toFixed(2) time: ((Date.now() - t) / 1000).toFixed(2)
}) })
) )
return await editOrReply(context, createEmbed("error", context, "Unable to create screenshot."))
}
return await editOrReply(context, { return await editOrReply(context, {
embeds: [createEmbed("image", context, { embeds: [createEmbed("image", context, {
url: "screenshot.png", url: "screenshot.png",
time: ((Date.now() - t) / 1000).toFixed(2) time: ((Date.now() - t) / 1000).toFixed(2)
})], })],
files: [{ filename: "screenshot.png", value: ss.response.body }] files: [{ filename: "screenshot.png", value: Buffer.from(ss.response.body.image, 'base64') }]
}) })
} catch (e) { } catch (e) {
console.log(e) console.log(e)
return await editOrReply(context, createEmbed("image", context, { return editOrReply(context, createEmbed("image", context, {
url: "https://bignutty.gitlab.io/webstorage4/v2/assets/screenshot/brand-update-2024/scr_unavailable.png" url: "https://bignutty.gitlab.io/webstorage4/v2/assets/screenshot/brand-update-2024/scr_unavailable.png"
})) }))
} }

View file

@ -4,7 +4,7 @@ const { editOrReply } = require("../../../labscore/utils/message");
const superagent = require('superagent') const superagent = require('superagent')
const { Permissions } = require("detritus-client/lib/constants"); const { Permissions } = require("detritus-client/lib/constants");
const { webshot } = require("../../../labscore/api/obelisk"); const { WebUtilsWebPageScreenshot} = require("../../../labscore/api/obelisk");
async function processJob(jobUrl) { async function processJob(jobUrl) {
let job = await superagent.get(jobUrl) let job = await superagent.get(jobUrl)
@ -33,24 +33,21 @@ module.exports = {
try { try {
const t = Date.now(); const t = Date.now();
let ss = await webshot(context, args.url, context.channel.nsfw) let ss = await WebUtilsWebPageScreenshot(context, args.url, false)
if (ss.response.body.status && ss.response.body.status !== 3) { if (ss.response.body.error) return await editOrReply(context,
if (ss.response.body.image) return await editOrReply(context,
createEmbed("image", context, { createEmbed("image", context, {
url: ss.response.body.image, url: ss.response.body.error.image_url,
time: ((Date.now() - t) / 1000).toFixed(2) time: ((Date.now() - t) / 1000).toFixed(2)
}) })
) )
return await editOrReply(context, createEmbed("error", context, "Unable to create screenshot."))
}
return await editOrReply(context, { return await editOrReply(context, {
embeds: [createEmbed("image", context, { embeds: [createEmbed("image", context, {
url: "screenshot.png", url: "screenshot.png",
time: ((Date.now() - t) / 1000).toFixed(2) time: ((Date.now() - t) / 1000).toFixed(2)
})], })],
files: [{ filename: "screenshot.png", value: ss.response.body }] files: [{ filename: "screenshot.png", value: Buffer.from(ss.response.body.image, 'base64') }]
}) })
} catch (e) { } catch (e) {
console.log(e) console.log(e)

View file

@ -12,6 +12,8 @@ const ObeliskApi = Object.freeze({
GENERATIVEIMAGES_MODELS_IMAGEN: "/generativeimages/v1/models/imagen", GENERATIVEIMAGES_MODELS_IMAGEN: "/generativeimages/v1/models/imagen",
WEBUTILS_WEBPAGE_SCREENSHOT: "/webutils/v1/webpage:screenshot",
SPARK_WEB_SUMMARIZE: "/spark-pa/v1/web:summarize", SPARK_WEB_SUMMARIZE: "/spark-pa/v1/web:summarize",
WOLFRAM_QUERY_COMPUTE: "/wolfram/v1/query:compute", WOLFRAM_QUERY_COMPUTE: "/wolfram/v1/query:compute",

View file

@ -62,6 +62,13 @@ module.exports.GenerativeImagesModelsImagen = async function(context, prompt){
}) })
} }
module.exports.WebUtilsWebPageScreenshot = async function(context, url, allow_adult){
return await request(ObeliskApi.WEBUTILS_WEBPAGE_SCREENSHOT, "POST", {}, {
url,
allow_adult
})
}
module.exports.SparkWebSummarize = async function(context, url){ module.exports.SparkWebSummarize = async function(context, url){
return await request(ObeliskApi.SPARK_WEB_SUMMARIZE, "POST", {}, { return await request(ObeliskApi.SPARK_WEB_SUMMARIZE, "POST", {}, {
url url