More restructuring and changes...

- Added 'time' util module
- Reworked 'string' util modules
- Added deprecate log function
- Renamed many modules function to include an action i.e. 'getX'
- Added Discord 'routes' submodule
- Changed module and submodule log badge colors
- Other stuff
pull/2/head
BakedPVP 4 years ago
parent 149e895b08
commit 9e5c8e58fd

@ -161,7 +161,6 @@
"no-unneeded-ternary": [ "warn" ],
"no-whitespace-before-property": [ "warn" ],
"object-curly-spacing": [ "warn", "always" ],
"object-property-newline": [ "warn" ],
"one-var-declaration-per-line": [ "warn", "initializations" ],
"operator-assignment": [ "warn", "always" ],
"operator-linebreak": [ "warn", "after", {
@ -172,7 +171,7 @@
}],
"padded-blocks": [ "warn", "never" ],
"quote-props": [ "warn", "as-needed" ],
"quotes": [ "warn", "single"/*, { "allowTemplateLiterals": true }*/ ],
"quotes": [ "warn", "single", { "allowTemplateLiterals": true } ],
"semi": [ "warn", "always" ],
"semi-spacing": [ "warn", {
"before": false,

@ -1,7 +1,7 @@
const { Plugin } = require('vizality/entities');
const { inject, uninject } = require('vizality/injector');
const { React, getModule } = require('vizality/webpack');
const { classNames } = require('vizality/util');
const { joinClassNames } = require('vizality/util');
const { Icon } = require('vizality/components');
module.exports = class UtilityClasses extends Plugin {
@ -21,7 +21,7 @@ module.exports = class UtilityClasses extends Plugin {
const { id } = returnValue.props;
returnValue.props.className = classNames(returnValue.props.className, 'vz-hasIcon');
returnValue.props.className = joinClassNames(returnValue.props.className, 'vz-hasIcon');
const type = [
id === 'textarea-context-languages' && 'atom',
@ -74,7 +74,7 @@ module.exports = class UtilityClasses extends Plugin {
const { id } = returnValue.props;
returnValue.props.className = classNames(returnValue.props.className, 'vz-hasIcon');
returnValue.props.className = joinClassNames(returnValue.props.className, 'vz-hasIcon');
const type = [
id === 'textarea-context-spellcheck' && 'atom',
@ -104,7 +104,7 @@ module.exports = class UtilityClasses extends Plugin {
const { id } = returnValue.props;
returnValue.props.className = classNames(returnValue.props.className, 'vz-hasIcon');
returnValue.props.className = joinClassNames(returnValue.props.className, 'vz-hasIcon');
const type = [
id === 'user-context-user-volume' && 'atom'

@ -1,6 +1,6 @@
const { inject, uninject } = require('vizality/injector');
const { React, getModule } = require('vizality/webpack');
const { classNames } = require('vizality/util');
const { joinClassNames } = require('vizality/util');
/*
* Adds server icons to the 'Invite to Server' context submenu.
@ -18,11 +18,11 @@ module.exports = async () => {
const guildIconUrl = GuildStore.getGuild(id).getIconURL();
returnValue.props.className = classNames(returnValue.props.className, { 'vz-hasNoGuildIcon': !guildIconUrl });
returnValue.props.className = joinClassNames(returnValue.props.className, { 'vz-hasNoGuildIcon': !guildIconUrl });
console.log(guildIconUrl);
const guildIcon = React.createElement('div', {
className: classNames('vizality-context-menu-icon-guild-icon', { 'vz-hasNoGuildIcon': !guildIconUrl }),
className: joinClassNames('vizality-context-menu-icon-guild-icon', { 'vz-hasNoGuildIcon': !guildIconUrl }),
style: {
backgroundImage: guildIconUrl ? `url(${guildIconUrl})` : null
}

@ -1,7 +1,7 @@
const { Plugin } = require('vizality/entities');
const { inject, uninject } = require('vizality/injector');
const { React, getModuleByDisplayName } = require('vizality/webpack');
const { classNames } = require('vizality/util');
const { joinClassNames } = require('vizality/util');
const { Tooltip } = require('vizality/components');
module.exports = class MembersActivityIcons extends Plugin {
@ -31,7 +31,7 @@ module.exports = class MembersActivityIcons extends Plugin {
}
));
returnValue.props.className = classNames(returnValue.props.className, 'vz-hasActivityIcon');
returnValue.props.className = joinClassNames(returnValue.props.className, 'vz-hasActivityIcon');
return returnValue;
}
@ -48,7 +48,7 @@ module.exports = class MembersActivityIcons extends Plugin {
}
));
returnValue.props.className = classNames(returnValue.props.className, 'vz-hasActivityIcon');
returnValue.props.className = joinClassNames(returnValue.props.className, 'vz-hasActivityIcon');
return returnValue;
}

@ -1,5 +1,5 @@
const { Flux, React, getModule, getModuleByDisplayName, i18n: { Messages } } = require('vizality/webpack');
const { classNames } = require('vizality/util');
const { joinClassNames } = require('vizality/util');
const { AsyncComponent, Tooltip, HeaderBar, Clickable, Icons } = require('vizality/components');
const ForceUI = require('./ForceUI');
const SplashScreen = require('./SplashScreen');
@ -35,7 +35,7 @@ class SdkWindow extends React.PureComponent {
renderHeaderBar () {
const { title } = getModule([ 'title', 'chatContent' ], false);
return (
<HeaderBar transparent={false} className={classNames(title, 'vizality-sdk-header')}>
<HeaderBar transparent={false} className={joinClassNames(title, 'vizality-sdk-header')}>
{this.renderIcon('Force UI', 'Arch', 'force-ui', 'right')}
{this.renderIcon('Discord Splash Screen', 'Arch', 'splash-screen')}
{this.renderIcon('SDK Settings', 'Gear', 'sdk-settings')}
@ -52,7 +52,7 @@ class SdkWindow extends React.PureComponent {
return (
<Tooltip text={tooltip} position={placement}>
<Clickable
className={classNames(headerBarClasses.iconWrapper, headerBarClasses.clickable)}
className={joinClassNames(headerBarClasses.iconWrapper, headerBarClasses.clickable)}
onClick={async () => {
if (!id) {
// Consider this is the always on top thing

@ -1,7 +1,7 @@
const { React, getModule, getModuleByDisplayName, contextMenu } = require('vizality/webpack');
const { PopoutWindow, Tooltip, ContextMenu, Icons: { CodeBraces } } = require('vizality/components');
const { inject, uninject } = require('vizality/injector');
const { getOwnerInstance, waitFor, classNames } = require('vizality/util');
const { getOwnerInstance, waitFor, joinClassNames } = require('vizality/util');
const { Plugin } = require('vizality/entities');
const SdkWindow = require('./components/SdkWindow');
@ -38,7 +38,7 @@ module.exports = class SDK extends Plugin {
inject('vz-sdk-icon', HeaderBarContainer.prototype, 'renderLoggedIn', (originalArgs, returnValue) => {
if (vizality.api.labs.isExperimentEnabled('vz-sdk') && this.sdkEnabled) {
const Switcher = React.createElement(Tooltip, {
className: classNames(classes.iconWrapper, classes.clickable),
className: joinClassNames(classes.iconWrapper, classes.clickable),
text: 'Vizality SDK',
position: 'bottom'
}, React.createElement(CodeBraces, {

@ -3,7 +3,7 @@ const { Clickable, Button, FormNotice, FormTitle, Tooltip, Icons: { FontAwesome
const { SwitchItem, TextInput, Category, ButtonItem } = require('vizality/components/settings');
const { open: openModal, close: closeModal } = require('vizality/modal');
const { Confirm } = require('vizality/components/modal');
const { classNames} = require('vizality/util');
const { joinClassNames } = require('vizality/util');
const { REPO_URL, CACHE_FOLDER } = require('vizality/constants');
const { clipboard } = require('electron');
const { readdirSync } = require('fs');
@ -339,7 +339,7 @@ module.exports = class UpdaterSettings extends React.PureComponent {
return <FormNotice
type={FormNotice.Types.PRIMARY}
body={<div className={ classNames('vizality-debug-info', { copied: this.state.copied })}>
body={<div className={ joinClassNames('vizality-debug-info', { copied: this.state.copied })}>
<code>
<b>System / Discord</b>
<div className='row'>

@ -1,6 +1,6 @@
const { inject, uninject } = require('vizality/injector');
const { getModule, i18n } = require('vizality/webpack');
const { getOwnerInstance, waitFor, forceUpdateElement, string, classNames } = require('vizality/util');
const { getOwnerInstance, waitFor, forceUpdateElement, string, joinClassNames } = require('vizality/util');
module.exports = async () => {
const channelHeaderButtonClasses = await getModule([ 'iconWrapper', 'toolbar' ]);
@ -20,7 +20,7 @@ module.exports = async () => {
if (key === 'PINNED_MESSAGES') {
if (returnValue.props.children[1]) {
returnValue.props.className = classNames(returnValue.props.className, 'vz-isUnread');
returnValue.props.className = joinClassNames(returnValue.props.className, 'vz-isUnread');
}
}
/*
@ -37,8 +37,8 @@ module.exports = async () => {
* return returnValue;
* }
*/
returnValue.props.className = classNames(returnValue.props.className, `vz-${string.camelCase(key)}Button`);
console.log(string.camelCase(key));
returnValue.props.className = joinClassNames(returnValue.props.className, `vz-${string.toCamelCase(key)}Button`);
console.log(string.toCamelCase(key));
}
}

@ -1,6 +1,6 @@
const { inject, uninject } = require('vizality/injector');
const { getModuleByDisplayName, getModule } = require('vizality/webpack');
const { forceUpdateElement, classNames } = require('vizality/util');
const { forceUpdateElement, joinClassNames } = require('vizality/util');
module.exports = async () => {
const MemberListItem = await getModuleByDisplayName('MemberListItem');
@ -12,7 +12,7 @@ module.exports = async () => {
if (user.id) returnValue.props['vz-user-id'] = user.id;
returnValue.props.className = classNames(
returnValue.props.className = joinClassNames(
returnValue.props.className, {
'vz-isCurrentUser': user.email,
'vz-isBotUser': user.bot,

@ -1,7 +1,7 @@
/* eslint-disable no-unused-expressions */
const { inject, uninject } = require('vizality/injector');
const { getModule } = require('vizality/webpack');
const { getOwnerInstance, waitFor, classNames } = require('vizality/util');
const { getOwnerInstance, waitFor, joinClassNames } = require('vizality/util');
module.exports = async () => {
const { chat } = await getModule([ 'chat' ]);
@ -12,7 +12,7 @@ module.exports = async () => {
const { channel } = this.props;
returnValue.props.className = classNames(
returnValue.props.className = joinClassNames(
returnValue.props.className, {
'vz-isGuildChannel': [ 0, 2, 4, 5, 6 ].includes(channel.type),
'vz-isPrivateChannel': [ 1, 3 ].includes(channel.type),

@ -1,7 +1,7 @@
/* eslint-disable no-unused-vars */
const { inject, uninject } = require('vizality/injector');
const { React, getModule } = require('vizality/webpack');
const { classNames } = require('vizality/util');
const { joinClassNames } = require('vizality/util');
/*
* This module does nothing currently. It is just here for future reference in the event context

@ -1,6 +1,6 @@
const { inject, uninject } = require('vizality/injector');
const { getModuleByDisplayName } = require('vizality/webpack');
const { classNames } = require('vizality/util');
const { joinClassNames } = require('vizality/util');
module.exports = async () => {
const PrivateChannel = await getModuleByDisplayName('PrivateChannel');
@ -16,7 +16,7 @@ module.exports = async () => {
* vz-isUser
*/
props.className = classNames(
props.className = joinClassNames(
props.className, {
'vz-isMuted': props.muted,
'vz-dmChannel': props.name,

@ -1,6 +1,6 @@
const { inject, uninject } = require('vizality/injector');
const { getModule } = require('vizality/webpack');
const { forceUpdateElement, getOwnerInstance, waitFor, classNames } = require('vizality/util');
const { forceUpdateElement, getOwnerInstance, waitFor, joinClassNames } = require('vizality/util');
module.exports = async () => {
/*
@ -21,7 +21,7 @@ module.exports = async () => {
const { props } = returnValue;
props.className = classNames(
props.className = joinClassNames(
props.className, {
'vz-isUnread': props.unread,
'vz-isSelected': props.selected,

@ -1,6 +1,6 @@
const { inject, uninject } = require('vizality/injector');
const { getModule } = require('vizality/webpack');
const { classNames } = require('vizality/util');
const { joinClassNames } = require('vizality/util');
module.exports = async () => {
const GameIcon = await getModule(m => m.default && m.default.displayName === 'GameIcon');
@ -10,7 +10,7 @@ module.exports = async () => {
const { game } = props;
returnValue.props.className = classNames(
returnValue.props.className = joinClassNames(
returnValue.props.className, {
'vz-hasNoGameIcon': game === null
});

@ -1,6 +1,6 @@
const { inject, uninject } = require('vizality/injector');
const { getModule } = require('vizality/webpack');
const { forceUpdateElement, getOwnerInstance, waitFor, classNames } = require('vizality/util');
const { forceUpdateElement, getOwnerInstance, waitFor, joinClassNames } = require('vizality/util');
module.exports = async () => {
const guildClasses = await getModule([ 'blobContainer' ]);
@ -10,7 +10,7 @@ module.exports = async () => {
inject('vz-utility-classes-guild', instance.__proto__, 'render', function (originalArgs, returnValue) {
const { audio, badge: mentions, selected, unread, video, screenshare } = this.props;
returnValue.props.className = classNames(
returnValue.props.className = joinClassNames(
returnValue.props.className, {
'vz-isUnread': unread,
'vz-isSelected': selected,

@ -1,6 +1,6 @@
const { inject, uninject } = require('vizality/injector');
const { getModule, getModuleByDisplayName } = require('vizality/webpack');
const { findInReactTree, classNames, forceUpdateElement } = require('vizality/util');
const { findInReactTree, joinClassNames, forceUpdateElement } = require('vizality/util');
module.exports = async () => {
return () => void 0;
@ -16,9 +16,11 @@ module.exports = async () => {
// const keys = [ 'friends', 'library', 'nitro' ];
// if (keys.includes(test.key)) {
// console.log('hmm');
// }
/*
* if (keys.includes(test.key)) {
* console.log('hmm');
* }
*/
console.log(originalArgs);
console.log(returnValue);
@ -28,14 +30,20 @@ module.exports = async () => {
setImmediate(() => forceUpdateElement('.scroller-2FKFPG'));
// return async () => uninject('vz-improved-navigation-dmChannels');
// const ConnectedPrivateChannelsList = await getModule(m => m.default && m.default.displayName === 'ConnectedPrivateChannelsList');
/*
* return async () => uninject('vz-improved-navigation-dmChannels');
* const ConnectedPrivateChannelsList = await getModule(m => m.default && m.default.displayName === 'ConnectedPrivateChannelsList');
*/
// inject('vz-improved-navigation-dmChannels', ConnectedPrivateChannelsList, 'default', (originalArgs, returnValue) => {
// console.log(returnValue);
/*
* inject('vz-improved-navigation-dmChannels', ConnectedPrivateChannelsList, 'default', (originalArgs, returnValue) => {
* console.log(returnValue);
*/
// return returnValue;
// });
/*
* return returnValue;
* });
*/
return async () => uninject('vz-improved-navigation-dmChannels');
};

@ -1,6 +1,6 @@
const { inject, uninject } = require('vizality/injector');
const { getModule } = require('vizality/webpack');
const { findInReactTree, classNames } = require('vizality/util');
const { findInReactTree, joinClassNames } = require('vizality/util');
module.exports = async () => {
const Message = await getModule(m => m.default && m.default.displayName === 'Message');
@ -13,7 +13,7 @@ module.exports = async () => {
if (!msg) {
if (findInReactTree(returnValue, n => n.className && !n.className.startsWith('blockedSystemMessage'))) {
returnValue.props.className = classNames(returnValue.props.className, 'vz-isBlockedMessage');
returnValue.props.className = joinClassNames(returnValue.props.className, 'vz-isBlockedMessage');
}
return returnValue;
}
@ -23,7 +23,7 @@ module.exports = async () => {
returnValue.props['vz-message-type'] = message.type;
returnValue.props['vz-author-id'] = message.author.id;
returnValue.props.className = classNames(
returnValue.props.className = joinClassNames(
returnValue.props.className, {
'vz-isBotUser': message.author.bot,
'vz-isCurrentUser': (message.author.id === currentUserId && message.type === 0),

@ -1,6 +1,6 @@
const { inject, uninject } = require('vizality/injector');
const { getModule } = require('vizality/webpack');
const { classNames } = require('vizality/util');
const { joinClassNames } = require('vizality/util');
module.exports = async () => {
const CallTile = await getModule(m => m.default && m.default.displayName === 'CallTile');
@ -13,7 +13,7 @@ module.exports = async () => {
returnValue.props['vz-user-id'] = participant.id;
returnValue.props['vz-user-name'] = participant.user.username;
returnValue.props.className = classNames(
returnValue.props.className = joinClassNames(
returnValue.props.className, {
'vz-isSpeaking': participant.speaking,
'vz-isRinging': participant.ringing,

@ -1,6 +1,6 @@
const { inject, uninject } = require('vizality/injector');
const { getModule } = require('vizality/webpack');
const { getOwnerInstance, waitFor, classNames } = require('vizality/util');
const { getOwnerInstance, waitFor, joinClassNames } = require('vizality/util');
module.exports = async () => {
const { role } = await getModule([ 'role', 'roleCircle', 'roleName', 'root' ]);
@ -15,7 +15,7 @@ module.exports = async () => {
returnValue.props['vz-role-name'] = role.name;
returnValue.props['vz-role-color-string'] = role.colorString;
returnValue.props.className = classNames(
returnValue.props.className = joinClassNames(
returnValue.props.className, {
'vz-isHoisted': role.hoist,
'vz-isMentionable': role.mentionable

@ -1,6 +1,6 @@
const { inject, uninject } = require('vizality/injector');
const { getModuleByDisplayName } = require('vizality/webpack');
const { string, classNames } = require('vizality/util');
const { string, joinClassNames } = require('vizality/util');
/*
* Modifies The TabBar component, which is used in various places throughout
@ -18,7 +18,7 @@ module.exports = async () => {
* We check if the item starts with vz- particularly for settings sidebar items
* for core plugins.
*/
const selected = string.camelCase(this.props.selectedItem.startsWith('vz-') ? this.props.selectedItem.replace('vz-', '') : this.props.selectedItem);
const selected = string.toCamelCase(this.props.selectedItem.startsWith('vz-') ? this.props.selectedItem.replace('vz-', '') : this.props.selectedItem);
returnValue.props['vz-item-selected'] = `vz-${selected}Item`;
@ -27,9 +27,9 @@ module.exports = async () => {
for (const item of tabBarItems) {
if (!item || !item.props || !item.props.id) continue;
const itemFormatted = string.camelCase(item.props.id.startsWith('vz-') ? item.props.id.replace('vz-', '') : item.props.id);
const itemFormatted = string.toCamelCase(item.props.id.startsWith('vz-') ? item.props.id.replace('vz-', '') : item.props.id);
item.props.className = classNames(item.props.className, `vz-${itemFormatted}Item`);
item.props.className = joinClassNames(item.props.className, `vz-${itemFormatted}Item`);
}
return returnValue;

@ -1,8 +1,8 @@
const { React } = require('vizality/webpack');
const { classNames } = require('vizality/util');
const { joinClassNames } = require('vizality/util');
module.exports = React.memo(({ type, wrapperClassName, className, ...props }) =>
<div className={classNames('vizality-icon-wrapper', wrapperClassName)}>
<icon className={classNames('vizality-icon', type, className)} {...props}></icon>
<div className={joinClassNames('vizality-icon-wrapper', wrapperClassName)}>
<icon className={joinClassNames('vizality-icon', type, className)} {...props}></icon>
</div>
);

@ -0,0 +1,18 @@
const { getModule } = require('vizality/webpack');
const _getRoutes = () => {
const DISCORD_ROUTES = getModule([ 'Routes' ], false).Routes;
const ROUTES = {
discover: DISCORD_ROUTES.GUILD_DISCOVERY,
// channel: '//channels/[0-9]+/.*/',
dm: '/channels/@me/',
friends: DISCORD_ROUTES.FRIENDS,
guild: '/channels/',
library: DISCORD_ROUTES.APPLICATION_LIBRARY,
nitro: DISCORD_ROUTES.APPLICATION_STORE
};
return ROUTES;
};
module.exports = _getRoutes;

@ -0,0 +1,28 @@
const { logger: { log, warn } } = require('vizality/util');
/* const currentWebContents = require('electron').remote.getCurrentWebContents(); */
const _getRoutes = require('./_getRoutes');
const getCurrentRoute = () => {
const MODULE = 'Module';
const SUBMODULE = 'Discord:routes:getCurrentRoute';
const routes = _getRoutes();
/* const historyRoute = currentWebContents.history[currentWebContents.history.length - 2]; */
for (const location in routes) {
if (window.location.href.includes(routes[location])) {
let locationStr = window.location.href.split('/');
locationStr = `/${locationStr[3]}/${locationStr[4]}/`;
/*
* if (location === 'guild' && historyRoute.includes(locationStr)) {
* location = 'channel';
* }
*/
return log(MODULE, SUBMODULE, null, `The current route is '${location}'.`);
}
}
return warn(MODULE, SUBMODULE, null, `The current route is unknown.`);
};
module.exports = getCurrentRoute;

@ -0,0 +1,15 @@
const { logger: { log } } = require('vizality/util');
const _getRoutes = require('./_getRoutes');
const getRoutes = () => {
const MODULE = 'Module';
const SUBMODULE = 'Discord:routes:getRoutes';
const routeList = Object.keys(_getRoutes().filter(r => r !== 'guild'));
log(MODULE, SUBMODULE, null, `List of available routes to be used with 'Discord.routes.goTo':`);
return console.log(routeList);
};
module.exports = getRoutes;

@ -0,0 +1,48 @@
const { getModule } = require('vizality/webpack');
const { logger: { warn } } = require('vizality/util');
const _getRoutes = require('./_getRoutes');
const goTo = (location) => {
const MODULE = 'Module';
const SUBMODULE = 'Discord:routes:goTo';
const routeList = Object.keys(_getRoutes().filter(r => r !== 'guild'));
if (!location) {
warn(MODULE, SUBMODULE, null, `You must enter a valid route string. List of available routes:`);
return console.warn(routeList);
}
const DISCORD_ROUTES = getModule([ 'Routes' ], false).Routes;
if (Object.keys(DISCORD_ROUTES).includes(location)) {
return getModule([ 'transitionTo' ], false).transitionTo(DISCORD_ROUTES[location]);
}
if (Object.values(DISCORD_ROUTES).includes(location)) {
return getModule([ 'transitionTo' ], false).transitionTo(location);
}
location = location.toLowerCase();
switch (location) {
case 'discover':
return getModule([ 'transitionTo' ], false).transitionTo(DISCORD_ROUTES.GUILD_DISCOVERY);
case 'dm':
return getModule([ 'transitionTo' ], false).transitionTo(
DISCORD_ROUTES.CHANNEL('@me', getModule([ 'getPrivateChannelIds' ], false).getPrivateChannelIds()[0])
);
case 'friends':
return getModule([ 'transitionTo' ], false).transitionTo(DISCORD_ROUTES.FRIENDS);
case 'library':
return getModule([ 'transitionTo' ], false).transitionTo(DISCORD_ROUTES.APPLICATION_LIBRARY);
case 'nitro':
return getModule([ 'transitionTo' ], false).transitionTo(DISCORD_ROUTES.APPLICATION_STORE);
default:
warn(MODULE, SUBMODULE, null, `The route '${location}' was not found. List of available routes:`);
return console.warn(routeList);
}
};
module.exports = goTo;

@ -0,0 +1,7 @@
require('fs')
.readdirSync(__dirname)
.filter(file => file !== 'index.js')
.forEach(filename => {
const moduleName = filename.split('.')[0];
exports[moduleName] = require(`${__dirname}/${filename}`);
});

@ -0,0 +1,11 @@
const { getModule } = require('vizality/webpack');
const _getSections = () => {
const DISCORD_SECTIONS = Object.values(getModule([ 'UserSettingsSections' ], false).UserSettingsSections);
const VIZALITY_SECTIONS = Object.keys(vizality.api.settings.tabs);
const ALL_SECTIONS = DISCORD_SECTIONS.concat(VIZALITY_SECTIONS);
return ALL_SECTIONS;
};
module.exports = _getSections;

@ -2,7 +2,8 @@ const { logger: { log, warn } } = require('vizality/util');
module.exports = function info (setting) {
const MODULE = 'Module';
const SUBMODULE = 'Discord:settings:info';
const SUBMODULE = 'Discord:settings:getInfo';
const SETTINGS_INFO = {
afkTimeout: [
'The number of seconds Discord will wait for activity before sending mobile push notifications.',
@ -117,10 +118,8 @@ module.exports = function info (setting) {
SETTINGS_INFO.showSpoilers = SETTINGS_INFO.renderSpoilers;
if (!setting) {
return log(MODULE, SUBMODULE, null,
`You may find out more info about user settings with settings.info(key),
where key is a settings string. You can find out more about valid settings strings from settings.get()`
);
log(MODULE, SUBMODULE, null, 'List of available settings:');
return console.log(Object.keys(SETTINGS_INFO));
}
for (const info of Object.keys(SETTINGS_INFO)) {

@ -0,0 +1,13 @@
const { logger: { log } } = require('vizality/util');
const _getSections = require('./_getSections');
const getSections = () => {
const MODULE = 'Module';
const SUBMODULE = 'Discord:settings:getSections';
log(MODULE, SUBMODULE, null, 'List of available user settings sections:');
return _getSections();
};
module.exports = getSections;

@ -1,14 +1,17 @@
const { getModule } = require('vizality/webpack');
const { logger: { warn } } = require('vizality/util');
const sections = require('./sections');
const _getSections = require('./_getSections');
module.exports = (section = 'My Account') => {
const MODULE = 'Module';
const SUBMODULE = 'Discord:settings:open';
const sections = _getSections();
if (!sections.includes(section)) {
return warn(MODULE, SUBMODULE, null, `Section '${section}' not found. Please check 'settings.section' for a list of available sections.`);
warn(MODULE, SUBMODULE, null, `Section '${section}' not found. List of available user settings sections:`);
return console.warn(sections);
}
return getModule([ 'open', 'updateAccount' ], false).open(

@ -1,18 +0,0 @@
const { getModule } = require('vizality/webpack');
const discordSections = {
...Object.values(getModule([ 'UserSettingsSections' ], false).UserSettingsSections)
};
const vizalitySections = {
...Object.keys(vizality.api.settings.tabs)
};
const sectionsObject = {
...vizalitySections,
...discordSections
};
const sections = Object.values(sectionsObject);
module.exports = sections;

@ -24,22 +24,6 @@ class Plugin extends Updatable {
return this.entityID.startsWith('vz-');
}
get colorContrast () {
if (this.manifest.color) {
const r = `0x${this.manifest.color[1]}${this.manifest.color[2]}`;
const g = `0x${this.manifest.color[3]}${this.manifest.color[4]}`;
const b = `0x${this.manifest.color[5]}${this.manifest.color[6]}`;
if ((r * 0.299) + (g * 0.587) + (b * 0.114) > 186) {
return '#000';
}
return '#fff';
}
return '#fff';
}
get dependencies () {
return this.manifest.dependencies;
}

@ -29,6 +29,9 @@ class HTTPError extends Error {
class GenericRequest {
constructor (method, uri) {
this.MODULE = 'HTTP';
this.SUBMODULE = this.constructor.name;
this.opts = {
method,
uri,
@ -94,7 +97,7 @@ class GenericRequest {
execute () {
return new Promise((resolve, reject) => {
const opts = Object.assign({}, this.opts);
this.log('Performing request to', opts.uri);
this.log(`Performing request to ${opts.uri}.`);
const { request } = opts.uri.startsWith('https')
? https
: http;
@ -180,15 +183,15 @@ class GenericRequest {
}
log (...data) {
logger.log('HTTP', this.constructor.name, null, ...data);
logger.log(this.MODULE, this.SUBMODULE, null, ...data);
}
error (...data) {
logger.log('HTTP', this.constructor.name, null, ...data);
logger.error(this.MODULE, this.SUBMODULE, null, ...data);
}
warn (...data) {
logger.log('HTTP', this.constructor.name, null, ...data);
logger.warn(this.MODULE, this.SUBMODULE, null, ...data);
}
}

@ -1,6 +1,9 @@
const { logger } = require('vizality/util');
const { randomBytes } = require('crypto');
const injector = {
MODULE: 'Module',
SUBMODULE: 'Injector',
injections: [],
/**
@ -13,11 +16,11 @@ const injector = {
*/
inject: (injectionId, moduleToPatch, functionName, patch, pre = false) => {
if (!moduleToPatch) {
return injector._error(`Tried to patch undefined (Injection ID "${injectionId}")`);
return injector._error(`Tried to patch undefined (Injection ID '${injectionId}').`);
}
if (injector.injections.find(i => i.id === injectionId)) {
return injector._error(`Injection ID "${injectionId}" is already used!`);
return injector._error(`Injection ID '${injectionId}' is already used!`);
}
if (!moduleToPatch.__vizalityInjectionId || !moduleToPatch.__vizalityInjectionId[functionName]) {
@ -96,14 +99,14 @@ const injector = {
try {
finalReturn = i.method.call(_this, originalArgs, finalReturn);
} catch (e) {
injector._error(`Failed to run injection "${i.id}"`, e);
injector._error(`Failed to run injection '${i.id}'.`, e);
}
});
return finalReturn;
},
_error: (...args) => {
console.error('%c[Vizality:Injector]', 'color: #7289da', ...args);
logger.error(injector.MODULE, injector.SUBMODULE, null, ...args);
}
};

@ -1,8 +1,15 @@
/* eslint-disable no-unused-vars */
const { getModule } = require('vizality/webpack');
const { logger } = require('vizality/util');
const currentWebContents = require('electron').remote.getCurrentWebContents();
module.exports = {
routes: {
const navigate = () => {
const MODULE = 'Navigate';
const SUBMODULE = 'Route:goTo';
const ROUTES = {
discover: getModule([ 'Routes' ], false).Routes.GUILD_DISCOVERY,
// channel: '//channels/[0-9]+/.*/',
dm: '/channels/@me/',
@ -10,9 +17,9 @@ module.exports = {
guild: '/channels/',
library: getModule([ 'Routes' ], false).Routes.APPLICATION_LIBRARY,
nitro: getModule([ 'Routes' ], false).Routes.APPLICATION_STORE
},
};
to: async (location) => {
async function goTo (location) {
if (location === 'discover') return (await getModule([ 'transitionTo' ])).transitionTo((await getModule([ 'Routes' ])).Routes.GUILD_DISCOVERY);
if (location === 'dm') {
return (await getModule([ 'transitionTo' ])).transitionTo(
@ -23,14 +30,13 @@ module.exports = {
if (location === 'library') return (await getModule([ 'transitionTo' ])).transitionTo((await getModule([ 'Routes' ])).Routes.APPLICATION_LIBRARY);
if (location === 'nitro') return (await getModule([ 'transitionTo' ])).transitionTo((await getModule([ 'Routes' ])).Routes.APPLICATION_STORE);
console.warn(`${location} not found.`);
},
return logger.warn(MODULE, SUBMODULE, null, `The route '${location}' was not found.`);
}
get currentRoute () {
const { routes } = this;
function currentRoute () {
const historyRoute = currentWebContents.history[currentWebContents.history.length - 2];
for (let location in routes) {
if (window.location.href.includes(routes[location])) {
for (let location in ROUTES) {
if (window.location.href.includes(ROUTES[location])) {
let locationStr = window.location.href.split('/');
locationStr = `/${locationStr[3]}/${locationStr[4]}/`;
@ -43,3 +49,5 @@ module.exports = {
return 'unknown';
}
};
module.exports = navigate;

@ -3,13 +3,20 @@
* @powercord: This function/module is only here to provide
* backwards-compatability with Powercord plugins that may utilize it.
*
* Plugins should be using `string.camelCase` instead.
* Plugins should be using `Util.string.toCamelCase` instead.
*/
const { string } = require('vizality/util');
const string = require('./string');
const logger = require('./logger');
module.exports = (str) => {
string.camelCase(str);
console.warn('camelCaseify is depcrated in Vizality. We recommend you use `string.camelCase` instead.');
const camelCaseify = (str) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:camelCaseify';
const REPLACEMENT_SUBMODULE = 'Util:string:toCamelCase';
logger.deprecate(MODULE, SUBMODULE, REPLACEMENT_SUBMODULE);
return string.toCamelCase(str);
};
module.exports = camelCaseify;

@ -1,17 +1,19 @@
const { log, warn } = require('./logger');
const logger = require('./logger');
module.exports = (...cases) => {
const checkPerformance = (...cases) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:checkPerformance';
if (cases.length < 2) {
return warn(MODULE, SUBMODULE, null, 'You must enter at least 2 code segments in the form of strings separated by a comma, which shall then be matched against each other in a race of performance.');
if (cases.length < 1) {
return logger.warn(MODULE, SUBMODULE, null, 'You must enter at least 1 code segment in the form of a string.');
}
const outcome = {};
let caseNumber = 0;
for (const testCase of cases) {
const caseNumber = cases.indexOf(testCase) + 1;
caseNumber++;
const before = performance.now();
eval(testCase);
@ -19,11 +21,14 @@ module.exports = (...cases) => {
const time = parseFloat((after - before).toFixed(4)).toString().replace(/^0+/, '');
log(MODULE, SUBMODULE, null, `Case #${caseNumber} took ${time} ms.`);
logger.log(MODULE, SUBMODULE, null, `Case #${caseNumber} took ${time} ms.`);
outcome[caseNumber] = time;
}
// No need to do the following if there's only 1 argument
if (cases.length === 1) return;
const winner = Object.entries(outcome).sort((current, next) => current[1] - next[1])[0];
const secondPlace = Object.entries(outcome).sort((current, next) => current[1] - next[1])[1];
const winningTime = winner[1];
@ -33,5 +38,7 @@ module.exports = (...cases) => {
const percentPerformanceGain = parseFloat(((timeDifference / winningTime) * 100).toFixed(2));
return log(MODULE, SUBMODULE, null, `Case #${winner[0]} is the winner with a time of ${winningTime} ms. That's ${percentPerformanceGain}% faster than second place!`);
return logger.log(MODULE, SUBMODULE, null, `Case #${winner[0]} is the winner with a time of ${winningTime} ms. That's ${percentPerformanceGain}% faster than second place!`);
};
module.exports = checkPerformance;

@ -1,11 +0,0 @@
/**
* @hack: Figure out why const { getModule } = require('vizality/webpack') doesn't work.
*/
let classNames;
module.exports = (...args) => {
if (!classNames) {
classNames = require('vizality/webpack').getModule(e => e.default && e.default.default, false);
}
return classNames(...args);
};

@ -1,4 +1,4 @@
module.exports = (color) => {
const _hex2hsl = (color) => {
// Convert hex to RGB first
let r, g, b;
@ -42,3 +42,5 @@ module.exports = (color) => {
return `hsl(${h} ${s}% ${l}%)`;
};
module.exports = _hex2hsl;

@ -1,7 +1,9 @@
module.exports = (color) => {
const _hex2int = (color) => {
if (color.length === 4) {
color = `#${color[1]}${color[1]}${color[2]}${color[2]}${color[3]}${color[3]}`;
}
return parseInt(color.slice(1), 16);
};
module.exports = _hex2int;

@ -1,4 +1,4 @@
module.exports = (color) => {
const _hex2rgb = (color) => {
let r, g, b;
// 3 digits
@ -16,3 +16,5 @@ module.exports = (color) => {
return `rgb(${+r} ${+g} ${+b})`;
};
module.exports = _hex2rgb;

@ -1,6 +1,8 @@
/* eslint-disable prefer-const */
module.exports = (color) => {
const _hex2hsl = require('./_hex2hsl');
const _hsl2hex = (color) => {
const ex = /^hsl\(((((([12]?[1-9]?\d)|[12]0\d|(3[0-5]\d))(\.\d+)?)|(\.\d+))(deg)?|(0|0?\.\d+)turn|(([0-6](\.\d+)?)|(\.\d+))rad)((,\s?(([1-9]?\d(\.\d+)?)|100|(\.\d+))%){2}|(\s(([1-9]?\d(\.\d+)?)|100|(\.\d+))%){2})\)$/i;
if (ex.test(color)) {
@ -75,3 +77,5 @@ module.exports = (color) => {
return `#${r}${g}${b}`;
}
};
module.exports = _hsl2hex;

@ -1,4 +1,4 @@
module.exports = (color) => {
const _hsl2int = (color) => {
const ex = /^hsl\(((((([12]?[1-9]?\d)|[12]0\d|(3[0-5]\d))(\.\d+)?)|(\.\d+))(deg)?|(0|0?\.\d+)turn|(([0-6](\.\d+)?)|(\.\d+))rad)((,\s?(([1-9]?\d(\.\d+)?)|100|(\.\d+))%){2}|(\s(([1-9]?\d(\.\d+)?)|100|(\.\d+))%){2})\)$/i;
if (ex.test(color)) {
@ -6,8 +6,8 @@ module.exports = (color) => {
color = color.substr(4).split(')')[0].split(sep);
let h = color[0];
let s = color[1].substr(0, color[1].length - 1) / 100;
let l = color[2].substr(0, color[2].length - 1) / 100;
const s = color[1].substr(0, color[1].length - 1) / 100;
const l = color[2].substr(0, color[2].length - 1) / 100;
// strip label and convert to degrees (if necessary)
if (h.indexOf('deg') > -1) {
@ -61,3 +61,5 @@ module.exports = (color) => {
return (r << 16) + (g << 16) + b;
}
};
module.exports = _hsl2int;

@ -1,6 +1,6 @@
/* eslint-disable prefer-const */
module.exports = (color) => {
const _hsl2rgb = (color) => {
const ex = /^hsl\(((((([12]?[1-9]?\d)|[12]0\d|(3[0-5]\d))(\.\d+)?)|(\.\d+))(deg)?|(0|0?\.\d+)turn|(([0-6](\.\d+)?)|(\.\d+))rad)((,\s?(([1-9]?\d(\.\d+)?)|100|(\.\d+))%){2}|(\s(([1-9]?\d(\.\d+)?)|100|(\.\d+))%){2})\)$/i;
if (ex.test(color)) {
@ -63,3 +63,5 @@ module.exports = (color) => {
return `rgb(${+r} ${+g} ${+b})`;
}
};
module.exports = _hsl2rgb;

@ -0,0 +1,5 @@
const _int2hex = (color) => {
return `#${((color) >>> 0).toString(16)}`;
};
module.exports = _int2hex;

@ -1,4 +1,4 @@
module.exports = (color) => {
const _int2hsl = (color) => {
// Convert int to hex first
const hex = `#${((color) >>> 0).toString(16)}`;
@ -34,3 +34,5 @@ module.exports = (color) => {
return `hsl(${h} ${s}% ${l}%)`;
};
module.exports = _int2hsl;

@ -1,3 +1,5 @@
module.exports = (color) => {
const _int2rgb = (color) => {
return `rgb(${(color >> 16 & 255)} ${(color >> 8 & 255)} ${(255 & color)})`;
};
module.exports = _int2rgb;

@ -1,4 +1,4 @@
module.exports = (color) => {
const _rgb2hex = (color) => {
const ex = /^rgb\((((((((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5]),\s?)){2}|((((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5])\s)){2})((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5]))|((((([1-9]?\d(\.\d+)?)|100|(\.\d+))%,\s?){2}|((([1-9]?\d(\.\d+)?)|100|(\.\d+))%\s){2})(([1-9]?\d(\.\d+)?)|100|(\.\d+))%))\)$/i;
if (ex.test(color)) {
@ -31,3 +31,5 @@ module.exports = (color) => {
return `#${r}${g}${b}`;
}
};
module.exports = _rgb2hex;

@ -1,4 +1,4 @@
module.exports = (color) => {
const _rgb2hsl = (color) => {
const ex = /^rgb\((((((((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5]),\s?)){2}|((((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5])\s)){2})((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5]))|((((([1-9]?\d(\.\d+)?)|100|(\.\d+))%,\s?){2}|((([1-9]?\d(\.\d+)?)|100|(\.\d+))%\s){2})(([1-9]?\d(\.\d+)?)|100|(\.\d+))%))\)$/i;
if (ex.test(color)) {
@ -56,3 +56,5 @@ module.exports = (color) => {
return `hsl(${h} ${s}% ${l}%)`;
}
};
module.exports = _rgb2hsl;

@ -1,4 +1,4 @@
module.exports = (color) => {
const _rgb2int = (color) => {
const ex = /^rgb\((((((((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5]),\s?)){2}|((((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5])\s)){2})((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5]))|((((([1-9]?\d(\.\d+)?)|100|(\.\d+))%,\s?){2}|((([1-9]?\d(\.\d+)?)|100|(\.\d+))%\s){2})(([1-9]?\d(\.\d+)?)|100|(\.\d+))%))\)$/i;
if (ex.test(color)) {
@ -27,3 +27,5 @@ module.exports = (color) => {
return (r << 16) + (g << 16) + b;
}
};
module.exports = _rgb2int;

@ -1,45 +0,0 @@
const rgb2hex = require('./rgb2hex');
const hsl2hex = require('./hsl2hex');
const int2hex = require('./int2hex');
module.exports = (color) => {
const ex = {
hex: /^#([\da-f]{3}){1,2}$/i,
rgb: /^rgb\((((((((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5]),\s?)){2}|((((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5])\s)){2})((1?[1-9]?\d)|10\d|(2[0-4]\d)|25[0-5]))|((((([1-9]?\d(\.\d+)?)|100|(\.\d+))%,\s?){2}|((([1-9]?\d(\.\d+)?)|100|(\.\d+))%\s){2})(([1-9]?\d(\.\d+)?)|100|(\.\d+))%))\)$/i,
hsl: /^hsl\(((((([12]?[1-9]?\d)|[12]0\d|(3[0-5]\d))(\.\d+)?)|(\.\d+))(deg)?|(0|0?\.\d+)turn|(([0-6](\.\d+)?)|(\.\d+))rad)((,\s?(([1-9]?\d(\.\d+)?)|100|(\.\d+))%){2}|(\s(([1-9]?\d(\.\d+)?)|100|(\.\d+))%){2})\)$/i
};
let r, g, b;
function _hex (arg) {
if (arg.length === 4) {
r = `0x${arg[1]}${arg[1]}`;
g = `0x${arg[2]}${arg[2]}`;
b = `0x${arg[3]}${arg[3]}`;
// 6 digits
} else if (arg.length === 7) {
r = `0x${arg[1]}${arg[2]}`;
g = `0x${arg[3]}${arg[4]}`;
b = `0x${arg[5]}${arg[6]}`;
}
}
if (ex.rgb.test(color)) {
_hex(rgb2hex(color));
} else if (ex.hex.test(color)) {
_hex(color);
} else if (ex.hsl.test(color)) {
_hex(hsl2hex(color));
} else if (Number.isInteger(color)) {
_hex(int2hex(color));
} else {
throw new Error('Invalid color type entered.');
}
if ((r * 0.299) + (g * 0.587) + (b * 0.114) > 186) return '#000';
return '#fff';
};

@ -0,0 +1,26 @@
const toHex = require('./toHex');
const getContrast = (color) => {
let r, g, b;
function _hex (arg) {
if (arg.length === 4) {
r = `0x${arg[1]}${arg[1]}`;
g = `0x${arg[2]}${arg[2]}`;
b = `0x${arg[3]}${arg[3]}`;
// 6 digits
} else if (arg.length === 7) {
r = `0x${arg[1]}${arg[2]}`;
g = `0x${arg[3]}${arg[4]}`;
b = `0x${arg[5]}${arg[6]}`;
}
}
_hex(toHex(color));
if ((r * 0.299) + (g * 0.587) + (b * 0.114) > 186) return '#000';
return '#fff';
};
module.exports = getContrast;

@ -0,0 +1,33 @@
const logger = require('../logger');
const _int2hex = require('./_int2hex');
const _rgb2hex = require('./_rgb2hex');
const _hsl2hex = require('./_hsl2hex');
const getRandom = (type) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:color:getRandom';
if (!type) type = 'hex';
String(type);
const base = '000000';
const number = Math.floor(Math.random() * 16777215).toString(16);
const color = `#${(base + number).substr(-6)}`;
switch (type) {
case 'hex':
return color;
case 'rgb':
return _rgb2hex(color);
case 'hsl':
return _hsl2hex(color);
case 'int':
return _int2hex(color);
default:
return logger.warn(MODULE, SUBMODULE, null, `Input type '${type}' is not a valid color type. Please choose 'hex', 'rgb', 'hsl', or 'int'.`);
}
};
module.exports = getRandom;

@ -1,4 +1,9 @@
module.exports = (color) => {
const logger = require('../logger');
const getType = (color) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:color:getType';
const ex = {
hex: /^#([\da-f]{3}){1,2}$/i,
@ -13,10 +18,11 @@ module.exports = (color) => {
return 'hex';
} else if (ex.hsl.test(color)) {
return 'hsl';
} else if (Number.isInteger(color)) {
} else if (Number.isInteger(parseInt(color))) {
return 'int';
}
console.error('Unknown color type entered.');
return null;
return logger.warn(MODULE, SUBMODULE, null, `Input color '${color}' is not a recognized color type.`);
};
module.exports = getType;

@ -1,26 +0,0 @@
const logger = require('../logger');
const int2hex = require('./int2hex');
const rgb2hex = require('./rgb2hex');
const hsl2hex = require('./hsl2hex');
const type = require('./type');
/**
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
*/
module.exports = (color) => {
const colorType = type(color);
switch (colorType) {
case 'hex':
return color;
case 'rgb':
return rgb2hex(color);
case 'hsl':
return hsl2hex(color);
case 'int':
return int2hex(color);
default:
logger.warn('Module', 'Util:color:hex', null, `Input color '${color}' is not a recognized color type.`);
}
};

@ -1,26 +0,0 @@
const logger = require('../logger');
const int2hsl = require('./int2hsl');
const hex2hsl = require('./hex2hsl');
const rgb2hsl = require('./rgb2hsl');
const type = require('./type');
/**
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
*/
module.exports = (color) => {
const colorType = type(color);
switch (colorType) {
case 'hsl':
return color;
case 'hex':
return hex2hsl(color);
case 'rgb':
return rgb2hsl(color);
case 'int':
return int2hsl(color);
default:
logger.warn('Module', 'Util:color:hsl', null, `Input color '${color}' is not a recognized color type.`);
}
};

@ -1,26 +0,0 @@
const logger = require('../logger');
const hex2int = require('./hex2int');
const rgb2int = require('./rgb2int');
const hsl2int = require('./hsl2int');
const type = require('./type');
/**
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
*/
module.exports = (color) => {
const colorType = type(color);
switch (colorType) {
case 'int':
return color;
case 'hex':
return hex2int(color);
case 'rgb':
return rgb2int(color);
case 'hsl':
return hsl2int(color);
default:
logger.warn('Module', 'Util:color:hsl', null, `Input color '${color}' is not a recognized color type.`);
}
};

@ -1,3 +0,0 @@
module.exports = (color) => {
return `#${((color) >>> 0).toString(16)}`;
};

@ -1,5 +0,0 @@
module.exports = () => {
const base = '000000';
const number = Math.floor(Math.random() * 16777215).toString(16);
return `#${(base + number).substr(-6)}`;
};

@ -1,26 +0,0 @@
const logger = require('../logger');
const int2rgb = require('./int2rgb');
const hex2rgb = require('./hex2rgb');
const hsl2rgb = require('./hsl2rgb');
const type = require('./type');
/**
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
*/
module.exports = (color) => {
const colorType = type(color);
switch (colorType) {
case 'rgb':
return color;
case 'hex':
return hex2rgb(color);
case 'hsl':
return hsl2rgb(color);
case 'int':
return int2rgb(color);
default:
logger.warn('Module', 'Util:color:hsl', null, `Input color '${color}' is not a recognized color type.`);
}
};

@ -0,0 +1,31 @@
const logger = require('../logger');
const _int2hex = require('./_int2hex');
const _rgb2hex = require('./_rgb2hex');
const _hsl2hex = require('./_hsl2hex');
const getType = require('./getType');
/**
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
*/
const toHex = (color) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:color:toHex';
const colorType = getType(color);
switch (colorType) {
case 'hex':
return color;
case 'rgb':
return _rgb2hex(color);
case 'hsl':
return _hsl2hex(color);
case 'int':
return _int2hex(color);
default:
return logger.warn(MODULE, SUBMODULE, null, `Input color '${color}' is not a recognized color type.`);
}
};
module.exports = toHex;

@ -0,0 +1,31 @@
const logger = require('../logger');
const _int2hsl = require('./_int2hsl');
const _hex2hsl = require('./_hex2hsl');
const _rgb2hsl = require('./_rgb2hsl');
const getType = require('./getType');
/**
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
*/
const toHsl = (color) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:color:toHsl';
const colorType = getType(color);
switch (colorType) {
case 'hsl':
return color;
case 'hex':
return _hex2hsl(color);
case 'rgb':
return _rgb2hsl(color);
case 'int':
return _int2hsl(color);
default:
return logger.warn(MODULE, SUBMODULE, null, `Input color '${color}' is not a recognized color type.`);
}
};
module.exports = toHsl;

@ -0,0 +1,31 @@
const logger = require('../logger');
const _hex2int = require('./_hex2int');
const _rgb2int = require('./_rgb2int');
const _hsl2int = require('./_hsl2int');
const getType = require('./getType');
/**
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
*/
const toInt = (color) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:color:toInt';
const colorType = getType(color);
switch (colorType) {
case 'int':
return color;
case 'hex':
return _hex2int(color);
case 'rgb':
return _rgb2int(color);
case 'hsl':
return _hsl2int(color);
default:
return logger.warn(MODULE, SUBMODULE, null, `Input color '${color}' is not a recognized color type.`);
}
};
module.exports = toInt;

@ -0,0 +1,31 @@
const logger = require('../logger');
const _int2rgb = require('./_int2rgb');
const _hex2rgb = require('./_hex2rgb');
const _hsl2rgb = require('./_hsl2rgb');
const getType = require('./getType');
/**
* @todo: Make this work with 8-digit hex numbers, rgba, and hsla.
*/
const toRgb = (color) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:color:toRgb';
const colorType = getType(color);
switch (colorType) {
case 'rgb':
return color;
case 'hex':
return _hex2rgb(color);
case 'hsl':
return _hsl2rgb(color);
case 'int':
return _int2rgb(color);
default:
return logger.warn(MODULE, SUBMODULE, null, `Input color '${color}' is not a recognized color type.`);
}
};
module.exports = toRgb;

@ -3,11 +3,18 @@
* @powercord: This function/module is only here to provide
* backwards-compatability with Powercord plugins that may utilize it.
*
* Plugins should be using `dom.createElement` instead.
* Plugins should be using `Util.dom.createElement` instead.
*/
const logger = require('./logger');
const createElement = (name, props) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:createElement';
const REPLACEMENT_SUBMODULE = 'Util:dom:createElement';
logger.deprecate(MODULE, SUBMODULE, REPLACEMENT_SUBMODULE);
module.exports = (name, props) => {
const element = document.createElement(name);
for (const prop in props) {
@ -23,3 +30,5 @@ module.exports = (name, props) => {
return element;
};
module.exports = createElement;

@ -1,4 +1,4 @@
module.exports = (name, props) => {
const createElement = (name, props) => {
const element = document.createElement(name);
for (const prop in props) {
@ -11,3 +11,5 @@ module.exports = (name, props) => {
return element;
};
module.exports = createElement;

@ -3,12 +3,22 @@
* @powercord: This function/module is only here to provide
* backwards-compatability with Powercord plugins that may utilize it.
*
* Plugins should be using `react.findInReactTree` instead.
* Plugins should be using `Util.react.findInReactTree` instead.
*/
const findInTree = require('./findInTree');
const logger = require('./logger');
module.exports = (tree, filter) =>
findInTree(tree, filter, {
const findInReactTree = (tree, filter) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:findInReactTree';
const REPLACEMENT_SUBMODULE = 'Util:react:findInReactTree';
logger.deprecate(MODULE, SUBMODULE, REPLACEMENT_SUBMODULE);
return findInTree(tree, filter, {
walkable: [ 'props', 'children', 'child', 'sibiling' ]
});
};
module.exports = findInReactTree;

@ -3,7 +3,7 @@
* @powercord: This function/module is only here to provide
* backwards-compatability with Powercord plugins that may utilize it.
*
* Plugins should be using `react.findInTree` instead.
* Plugins should be using `Util.react.findInTree` instead.
*/
/**
@ -12,7 +12,15 @@
* <https://github.com/rauenzi/BDPluginLibrary/blob/master/release/0PluginLibrary.plugin.js#L3302-L3336>
*/
module.exports = function findInTree (tree, filter, { walkable = null, ignore = [] } = {}) {
const logger = require('./logger');
const findInTree = function findInTree (tree, filter, { walkable = null, ignore = [] } = {}) {
const MODULE = 'Module';
const SUBMODULE = 'Util:findInTree';
const REPLACEMENT_SUBMODULE = 'Util:react:findInTree';
logger.deprecate(MODULE, SUBMODULE, REPLACEMENT_SUBMODULE);
if (!tree || typeof tree !== 'object') {
return null;
}
@ -61,3 +69,5 @@ module.exports = function findInTree (tree, filter, { walkable = null, ignore =
return returnValue;
};
module.exports = findInTree;

@ -3,14 +3,24 @@
* @powercord: This function/module is only here to provide
* backwards-compatability with Powercord plugins that may utilize it.
*
* Plugins should be using `react.forceUpdateElement` instead.
* Plugins should be using `Util.react.forceUpdateElement` instead.
*/
const getOwnerInstance = require('./getOwnerInstance');
const logger = require('./logger');
const forceUpdateElement = (query, all = false) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:forceUpdateElement';
const REPLACEMENT_SUBMODULE = 'Util:react:forceUpdateElement';
logger.deprecate(MODULE, SUBMODULE, REPLACEMENT_SUBMODULE);
module.exports = (query, all = false) => {
const elements = all ? [ ...document.querySelectorAll(query) ] : [ document.querySelector(query) ];
elements.filter(Boolean).forEach(element => {
return elements.filter(Boolean).forEach(element => {
getOwnerInstance(element).forceUpdate();
});
};
module.exports = forceUpdateElement;

@ -1,10 +1,35 @@
module.exports = (time) => {
/**
* @deprecated:
* @powercord: This function/module is only here to provide
* backwards-compatability with Powercord plugins that may utilize it.
*
* There is no replacement for this as it has been removed entirely from Vizality,
* due the seemingly niche nature of it. If you want it left in, let us know!
*/
/**
* Converts milliseconds to hours:minutes:seconds
* @param {*} time
*/
const logger = require('./logger');
const formatTime = (time) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:formatTime';
logger.deprecate(MODULE, SUBMODULE, null);
time = Math.floor(time / 1000);
const hours = Math.floor(time / 3600) % 24;
const minutes = Math.floor(time / 60) % 60;
const seconds = time % 60;
return [ hours, minutes, seconds ]
.map(v => v < 10 ? `0${v}` : v)
.filter((v, i) => v !== '00' || i > 0)
.join(':');
};
module.exports = formatTime;

@ -1,6 +1,21 @@
/**
* @deprecated:
* @powercord: This function/module is only here to provide
* backwards-compatability with Powercord plugins that may utilize it.
*
* Plugins should be using `Util.react.getOwnerInstance` instead.
*/
const getReactInstance = require('./getReactInstance');
const logger = require('./logger');
const getOwnerInstance = (node) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:getOwnerInstance';
const REPLACEMENT_SUBMODULE = 'Util:react:getOwnerInstance';
logger.deprecate(MODULE, SUBMODULE, REPLACEMENT_SUBMODULE);
module.exports = (node) => {
for (let curr = getReactInstance(node); curr; curr = curr.return) {
const owner = curr.stateNode;
if (owner && !(owner instanceof HTMLElement)) {
@ -10,3 +25,5 @@ module.exports = (node) => {
return null;
};
module.exports = getOwnerInstance;

@ -1,6 +1,24 @@
module.exports = (node) => {
/**
* @deprecated:
* @powercord: This function/module is only here to provide
* backwards-compatability with Powercord plugins that may utilize it.
*
* Plugins should be using `Util.react.getReactInstance` instead.
*/
const logger = require('./logger');
const getReactInstance = (node) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:getReactInstance';
const REPLACEMENT_SUBMODULE = 'Util:react:getReactInstance';
logger.deprecate(MODULE, SUBMODULE, REPLACEMENT_SUBMODULE);
if (!node) return null;
if (!Object.keys(node) || !Object.keys(node).length) return null;
const reactInternalInstanceKey = Object.keys(node).find(key => key.startsWith('__reactInternalInstance'));
return reactInternalInstanceKey ? node[reactInternalInstanceKey] : null;
};
module.exports = getReactInstance;

@ -0,0 +1,13 @@
/**
* @hack: Figure out why const { getModule } = require('vizality/webpack') doesn't work.
*/
let joinClassNamesModule;
const joinClassNames = (...args) => {
if (!joinClassNamesModule) joinClassNamesModule = require('vizality/webpack').getModule(e => e.default && e.default.default, false);
return joinClassNamesModule(...args);
};
module.exports = joinClassNames;

@ -9,37 +9,52 @@ const color = require('../color');
* @param {any|Array<any>} message - Messages to have logged.
* @param {module:logger.logTypes} type - Type of log to use in console.
*/
module.exports = (module, submodule, submoduleColor, message, logType = 'log') => {
const _log = (module, submodule, submoduleColor, message, logType) => {
logType = _parseType(logType);
if (!Array.isArray(message)) message = [ message ];
const BADGE_COLORS = {
API: {
module: '#8a50cc',
submodule: '#15819c'
module: '#dc2167',
submodule: '#242a85'
},
HTTP: {
module: '#3636e0',
submodule: '#cf3e0b'
module: '#ff683b',
submodule: '#2e89c9'
},
StyleManager: {
module: '#591870',
submodule: '#ce03e5'
},
PluginManager: {
module: '#1e2963',
submodule: '#782049'
},
Plugin: {
module: '#d021a1',
submodule: '#158547'
module: '#057b81',
submodule: '#5b3c89'
},
Theme: {
module: '#90b900',
submodule: '#6b159c'
module: '#e23773',
submodule: '#568763'
},
Discord: {
module: '#7289DA',
submodule: '#6e5a00'
submodule: '#d6409a'
},
Module: {
module: '#159c81',
submodule: '#f21956'
module: '#e56e60',
submodule: '#34426e'
},
Injector: {
module: '#a70338',
submodule: '#0195b5'
}
};
const randomModuleColor = color.getRandom();
const randomSubmoduleColor = color.getRandom();
const baseBadgeStyles =
`border-radius: 3px;
text-align: center;
@ -65,13 +80,13 @@ module.exports = (module, submodule, submoduleColor, message, logType = 'log') =
const moduleStyles =
`${baseBadgeStyles}
color: #fff;
background: ${BADGE_COLORS[module].module || '#000'};`;
color: ${BADGE_COLORS[module] && BADGE_COLORS[module].module ? color.getContrast(BADGE_COLORS[module].module) : color.getContrast(randomModuleColor)};
background: ${BADGE_COLORS[module] && BADGE_COLORS[module].module || randomModuleColor};`;
const submoduleStyles =
`${baseBadgeStyles};
color: ${submoduleColor ? color.contrast(submoduleColor) : '#fff'};
background: ${submoduleColor || BADGE_COLORS[module].submodule || '#000'};`;
color: ${submoduleColor ? color.getContrast(submoduleColor) : BADGE_COLORS[module] && BADGE_COLORS[module].submodule ? color.getContrast(BADGE_COLORS[module].submodule) : color.getContrast(randomSubmoduleColor)};
background: ${submoduleColor || BADGE_COLORS[module] && BADGE_COLORS[module].submodule || randomSubmoduleColor};`;
return console[logType](
`%c %c${module}%c${submodule}%c`,
@ -82,3 +97,5 @@ module.exports = (module, submodule, submoduleColor, message, logType = 'log') =
...message
);
};
module.exports = _log;

@ -1,4 +1,4 @@
module.exports = (logType) => {
const _parseType = (logType) => {
const LOG_TYPES = {
error: 'error',
log: 'log',
@ -7,3 +7,5 @@ module.exports = (logType) => {
return LOG_TYPES.hasOwnProperty(logType) ? LOG_TYPES[logType] : 'log';
};
module.exports = _parseType;

@ -0,0 +1,16 @@
const logger = require('../logger');
/**
* Logs a warning message to let the user know the method is deprecated.
*
* @param {string} module - Name of the calling module.
* @param {string} message - Message to have logged.
*/
const deprecate = (module, submodule, replacement) => {
return void 0;
// const message = `${submodule} is deprecated in Vizality.${replacement ? ` We recommend you use ${replacement} instead.` : ''}`;
// return logger._log(module, submodule, null, message, 'warn');
};
module.exports = deprecate;

@ -6,6 +6,8 @@ const logger = require('../logger');
* @param {string} module - Name of the calling module.
* @param {string} message - Message or error to have logged.
*/
module.exports = (module, submodule, submoduleColor, ...message) => {
const error = (module, submodule, submoduleColor, ...message) => {
return logger._log(module, submodule, submoduleColor, message, 'error');
};
module.exports = error;

@ -7,6 +7,8 @@ const logger = require('../logger');
* @param {string} submodule - Name of the calling submodule.
* @param {...any} message - Messages to have logged.
*/
module.exports = (module, submodule, submoduleColor, ...message) => {
const log = (module, submodule, submoduleColor, ...message) => {
return logger._log(module, submodule, submoduleColor, message);
};
module.exports = log;

@ -6,6 +6,8 @@ const logger = require('../logger');
* @param {string} module - Name of the calling module.
* @param {...any} message - Messages to have logged.
*/
module.exports = (module, submodule, submoduleColor, ...message) => {
const warn = (module, submodule, submoduleColor, ...message) => {
return logger._log(module, submodule, submoduleColor, message, 'warn');
};
module.exports = warn;

@ -1,5 +1,9 @@
// @todo: Rework to note use lodash
const { get } = require('lodash');
module.exports = (object, path, defaultValue) => {
const getNestedProp = (object, path, defaultValue) => {
return get(object, path, defaultValue);
};
module.exports = getNestedProp;

@ -1,4 +1,9 @@
module.exports = (object) => {
const logger = require('../logger');
const memoize = (object) => {
const MODULE = 'Module';
const SUBMODULE = 'Util:object:memoize';
const proxy = new Proxy(object, {
get (obj, mod) {
if (!obj.hasOwnProperty(mod)) return undefined;
@ -10,7 +15,7 @@ module.exports = (object) => {
return obj[mod];
},
set (obj, mod, value) {
if (obj.hasOwnProperty(mod)) return console.warn('MemoizedObject - Trying to overwrite existing property');
if (obj.hasOwnProperty(mod)) return logger.warn(MODULE, SUBMODULE, null, 'Trying to overwrite existing property.');
obj[mod] = value;
return obj[mod];
}
@ -22,3 +27,5 @@ module.exports = (object) => {
return proxy;
};
module.exports = memoize;

@ -1,5 +1,4 @@
const { existsSync } = require('fs');
const { readdir, lstat, unlink, rmdir } = require('fs').promises;
const { existsSync, promises: { readdir, lstat, unlink, rmdir } } = require('fs');
const rmdirRf = async (path) => {
if (existsSync(path)) {

@ -1,4 +1,7 @@
module.exports = (time) =>
new Promise(resolve =>
const sleep = (time) => {
return new Promise(resolve =>
setTimeout(resolve, time)
);
};
module.exports = sleep;

@ -1,5 +0,0 @@
const convert = require('js-convert-case');
module.exports = (str) => {
return convert.toCamelCase(str);
};

@ -1,5 +0,0 @@
const convert = require('js-convert-case');
module.exports = (str) => {
return convert.toDotCase(str);
};

@ -1,5 +0,0 @@
const convert = require('js-convert-case');
module.exports = (str) => {
return convert.toHeaderCase(str);
};

@ -1,5 +0,0 @@
const convert = require('js-convert-case');
module.exports = (str) => {
return convert.toPascalCase(str);
};

@ -1,5 +0,0 @@
const convert = require('js-convert-case');
module.exports = (str) => {
return convert.toPathCase(str);
};

@ -1,5 +0,0 @@
const convert = require('js-convert-case');
module.exports = (str) => {
return convert.toSentenceCase(str);
};

@ -1,5 +0,0 @@
const convert = require('js-convert-case');
module.exports = (str) => {
return convert.toSnakeCase(str);
};

@ -0,0 +1,16 @@
const toCamelCase = (string) => {
if (!string) return '';
return String(string)
.replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')
.replace(/[^A-Za-z0-9]+/g, '$')
.replace(/([a-z])([A-Z])/g, (m, a, b) => {
return `${a}$${b}`;
})
.toLowerCase().trim()
.replace(/(\$)(\w)/g, (m, a, b) => {
return b.toUpperCase();
});
};
module.exports = toCamelCase;

@ -0,0 +1,13 @@
const toDotCase = (string) => {
if (!string) return '';
return String(string)
.replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')
.replace(/([a-z])([A-Z])/g, (m, a, b) => {
return `${a}_${b.toLowerCase()}`;
})
.replace(/[^A-Za-z0-9]+|_+/g, '.')
.toLowerCase().trim();
};
module.exports = toDotCase;

@ -0,0 +1,16 @@
const toHeaderCase = (string) => {
if (!string) return '';
return String(string)
.replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')
.replace(/([a-z])([A-Z])/g, (m, a, b) => {
return `${a}_${b.toLowerCase()}`;
})
.replace(/[^A-Za-z0-9]+|_+/g, ' ')
.toLowerCase().trim()
.replace(/( ?)(\w+)( ?)/g, (m, a, b, c) => {
return a + b.charAt(0).toUpperCase() + b.slice(1) + c;
});
};
module.exports = toHeaderCase;

@ -0,0 +1,27 @@
const toKebabCase = (string) => {
if (!string) return '';
let from = 'ąàáäâãåæăćčĉęèéëêĝĥìíïîĵłľńňòóöőôõðøśșşšŝťțţŭùúüűûñÿýçżźž';
let to = 'aaaaaaaaaccceeeeeghiiiijllnnoooooooossssstttuuuuuunyyczzz';
from += from.toUpperCase();
to += to.toUpperCase();
to = to.split('');
// for tokens requiring multitoken output
from += 'ß';
to.push('ss');
return String(string)
.trim()
.replace(/.{1}/g, c => {
const index = from.indexOf(c);
return index === -1 ? c : to[index];
})
.replace(/[^\w\s-]/g, '-').toLowerCase()
.replace(/([A-Z])/g, '-$1')
.replace(/[-_\s]+/g, '-').toLowerCase();
};
module.exports = toKebabCase;

@ -0,0 +1,16 @@
const toPascalCase = (string) => {
if (!string) return '';
return String(string)
.replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '$')
.replace(/[^A-Za-z0-9]+/g, '$')
.replace(/([a-z])([A-Z])/g, (m, a, b) => {
return `${a}$${b}`;
})
.toLowerCase().trim()
.replace(/(\$)(\w?)/g, (m, a, b) => {
return b.toUpperCase();
});
};
module.exports = toPascalCase;

@ -0,0 +1,13 @@
const toPathCase = (string) => {
if (!string) return '';
return String(string)
.replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')
.replace(/([a-z])([A-Z])/g, (m, a, b) => {
return `${a}_${b.toLowerCase()}`;
})
.replace(/[^A-Za-z0-9]+|_+/g, '/')
.toLowerCase().trim();
};
module.exports = toPathCase;

@ -0,0 +1,15 @@
const toSentenceCase = (string) => {
if (!string) return '';
const textcase = String(string)
.replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')
.replace(/([a-z])([A-Z])/g, (m, a, b) => {
return `${a}_${b.toLowerCase()}`;
})
.replace(/[^A-Za-z0-9]+|_+/g, ' ')
.toLowerCase().trim();
return textcase.charAt(0).toUpperCase() + textcase.slice(1);
};
module.exports = toSentenceCase;

@ -0,0 +1,13 @@
const toSnakeCase = (string) => {
if (!string) return '';
return String(string)
.replace(/^[^A-Za-z0-9]*|[^A-Za-z0-9]*$/g, '')
.replace(/([a-z])([A-Z])/g, (m, a, b) => {
return `${a}_${b.toLowerCase()}`;
})
.replace(/[^A-Za-z0-9]+|_+/g, '_')
.toLowerCase().trim();
};
module.exports = toSnakeCase;

@ -0,0 +1,11 @@
/*
* moment().add(Number, String);
* moment().add(Duration);
* moment().add(Object);
*/
const moment = require('./moment');
module.exports = (...args) => {
return moment().add(...args);
};

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save