lib
This commit is contained in:
parent
b0d7545fec
commit
261905ef41
File diff suppressed because one or more lines are too long
|
@ -267,7 +267,7 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
|
||||||
|
|
||||||
BDFDB.checkUpdate = function (plugname, url) {
|
BDFDB.checkUpdate = function (plugname, url) {
|
||||||
if (BDFDB.isBDv2()) return;
|
if (BDFDB.isBDv2()) return;
|
||||||
require('request')(url, (error, response, result) => {
|
LibraryRequires.request(url, (error, response, result) => {
|
||||||
if (error) return;
|
if (error) return;
|
||||||
var newversion = result.match(/['"][0-9]+\.[0-9]+\.[0-9]+['"]/i);
|
var newversion = result.match(/['"][0-9]+\.[0-9]+\.[0-9]+['"]/i);
|
||||||
if (!newversion) return;
|
if (!newversion) return;
|
||||||
|
@ -360,12 +360,12 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
|
||||||
};
|
};
|
||||||
|
|
||||||
BDFDB.downloadPlugin = function (plugname, url) {
|
BDFDB.downloadPlugin = function (plugname, url) {
|
||||||
require('request')(url, (error, response, result) => {
|
LibraryRequires.request(url, (error, response, result) => {
|
||||||
if (error) return console.warn(`%c[BDFDB]%c`, 'color:#3a71c1; font-weight:700;', '', 'Unable to get update for ' + plugname);
|
if (error) return console.warn(`%c[BDFDB]%c`, 'color:#3a71c1; font-weight:700;', '', 'Unable to get update for ' + plugname);
|
||||||
BDFDB.creationTime = 0;
|
BDFDB.creationTime = 0;
|
||||||
var newversion = result.match(/['"][0-9]+\.[0-9]+\.[0-9]+['"]/i);
|
var newversion = result.match(/['"][0-9]+\.[0-9]+\.[0-9]+['"]/i);
|
||||||
newversion = newversion.toString().replace(/['"]/g, '');
|
newversion = newversion.toString().replace(/['"]/g, '');
|
||||||
require('fs').writeFileSync(require('path').join(BDFDB.getPluginsFolder(), (bdplugins[plugname] ? bdplugins[plugname].filename : url.split("/").slice(-1)[0])), result);
|
LibraryRequires.fs.writeFileSync(LibraryRequires.path.join(BDFDB.getPluginsFolder(), (bdplugins[plugname] ? bdplugins[plugname].filename : url.split("/").slice(-1)[0])), result);
|
||||||
BDFDB.showToast(`${plugname} v${window.PluginUpdates.plugins[url].version} has been replaced by ${plugname} v${newversion}.`, {nopointer:true, selector:'plugin-updated-toast'});
|
BDFDB.showToast(`${plugname} v${window.PluginUpdates.plugins[url].version} has been replaced by ${plugname} v${newversion}.`, {nopointer:true, selector:'plugin-updated-toast'});
|
||||||
var updatenotice = document.querySelector('#pluginNotice');
|
var updatenotice = document.querySelector('#pluginNotice');
|
||||||
if (updatenotice) {
|
if (updatenotice) {
|
||||||
|
@ -694,36 +694,32 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
|
||||||
BDFDB.getDiscordFolder = function () {
|
BDFDB.getDiscordFolder = function () {
|
||||||
var built = BDFDB.getDiscordBuilt();
|
var built = BDFDB.getDiscordBuilt();
|
||||||
built = 'discord' + (built == 'stable' ? '' : built);
|
built = 'discord' + (built == 'stable' ? '' : built);
|
||||||
return require('path').resolve(require('electron').remote.app.getPath('appData'), built, BDFDB.getDiscordVersion());
|
return LibraryRequires.path.resolve(LibraryRequires.electron.remote.app.getPath('appData'), built, BDFDB.getDiscordVersion());
|
||||||
};
|
};
|
||||||
|
|
||||||
BDFDB.getPluginsFolder = function () {
|
BDFDB.getPluginsFolder = function () {
|
||||||
var process = require('process');
|
if (LibraryRequires.process.env.injDir) return LibraryRequires.path.resolve(LibraryRequires.process.env.injDir, 'plugins/');
|
||||||
var path = require('path');
|
switch (LibraryRequires.process.platform) {
|
||||||
if (process.env.injDir) return path.resolve(process.env.injDir, 'plugins/');
|
|
||||||
switch (process.platform) {
|
|
||||||
case 'win32':
|
case 'win32':
|
||||||
return path.resolve(process.env.appdata, 'BetterDiscord/plugins/');
|
return LibraryRequires.path.resolve(LibraryRequires.process.env.appdata, 'BetterDiscord/plugins/');
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
return path.resolve(process.env.HOME, 'Library/Preferences/BetterDiscord/plugins/');
|
return LibraryRequires.path.resolve(LibraryRequires.process.env.HOME, 'Library/Preferences/BetterDiscord/plugins/');
|
||||||
default:
|
default:
|
||||||
if (process.env.XDG_CONFIG_HOME) return path.resolve(process.env.XDG_CONFIG_HOME, 'BetterDiscord/plugins/');
|
if (LibraryRequires.process.env.XDG_CONFIG_HOME) return LibraryRequires.path.resolve(LibraryRequires.process.env.XDG_CONFIG_HOME, 'BetterDiscord/plugins/');
|
||||||
else return path.resolve(process.env.HOME, '.config/BetterDiscord/plugins/');
|
else return LibraryRequires.path.resolve(LibraryRequires.process.env.HOME, '.config/BetterDiscord/plugins/');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BDFDB.getThemesFolder = function () {
|
BDFDB.getThemesFolder = function () {
|
||||||
var process = require('process');
|
if (LibraryRequires.process.env.injDir) return LibraryRequires.path.resolve(LibraryRequires.process.env.injDir, 'plugins/');
|
||||||
var path = require('path');
|
switch (LibraryRequires.process.platform) {
|
||||||
if (process.env.injDir) return path.resolve(process.env.injDir, 'plugins/');
|
|
||||||
switch (process.platform) {
|
|
||||||
case 'win32':
|
case 'win32':
|
||||||
return path.resolve(process.env.appdata, 'BetterDiscord/themes/');
|
return LibraryRequires.path.resolve(LibraryRequires.process.env.appdata, 'BetterDiscord/themes/');
|
||||||
case 'darwin':
|
case 'darwin':
|
||||||
return path.resolve(process.env.HOME, 'Library/Preferences/BetterDiscord/themes/');
|
return LibraryRequires.path.resolve(LibraryRequires.process.env.HOME, 'Library/Preferences/BetterDiscord/themes/');
|
||||||
default:
|
default:
|
||||||
if (process.env.XDG_CONFIG_HOME) return path.resolve(process.env.XDG_CONFIG_HOME, 'BetterDiscord/themes/');
|
if (LibraryRequires.process.env.XDG_CONFIG_HOME) return LibraryRequires.path.resolve(LibraryRequires.process.env.XDG_CONFIG_HOME, 'BetterDiscord/themes/');
|
||||||
else return path.resolve(process.env.HOME, '.config/BetterDiscord/themes/');
|
else return LibraryRequires.path.resolve(LibraryRequires.process.env.HOME, '.config/BetterDiscord/themes/');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -984,9 +980,9 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
|
||||||
if (BDFDB.getDiscordBuilt.built) return BDFDB.getDiscordBuilt.built;
|
if (BDFDB.getDiscordBuilt.built) return BDFDB.getDiscordBuilt.built;
|
||||||
else {
|
else {
|
||||||
var built = null;
|
var built = null;
|
||||||
try {built = require(require('electron').remote.app.getAppPath() + '/build_info.json').releaseChannel.toLowerCase();}
|
try {built = require(LibraryRequires.electron.remote.app.getAppPath() + '/build_info.json').releaseChannel.toLowerCase();}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
try {built = require(require('electron').remote.app.getAppPath().replace('\app.asar', '') + '/build_info.json').releaseChannel.toLowerCase();}
|
try {built = require(LibraryRequires.electron.remote.app.getAppPath().replace('\app.asar', '') + '/build_info.json').releaseChannel.toLowerCase();}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
var version = BDFDB.getDiscordVersion();
|
var version = BDFDB.getDiscordVersion();
|
||||||
if (version) {
|
if (version) {
|
||||||
|
@ -1006,7 +1002,7 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
|
||||||
if (BDFDB.getDiscordBuilt.version) return BDFDB.getDiscordBuilt.version;
|
if (BDFDB.getDiscordBuilt.version) return BDFDB.getDiscordBuilt.version;
|
||||||
else {
|
else {
|
||||||
var version = null;
|
var version = null;
|
||||||
try {version = require('electron').remote.app.getVersion();}
|
try {version = LibraryRequires.electron.remote.app.getVersion();}
|
||||||
catch (version) {version = '';}
|
catch (version) {version = '';}
|
||||||
BDFDB.getDiscordBuilt.version = version;
|
BDFDB.getDiscordBuilt.version = version;
|
||||||
return version;
|
return version;
|
||||||
|
@ -1255,6 +1251,12 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
|
||||||
|
|
||||||
BDFDB.DiscordConstants = BDFDB.WebModules.findByProperties('Permissions', 'ActivityTypes');
|
BDFDB.DiscordConstants = BDFDB.WebModules.findByProperties('Permissions', 'ActivityTypes');
|
||||||
|
|
||||||
|
var LibraryRequires = {};
|
||||||
|
for (let name of ['child_process', 'electron', 'fs', 'path', 'process', 'request']) {
|
||||||
|
try {LibraryRequires[name] = require(name);} catch (err) {}
|
||||||
|
}
|
||||||
|
BDFDB.LibraryRequires = Object.assign({}, LibraryRequires);
|
||||||
|
|
||||||
var LibraryModules = {};
|
var LibraryModules = {};
|
||||||
LibraryModules.AckUtils = BDFDB.WebModules.findByProperties('localAck', 'bulkAck');
|
LibraryModules.AckUtils = BDFDB.WebModules.findByProperties('localAck', 'bulkAck');
|
||||||
LibraryModules.APIUtils = BDFDB.WebModules.findByProperties('getAPIBaseURL');
|
LibraryModules.APIUtils = BDFDB.WebModules.findByProperties('getAPIBaseURL');
|
||||||
|
@ -2064,44 +2066,44 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
|
||||||
};
|
};
|
||||||
|
|
||||||
BDFDB.saveAllData = function (data, plugin, key) {
|
BDFDB.saveAllData = function (data, plugin, key) {
|
||||||
var fs = require('fs'), configpath, plugname;
|
var configpath, plugname;
|
||||||
if (!BDFDB.isBDv2()) {
|
if (!BDFDB.isBDv2()) {
|
||||||
plugname = typeof plugin === 'string' ? plugin : plugin.name;
|
plugname = typeof plugin === 'string' ? plugin : plugin.name;
|
||||||
configpath = require('path').join(BDFDB.getPluginsFolder(), plugname + '.config.json');
|
configpath = LibraryRequires.path.join(BDFDB.getPluginsFolder(), plugname + '.config.json');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plugname = typeof plugin === 'string' ? plugin.toLowerCase() : null;
|
plugname = typeof plugin === 'string' ? plugin.toLowerCase() : null;
|
||||||
var contentpath = plugname ? BDFDB.Plugins[plugname] ? BDFDB.Plugins[plugname].contentPath : null : plugin.contentPath;
|
var contentpath = plugname ? BDFDB.Plugins[plugname] ? BDFDB.Plugins[plugname].contentPath : null : plugin.contentPath;
|
||||||
if (!contentpath) return;
|
if (!contentpath) return;
|
||||||
configpath = require('path').join(contentpath, 'settings.json');
|
configpath = LibraryRequires.path.join(contentpath, 'settings.json');
|
||||||
}
|
}
|
||||||
var exists = fs.existsSync(configpath);
|
var exists = LibraryRequires.fs.existsSync(configpath);
|
||||||
var config = !exists ? {} : typeof BDFDB.cachedData[plugname] !== 'undefined' ? BDFDB.cachedData[plugname] : BDFDB.readConfig(configpath);
|
var config = !exists ? {} : typeof BDFDB.cachedData[plugname] !== 'undefined' ? BDFDB.cachedData[plugname] : BDFDB.readConfig(configpath);
|
||||||
config[key] = data;
|
config[key] = data;
|
||||||
if (BDFDB.isObjectEmpty(config[key])) delete config[key];
|
if (BDFDB.isObjectEmpty(config[key])) delete config[key];
|
||||||
if (BDFDB.isObjectEmpty(config)) {
|
if (BDFDB.isObjectEmpty(config)) {
|
||||||
delete BDFDB.cachedData[plugname];
|
delete BDFDB.cachedData[plugname];
|
||||||
if (exists) fs.unlinkSync(configpath);
|
if (exists) LibraryRequires.fs.unlinkSync(configpath);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BDFDB.cachedData[plugname] = config;
|
BDFDB.cachedData[plugname] = config;
|
||||||
fs.writeFileSync(configpath, JSON.stringify(config, null, ' '));
|
LibraryRequires.fs.writeFileSync(configpath, JSON.stringify(config, null, ' '));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BDFDB.loadAllData = function (plugin, key) {
|
BDFDB.loadAllData = function (plugin, key) {
|
||||||
var fs = require('fs'), configpath, plugname;
|
var configpath, plugname;
|
||||||
if (!BDFDB.isBDv2()) {
|
if (!BDFDB.isBDv2()) {
|
||||||
plugname = typeof plugin === 'string' ? plugin : plugin.name;
|
plugname = typeof plugin === 'string' ? plugin : plugin.name;
|
||||||
configpath = require('path').join(BDFDB.getPluginsFolder(), plugname + '.config.json');
|
configpath = LibraryRequires.path.join(BDFDB.getPluginsFolder(), plugname + '.config.json');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plugname = typeof plugin === 'string' ? plugin.toLowerCase() : null;
|
plugname = typeof plugin === 'string' ? plugin.toLowerCase() : null;
|
||||||
var contentpath = plugname ? BDFDB.Plugins[plugname] ? BDFDB.Plugins[plugname].contentPath : null : plugin.contentPath;
|
var contentpath = plugname ? BDFDB.Plugins[plugname] ? BDFDB.Plugins[plugname].contentPath : null : plugin.contentPath;
|
||||||
if (!contentpath) return {};
|
if (!contentpath) return {};
|
||||||
configpath = require('path').join(contentpath, 'settings.json');
|
configpath = LibraryRequires.path.join(contentpath, 'settings.json');
|
||||||
}
|
}
|
||||||
if (!fs.existsSync(configpath)) {
|
if (!LibraryRequires.fs.existsSync(configpath)) {
|
||||||
delete BDFDB.cachedData[plugname];
|
delete BDFDB.cachedData[plugname];
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@ -2111,27 +2113,27 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
|
||||||
};
|
};
|
||||||
|
|
||||||
BDFDB.removeAllData = function (plugin, key) {
|
BDFDB.removeAllData = function (plugin, key) {
|
||||||
var fs = require('fs'), configpath, plugname;
|
var configpath, plugname;
|
||||||
if (!BDFDB.isBDv2()) {
|
if (!BDFDB.isBDv2()) {
|
||||||
plugname = typeof plugin === 'string' ? plugin : plugin.name;
|
plugname = typeof plugin === 'string' ? plugin : plugin.name;
|
||||||
configpath = require('path').join(BDFDB.getPluginsFolder(), plugname + '.config.json');
|
configpath = LibraryRequires.path.join(BDFDB.getPluginsFolder(), plugname + '.config.json');
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
plugname = typeof plugin === 'string' ? plugin.toLowerCase() : null;
|
plugname = typeof plugin === 'string' ? plugin.toLowerCase() : null;
|
||||||
var contentpath = plugname ? BDFDB.Plugins[plugname] ? BDFDB.Plugins[plugname].contentPath : null : plugin.contentPath;
|
var contentpath = plugname ? BDFDB.Plugins[plugname] ? BDFDB.Plugins[plugname].contentPath : null : plugin.contentPath;
|
||||||
if (!contentpath) return;
|
if (!contentpath) return;
|
||||||
configpath = require('path').join(contentpath, 'settings.json');
|
configpath = LibraryRequires.path.join(contentpath, 'settings.json');
|
||||||
}
|
}
|
||||||
var exists = fs.existsSync(configpath);
|
var exists = LibraryRequires.fs.existsSync(configpath);
|
||||||
var config = !exists ? {} : typeof BDFDB.cachedData[plugname] !== 'undefined' ? BDFDB.cachedData[plugname] : BDFDB.readConfig(configpath);
|
var config = !exists ? {} : typeof BDFDB.cachedData[plugname] !== 'undefined' ? BDFDB.cachedData[plugname] : BDFDB.readConfig(configpath);
|
||||||
delete config[key];
|
delete config[key];
|
||||||
if (BDFDB.isObjectEmpty(config)) {
|
if (BDFDB.isObjectEmpty(config)) {
|
||||||
delete BDFDB.cachedData[plugname];
|
delete BDFDB.cachedData[plugname];
|
||||||
if (exists) fs.unlinkSync(configpath);
|
if (exists) LibraryRequires.fs.unlinkSync(configpath);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
BDFDB.cachedData[plugname] = config;
|
BDFDB.cachedData[plugname] = config;
|
||||||
fs.writeFileSync(configpath, JSON.stringify(config, null, ' '));
|
LibraryRequires.fs.writeFileSync(configpath, JSON.stringify(config, null, ' '));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2150,7 +2152,7 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
|
||||||
};
|
};
|
||||||
|
|
||||||
BDFDB.readConfig = function (path) {
|
BDFDB.readConfig = function (path) {
|
||||||
try {return JSON.parse(require('fs').readFileSync(path));}
|
try {return JSON.parse(LibraryRequires.fs.readFileSync(path));}
|
||||||
catch (err) {return {};}
|
catch (err) {return {};}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -6231,6 +6233,7 @@ var BDFDB = {myPlugins: BDFDB && BDFDB.myPlugins ? BDFDB.myPlugins : {}, BDv2Api
|
||||||
|
|
||||||
if (BDFDB.myData.id == "278543574059057154") {
|
if (BDFDB.myData.id == "278543574059057154") {
|
||||||
for (let module in DiscordClassModules) if (!DiscordClassModules[module]) console.warn(`%c[BDFDB]%c`, 'color: #3a71c1; font-weight: 700;', '', module + ' not initialized in DiscordClassModules');
|
for (let module in DiscordClassModules) if (!DiscordClassModules[module]) console.warn(`%c[BDFDB]%c`, 'color: #3a71c1; font-weight: 700;', '', module + ' not initialized in DiscordClassModules');
|
||||||
|
for (let require in LibraryRequires) if (!LibraryRequires[require]) console.warn(`%c[BDFDB]%c`, 'color: #3a71c1; font-weight: 700;', '', require + ' not initialized in LibraryRequires');
|
||||||
for (let module in LibraryModules) if (!LibraryModules[module]) console.warn(`%c[BDFDB]%c`, 'color: #3a71c1; font-weight: 700;', '', module + ' not initialized in LibraryModules');
|
for (let module in LibraryModules) if (!LibraryModules[module]) console.warn(`%c[BDFDB]%c`, 'color: #3a71c1; font-weight: 700;', '', module + ' not initialized in LibraryModules');
|
||||||
|
|
||||||
BDFDB.WebModules.DevFuncs = {};
|
BDFDB.WebModules.DevFuncs = {};
|
||||||
|
|
Loading…
Reference in New Issue