This commit is contained in:
Mirco Wittrien 2022-04-10 09:43:05 +02:00
parent 549eb59695
commit 617a7ca9dc
3 changed files with 108 additions and 52 deletions

View File

@ -2,7 +2,7 @@
* @name BDFDB
* @author DevilBro
* @authorId 278543574059057154
* @version 2.2.8
* @version 2.2.9
* @description Required Library for DevilBro's Plugins
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -19,10 +19,15 @@ module.exports = (_ => {
"info": {
"name": "BDFDB",
"author": "DevilBro",
"version": "2.2.8",
"version": "2.2.9",
"description": "Required Library for DevilBro's Plugins"
},
"rawUrl": "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js"
"rawUrl": "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js",
"changeLog": {
"added": {
"Plugin Config Sync": "Allows you to disable the synchronization of plugin config files between Discord Accounts"
}
}
};
const Cache = {data: {}, modules: {}};
@ -41,9 +46,14 @@ module.exports = (_ => {
const Internal = Object.assign({}, BDFDB, {
patchPriority: 0,
forceSyncData: true,
settings: {},
defaults: {
general: {
shareData: {
value: true,
onChange: _ => Cache.data = {}
},
showToasts: {
value: true,
isDisabled: data => data.nativeValue,
@ -973,14 +983,32 @@ module.exports = (_ => {
const request = require("request"), fs = require("fs"), path = require("path");
Internal.writeConfig = function (path, config) {
try {fs.writeFileSync(path, JSON.stringify(config, null, " "));}
Internal.writeConfig = function (plugin, path, config) {
let sync = Internal.shouldSyncConfig(plugin);
let allData = {};
try {allData = JSON.parse(fs.readFileSync(path));}
catch (err) {allData = {};}
try {
BDFDB.ObjectUtils.deepAssign(allData, !sync ? (plugin.neverSyncData ? {[BDFDB.UserUtils.me.id]: config} : {all: config, [BDFDB.UserUtils.me.id]: config}) : {all: config});
fs.writeFileSync(path, JSON.stringify(allData, null, " "));
}
catch (err) {}
};
Internal.readConfig = function (path) {
try {return JSON.parse(fs.readFileSync(path));}
Internal.readConfig = function (plugin, path) {
let sync = Internal.shouldSyncConfig(plugin);
try {
let config = JSON.parse(fs.readFileSync(path));
if (config && Object.keys(config).some(n => !(n == "all" || parseInt(n)))) {
try {fs.writeFileSync(path, JSON.stringify(!sync ? (plugin.neverSyncData ? {[BDFDB.UserUtils.me.id]: config} : {all: config, [BDFDB.UserUtils.me.id]: config}) : {all: config}, null, " "));}
catch (err) {}
}
return config && config[sync ? "all" : BDFDB.UserUtils.me.id] || {};
}
catch (err) {return {};}
};
Internal.shouldSyncConfig = function (plugin) {
return plugin.neverSyncData !== undefined ? !plugin.neverSyncData : (plugin.forceSyncData || Internal.settings.general.shareData);
};
BDFDB.DataUtils = {};
BDFDB.DataUtils.save = function (data, plugin, key, id) {
@ -989,7 +1017,7 @@ module.exports = (_ => {
let fileName = pluginName == "BDFDB" ? "0BDFDB" : pluginName;
let configPath = path.join(BDFDB.BDUtils.getPluginsFolder(), fileName + ".config.json");
let config = Cache.data[pluginName] !== undefined ? Cache.data[pluginName] : (Internal.readConfig(configPath) || {});
let config = Cache.data[pluginName] !== undefined ? Cache.data[pluginName] : (Internal.readConfig(plugin, configPath) || {});
if (key === undefined) config = BDFDB.ObjectUtils.is(data) ? BDFDB.ObjectUtils.sort(data) : data;
else {
@ -1009,7 +1037,7 @@ module.exports = (_ => {
else {
if (configIsObject) config = BDFDB.ObjectUtils.sort(config);
Cache.data[pluginName] = configIsObject ? BDFDB.ObjectUtils.deepAssign({}, config) : config;
Internal.writeConfig(configPath, config);
Internal.writeConfig(plugin, configPath, config);
}
};
@ -1019,7 +1047,7 @@ module.exports = (_ => {
let fileName = pluginName == "BDFDB" ? "0BDFDB" : pluginName;
let configPath = path.join(BDFDB.BDUtils.getPluginsFolder(), fileName + ".config.json");
let config = Cache.data[pluginName] !== undefined ? Cache.data[pluginName] : (Internal.readConfig(configPath) || {});
let config = Cache.data[pluginName] !== undefined ? Cache.data[pluginName] : (Internal.readConfig(plugin, configPath) || {});
let configIsObject = BDFDB.ObjectUtils.is(config);
Cache.data[pluginName] = configIsObject ? BDFDB.ObjectUtils.deepAssign({}, config) : config;
@ -1036,7 +1064,7 @@ module.exports = (_ => {
let fileName = pluginName == "BDFDB" ? "0BDFDB" : pluginName;
let configPath = path.join(BDFDB.BDUtils.getPluginsFolder(), fileName + ".config.json");
let config = Cache.data[pluginName] !== undefined ? Cache.data[pluginName] : (Internal.readConfig(configPath) || {});
let config = Cache.data[pluginName] !== undefined ? Cache.data[pluginName] : (Internal.readConfig(plugin, configPath) || {});
let configIsObject = BDFDB.ObjectUtils.is(config);
if (key === undefined || !configIsObject) config = {};
@ -1053,7 +1081,7 @@ module.exports = (_ => {
else {
if (configIsObject) config = BDFDB.ObjectUtils.sort(config);
Cache.data[pluginName] = configIsObject ? BDFDB.ObjectUtils.deepAssign({}, config) : config;
Internal.writeConfig(configPath, config);
Internal.writeConfig(plugin, configPath, config);
}
};
BDFDB.DataUtils.get = function (plugin, key, id) {
@ -3165,6 +3193,7 @@ module.exports = (_ => {
get: function (list, item) {
const user = Internal.LibraryModules.UserStore && Internal.LibraryModules.UserStore.getCurrentUser && Internal.LibraryModules.UserStore.getCurrentUser();
if (user && BDFDB.UserUtils._id != user.id) {
Cache.data = {};
document.body.setAttribute("data-current-user-id", user.id);
BDFDB.UserUtils._id = user.id;
}
@ -3210,10 +3239,7 @@ module.exports = (_ => {
if (!BDFDB.DiscordConstants.Permissions[permission]) BDFDB.LogUtils.warn([permission, "not found in Permissions"]);
else {
let channel = Internal.LibraryModules.ChannelStore.getChannel(channelId);
if (channel) {
try {return Internal.LibraryModules.PermissionRoleUtils.can(BDFDB.DiscordConstants.Permissions[permission], id, channel) || Internal.LibraryModules.PermissionRoleUtils.can({permission: BDFDB.DiscordConstants.Permissions[permission], user: id, context: channel});}
catch (err) {}
}
if (channel) return Internal.LibraryModules.PermissionRoleUtils.can({permission: BDFDB.DiscordConstants.Permissions[permission], user: id, context: channel});
}
return false;
};
@ -9041,7 +9067,8 @@ module.exports = (_ => {
value: Internal.settings.general[key],
nativeValue: nativeSetting,
disabled: disabled
}) : true) && (Internal.settings.general[key] || nativeSetting)
}) : true) && (Internal.settings.general[key] || nativeSetting),
onChange: typeof Internal.defaults.general[key].onChange == "function" ? Internal.defaults.general[key].onChange : (_ => {})
}));
}
settingsItems.push(BDFDB.ReactUtils.createElement(Internal.LibraryComponents.SettingsItem, {

View File

@ -2,7 +2,7 @@
* @name BDFDB
* @author DevilBro
* @authorId 278543574059057154
* @version 2.2.8
* @version 2.2.9
* @description Required Library for DevilBro's Plugins
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -19,10 +19,15 @@ module.exports = (_ => {
"info": {
"name": "BDFDB",
"author": "DevilBro",
"version": "2.2.8",
"version": "2.2.9",
"description": "Required Library for DevilBro's Plugins"
},
"rawUrl": "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js"
"rawUrl": "https://mwittrien.github.io/BetterDiscordAddons/Library/0BDFDB.plugin.js",
"changeLog": {
"added": {
"Plugin Config Sync": "Allows you to disable the synchronization of plugin config files between Discord Accounts"
}
}
};
const Cache = {data: {}, modules: {}};
@ -41,9 +46,14 @@ module.exports = (_ => {
const Internal = Object.assign({}, BDFDB, {
patchPriority: 0,
forceSyncData: true,
settings: {},
defaults: {
general: {
shareData: {
value: true,
onChange: _ => Cache.data = {}
},
showToasts: {
value: true,
isDisabled: data => data.nativeValue,
@ -973,14 +983,32 @@ module.exports = (_ => {
const request = require("request"), fs = require("fs"), path = require("path");
Internal.writeConfig = function (path, config) {
try {fs.writeFileSync(path, JSON.stringify(config, null, " "));}
Internal.writeConfig = function (plugin, path, config) {
let sync = Internal.shouldSyncConfig(plugin);
let allData = {};
try {allData = JSON.parse(fs.readFileSync(path));}
catch (err) {allData = {};}
try {
BDFDB.ObjectUtils.deepAssign(allData, !sync ? (plugin.neverSyncData ? {[BDFDB.UserUtils.me.id]: config} : {all: config, [BDFDB.UserUtils.me.id]: config}) : {all: config});
fs.writeFileSync(path, JSON.stringify(allData, null, " "));
}
catch (err) {}
};
Internal.readConfig = function (path) {
try {return JSON.parse(fs.readFileSync(path));}
Internal.readConfig = function (plugin, path) {
let sync = Internal.shouldSyncConfig(plugin);
try {
let config = JSON.parse(fs.readFileSync(path));
if (config && Object.keys(config).some(n => !(n == "all" || parseInt(n)))) {
try {fs.writeFileSync(path, JSON.stringify(!sync ? (plugin.neverSyncData ? {[BDFDB.UserUtils.me.id]: config} : {all: config, [BDFDB.UserUtils.me.id]: config}) : {all: config}, null, " "));}
catch (err) {}
}
return config && config[sync ? "all" : BDFDB.UserUtils.me.id] || {};
}
catch (err) {return {};}
};
Internal.shouldSyncConfig = function (plugin) {
return plugin.neverSyncData !== undefined ? !plugin.neverSyncData : (plugin.forceSyncData || Internal.settings.general.shareData);
};
BDFDB.DataUtils = {};
BDFDB.DataUtils.save = function (data, plugin, key, id) {
@ -989,7 +1017,7 @@ module.exports = (_ => {
let fileName = pluginName == "BDFDB" ? "0BDFDB" : pluginName;
let configPath = path.join(BDFDB.BDUtils.getPluginsFolder(), fileName + ".config.json");
let config = Cache.data[pluginName] !== undefined ? Cache.data[pluginName] : (Internal.readConfig(configPath) || {});
let config = Cache.data[pluginName] !== undefined ? Cache.data[pluginName] : (Internal.readConfig(plugin, configPath) || {});
if (key === undefined) config = BDFDB.ObjectUtils.is(data) ? BDFDB.ObjectUtils.sort(data) : data;
else {
@ -1009,7 +1037,7 @@ module.exports = (_ => {
else {
if (configIsObject) config = BDFDB.ObjectUtils.sort(config);
Cache.data[pluginName] = configIsObject ? BDFDB.ObjectUtils.deepAssign({}, config) : config;
Internal.writeConfig(configPath, config);
Internal.writeConfig(plugin, configPath, config);
}
};
@ -1019,7 +1047,7 @@ module.exports = (_ => {
let fileName = pluginName == "BDFDB" ? "0BDFDB" : pluginName;
let configPath = path.join(BDFDB.BDUtils.getPluginsFolder(), fileName + ".config.json");
let config = Cache.data[pluginName] !== undefined ? Cache.data[pluginName] : (Internal.readConfig(configPath) || {});
let config = Cache.data[pluginName] !== undefined ? Cache.data[pluginName] : (Internal.readConfig(plugin, configPath) || {});
let configIsObject = BDFDB.ObjectUtils.is(config);
Cache.data[pluginName] = configIsObject ? BDFDB.ObjectUtils.deepAssign({}, config) : config;
@ -1036,7 +1064,7 @@ module.exports = (_ => {
let fileName = pluginName == "BDFDB" ? "0BDFDB" : pluginName;
let configPath = path.join(BDFDB.BDUtils.getPluginsFolder(), fileName + ".config.json");
let config = Cache.data[pluginName] !== undefined ? Cache.data[pluginName] : (Internal.readConfig(configPath) || {});
let config = Cache.data[pluginName] !== undefined ? Cache.data[pluginName] : (Internal.readConfig(plugin, configPath) || {});
let configIsObject = BDFDB.ObjectUtils.is(config);
if (key === undefined || !configIsObject) config = {};
@ -1053,7 +1081,7 @@ module.exports = (_ => {
else {
if (configIsObject) config = BDFDB.ObjectUtils.sort(config);
Cache.data[pluginName] = configIsObject ? BDFDB.ObjectUtils.deepAssign({}, config) : config;
Internal.writeConfig(configPath, config);
Internal.writeConfig(plugin, configPath, config);
}
};
BDFDB.DataUtils.get = function (plugin, key, id) {
@ -3165,6 +3193,7 @@ module.exports = (_ => {
get: function (list, item) {
const user = Internal.LibraryModules.UserStore && Internal.LibraryModules.UserStore.getCurrentUser && Internal.LibraryModules.UserStore.getCurrentUser();
if (user && BDFDB.UserUtils._id != user.id) {
Cache.data = {};
document.body.setAttribute("data-current-user-id", user.id);
BDFDB.UserUtils._id = user.id;
}
@ -3210,10 +3239,7 @@ module.exports = (_ => {
if (!BDFDB.DiscordConstants.Permissions[permission]) BDFDB.LogUtils.warn([permission, "not found in Permissions"]);
else {
let channel = Internal.LibraryModules.ChannelStore.getChannel(channelId);
if (channel) {
try {return Internal.LibraryModules.PermissionRoleUtils.can(BDFDB.DiscordConstants.Permissions[permission], id, channel) || Internal.LibraryModules.PermissionRoleUtils.can({permission: BDFDB.DiscordConstants.Permissions[permission], user: id, context: channel});}
catch (err) {}
}
if (channel) return Internal.LibraryModules.PermissionRoleUtils.can({permission: BDFDB.DiscordConstants.Permissions[permission], user: id, context: channel});
}
return false;
};
@ -9041,7 +9067,8 @@ module.exports = (_ => {
value: Internal.settings.general[key],
nativeValue: nativeSetting,
disabled: disabled
}) : true) && (Internal.settings.general[key] || nativeSetting)
}) : true) && (Internal.settings.general[key] || nativeSetting),
onChange: typeof Internal.defaults.general[key].onChange == "function" ? Internal.defaults.general[key].onChange : (_ => {})
}));
}
settingsItems.push(BDFDB.ReactUtils.createElement(Internal.LibraryComponents.SettingsItem, {

View File

@ -2,7 +2,7 @@
* @name FriendNotifications
* @author DevilBro
* @authorId 278543574059057154
* @version 1.8.1
* @version 1.8.2
* @description Shows a Notification when a Friend or a User, you choose to observe, changes their Status
* @invite Jx3TjNS
* @donate https://www.paypal.me/MircoWittrien
@ -17,13 +17,8 @@ module.exports = (_ => {
"info": {
"name": "FriendNotifications",
"author": "DevilBro",
"version": "1.8.1",
"version": "1.8.2",
"description": "Shows a Notification when a Friend or a User, you choose to observe, changes their Status"
},
"changeLog": {
"fixed": {
"Status Crash": "No longer crashes Discord when clicking on the status notification adn trying to open the DM of a User you don't share a DM with"
}
}
};
@ -206,6 +201,8 @@ module.exports = (_ => {
timeLog = [];
lastTimes = {};
friendCounter = null;
this.neverSyncData = true;
this.defaults = {
general: {
@ -274,7 +271,11 @@ module.exports = (_ => {
}
}
onStart () {
onStart () {
// REMOVE 09.04.2022
let observed = BDFDB.DataUtils.load(this, "observed");
if (observed) BDFDB.DataUtils.save(observed, this, "observed");
this.startInterval();
this.forceUpdateAll();
@ -311,7 +312,7 @@ module.exports = (_ => {
for (let id in specificObserved) specificObserved[id][config] = notificationTypes[disabled ? "DISABLED" : notificationType].value;
}
observed[type] = specificObserved
BDFDB.DataUtils.save(observed, this, "observed", BDFDB.UserUtils.me.id);
BDFDB.DataUtils.save(observed, this, "observed");
this.SettingsUpdated = true;
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
};
@ -430,7 +431,7 @@ module.exports = (_ => {
let data = observed[type][cardData.id] || Object.assign({}, defaultSettings);
data.disabled = !data.disabled;
observed[type][data.id] = data;
BDFDB.DataUtils.save(observed, this, "observed", BDFDB.UserUtils.me.id);
BDFDB.DataUtils.save(observed, this, "observed");
this.SettingsUpdated = true;
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
},
@ -445,7 +446,7 @@ module.exports = (_ => {
}
for (let config in statuses) if (data[config] != notificationTypes.DISABLED.value) data[config] = batchType;
observed[type][data.id] = data;
BDFDB.DataUtils.save(observed, this, "observed", BDFDB.UserUtils.me.id);
BDFDB.DataUtils.save(observed, this, "observed");
this.SettingsUpdated = true;
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
}
@ -465,14 +466,14 @@ module.exports = (_ => {
let data = observed[type][instance.props.cardId] || Object.assign({}, defaultSettings);
data[instance.props.settingId] = value;
observed[type][instance.props.cardId] = data;
BDFDB.DataUtils.save(observed, this, "observed", BDFDB.UserUtils.me.id);
BDFDB.DataUtils.save(observed, this, "observed");
this.SettingsUpdated = true;
},
noRemove: type == "friends",
onRemove: (e, instance) => {
let observed = this.getObservedData();
delete observed[type][instance.props.cardId];
BDFDB.DataUtils.save(observed, this, "observed", BDFDB.UserUtils.me.id);
BDFDB.DataUtils.save(observed, this, "observed");
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
this.SettingsUpdated = true;
}
@ -577,7 +578,7 @@ module.exports = (_ => {
let user = /.+#[0-9]{4}/.test(userId) ? BDFDB.LibraryModules.UserStore.findByTag(userId.split("#").slice(0, -1).join("#"), userId.split("#").pop()) : BDFDB.LibraryModules.UserStore.getUser(userId);
if (user) {
observed.strangers[user.id || userId] = Object.assign({}, defaultSettings);
BDFDB.DataUtils.save(observed, this, "observed", BDFDB.UserUtils.me.id);
BDFDB.DataUtils.save(observed, this, "observed");
BDFDB.PluginUtils.refreshSettingsPanel(this, settingsPanel, collapseStates);
this.SettingsUpdated = true;
}
@ -736,7 +737,7 @@ module.exports = (_ => {
}
getObservedData () {
let observed = Object.assign({friends: {}, strangers: {}}, BDFDB.DataUtils.load(this, "observed", BDFDB.UserUtils.me.id));
let observed = Object.assign({friends: {}, strangers: {}}, BDFDB.DataUtils.load(this, "observed"));
let friendIds = BDFDB.LibraryModules.RelationshipStore.getFriendIDs();
for (let id of friendIds) {
@ -753,7 +754,7 @@ module.exports = (_ => {
delete observed.friends[BDFDB.UserUtils.me.id];
delete observed.strangers[BDFDB.UserUtils.me.id];
BDFDB.DataUtils.save(observed, this, "observed", BDFDB.UserUtils.me.id);
BDFDB.DataUtils.save(observed, this, "observed");
return observed;
}
@ -841,6 +842,7 @@ module.exports = (_ => {
if (observedUsers[id].timelog == undefined || observedUsers[id].timelog) timeLog.unshift({
string: toastString,
avatar: avatar,
id: id,
name: name,
status: statusType,
mobile: status.mobile,
@ -930,7 +932,7 @@ module.exports = (_ => {
BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SearchBar, {
autoFocus: true,
query: "",
onChange: (value, instance) => {
onChange: value => {
BDFDB.TimeUtils.clear(searchTimeout);
searchTimeout = BDFDB.TimeUtils.timeout(_ => {
let searchString = value.toUpperCase();
@ -938,7 +940,7 @@ module.exports = (_ => {
BDFDB.ReactUtils.forceUpdate(timeLogList);
}, 1000);
},
onClear: instance => {
onClear: _ => {
timeLogList.props.entries = timeLog;
BDFDB.ReactUtils.forceUpdate(timeLogList);
}