1
0
Fork 0
mirror of https://github.com/1disk/edp445.git synced 2024-08-14 22:47:02 +00:00

Changed alot of things.

This commit is contained in:
koelo 2022-12-03 05:44:44 +00:00
parent a5a0523e5a
commit 3513d5390c
2016 changed files with 336930 additions and 9 deletions

172
node_modules/canvacord/plugins/Util.js generated vendored Normal file
View file

@ -0,0 +1,172 @@
const moment = require("moment");
const abbrev = require("./abbrev");
const renderEmoji = require("./renderEmoji");
const momentDurationFormatSetup = require("moment-duration-format");
momentDurationFormatSetup(moment);
class Util {
/**
* Canvacord Util
*/
constructor() {
throw new Error(`The ${this.constructor.name} class may not be instantiated!`);
}
/**
* Validates hex
* @param {string} hex Hex code to validate
* @returns {boolean}
*/
static validateHex(hex) {
if (!hex || typeof hex !== "string") return false;
return /^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/.test(hex);
}
/**
* Converts regular timestamp to discord like time
* @param {Date|number} time Timestamp to convert
* @returns {string}
*/
static discordTime(time = new Date()) {
let date = time && time instanceof Date ? time : new Date();
let hours = date.getHours() < 10 ? `0${date.getHours()}` : date.getHours();
let minutes = date.getMinutes() < 10 ? `0${date.getMinutes()}` : date.getMinutes();
return `Today at ${hours}:${minutes}`;
}
/**
* Formats time
* @param {number} time Time to format
* @returns {string}
*/
static formatTime(time) {
if (!time) return "00:00";
const fmt = moment.duration(time).format("dd:hh:mm:ss");
const chunk = fmt.split(":");
if (chunk.length < 2) chunk.unshift("00");
return chunk.join(":");
}
/**
* Shorten text.
* @param {string} text Text to shorten
* @param {number} len Max Length
* @returns {string}
*/
static shorten(text, len) {
if (typeof text !== "string") return "";
if (text.length <= len) return text;
return text.substr(0, len).trim() + "...";
}
/**
* Converts numbers into units like `1K`, `1M`, `1B` etc.
* @param {number|string} num
* @returns {string}
* @returns {string}
*/
static toAbbrev(num) {
return abbrev(num);
}
/**
* Renders text with emoji
* @param {CanvasRenderingContext2D} ctx CanvasRenderingContext2D
* @param {string} msg Message
* @param {number} x X
* @param {number} y Y
* @returns {Promise<void>}
*/
static renderEmoji(ctx, msg, x, y) {
return renderEmoji(ctx, msg, x, y);
}
/**
* Returns formatted hex code
* @param {string} hex Hex code to format
* @param {string} alt Alt color
* @returns {string}
*/
static formatHex(hex, alt = "#000000") {
if (!hex || typeof hex !== "string") return alt || "#000000";
hex = hex.replace("#", "");
if (hex.length === 3) hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
if (hex.length !== 6) return alt || "#000000";
return `#${hex}`;
}
/**
* Inverts hex color
* @param {string} hex Hex color code to invert
* @returns {string}
*/
static invertColor(hex) {
if (!hex || typeof hex !== "string") return "#FFFFFF";
hex = hex.replace("#", "");
// match hex color
if (hex.length === 3) hex = hex[0] + hex[0] + hex[1] + hex[1] + hex[2] + hex[2];
if (hex.length !== 6) return "#FFFFFF";
// invert colors
const r = (255 - parseInt(hex.slice(0, 2), 16)).toString(16);
const g = (255 - parseInt(hex.slice(2, 4), 16)).toString(16);
const b = (255 - parseInt(hex.slice(4, 6), 16)).toString(16);
// return new hex
const pad = (txt, length) => {
length = length || 2;
let arr = [length].join("0");
return (arr + txt).slice(-length);
};
const finalHex = `#${pad(r)}${pad(g)}${pad(b)}`;
return finalHex;
}
/**
* Returns acronym
* @param {string} name Name to parse acronym
* @returns {string}
*/
static getAcronym(name) {
if (!name || typeof name !== "string") return "";
return name
.replace(/'s /g, " ")
.replace(/\w+/g, e => e[0])
.replace(/\s/g, "");
}
/**
* Returns array of lines
* @param {object} params Params
* @param {string} text Text
* @param {CanvasRenderingContext2D} ctx CanvasRenderingContext2D
* @param {number} maxWidth Max width
* @returns {string[]}
*/
static getLines({ text, ctx, maxWidth }) {
if (!text) return [];
if (!ctx) throw new Error("Canvas context was not provided!");
if (!maxWidth) throw new Error("No max-width provided!");
const lines = [];
while (text.length) {
let i;
for (i = text.length; ctx.measureText(text.substr(0, i)).width > maxWidth; i -= 1);
const result = text.substr(0, i);
let j;
if (i !== text.length) for (j = 0; result.indexOf(" ", j) !== -1; j = result.indexOf(" ", j) + 1);
lines.push(result.substr(0, j || result.length));
text = text.substr(lines[lines.length - 1].length, text.length);
}
return lines;
}
}
module.exports = Util;

24
node_modules/canvacord/plugins/abbrev.js generated vendored Normal file
View file

@ -0,0 +1,24 @@
module.exports = num => {
if (!num || isNaN(num)) return "0";
if (typeof num === "string") num = parseInt(num);
if (typeof Intl !== "undefined") {
return new Intl.NumberFormat("en", { notation: "compact" }).format(num);
} else {
let decPlaces = Math.pow(10, 1);
var abbrev = ["K", "M", "B", "T"];
for (var i = abbrev.length - 1; i >= 0; i--) {
var size = Math.pow(10, (i + 1) * 3);
if (size <= num) {
num = Math.round((num * decPlaces) / size) / decPlaces;
if (num == 1000 && i < abbrev.length - 1) {
num = 1;
i++;
}
num += abbrev[i];
break;
}
}
return `${num}`;
}
};

8
node_modules/canvacord/plugins/circle.js generated vendored Normal file
View file

@ -0,0 +1,8 @@
module.exports = (ctx, w, h) => {
ctx.globalCompositeOperation = "destination-in";
ctx.beginPath();
ctx.arc(w / 2, h / 2, h / 2, 0, Math.PI * 2);
ctx.closePath();
ctx.fill();
return ctx;
};

46
node_modules/canvacord/plugins/convolute.js generated vendored Normal file
View file

@ -0,0 +1,46 @@
module.exports = (ctx, canvas, matrix, opaque) => {
const side = Math.round(Math.sqrt(matrix.length));
const halfSide = Math.floor(side / 2);
const pixels = ctx.getImageData(0, 0, canvas.width, canvas.height);
const src = pixels.data;
const sw = pixels.width;
const sh = pixels.height;
const w = sw;
const h = sh;
const output = ctx.getImageData(0, 0, canvas.width, canvas.height);
const dst = output.data;
const alphaFac = opaque ? 1 : 0;
for (let y = 0; y < h; y++) {
for (let x = 0; x < w; x++) {
const sy = y;
const sx = x;
const dstOff = (y * w + x) * 4;
let r = 0;
let g = 0;
let b = 0;
let a = 0;
for (let cy = 0; cy < side; cy++) {
for (let cx = 0; cx < side; cx++) {
const scy = sy + cy - halfSide;
const scx = sx + cx - halfSide;
if (scy >= 0 && scy < sh && scx >= 0 && scx < sw) {
const srcOff = (scy * sw + scx) * 4;
const wt = matrix[cy * side + cx];
r += src[srcOff] * wt;
g += src[srcOff + 1] * wt;
b += src[srcOff + 2] * wt;
a += src[srcOff + 3] * wt;
}
}
}
dst[dstOff] = r;
dst[dstOff + 1] = g;
dst[dstOff + 2] = b;
dst[dstOff + 3] = a + alphaFac * (255 - a);
}
}
ctx.putImageData(output, 0, 0);
return ctx;
};

22
node_modules/canvacord/plugins/rect.js generated vendored Normal file
View file

@ -0,0 +1,22 @@
module.exports = (ctx, x, y, height, width, color, stroke = false, lineWidth = 1) => {
if (!ctx) throw new Error("Missing canvas context!");
if (isNaN(x)) throw new Error(`Expected height to be a number, received ${typeof height}!`);
if (isNaN(y)) throw new Error(`Expected width to be a number, received ${typeof width}!`);
if (isNaN(height)) throw new Error(`Expected height to be a number, received ${typeof height}!`);
if (isNaN(width)) throw new Error(`Expected width to be a number, received ${typeof width}!`);
if (!color) color = "#000000";
stroke = !!stroke;
ctx.beginPath();
if (stroke) {
ctx.lineWidth = lineWidth;
ctx.strokeStyle = color;
ctx.rect(x, y, width, height);
ctx.stroke();
} else {
ctx.fillStyle = color;
ctx.fillRect(x, y, width, height);
}
ctx.closePath();
return ctx;
};

3
node_modules/canvacord/plugins/renderEmoji.js generated vendored Normal file
View file

@ -0,0 +1,3 @@
module.exports = async (ctx, message, x, y) => {
return ctx.fillText(message, x, y);
};

19
node_modules/canvacord/plugins/round.js generated vendored Normal file
View file

@ -0,0 +1,19 @@
module.exports = (ctx, x, y, width, height, radius) => {
if (radius === true) radius = 5;
if (!radius || typeof radius !== "number") radius = 0;
ctx.beginPath();
ctx.moveTo(x + radius, y);
ctx.lineTo(x + width - radius, y);
ctx.quadraticCurveTo(x + width, y, x + width, y + radius);
ctx.lineTo(x + width, y + height - radius);
ctx.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);
ctx.lineTo(x + radius, y + height);
ctx.quadraticCurveTo(x, y + height, x, y + height - radius);
ctx.lineTo(x, y + radius);
ctx.quadraticCurveTo(x, y, x + radius, y);
ctx.closePath();
ctx.fill();
return ctx;
};