This commit is contained in:
derpystuff 2022-05-21 16:21:08 +02:00
parent 7195d43c74
commit 6173b085a3
26 changed files with 1112 additions and 91 deletions

33
labscore/utils/ansi.js Normal file
View file

@ -0,0 +1,33 @@
const ANSI_COLORS = {
"reset": "",
"black": "",
"red": "",
"green": "",
"yellow": "",
"blue": "",
"magenta": "",
"cyan": "",
"white": ""
}
const ALIASES = {
"b": "black",
"r": "red",
"g": "green",
"y": "yellow",
"bl": "blue",
"m": "magenta",
"c": "cyan",
"w": "white",
"rs": "reset"
}
function format(text, color){
if(!ANSI_COLORS[color] && !ALIASES[color]) throw "Invalid ANSI Color"
if(!ANSI_COLORS[color]) color = ALIASES[color]
return `${ANSI_COLORS[color]}${text}${ANSI_COLORS.reset}`
}
module.exports = {
format
}

69
labscore/utils/embed.js Normal file
View file

@ -0,0 +1,69 @@
const { COLORS } = require('../constants')
const embedTypes = Object.freeze({
"default": (context) => {
return {
color: COLORS.embed,
footer: {
iconUrl: `https://cdn.discordapp.com/avatars/${context.application.id}/${context.application.icon}.png?size=256`,
text: context.application.name
}
}
},
"warning": (context) => {
return {
author: {
iconUrl: `https://derpystuff.gitlab.io/webstorage4/v2/assets/icons/ico_warning_small.png`,
name: `Warning`
},
color: COLORS.warning
}
},
"error": (context) => {
return {
author: {
iconUrl: `https://derpystuff.gitlab.io/webstorage4/v2/assets/icons/ico_error_small.png`,
name: `Error`
},
color: COLORS.error
}
}
})
// Returns a formatted embed
module.exports.createEmbed = function(type, context, content){
if(!embedTypes[type]) throw "Invalid Embed Type"
if(!content) embedTypes[type](context)
let emb = embedTypes[type](context)
if(["warning","error"].includes(type)){
emb.author.name = content
return emb
}
return Object.assign(emb, content)
}
// Adds formatted page numbers to the embed footer
module.exports.formatPaginationEmbeds = function(embeds){
let i = 0;
let l = embeds.length;
let formatted = [];
for(const e of embeds){
i += 1;
let ne = e;
if(e.embed){
ne.embed.footer.text = e.embed.footer.text + ` • Page ${i}/${l}`
formatted.push(ne)
} else if (e.embeds){
let fse = []
for(const se of e.embeds){
se.footer.text = se.footer.text + ` • Page ${i}/${l}`
fse.push(se)
}
ne.embeds = fse
formatted.push(ne)
} else {
formatted.push(e)
}
}
return formatted;
}

View file

@ -0,0 +1,19 @@
const { ICONS } = require('../constants')
module.exports.icon = function(icon){
if(!ICONS[icon]) return ICONS.question
return ICONS[icon]
}
module.exports.highlight = function(content){
return "`" + content + "`"
}
module.exports.codeblock = function(type, content){
return "```" + type + "\n" + content.join('\n') + "\n```"
}
module.exports.link = function(url, masked){
if(masked) return `[${masked}](${url})`
return url
}

View file

@ -0,0 +1,6 @@
module.exports.editOrReply = function(context, message, disableReference = false){
// Apply message_reference
if(!message.message_reference && !disableReference) message.reference = true
if(!message.allowedMentions) message.allowedMentions = {parse: [], repliedUser: false}
return context.editOrReply(message)
}

33
labscore/utils/statics.js Normal file
View file

@ -0,0 +1,33 @@
const { Hosts } = require('../api/endpoints')
const Statics = Object.freeze({
brands: {
photofunia: {
file: "brands/photofunia.png",
revision: 1
},
genius: {
file: "brands/genius.png",
revision: 0
},
bing: {
file: "brands/bing.png",
revision: 0
},
google: {
file: "brands/google.png",
revision: 0
}
}
})
function staticAsset(static){
return Hosts.statics + `assets/` + static.file + "?r=" + static.revision
}
module.exports.STATICS = Object.freeze({
photofunia: staticAsset(Statics.brands.photofunia),
genius: staticAsset(Statics.brands.genius),
bing: staticAsset(Statics.brands.bing),
google: staticAsset(Statics.brands.google)
})