diff --git a/ShowHiddenChannels.plugin.js b/ShowHiddenChannels.plugin.js index 591954d..ef9c7de 100644 --- a/ShowHiddenChannels.plugin.js +++ b/ShowHiddenChannels.plugin.js @@ -1,7 +1,7 @@ /** * @name ShowHiddenChannels * @displayName Show Hidden Channels (SHC) - * @version 0.5.3 + * @version 0.5.4 * @author JustOptimize (Oggetto) * @authorId 619203349954166804 * @source https://github.com/JustOptimize/ShowHiddenChannels @@ -901,11 +901,17 @@ const config = { ], description: "A plugin which displays all hidden Channels and allows users to view information about them, this won't allow you to read them (impossible).", - version: "0.5.3", + version: "0.5.4", github: 'https://github.com/JustOptimize/ShowHiddenChannels', }, changelog: [ + { + title: 'v0.5.4 - Fix Crash', + items: [ + 'Fix Crash when muting/unmuting specific servers. (#214)', + ], + }, { title: 'v0.5.3 - Module Fix', items: [ @@ -918,13 +924,6 @@ const config = { 'Fixed the plugin not working due to a module not being found.', ], }, - { - title: 'v0.5.1 - Refactor & Update System', - items: [ - 'Now using github releases tags to check for updates.', - 'Remove "return-" from the plugin name to avoid confusion.', - ], - }, ], main: 'ShowHiddenChannels.plugin.js', @@ -1600,6 +1599,7 @@ class MissingZeresDummy { HiddenCategory.channels = Object.fromEntries( Object.entries(HiddenChannels.records).map(([id, channel]) => { channel.category = HiddenCategory; + channel.record.parent_id = hiddenCategoryId; return [id, channel]; }) ); @@ -1701,28 +1701,38 @@ class MissingZeresDummy { } for (const category of categories) { - // Get the channels that are hidden - const newHiddenChannels = Object.entries(category.channels).filter(([channelId]) => - hiddenChannels.channels.some((channel) => channel.id === channelId) - ); - - // Add the channels to the cache and remove them from the original category - for (const [channelId, channel] of newHiddenChannels) { - const isCached = this.hiddenChannelCache[guildId].some(([cachedChannelId]) => cachedChannelId === channelId); - - if (!isCached) { - this.hiddenChannelCache[guildId].push([channelId, channel]); - } + const channelRecords = Object.entries(category.channels); + const filteredChannelRecords = channelRecords + .map( + ([channelID, channelRecord]) => { + if (hiddenChannels.channels.some((m) => m.id === channelID)) { + if (!this.hiddenChannelCache[guildId].some((m) => m[0] === channelID)) { + this.hiddenChannelCache[guildId].push([channelID, channelRecord]); + } + return false; + } + return [channelID, channelRecord]; + } + ) + .filter(Boolean); - // Remove the channel from original category - delete category.channels[channelId]; + category.channels = Object.fromEntries(filteredChannelRecords); + if (category.hiddenChannelIds) { + category.hiddenChannelIds = category.hiddenChannelIds.filter((v) => + filteredChannelRecords.some(([id]) => id == v) + ); + } + + if (category.shownChannelIds) { + category.shownChannelIds = category.shownChannelIds.filter((v) => + filteredChannelRecords.some(([id]) => id == v) + ); } } return { records: Object.fromEntries(this.hiddenChannelCache[guildId]), - channels: hiddenChannels ? hiddenChannels.channels : [], - amount: hiddenChannels ? hiddenChannels.amount : 0, + ...hiddenChannels, }; } diff --git a/src/config.json b/src/config.json index 655e2b8..2e44312 100644 --- a/src/config.json +++ b/src/config.json @@ -1,7 +1,7 @@ { "name": "ShowHiddenChannels", "displayName": "Show Hidden Channels (SHC)", - "version": "0.5.3", + "version": "0.5.4", "author": "JustOptimize (Oggetto)", "authorId": "619203349954166804", "source": "https://github.com/JustOptimize/ShowHiddenChannels", diff --git a/src/index.js b/src/index.js index 8cc2f14..7a24b7b 100644 --- a/src/index.js +++ b/src/index.js @@ -15,6 +15,12 @@ const config = { }, changelog: [ + { + title: 'v0.5.4 - Fix Crash', + items: [ + 'Fix Crash when muting/unmuting specific servers. (#214)', + ], + }, { title: 'v0.5.3 - Module Fix', items: [ @@ -27,13 +33,6 @@ const config = { 'Fixed the plugin not working due to a module not being found.', ], }, - { - title: 'v0.5.1 - Refactor & Update System', - items: [ - 'Now using github releases tags to check for updates.', - 'Remove "return-" from the plugin name to avoid confusion.', - ], - }, ], main: 'ShowHiddenChannels.plugin.js', @@ -709,6 +708,7 @@ export default !global.ZeresPluginLibrary HiddenCategory.channels = Object.fromEntries( Object.entries(HiddenChannels.records).map(([id, channel]) => { channel.category = HiddenCategory; + channel.record.parent_id = hiddenCategoryId; return [id, channel]; }) ); @@ -810,28 +810,38 @@ export default !global.ZeresPluginLibrary } for (const category of categories) { - // Get the channels that are hidden - const newHiddenChannels = Object.entries(category.channels).filter(([channelId]) => - hiddenChannels.channels.some((channel) => channel.id === channelId) - ); - - // Add the channels to the cache and remove them from the original category - for (const [channelId, channel] of newHiddenChannels) { - const isCached = this.hiddenChannelCache[guildId].some(([cachedChannelId]) => cachedChannelId === channelId); - - if (!isCached) { - this.hiddenChannelCache[guildId].push([channelId, channel]); - } + const channelRecords = Object.entries(category.channels); + const filteredChannelRecords = channelRecords + .map( + ([channelID, channelRecord]) => { + if (hiddenChannels.channels.some((m) => m.id === channelID)) { + if (!this.hiddenChannelCache[guildId].some((m) => m[0] === channelID)) { + this.hiddenChannelCache[guildId].push([channelID, channelRecord]); + } + return false; + } + return [channelID, channelRecord]; + } + ) + .filter(Boolean); - // Remove the channel from original category - delete category.channels[channelId]; + category.channels = Object.fromEntries(filteredChannelRecords); + if (category.hiddenChannelIds) { + category.hiddenChannelIds = category.hiddenChannelIds.filter((v) => + filteredChannelRecords.some(([id]) => id == v) + ); + } + + if (category.shownChannelIds) { + category.shownChannelIds = category.shownChannelIds.filter((v) => + filteredChannelRecords.some(([id]) => id == v) + ); } } return { records: Object.fromEntries(this.hiddenChannelCache[guildId]), - channels: hiddenChannels ? hiddenChannels.channels : [], - amount: hiddenChannels ? hiddenChannels.amount : 0, + ...hiddenChannels, }; }