mirror of
https://gitlab.com/bignutty/labscore.git
synced 2025-06-07 13:43:06 -04:00
79 lines
2.9 KiB
JavaScript
79 lines
2.9 KiB
JavaScript
const { PERMISSION_GROUPS } = require("#constants");
|
|
const { wallpaper } = require("#obelisk");
|
|
|
|
const { createEmbed } = require("#utils/embed");
|
|
const { iconPill, stringwrap } = require("#utils/markdown");
|
|
const { editOrReply } = require("#utils/message");
|
|
const { STATIC_ICONS, STATIC_ASSETS } = require("#utils/statics");
|
|
const { hasFeature } = require("#utils/testing");
|
|
|
|
module.exports = {
|
|
name: 'wallpaper',
|
|
label: 'text',
|
|
aliases: ['aiwp'],
|
|
metadata: {
|
|
description: `${iconPill("generative_ai", "LIMITED TESTING")}\n\nGenerate AI Wallpapers`,
|
|
description_short: 'Create Wallpapers',
|
|
examples: ['wallpaper a painting of northern lights, in the bauhaus style -format square'],
|
|
category: 'limited',
|
|
usage: 'wallpaper <prompt> [-format <square|wide>]'
|
|
},
|
|
args: [
|
|
{ name: 'format', default: 'wide', required: false, help: "Image style (wide, square)." }
|
|
],
|
|
permissionsClient: [...PERMISSION_GROUPS.baseline, ...PERMISSION_GROUPS.attachments],
|
|
run: async (context, args) => {
|
|
if(!await hasFeature(context, "ai/wallpapers")) return;
|
|
context.triggerTyping();
|
|
|
|
if(!args.text) return editOrReply(context, createEmbed("warning", context, `Missing Parameter (prompt).`))
|
|
if(!["wide","square"].includes(args.format.toLowerCase())) return editOrReply(context, createEmbed("warning", context, `Invalid Parameter (format).`))
|
|
try{
|
|
let load = createEmbed("defaultNoFooter", context, {
|
|
url: "https://bignutty.gitlab.io",
|
|
author: {
|
|
iconUrl: STATIC_ICONS.ai_image_processing,
|
|
name: "Generating images..."
|
|
},
|
|
image: {
|
|
url: STATIC_ASSETS.image_loading
|
|
}
|
|
})
|
|
let loadingEmbeds = [load, load, load, load]
|
|
|
|
await editOrReply(context, {embeds: loadingEmbeds});
|
|
|
|
let res = await wallpaper(context, args.text, args.format.toLowerCase());
|
|
|
|
// Construct Embeds
|
|
let files = [];
|
|
let embeds = res.response.body.images.map((i)=>{
|
|
let imgName = `lcigen.${(Date.now() + Math.random()).toString(36)}.jpeg`;
|
|
|
|
files.push({
|
|
filename: imgName,
|
|
value: Buffer.from(i, 'base64')
|
|
})
|
|
return createEmbed("defaultNoFooter", context, {
|
|
url: "https://bignutty.gitlab.io",
|
|
author: {
|
|
iconUrl: STATIC_ICONS.ai_image,
|
|
name: stringwrap(args.text, 50, false),
|
|
},
|
|
image: {
|
|
url: `attachment://${imgName}`
|
|
},
|
|
footer: {
|
|
text: `Generative AI is experimental • Use AI Images responsibly.`
|
|
}
|
|
})
|
|
});
|
|
|
|
return editOrReply(context, {embeds, files});
|
|
} catch(e){
|
|
console.log(e)
|
|
if(e.response?.body?.message) return editOrReply(context, createEmbed("error", context, e.response.body.message))
|
|
return editOrReply(context, createEmbed("error", context, `Unable to generate image.`))
|
|
}
|
|
}
|
|
};
|