diff --git a/Plugins/PluginRepo/PluginRepo.plugin.js b/Plugins/PluginRepo/PluginRepo.plugin.js index 01471a82b7..9a2312786b 100644 --- a/Plugins/PluginRepo/PluginRepo.plugin.js +++ b/Plugins/PluginRepo/PluginRepo.plugin.js @@ -2,7 +2,7 @@ * @name PluginRepo * @author DevilBro * @authorId 278543574059057154 - * @version 2.2.2 + * @version 2.2.3 * @description Allows you to download all Plugins from BD's Website within Discord * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -17,15 +17,12 @@ module.exports = (_ => { "info": { "name": "PluginRepo", "author": "DevilBro", - "version": "2.2.2", + "version": "2.2.3", "description": "Allows you to download all Plugins from BD's Website within Discord" }, "changeLog": { - "improved": { - "Thumbnail Conversion": "Moved Thumbnail Conversion to Card Component to reduce stress on BD Website" - }, - "fixed": { - "Settings": "No longer get reset" + "progress": { + "Changed Api": "Preparing Plugin for API Changes" } } }; @@ -103,18 +100,18 @@ module.exports = (_ => { } }; const reverseSorts = [ - "DOWNLOADS", "LIKES", "FAV", "NEW" + "RELEASEDATE", "DOWNLOADS", "LIKES", "FAV" ]; const sortKeys = { NAME: "Name", - AUTHOR: "Author", + AUTHORNAME: "Author", VERSION: "Version", DESCRIPTION: "Description", + RELEASEDATE: "Release Date", STATE: "Update State", DOWNLOADS: "Downloads", LIKES: "Likes", - FAV: "Favorites", - NEW: "New Plugins" + FAV: "Favorites" }; const orderKeys = { ASC: "ascending", @@ -140,7 +137,7 @@ module.exports = (_ => { const installedPlugin = _this.getInstalledPlugin(plugin); const state = installedPlugin ? (plugin.version && BDFDB.NumberUtils.compareVersions(plugin.version, _this.getString(installedPlugin.version)) ? pluginStates.OUTDATED : pluginStates.INSTALLED) : pluginStates.DOWNLOADABLE; return Object.assign(plugin, { - search: [plugin.name, plugin.version, plugin.author, plugin.description, plugin.tags].flat(10).filter(n => typeof n == "string").join(" ").toUpperCase(), + search: [plugin.name, plugin.version, plugin.authorname, plugin.description, plugin.tags].flat(10).filter(n => typeof n == "string").join(" ").toUpperCase(), description: plugin.description || "No Description found", fav: favorites.includes(plugin.id) && 1, new: state == pluginStates.DOWNLOADABLE && !cachedPlugins.includes(plugin.id) && 1, @@ -155,10 +152,9 @@ module.exports = (_ => { plugins = plugins.filter(plugin => plugin.search.indexOf(usedSearchString) > -1); } - const sortKey = !this.props.sortKey || this.props.sortKey == "NEW" && !plugins.some(plugin => plugin.new) ? Object.keys(sortKeys)[0] : this.props.sortKey; - BDFDB.ArrayUtils.keySort(plugins, sortKey.toLowerCase()); + BDFDB.ArrayUtils.keySort(plugins, this.props.sortKey.toLowerCase()); if (this.props.orderKey == "DESC") plugins.reverse(); - if (reverseSorts.includes(sortKey)) plugins.reverse(); + if (reverseSorts.includes(this.props.sortKey)) plugins.reverse(); return plugins; } render() { @@ -326,7 +322,10 @@ module.exports = (_ => { }), BDFDB.ReactUtils.createElement("div", { className: BDFDB.disCN.discoverycardiconwrapper, - children: BDFDB.ReactUtils.createElement("div", { + children: this.props.data.author && this.props.data.author.discord_avatar_hash && this.props.data.author.discord_snowflake ? BDFDB.ReactUtils.createElement("img", { + className: BDFDB.disCN.discoverycardicon, + src: `https://cdn.discordapp.com/avatars/${this.props.data.author.discord_snowflake}/${this.props.data.author.discord_avatar_hash}.webp?size=128` + }) : BDFDB.ReactUtils.createElement("div", { className: BDFDB.disCN.discoverycardicon, children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { nativeClass: true, @@ -360,7 +359,7 @@ module.exports = (_ => { }), BDFDB.ReactUtils.createElement("div", { className: BDFDB.disCN.discoverycardauthor, - children: `by ${this.props.data.author}` + children: `by ${this.props.data.authorname}` }), BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Scrollers.Thin, { className: BDFDB.disCN.discoverycarddescription, @@ -559,7 +558,7 @@ module.exports = (_ => { label: sortKeys[this.props.sortKey], value: this.props.sortKey }, - options: Object.keys(sortKeys).filter(n => n != "NEW" || grabbedPlugins.some(p => !cachedPlugins.includes(p.id))).map(key => ({ + options: Object.keys(sortKeys).map(key => ({ label: sortKeys[key], value: key })), @@ -726,7 +725,7 @@ module.exports = (_ => { const checkPlugin = _ => { if (checksRunning > 20) return; - else if (grabbedPlugins.every(p => p.loaded || !p.latestSourceUrl) || !this.started || !loading.is) { + else if (grabbedPlugins.every(p => p.loaded || (!p.latestSourceUrl && !p.latest_source_url)) || !this.started || !loading.is) { if (!callbackCalled) { callbackCalled = true; if (!this.started) return BDFDB.TimeUtils.clear(loading.timeout); @@ -766,7 +765,7 @@ module.exports = (_ => { contents: BDFDB.LanguageUtils.LanguageStrings.OPEN, close: true, onClick: _ => { - forcedSort = "NEW"; + forcedSort = "RELEASEDATE"; forcedOrder = "ASC"; BDFDB.LibraryModules.UserSettingsUtils.open("pluginrepo"); } @@ -779,15 +778,21 @@ module.exports = (_ => { else if (checkIndex > grabbedPlugins.length) return; const plugin = grabbedPlugins[checkIndex++]; - if (!plugin || !plugin.latestSourceUrl) checkPlugin(); + if (!plugin || (!plugin.latestSourceUrl && !plugin.latest_source_url)) checkPlugin(); else { checksRunning++; + plugin.releasedate = new Date(plugin.releaseDate || plugin.release_date || 0).getTime(); + plugin.latestSourceUrl = plugin.latestSourceUrl || plugin.latest_source_url; plugin.rawSourceUrl = plugin.latestSourceUrl.replace("https://github.com/", "https://raw.githubusercontent.com/").replace(/\/blob\/(.{32,})/i, "/$1"); + plugin.thumbnailUrl = plugin.thumbnailUrl || plugin.thumbnail_url; plugin.thumbnailUrl = plugin.thumbnailUrl ? (plugin.thumbnailUrl.startsWith("https://") ? plugin.thumbnailUrl : `https://betterdiscord.app${plugin.thumbnailUrl}`) : ""; + 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) { plugin.name = BDFDB.LibraryModules.StringUtils.upperCaseFirstChar((/@name\s+([^\s^\t^\r^\n]+)|\/\/\**META.*["']name["']\s*:\s*["'](.+?)["']/i.exec(body) || []).filter(n => n)[1] || plugin.name || ""); - plugin.author = (/@author\s+(.+)|\/\/\**META.*["']author["']\s*:\s*["'](.+?)["']/i.exec(body) || []).filter(n => n)[1] || plugin.author; + plugin.authorname = (/@author\s+(.+)|\/\/\**META.*["']author["']\s*:\s*["'](.+?)["']/i.exec(body) || []).filter(n => n)[1] || plugin.author.display_name || plugin.author; const version = (/@version\s+(.+)|\/\/\**META.*["']version["']\s*:\s*["'](.+?)["']/i.exec(body) || []).filter(n => n)[1]; if (version) { plugin.version = version; @@ -856,12 +861,12 @@ module.exports = (_ => { } getInstalledPlugin (plugin) { - if (!plugin || typeof plugin.author != "string") return; + if (!plugin || typeof plugin.authorname != "string") return; const iPlugin = BDFDB.BDUtils.getPlugin(plugin.name, false, true); - if (iPlugin && plugin.author.toUpperCase() == this.getString(iPlugin.author).toUpperCase()) return iPlugin; + if (iPlugin && plugin.authorname.toUpperCase() == this.getString(iPlugin.author).toUpperCase()) return iPlugin; else if (plugin.rawSourceUrl && window.BdApi && BdApi.Plugins && typeof BdApi.Plugins.getAll == "function") { const filename = plugin.rawSourceUrl.split("/").pop(); - for (let p of BdApi.Plugins.getAll()) if (p.filename == filename && plugin.author.toUpperCase() == this.getString(p.author).toUpperCase()) return p; + for (let p of BdApi.Plugins.getAll()) if (p.filename == filename && plugin.authorname.toUpperCase() == this.getString(p.author).toUpperCase()) return p; } } diff --git a/Plugins/ThemeRepo/ThemeRepo.plugin.js b/Plugins/ThemeRepo/ThemeRepo.plugin.js index ced4eb08ac..2e0833b10e 100644 --- a/Plugins/ThemeRepo/ThemeRepo.plugin.js +++ b/Plugins/ThemeRepo/ThemeRepo.plugin.js @@ -2,7 +2,7 @@ * @name ThemeRepo * @author DevilBro * @authorId 278543574059057154 - * @version 2.2.2 + * @version 2.2.3 * @description Allows you to download all Themes from BD's Website within Discord * @invite Jx3TjNS * @donate https://www.paypal.me/MircoWittrien @@ -17,15 +17,12 @@ module.exports = (_ => { "info": { "name": "ThemeRepo", "author": "DevilBro", - "version": "2.2.2", + "version": "2.2.3", "description": "Allows you to download all Themes from BD's Website within Discord" }, "changeLog": { - "improved": { - "Thumbnail Conversion": "Moved Thumbnail Conversion to Card Component to reduce stress on BD Website" - }, - "fixed": { - "Settings": "No longer get reset" + "progress": { + "Changed Api": "Preparing Plugin for API Changes" } } }; @@ -104,18 +101,18 @@ module.exports = (_ => { } }; const reverseSorts = [ - "DOWNLOADS", "LIKES", "FAV", "NEW" + "RELEASEDATE", "DOWNLOADS", "LIKES", "FAV" ]; const sortKeys = { NAME: "Name", - AUTHOR: "Author", + AUTHORNAME: "Author", VERSION: "Version", DESCRIPTION: "Description", + RELEASEDATE: "Release Date", STATE: "Update State", DOWNLOADS: "Downloads", LIKES: "Likes", - FAV: "Favorites", - NEW: "New Themes" + FAV: "Favorites" }; const orderKeys = { ASC: "ascending", @@ -142,7 +139,7 @@ module.exports = (_ => { const installedTheme = _this.getInstalledTheme(theme); const state = installedTheme ? (theme.version && BDFDB.NumberUtils.compareVersions(theme.version, _this.getString(installedTheme.version)) ? themeStates.OUTDATED : themeStates.INSTALLED) : themeStates.DOWNLOADABLE; return Object.assign(theme, { - search: [theme.name, theme.version, theme.author, theme.description, theme.tags].flat(10).filter(n => typeof n == "string").join(" ").toUpperCase(), + search: [theme.name, theme.version, theme.authorname, theme.description, theme.tags].flat(10).filter(n => typeof n == "string").join(" ").toUpperCase(), description: theme.description || "No Description found", fav: favorites.includes(theme.id) && 1, new: state == themeStates.DOWNLOADABLE && !cachedThemes.includes(theme.id) && 1, @@ -157,10 +154,9 @@ module.exports = (_ => { themes = themes.filter(theme => theme.search.indexOf(usedSearchString) > -1); } - const sortKey = !this.props.sortKey || this.props.sortKey == "NEW" && !themes.some(theme => theme.new) ? Object.keys(sortKeys)[0] : this.props.sortKey; - BDFDB.ArrayUtils.keySort(themes, sortKey.toLowerCase()); + BDFDB.ArrayUtils.keySort(themes, this.props.sortKey.toLowerCase()); if (this.props.orderKey == "DESC") themes.reverse(); - if (reverseSorts.includes(sortKey)) themes.reverse(); + if (reverseSorts.includes(this.props.sortKey)) themes.reverse(); return themes; } openPreview() { @@ -523,7 +519,7 @@ module.exports = (_ => { mode: childMode, filter: childType == "file" && "image" }, - label: varName[0].toUpperCase() + varName.slice(1), + label: varName.split("-").map(BDFDB.LibraryModules.StringUtils.upperCaseFirstChar).join(" "), note: varDescription && varDescription.indexOf("*") == 0 ? varDescription.slice(1) : varDescription, basis: "70%", value: oldValue, @@ -731,7 +727,10 @@ module.exports = (_ => { }), BDFDB.ReactUtils.createElement("div", { className: BDFDB.disCN.discoverycardiconwrapper, - children: BDFDB.ReactUtils.createElement("div", { + children: this.props.data.author && this.props.data.author.discord_avatar_hash && this.props.data.author.discord_snowflake ? BDFDB.ReactUtils.createElement("img", { + className: BDFDB.disCN.discoverycardicon, + src: `https://cdn.discordapp.com/avatars/${this.props.data.author.discord_snowflake}/${this.props.data.author.discord_avatar_hash}.webp?size=128` + }) : BDFDB.ReactUtils.createElement("div", { className: BDFDB.disCN.discoverycardicon, children: BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.SvgIcon, { nativeClass: true, @@ -793,7 +792,7 @@ module.exports = (_ => { }), BDFDB.ReactUtils.createElement("div", { className: BDFDB.disCN.discoverycardauthor, - children: `by ${this.props.data.author}` + children: `by ${this.props.data.authorname}` }), BDFDB.ReactUtils.createElement(BDFDB.LibraryComponents.Scrollers.Thin, { className: BDFDB.disCN.discoverycarddescription, @@ -978,7 +977,7 @@ module.exports = (_ => { label: sortKeys[this.props.sortKey], value: this.props.sortKey }, - options: Object.keys(sortKeys).filter(n => n != "NEW" || grabbedThemes.some(t => !cachedThemes.includes(t.id))).map(key => ({ + options: Object.keys(sortKeys).map(key => ({ label: sortKeys[key], value: key })), @@ -1243,7 +1242,7 @@ module.exports = (_ => { const checkTheme = _ => { if (checksRunning > 20) return; - else if (grabbedThemes.every(t => t.loaded || !t.latestSourceUrl) || !this.started || !loading.is) { + else if (grabbedThemes.every(t => t.loaded || (!t.latestSourceUrl && !t.latest_source_url)) || !this.started || !loading.is) { if (!callbackCalled) { callbackCalled = true; if (!this.started) return BDFDB.TimeUtils.clear(loading.timeout); @@ -1283,7 +1282,7 @@ module.exports = (_ => { contents: BDFDB.LanguageUtils.LanguageStrings.OPEN, close: true, onClick: _ => { - forcedSort = "NEW"; + forcedSort = "RELEASEDATE"; forcedOrder = "ASC"; BDFDB.LibraryModules.UserSettingsUtils.open("themerepo"); } @@ -1313,15 +1312,21 @@ module.exports = (_ => { else if (checkIndex > grabbedThemes.length) return; const theme = grabbedThemes[checkIndex++]; - if (!theme || !theme.latestSourceUrl) checkTheme(); + if (!theme || (!theme.latestSourceUrl && !theme.latest_source_url)) checkTheme(); else { checksRunning++; + theme.releasedate = new Date(theme.releaseDate || theme.release_date || 0).getTime(); + theme.latestSourceUrl = theme.latestSourceUrl || theme.latest_source_url; theme.rawSourceUrl = theme.latestSourceUrl.replace("https://github.com/", "https://raw.githubusercontent.com/").replace(/\/blob\/(.{32,})/i, "/$1"); + theme.thumbnailUrl = theme.thumbnailUrl || theme.thumbnail_url; theme.thumbnailUrl = theme.thumbnailUrl ? (theme.thumbnailUrl.startsWith("https://") ? theme.thumbnailUrl : `https://betterdiscord.app${theme.thumbnailUrl}`) : ""; + 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) { theme.name = BDFDB.LibraryModules.StringUtils.upperCaseFirstChar((/@name\s+([^\s^\t^\r^\n]+)|\/\/\**META.*["']name["']\s*:\s*["'](.+?)["']/i.exec(body) || []).filter(n => n)[1] || theme.name || ""); - theme.author = (/@author\s+(.+)|\/\/\**META.*["']author["']\s*:\s*["'](.+?)["']/i.exec(body) || []).filter(n => n)[1] || theme.author; + theme.authorname = (/@author\s+(.+)|\/\/\**META.*["']author["']\s*:\s*["'](.+?)["']/i.exec(body) || []).filter(n => n)[1] || theme.author.display_name || theme.author; const version = (/@version\s+(.+)|\/\/\**META.*["']version["']\s*:\s*["'](.+?)["']/i.exec(body) || []).filter(n => n)[1]; if (version) { theme.version = version; @@ -1410,12 +1415,12 @@ module.exports = (_ => { } getInstalledTheme (theme) { - if (!theme || typeof theme.author != "string") return; + if (!theme || typeof theme.authoName != "string") return; const iTheme = BDFDB.BDUtils.getTheme(theme.name, false, true); - if (iTheme && theme.author.toUpperCase() == this.getString(iTheme.author).toUpperCase()) return iTheme; + if (iTheme && theme.authorname.toUpperCase() == this.getString(iTheme.author).toUpperCase()) return iTheme; else if (theme.rawSourceUrl && window.BdApi && BdApi.Themes && typeof BdApi.Themes.getAll == "function") { const filename = theme.rawSourceUrl.split("/").pop(); - for (let t of BdApi.Themes.getAll()) if (t.filename == filename && theme.author.toUpperCase() == this.getString(t.author).toUpperCase()) return t; + for (let t of BdApi.Themes.getAll()) if (t.filename == filename && theme.authorname.toUpperCase() == this.getString(t.author).toUpperCase()) return t; } }