Skip to content

Commit

Permalink
v0.5.4 - Fix crash when muting/unmuting specific servers
Browse files Browse the repository at this point in the history
  • Loading branch information
JustOptimize authored Sep 28, 2024
1 parent f6cb3a8 commit cd1c60d
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 49 deletions.
60 changes: 35 additions & 25 deletions ShowHiddenChannels.plugin.js
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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: [
Expand All @@ -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',
Expand Down Expand Up @@ -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];
})
);
Expand Down Expand Up @@ -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,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/config.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
56 changes: 33 additions & 23 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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',
Expand Down Expand Up @@ -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];
})
);
Expand Down Expand Up @@ -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,
};
}

Expand Down

0 comments on commit cd1c60d

Please sign in to comment.