This commit is contained in:
poslop
2023-03-24 15:23:01 -05:00
parent a3e93cd5a2
commit adfa36a4fd
13 changed files with 493 additions and 376 deletions

View File

@@ -2,7 +2,7 @@
* @name BDFDB
* @author DevilBro
* @authorId 278543574059057154
* @version 3.0.7
* @version 3.2.0
* @description Required Library for DevilBro's Plugins
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@@ -1094,14 +1094,16 @@ module.exports = (_ => {
const requestLibraryHashes = tryAgain => {
requestFunction("https://api.github.com/repos/mwittrien/BetterDiscordAddons/contents/Library/_res/", {headers: {"user-agent": "node.js"}, timeout: 60000}, (e, r, b) => {
if ((e || !b || r.statusCode != 200) && tryAgain) return BDFDB.TimeUtils.timeout(_ => requestLibraryHashes(), 10000);
try {
b = JSON.parse(b);
libHashes[cssFileName] = (b.find(n => n && n.name == cssFileName) || {}).sha;
libHashes[dataFileName] = (b.find(n => n && n.name == dataFileName) || {}).sha;
BDFDB.DataUtils.save(libHashes, BDFDB, "hashes");
else {
try {
b = JSON.parse(b);
libHashes[cssFileName] = (b.find(n => n && n.name == cssFileName) || {}).sha;
libHashes[dataFileName] = (b.find(n => n && n.name == dataFileName) || {}).sha;
BDFDB.DataUtils.save(libHashes, BDFDB, "hashes");
}
catch (err) {}
requestLibraryData(true);
}
catch (err) {requestLibraryData(true);}
});
};
const requestLibraryData = tryAgain => {
@@ -1687,7 +1689,7 @@ module.exports = (_ => {
let icon = data.config.avatar ? BDFDB.ReactUtils.createElement(Internal.LibraryComponents.Avatars.Avatar, {
src: data.config.avatar,
size: Internal.LibraryComponents.Avatars.Sizes.SIZE_24
size: Internal.LibraryComponents.AvatarConstants.Sizes.SIZE_24
}) : ((data.config.icon || data.config.type && Internal.DiscordConstants.ToastIcons[data.config.type]) ? BDFDB.ReactUtils.createElement(Internal.LibraryComponents.SvgIcon, {
name: data.config.type && Internal.DiscordConstants.ToastIcons[data.config.type] && Internal.LibraryComponents.SvgIcon.Names[Internal.DiscordConstants.ToastIcons[data.config.type]],
iconSVG: data.config.icon,
@@ -2463,14 +2465,14 @@ module.exports = (_ => {
}
return parent.props.children;
}
MyReact.createElement = function (component, props = {}, errorWrap = false) {
MyReact.createElement = function (component, props = {}, errorWrap = false, ignoreErrors = false) {
if (component && component.defaultProps) for (let key in component.defaultProps) if (props[key] == null) props[key] = component.defaultProps[key];
try {
let child = Internal.LibraryModules.React.createElement(component || "div", props) || null;
if (errorWrap) return Internal.LibraryModules.React.createElement(Internal.ErrorBoundary, {key: child && child.key || ""}, child) || null;
else return child;
}
catch (err) {BDFDB.LogUtils.error(["Could not create React Element!", err]);}
catch (err) {!ignoreErrors && BDFDB.LogUtils.error(["Could not create React Element!", err]);}
return null;
};
MyReact.objectToReact = function (obj) {
@@ -2845,7 +2847,7 @@ module.exports = (_ => {
if (!BDFDB.ObjectUtils.is(node)) return null;
return node[Object.keys(node).find(key => key.startsWith("__reactInternalInstance") || key.startsWith("__reactFiber"))];
};
MyReact.render = function (component, node) {
MyReact.render = function (component, node, ignoreErrors = false) {
if (!BDFDB.ReactUtils.isValidElement(component) || !Node.prototype.isPrototypeOf(node)) return;
try {
Internal.LibraryModules.ReactDOM.render(component, node);
@@ -2858,15 +2860,15 @@ module.exports = (_ => {
}));
observer.observe(document.body, {subtree: true, childList: true});
}
catch (err) {BDFDB.LogUtils.error(["Could not render React Element!", err]);}
catch (err) {!ignoreErrors && BDFDB.LogUtils.error(["Could not render React Element!", err]);}
};
MyReact.hookCall = function (callback, args) {
MyReact.hookCall = function (callback, args, ignoreErrors = false) {
if (typeof callback != "function") return null;
let returnValue = null, tempNode = document.createElement("div");
BDFDB.ReactUtils.render(BDFDB.ReactUtils.createElement(_ => {
returnValue = callback(args);
return null;
}), tempNode);
}, {}, false, ignoreErrors), tempNode, ignoreErrors);
BDFDB.ReactUtils.unmountComponentAtNode(tempNode);
return returnValue;
};
@@ -2942,15 +2944,17 @@ module.exports = (_ => {
BDFDB.UserUtils.getStatusColor = function (status, useColor) {
if (!Internal.DiscordConstants.Colors) return null;
status = typeof status == "string" ? status.toLowerCase() : null;
let color = "";
switch (status) {
case "online": return useColor ? Internal.DiscordConstants.Colors.STATUS_GREEN_600 : "var(--status-positive)";
case "idle": return useColor ? Internal.DiscordConstants.Colors.STATUS_YELLOW : "var(--status-warning)";
case "dnd": return useColor ? Internal.DiscordConstants.Colors.STATUS_RED : "var(--status-danger)";
case "playing": return useColor ? Internal.DiscordConstants.Colors.BRAND : "var(--bdfdb-blurple)";
case "listening": return Internal.DiscordConstants.Colors.SPOTIFY;
case "streaming": return Internal.DiscordConstants.Colors.TWITCH;
default: return Internal.DiscordConstants.Colors.STATUS_GREY;
case "online": color = (useColor ? Internal.DiscordConstants.Colors.GREEN_360 : "var(--status-positive)"); break;
case "idle": color = (useColor ? Internal.DiscordConstants.Colors.YELLOW_300 : "var(--status-warning)"); break;
case "dnd": color = (useColor ? Internal.DiscordConstants.Colors.RED_400 : "var(--status-danger)"); break;
case "playing": color = (useColor ? Internal.DiscordConstants.Colors.BRAND : "var(--bdfdb-blurple)"); break;
case "listening": color = Internal.DiscordConstants.Colors.SPOTIFY; break;
case "streaming": color = Internal.DiscordConstants.Colors.TWITCH; break;
default: color = Internal.DiscordConstants.Colors.PRIMARY_400; break;
}
return (color || Internal.DiscordConstants.Colors.GREEN_360).replace(/calc\(.+\s*\*\s*([0-9\.\%]+)\)/g, "$1");
};
BDFDB.UserUtils.getActivity = function (id = BDFDB.UserUtils.me.id) {
for (let activity of Internal.LibraryStores.PresenceStore.getActivities(id)) if (activity.type != Internal.DiscordConstants.ActivityTypes.CUSTOM_STATUS) return activity;
@@ -3119,11 +3123,12 @@ module.exports = (_ => {
BDFDB.ColorUtils = {};
BDFDB.ColorUtils.convert = function (color, conv, type) {
if (BDFDB.ObjectUtils.is(color)) {
var newColor = {};
let newColor = {};
for (let pos in color) newColor[pos] = BDFDB.ColorUtils.convert(color[pos], conv, type);
return newColor;
}
else {
if (typeof color == "string") color = color.replace(/calc\(.+\s*\*\s*([0-9\.\%]+)\)/g, "$1");
conv = conv === undefined || !conv ? conv = "RGBCOMP" : conv.toUpperCase();
type = type === undefined || !type || !["RGB", "RGBA", "RGBCOMP", "HSL", "HSLA", "HSLCOMP", "HEX", "HEXA", "INT"].includes(type.toUpperCase()) ? BDFDB.ColorUtils.getType(color) : type.toUpperCase();
if (conv == "RGBCOMP") {
@@ -3153,16 +3158,10 @@ module.exports = (_ => {
case "HSL":
var hslComp = processHSL(color.replace(/\s/g, "").slice(4, -1).split(","));
var r, g, b, m, c, x, p, q;
var h = hslComp[0] / 360, l = parseInt(hslComp[1]) / 100, s = parseInt(hslComp[2]) / 100; m = Math.floor(h * 6); c = h * 6 - m; x = s * (1 - l); p = s * (1 - c * l); q = s * (1 - (1 - c) * l);
switch (m % 6) {
case 0: r = s, g = q, b = x; break;
case 1: r = p, g = s, b = x; break;
case 2: r = x, g = s, b = q; break;
case 3: r = x, g = p, b = s; break;
case 4: r = q, g = x, b = s; break;
case 5: r = s, g = x, b = p; break;
}
return [Math.round(r * 255), Math.round(g * 255), Math.round(b * 255)];
var h = hslComp[0], s = processPercentage(hslComp[1]), l = processPercentage(hslComp[2]);
var a = s * Math.min(l, 1-l);
var f = (n, k = (n+h / 30) % 12) => parseInt((l - a * Math.max(Math.min(k-3, 9-k, 1), -1)) * 255);
return [f(0), f(8), f(4)];
case "HSLA":
var hslComp = color.replace(/\s/g, "").slice(5, -1).split(",");
return BDFDB.ColorUtils.convert(`hsl(${hslComp.slice(0, 3).join(",")})`, "RGBCOMP").concat(processA(hslComp.pop()));
@@ -3240,12 +3239,48 @@ module.exports = (_ => {
}
}
return null;
function processC(c) {if (c == null) {return 255;} else {c = parseInt(c.toString().replace(/[^0-9\-]/g, ""));return isNaN(c) || c > 255 ? 255 : c < 0 ? 0 : c;}};
function processRGB(comp) {return [].concat(comp).map(c => {return processC(c);});};
function processA(a) {if (a == null) {return 1;} else {a = a.toString();a = (a.indexOf("%") > -1 ? 0.01 : 1) * parseFloat(a.replace(/[^0-9\.\-]/g, ""));return isNaN(a) || a > 1 ? 1 : a < 0 ? 0 : a;}};
function processSL(sl) {if (sl == null) {return "100%";} else {sl = parseFloat(sl.toString().replace(/[^0-9\.\-]/g, ""));return (isNaN(sl) || sl > 100 ? 100 : sl < 0 ? 0 : sl) + "%";}};
function processHSL(comp) {comp = [].concat(comp);let h = parseFloat(comp.shift().toString().replace(/[^0-9\.\-]/g, ""));h = isNaN(h) || h > 360 ? 360 : h < 0 ? 0 : h;return [h].concat(comp.map(sl => {return processSL(sl);}));};
function processINT(c) {if (c == null) {return 16777215;} else {c = parseInt(c.toString().replace(/[^0-9]/g, ""));return isNaN(c) || c > 16777215 ? 16777215 : c < 0 ? 0 : c;}};
function processC (c) {
if (c == null) return 255;
else {
c = parseInt(c.toString().replace(/[^0-9\-]/g, ""));
return isNaN(c) || c > 255 ? 255 : c < 0 ? 0 : c;
}
};
function processRGB (comp) {
return [].concat(comp).map(processC);
};
function processA (a) {
if (a == null) return 1;
else {
a = a.toString();
a = (a.indexOf("%") > -1 ? 0.01 : 1) * parseFloat(a.replace(/[^0-9\.\-]/g, ""));
return isNaN(a) || a > 1 ? 1 : a < 0 ? 0 : a;
}
};
function processPercentage (p) {
if (p == null) return 1;
else return p.indexOf("%") > -1 ? parseFloat(p)/100 : p;
};
function processSL (sl) {
if (sl == null) return "100%";
else {
sl = parseFloat(sl.toString().replace(/[^0-9\.\-]/g, ""));
return (isNaN(sl) || sl > 100 ? 100 : sl < 0 ? 0 : sl) + "%";
}
};
function processHSL (comp) {
comp = [].concat(comp);
let h = parseFloat(comp.shift().toString().replace(/[^0-9\.\-]/g, ""));
h = isNaN(h) || h > 360 ? 360 : h < 0 ? 0 : h;
return [h].concat(comp.map(processSL));
};
function processINT (c) {
if (c == null) return 16777215;
else {
c = parseInt(c.toString().replace(/[^0-9]/g, ""));
return isNaN(c) || c > 16777215 ? 16777215 : c < 0 ? 0 : c;
}
};
};
BDFDB.ColorUtils.setAlpha = function (color, a, conv) {
if (BDFDB.ObjectUtils.is(color)) {
@@ -3336,12 +3371,13 @@ module.exports = (_ => {
return parseInt(compare) < Math.sqrt(0.299 * color[0]**2 + 0.587 * color[1]**2 + 0.144 * color[2]**2);
};
BDFDB.ColorUtils.getType = function (color) {
if (color != null) {
if (color !== null) {
if (typeof color === "object" && (color.length == 3 || color.length == 4)) {
if (isRGB(color)) return "RGBCOMP";
else if (isHSL(color)) return "HSLCOMP";
}
else if (typeof color === "string") {
color = color.replace(/calc\(.+\s*\*\s*([0-9\.\%]+)\)/g, "$1");
if (/^#[a-f\d]{3}$|^#[a-f\d]{6}$/i.test(color)) return "HEX";
else if (/^#[a-f\d]{4}$|^#[a-f\d]{8}$/i.test(color)) return "HEXA";
else {
@@ -3815,11 +3851,11 @@ module.exports = (_ => {
});
};
const MappedMenuItems = {}, RealMenuItems = BDFDB.ModuleUtils.find(m => {
var MappedMenuItems = {}, RealMenuItems = BDFDB.ModuleUtils.find(m => {
if (!m || typeof m != "function") return false;
let string = m.toString();
return string.endsWith("{return null}}") && string.indexOf("(){return null}") > -1 && string.indexOf("catch(") == -1;
});
}) || BDFDB.ModuleUtils.findByString("(){return null}function");
if (!RealMenuItems) {
RealMenuItems = {};
BDFDB.LogUtils.error(["could not find Module for MenuItems"]);
@@ -4560,7 +4596,7 @@ module.exports = (_ => {
render() {
if (this.state.hasError) return Internal.LibraryModules.React.createElement("span", {
style: {
background: Internal.DiscordConstants.Colors.PRIMARY_DARK,
background: Internal.DiscordConstants.Colors.PRIMARY,
borderRadius: 5,
color: "var(--status-danger)",
fontSize: 12,
@@ -4575,6 +4611,17 @@ module.exports = (_ => {
}
};
Internal.NativeSubComponents = new Proxy(NativeSubComponents, {
get: function (_, item) {
if (NativeSubComponents[item]) return NativeSubComponents[item];
if (!InternalData.NativeSubComponents[item]) return "div";
Internal.findModuleViaData(NativeSubComponents, InternalData.NativeSubComponents, item);
return NativeSubComponents[item] ? NativeSubComponents[item] : "div";
}
});
CustomComponents.AutoFocusCatcher = reactInitialized && class BDFDB_AutoFocusCatcher extends Internal.LibraryModules.React.Component {
render() {
const style = {padding: 0, margin: 0, border: "none", width: 0, maxWidth: 0, height: 0, maxHeight: 0, visibility: "hidden"};
@@ -4725,7 +4772,7 @@ module.exports = (_ => {
children: [
!this.props.noRemove ? BDFDB.ReactUtils.createElement(Internal.LibraryComponents.Clickable, {
"aria-label": BDFDB.LanguageUtils.LanguageStrings.REMOVE,
className: BDFDB.disCNS.hovercardremovebutton + BDFDB.disCNS.hovercardremovebuttondefault,
className: BDFDB.disCNS.hovercardremovebutton + BDFDB.disCN.hovercardremovebuttondefault,
onClick: e => {
if (typeof this.props.onRemove == "function") this.props.onRemove(e, this);
BDFDB.ListenerUtils.stopEvent(e);
@@ -6135,7 +6182,7 @@ module.exports = (_ => {
handleClick(e) {if (typeof this.props.onClick == "function") this.props.onClick(e, this);}
handleContextMenu(e) {if (typeof this.props.onContextMenu == "function") this.props.onContextMenu(e, this);}
render() {
let color = BDFDB.ColorUtils.convert(this.props.role.colorString, "RGB") || Internal.DiscordConstants.Colors.PRIMARY_DARK_300;
let color = BDFDB.ColorUtils.convert(this.props.role.colorString, "RGB") || Internal.DiscordConstants.Colors.PRIMARY_300;
return BDFDB.ReactUtils.createElement("li", {
className: BDFDB.DOMUtils.formatClassName(BDFDB.disCN.userrole, this.props.className),
style: {borderColor: BDFDB.ColorUtils.setAlpha(color, 0.6)},
@@ -6558,6 +6605,22 @@ module.exports = (_ => {
});
}
};
CustomComponents.PopoutContainer.Align = {
BOTTOM: "bottom",
CENTER: "center",
LEFT: "left",
RIGHT: "right",
TOP: "top"
};
CustomComponents.PopoutContainer.Positions = {
BOTTOM: "bottom",
CENTER: "center",
LEFT: "left",
RIGHT: "right",
TOP: "top",
WINDOW_CENTER: "window_center"
};
CustomComponents.PopoutContainer.ObjectProperties = ["Animation"];
Internal.setDefaultProps(CustomComponents.PopoutContainer, {wrap: true});
CustomComponents.PopoutCSSAnimator = function (props) {
@@ -7170,7 +7233,7 @@ module.exports = (_ => {
let mini = props.size == Internal.LibraryComponents.Switch.Sizes.MINI;
return BDFDB.ReactUtils.createElement(Internal.LibraryComponents.Animations.animated.div, {
className: BDFDB.DOMUtils.formatClassName(props.className, BDFDB.disCN.switch, mini && BDFDB.disCN.switchmini),
className: BDFDB.DOMUtils.formatClassName(props.className, BDFDB.disCN.switch, mini && BDFDB.disCN.switchmini, "default-colors"),
onMouseDown: _ => {
return !props.disabled && state[1](true);
},
@@ -7284,7 +7347,7 @@ module.exports = (_ => {
};
Internal.setDefaultProps(CustomComponents.Switch, {
size: CustomComponents.Switch.Sizes.DEFAULT,
uncheckedColor: Internal.DiscordConstants.Colors.PRIMARY_DARK_400,
uncheckedColor: Internal.DiscordConstants.Colors.PRIMARY_400,
checkedColor: Internal.DiscordConstants.Colors.BRAND
});
@@ -7311,6 +7374,19 @@ module.exports = (_ => {
}), "itemClassName", "items", "renderItem"));
}
};
CustomComponents.TabBar.Types = {
SIDE: "side",
TOP: "top",
TOP_PILL: "top-pill"
};
CustomComponents.TabBar.Looks = {
0: "GREY",
1: "BRAND",
2: "CUSTOM",
GREY: 0,
BRAND: 1,
CUSTOM: 2
};
CustomComponents.Table = reactInitialized && class BDFDB_Table extends Internal.LibraryModules.React.Component {
render() {
@@ -7604,6 +7680,14 @@ module.exports = (_ => {
});
}
};
CustomComponents.TooltipContainer.Positions = {
BOTTOM: "bottom",
CENTER: "center",
LEFT: "left",
RIGHT: "right",
TOP: "top",
WINDOW_CENTER: "window_center"
};
CustomComponents.UserPopoutContainer = reactInitialized && class BDFDB_UserPopoutContainer extends Internal.LibraryModules.React.Component {
render() {
@@ -7667,17 +7751,6 @@ module.exports = (_ => {
}
};
Internal.NativeSubComponents = new Proxy(NativeSubComponents, {
get: function (_, item) {
if (NativeSubComponents[item]) return NativeSubComponents[item];
if (!InternalData.NativeSubComponents[item]) return "div";
Internal.findModuleViaData(NativeSubComponents, InternalData.NativeSubComponents, item);
return NativeSubComponents[item] ? NativeSubComponents[item] : "div";
}
});
Internal.LibraryComponents = new Proxy(LibraryComponents, {
get: function (_, item) {
if (LibraryComponents[item]) return LibraryComponents[item];
@@ -7693,6 +7766,7 @@ module.exports = (_ => {
if (key == "defaultProps") LibraryComponents[item][key] = Object.assign({}, LibraryComponents[item][key], NativeComponent[key]);
else if (!LibraryComponents[item][key]) LibraryComponents[item][key] = NativeComponent[key];
}
if (LibraryComponents[item].ObjectProperties) for (let key of LibraryComponents[item].ObjectProperties) if (!LibraryComponents[item][key]) LibraryComponents[item][key] = {};
}
return LibraryComponents[item] ? LibraryComponents[item] : "div";
}
@@ -7722,8 +7796,9 @@ module.exports = (_ => {
});
}
for (let type of Object.keys(RealMenuItems)) {
let children = BDFDB.ObjectUtils.get(BDFDB.ReactUtils.hookCall(Internal.LibraryComponents.Menu, {hideScroller: true, children: BDFDB.ReactUtils.createElement(RealMenuItems[type], {})}), "props.children.props.children.props.children");
const RealFilteredMenuItems = Object.keys(RealMenuItems).filter(type => typeof RealMenuItems[type] == "function" && RealMenuItems[type].toString().replace(/[\n\t\r]/g, "").endsWith("{return null}"));
for (let type of RealFilteredMenuItems) {
let children = BDFDB.ObjectUtils.get(BDFDB.ReactUtils.hookCall(Internal.LibraryComponents.Menu, {hideScroller: true, children: BDFDB.ReactUtils.createElement(RealMenuItems[type], {})}, true), "props.children.props.children.props.children");
let menuItem = (BDFDB.ArrayUtils.is(children) ? children : []).flat(10).filter(n => n)[0];
if (menuItem) {
let menuItemsProps = BDFDB.ReactUtils.findValue(menuItem, "menuItemProps");
@@ -7745,7 +7820,7 @@ module.exports = (_ => {
}
}
}
LibraryComponents.MenuItems = new Proxy(RealMenuItems, {
LibraryComponents.MenuItems = new Proxy(RealFilteredMenuItems.reduce((a, v) => ({ ...a, [v]: v}), {}) , {
get: function (_, item) {
if (RealMenuItems[item]) return RealMenuItems[item];
if (CustomComponents.MenuItems[item]) return CustomComponents.MenuItems[item];
@@ -7856,7 +7931,7 @@ module.exports = (_ => {
}
if (role) {
if (avatar.type == "img") avatar = BDFDB.ReactUtils.createElement(Internal.LibraryComponents.Avatars.Avatar, Object.assign({}, avatar.props, {
size: Internal.LibraryComponents.Avatars.Sizes.SIZE_40
size: Internal.LibraryComponents.AvatarConstants.Sizes.SIZE_40
}));
delete avatar.props.className;
let newProps = {