Repo Updates
This commit is contained in:
parent
761ae7beeb
commit
d3cb62b46a
|
@ -2,7 +2,7 @@
|
|||
* @name PluginRepo
|
||||
* @author DevilBro
|
||||
* @authorId 278543574059057154
|
||||
* @version 2.4.2
|
||||
* @version 2.4.3
|
||||
* @description Allows you to download all Plugins from BD's Website within Discord
|
||||
* @invite Jx3TjNS
|
||||
* @donate https://www.paypal.me/MircoWittrien
|
||||
|
@ -122,6 +122,7 @@ module.exports = (_ => {
|
|||
}
|
||||
filterPlugins() {
|
||||
let plugins = grabbedPlugins.map(plugin => {
|
||||
if (plugin.failed) return;
|
||||
const installedPlugin = _this.getInstalledPlugin(plugin);
|
||||
const state = installedPlugin ? (plugin.version && _this.compareVersions(plugin.version, _this.getString(installedPlugin.version)) ? pluginStates.OUTDATED : pluginStates.INSTALLED) : pluginStates.DOWNLOADABLE;
|
||||
return Object.assign(plugin, {
|
||||
|
@ -131,7 +132,7 @@ module.exports = (_ => {
|
|||
new: state == pluginStates.DOWNLOADABLE && !cachedPlugins.includes(plugin.id) && 1,
|
||||
state: state
|
||||
});
|
||||
});
|
||||
}).filter(n => n);
|
||||
if (!this.props.updated) plugins = plugins.filter(plugin => plugin.state != pluginStates.INSTALLED);
|
||||
if (!this.props.outdated) plugins = plugins.filter(plugin => plugin.state != pluginStates.OUTDATED);
|
||||
if (!this.props.downloadable) plugins = plugins.filter(plugin => plugin.state != pluginStates.DOWNLOADABLE);
|
||||
|
@ -483,30 +484,28 @@ module.exports = (_ => {
|
|||
this.props.downloading = true;
|
||||
let loadingToast = BDFDB.NotificationUtils.toast(`${BDFDB.LanguageUtils.LibraryStringsFormat("loading", this.props.data.name)} - ${BDFDB.LanguageUtils.LibraryStrings.please_wait}`, {timeout: 0, ellipsis: true});
|
||||
let autoloadKey = this.props.data.state == pluginStates.OUTDATED ? "startUpdated" : "startDownloaded";
|
||||
BDFDB.LibraryRequires.request(this.props.data.rawSourceUrl, (error, response, body) => {
|
||||
if (error) {
|
||||
BDFDB.DiscordUtils.requestFileData(this.props.data.rawSourceUrl, {timeout: 10000}, (error, buffer) => {
|
||||
if (error || !buffer) {
|
||||
delete this.props.downloading;
|
||||
loadingToast.close();
|
||||
BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("download_fail", `Plugin "${this.props.data.name}"`), {type: "danger"});
|
||||
}
|
||||
else {
|
||||
BDFDB.LibraryRequires.fs.writeFile(BDFDB.LibraryRequires.path.join(BDFDB.BDUtils.getPluginsFolder(), this.props.data.rawSourceUrl.split("/").pop()), body, error2 => {
|
||||
delete this.props.downloading;
|
||||
loadingToast.close();
|
||||
if (error2) BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("save_fail", `Plugin "${this.props.data.name}"`), {type: "danger"});
|
||||
else {
|
||||
BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("save_success", `Plugin "${this.props.data.name}"`), {type: "success"});
|
||||
if (_this.settings.general[autoloadKey]) BDFDB.TimeUtils.timeout(_ => {
|
||||
if (this.props.data.state == pluginStates.INSTALLED && BDFDB.BDUtils.isPluginEnabled(this.props.data.name) == false) {
|
||||
BDFDB.BDUtils.enablePlugin(this.props.data.name, false);
|
||||
BDFDB.LogUtils.log(BDFDB.LanguageUtils.LibraryStringsFormat("toast_plugin_started", this.props.data.name), _this);
|
||||
}
|
||||
}, 3000);
|
||||
this.props.data.state = pluginStates.INSTALLED;
|
||||
BDFDB.ReactUtils.forceUpdate(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
else BDFDB.LibraryRequires.fs.writeFile(BDFDB.LibraryRequires.path.join(BDFDB.BDUtils.getPluginsFolder(), this.props.data.rawSourceUrl.split("/").pop()), Buffer.from(buffer).toString(), error2 => {
|
||||
delete this.props.downloading;
|
||||
loadingToast.close();
|
||||
if (error2) BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("save_fail", `Plugin "${this.props.data.name}"`), {type: "danger"});
|
||||
else {
|
||||
BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("save_success", `Plugin "${this.props.data.name}"`), {type: "success"});
|
||||
if (_this.settings.general[autoloadKey]) BDFDB.TimeUtils.timeout(_ => {
|
||||
if (this.props.data.state == pluginStates.INSTALLED && BDFDB.BDUtils.isPluginEnabled(this.props.data.name) == false) {
|
||||
BDFDB.BDUtils.enablePlugin(this.props.data.name, false);
|
||||
BDFDB.LogUtils.log(BDFDB.LanguageUtils.LibraryStringsFormat("toast_plugin_started", this.props.data.name), _this);
|
||||
}
|
||||
}, 3000);
|
||||
this.props.data.state = pluginStates.INSTALLED;
|
||||
BDFDB.ReactUtils.forceUpdate(this);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
onDelete: _ => {
|
||||
|
@ -579,10 +578,10 @@ module.exports = (_ => {
|
|||
|
||||
this.defaults = {
|
||||
general: {
|
||||
notifyOutdated: {value: true, autoload: false, description: "Get a Notification when one of your Plugins is outdated"},
|
||||
notifyNewEntries: {value: true, autoload: false, description: "Get a Notification when there are new Entries in the Repo"},
|
||||
startDownloaded: {value: false, autoload: true, description: "Start new Plugins after Download"},
|
||||
startUpdated: {value: false, autoload: true, description: "Start updated Plugins after Download"}
|
||||
notifyOutdated: {value: true, autoload: false, description: "Shows a Notification when one of your Plugins is outdated"},
|
||||
notifyNewEntries: {value: true, autoload: false, description: "Shows a Notification when there are new Entries in the Repo"},
|
||||
startDownloaded: {value: false, autoload: true, description: "Starts new Plugins after Download"},
|
||||
startUpdated: {value: false, autoload: true, description: "Starts updated Plugins after Download"}
|
||||
},
|
||||
filters: {
|
||||
updated: {value: true, description: "Updated"},
|
||||
|
@ -755,19 +754,23 @@ module.exports = (_ => {
|
|||
delete plugin.release_date;
|
||||
delete plugin.latest_source_url;
|
||||
delete plugin.thumbnail_url;
|
||||
BDFDB.LibraryRequires.request(plugin.rawSourceUrl, (error, response, body) => {
|
||||
if (body && body.indexOf("404: Not Found") != 0 && response.statusCode == 200) {
|
||||
const META = body.split("*/")[0];
|
||||
plugin.name = BDFDB.StringUtils.upperCaseFirstChar((/@name\s+([^\t^\r^\n]+)|\/\/\**META.*["']name["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1] || plugin.name || "");
|
||||
plugin.authorname = (/@author\s+(.+)|\/\/\**META.*["']author["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1] || plugin.author.display_name || plugin.author;
|
||||
const version = (/@version\s+(.+)|\/\/\**META.*["']version["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1];
|
||||
if (version) {
|
||||
plugin.version = version;
|
||||
const installedPlugin = this.getInstalledPlugin(plugin);
|
||||
if (installedPlugin && this.compareVersions(version, this.getString(installedPlugin.version))) outdatedEntries++;
|
||||
BDFDB.DiscordUtils.requestFileData(plugin.rawSourceUrl, {timeout: 10000}, (error, buffer) => {
|
||||
if (error || !buffer) plugin.failed = true;
|
||||
else {
|
||||
let body = Buffer.from(buffer).toString();
|
||||
if (body && body.indexOf("404: Not Found") != 0) {
|
||||
const META = body.split("*/")[0];
|
||||
plugin.name = BDFDB.StringUtils.upperCaseFirstChar((/@name\s+([^\t^\r^\n]+)|\/\/\**META.*["']name["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1] || plugin.name || "");
|
||||
plugin.authorname = (/@author\s+(.+)|\/\/\**META.*["']author["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1] || plugin.author.display_name || plugin.author;
|
||||
const version = (/@version\s+(.+)|\/\/\**META.*["']version["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1];
|
||||
if (version) {
|
||||
plugin.version = version;
|
||||
const installedPlugin = this.getInstalledPlugin(plugin);
|
||||
if (installedPlugin && this.compareVersions(version, this.getString(installedPlugin.version))) outdatedEntries++;
|
||||
}
|
||||
}
|
||||
if (!cachedPlugins.includes(plugin.id)) newEntries++;
|
||||
}
|
||||
if (!cachedPlugins.includes(plugin.id)) newEntries++;
|
||||
|
||||
plugin.loaded = true;
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* @name ThemeRepo
|
||||
* @author DevilBro
|
||||
* @authorId 278543574059057154
|
||||
* @version 2.4.4
|
||||
* @version 2.4.5
|
||||
* @description Allows you to download all Themes from BD's Website within Discord
|
||||
* @invite Jx3TjNS
|
||||
* @donate https://www.paypal.me/MircoWittrien
|
||||
|
@ -123,6 +123,7 @@ module.exports = (_ => {
|
|||
}
|
||||
filterThemes() {
|
||||
let themes = grabbedThemes.map(theme => {
|
||||
if (theme.failed) return;
|
||||
const installedTheme = _this.getInstalledTheme(theme);
|
||||
const state = installedTheme ? (theme.version && _this.compareVersions(theme.version, _this.getString(installedTheme.version)) ? themeStates.OUTDATED : themeStates.INSTALLED) : themeStates.DOWNLOADABLE;
|
||||
return Object.assign(theme, {
|
||||
|
@ -132,7 +133,7 @@ module.exports = (_ => {
|
|||
new: state == themeStates.DOWNLOADABLE && !cachedThemes.includes(theme.id) && 1,
|
||||
state: state
|
||||
});
|
||||
});
|
||||
}).filter(n => n);
|
||||
if (!this.props.updated) themes = themes.filter(theme => theme.state != themeStates.INSTALLED);
|
||||
if (!this.props.outdated) themes = themes.filter(theme => theme.state != themeStates.OUTDATED);
|
||||
if (!this.props.downloadable) themes = themes.filter(theme => theme.state != themeStates.DOWNLOADABLE);
|
||||
|
@ -631,8 +632,8 @@ module.exports = (_ => {
|
|||
this.props.downloading = true;
|
||||
let loadingToast = BDFDB.NotificationUtils.toast(`${BDFDB.LanguageUtils.LibraryStringsFormat("loading", this.props.data.name)} - ${BDFDB.LanguageUtils.LibraryStrings.please_wait}`, {timeout: 0, ellipsis: true});
|
||||
let autoloadKey = this.props.data.state == themeStates ? "startUpdated" : "startDownloaded";
|
||||
BDFDB.LibraryRequires.request(this.props.data.rawSourceUrl, (error, response, body) => {
|
||||
if (error) {
|
||||
BDFDB.DiscordUtils.requestFileData(this.props.data.rawSourceUrl, {timeout: 10000}, (error, buffer) => {
|
||||
if (error || !buffer) {
|
||||
delete this.props.downloading;
|
||||
loadingToast.close();
|
||||
BDFDB.NotificationUtils.toast(BDFDB.LanguageUtils.LibraryStringsFormat("download_fail", `Theme "${this.props.data.name}"`), {type: "danger"});
|
||||
|
@ -718,10 +719,10 @@ module.exports = (_ => {
|
|||
|
||||
this.defaults = {
|
||||
general: {
|
||||
notifyOutdated: {value: true, autoload: false, description: "Get a Notification when one of your Themes is outdated"},
|
||||
notifyNewEntries: {value: true, autoload: false, description: "Get a Notification when there are new Entries in the Repo"},
|
||||
startDownloaded: {value: false, autoload: true, description: "Start new Themes after Download"},
|
||||
startUpdated: {value: false, autoload: true, description: "Start updated Themes after Download"}
|
||||
notifyOutdated: {value: true, autoload: false, description: "Shows a Notification when one of your Themes is outdated"},
|
||||
notifyNewEntries: {value: true, autoload: false, description: "Shows a Notification when there are new Entries in the Repo"},
|
||||
startDownloaded: {value: false, autoload: true, description: "Starts new Themes after Download"},
|
||||
startUpdated: {value: false, autoload: true, description: "Starts updated Themes after Download"}
|
||||
},
|
||||
filters: {
|
||||
updated: {value: true, description: "Updated"},
|
||||
|
@ -886,16 +887,17 @@ module.exports = (_ => {
|
|||
});
|
||||
}
|
||||
|
||||
BDFDB.LibraryRequires.request("https://mwittrien.github.io/BetterDiscordAddons/Plugins/ThemeRepo/_res/GeneratorList.txt", (error, response, body) => {
|
||||
if (!error && body) for (let id of body.replace(/[\r\t]/g, "").split(" ").map(n => parseInt(n)).filter(n => n != null)) {
|
||||
BDFDB.DiscordUtils.requestFileData("https://mwittrien.github.io/BetterDiscordAddons/Plugins/ThemeRepo/_res/GeneratorList.txt", {timeout: 10000}, (error, buffer) => {
|
||||
let body = !error && buffer && Buffer.from(buffer).toString();
|
||||
if (body) for (let id of body.replace(/[\r\t]/g, "").split(" ").map(n => parseInt(n)).filter(n => n != null)) {
|
||||
let theme = grabbedThemes.find(t => t.id == id);
|
||||
if (theme) generatorThemes.push(theme);
|
||||
}
|
||||
});
|
||||
|
||||
BDFDB.LibraryRequires.request(document.querySelector("head link[rel='stylesheet'][integrity]").href, (error, response, body) => {
|
||||
if (!error && body) {
|
||||
nativeCSS = body;
|
||||
BDFDB.DiscordUtils.requestFileData(document.querySelector("head link[rel='stylesheet'][integrity]").href, {timeout: 10000}, (error, buffer) => {
|
||||
let nativeCSS = !error && buffer && Buffer.from(buffer).toString();
|
||||
if (nativeCSS) {
|
||||
let theme = BDFDB.DiscordUtils.getTheme();
|
||||
let vars = (nativeCSS.split(`.${theme}{`)[1] || "").split("}")[0];
|
||||
nativeCSSvars = vars ? `.theme-dark, .theme-light {${vars}}` : "";
|
||||
|
@ -919,39 +921,43 @@ module.exports = (_ => {
|
|||
delete theme.release_date;
|
||||
delete theme.latest_source_url;
|
||||
delete theme.thumbnail_url;
|
||||
BDFDB.LibraryRequires.request(theme.rawSourceUrl, (error, response, body) => {
|
||||
if (body && body.indexOf("404: Not Found") != 0 && response.statusCode == 200) {
|
||||
const META = body.split("*/")[0];
|
||||
theme.name = BDFDB.StringUtils.upperCaseFirstChar((/@name\s+([^\t^\r^\n]+)|\/\/\**META.*["']name["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1] || theme.name || "");
|
||||
theme.authorname = (/@author\s+(.+)|\/\/\**META.*["']author["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1] || theme.author.display_name || theme.author;
|
||||
const version = (/@version\s+(.+)|\/\/\**META.*["']version["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1];
|
||||
if (version) theme.version = version;
|
||||
if (theme.version) {
|
||||
const installedTheme = this.getInstalledTheme(theme);
|
||||
if (installedTheme && this.compareVersions(version, this.getString(installedTheme.version))) outdatedEntries++;
|
||||
}
|
||||
let text = body.trim();
|
||||
let hasMETAline = text.replace(/\s/g, "").indexOf("//META{"), newMeta = "";
|
||||
if (hasMETAline < 20 && hasMETAline > -1) {
|
||||
let i = 0, j = 0, metaString = "";
|
||||
try {
|
||||
for (let c of `{${text.split("{").slice(1).join("{")}`) {
|
||||
metaString += c;
|
||||
if (c == "{") i++;
|
||||
else if (c == "}") j++;
|
||||
if (i > 0 && i == j) break;
|
||||
}
|
||||
let metaObj = JSON.parse(metaString);
|
||||
newMeta = "/**\n";
|
||||
for (let key in metaObj) newMeta += ` * @${key} ${metaObj[key]}\n`;
|
||||
newMeta += "*/";
|
||||
BDFDB.DiscordUtils.requestFileData(theme.rawSourceUrl, {timeout: 10000}, (error, buffer) => {
|
||||
if (error || !buffer) theme.failed = true;
|
||||
else {
|
||||
let body = Buffer.from(buffer).toString();
|
||||
if (body && body.indexOf("404: Not Found") != 0) {
|
||||
const META = body.split("*/")[0];
|
||||
theme.name = BDFDB.StringUtils.upperCaseFirstChar((/@name\s+([^\t^\r^\n]+)|\/\/\**META.*["']name["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1] || theme.name || "");
|
||||
theme.authorname = (/@author\s+(.+)|\/\/\**META.*["']author["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1] || theme.author.display_name || theme.author;
|
||||
const version = (/@version\s+(.+)|\/\/\**META.*["']version["']\s*:\s*["'](.+?)["']/i.exec(META) || []).filter(n => n)[1];
|
||||
if (version) theme.version = version;
|
||||
if (theme.version) {
|
||||
const installedTheme = this.getInstalledTheme(theme);
|
||||
if (installedTheme && this.compareVersions(version, this.getString(installedTheme.version))) outdatedEntries++;
|
||||
}
|
||||
catch (err) {newMeta = "";}
|
||||
let text = body.trim();
|
||||
let hasMETAline = text.replace(/\s/g, "").indexOf("//META{"), newMeta = "";
|
||||
if (hasMETAline < 20 && hasMETAline > -1) {
|
||||
let i = 0, j = 0, metaString = "";
|
||||
try {
|
||||
for (let c of `{${text.split("{").slice(1).join("{")}`) {
|
||||
metaString += c;
|
||||
if (c == "{") i++;
|
||||
else if (c == "}") j++;
|
||||
if (i > 0 && i == j) break;
|
||||
}
|
||||
let metaObj = JSON.parse(metaString);
|
||||
newMeta = "/**\n";
|
||||
for (let key in metaObj) newMeta += ` * @${key} ${metaObj[key]}\n`;
|
||||
newMeta += "*/";
|
||||
}
|
||||
catch (err) {newMeta = "";}
|
||||
}
|
||||
theme.fullCSS = [newMeta, newMeta ? text.split("\n").slice(1).join("\n") : text].filter(n => n).join("\n");
|
||||
theme.css = (hasMETAline < 20 && hasMETAline > -1 ? text.split("\n").slice(1).join("\n") : text).replace(/[\r|\n|\t]/g, "");
|
||||
}
|
||||
theme.fullCSS = [newMeta, newMeta ? text.split("\n").slice(1).join("\n") : text].filter(n => n).join("\n");
|
||||
theme.css = (hasMETAline < 20 && hasMETAline > -1 ? text.split("\n").slice(1).join("\n") : text).replace(/[\r|\n|\t]/g, "");
|
||||
if (!cachedThemes.includes(theme.id)) newEntries++;
|
||||
}
|
||||
if (!cachedThemes.includes(theme.id)) newEntries++;
|
||||
|
||||
theme.loaded = true;
|
||||
|
||||
|
|
Loading…
Reference in New Issue