added random colour for embeds

pull/15/head
tycrek 4 years ago
parent 7cae3b0e68
commit de61d73c1e
No known key found for this signature in database
GPG Key ID: 25D74F3943625263

@ -1,7 +1,7 @@
const Mustache = require('mustache');
const DateTime = require('luxon').DateTime;
const github = require('./package.json').homepage;
const { formatBytes } = require('./utils');
const { formatBytes, randomHexColour } = require('./utils');
//
class OpenGraph {
@ -50,7 +50,7 @@ class OpenGraph {
title: (this.title.length != 0) ? `<meta property="og:title" content="${this.title}">` : '',
description: (this.description.length != 0) ? `<meta property="og:description" content="${this.description}">` : '',
site: (this.author.length != 0) ? `<meta property="og:site_name" content="${this.author}">` : '',
color: (this.color.length != 0) ? `<meta name="theme-color" content="${this.color}">` : '',
color: (this.color.length != 0) ? `<meta name="theme-color" content="${this.color === '&random' ? randomHexColour() : this.color}">` : '',
card: !this.type.includes('video') ? `<meta name="twitter:card" content="summary_large_image">` : '',
})
.replace(new RegExp('&size', 'g'), formatBytes(this.size))

@ -26,5 +26,11 @@ module.exports = {
let sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
let i = Math.floor(Math.log(bytes) / Math.log(1024));
return parseFloat((bytes / Math.pow(1024, i)).toFixed(decimals < 0 ? 0 : decimals)) + ' ' + sizes[i];
},
randomHexColour: () => { // From: https://www.geeksforgeeks.org/javascript-generate-random-hex-codes-color/
let letters = "0123456789ABCDEF";
let colour = '#';
for (var i = 0; i < 6; i++) colour += letters[(Math.floor(Math.random() * 16))];
return colour;
}
}

Loading…
Cancel
Save