Skip to content

Commit

Permalink
archive method now sends channel to latest archive category to allow …
Browse files Browse the repository at this point in the history
…correct rotation between auto-archive/auto-delete
  • Loading branch information
BodomBeach committed Jul 5, 2024
1 parent cf4d4c7 commit 452c4f4
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions src/utils/archive.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,33 @@
// TODO -> Archive by transforming channel into a thread in the 'archives' channel
async function archive(channel) {
const archiveCategories = channel.guild.channels.cache.filter(channel => channel.type === 4 && channel.name.slice(0,11).toLowerCase() === '📁archives_');
let available_archive = archiveCategories.find(cat => cat.children.cache.size < 50)
const archiveCategories = channel.guild.channels.cache.filter(
(channel) =>
channel.type === 4 &&
channel.name.slice(0, 11).toLowerCase() === "📁archives_"
);
const latestCategory = channel.guild.channels.cache
.filter(
(channel) =>
channel.type === 4 &&
channel.name.slice(0, 11).toLowerCase() === "📁archives_"
)
.sort((channel) => parseInt(channel.name.split("_")[1]))
.last();

if (available_archive) {
channel.setParent(available_archive)
} else {
// creating a new archive category
const count = Math.max(...archiveCategories.map(cat => parseInt(cat.name.split('_')[1])))
available_archive = await channel.guild.channels.create({
name: `📁ARCHIVES_${count + 1}`,
type: 4,
})
console.log('Created new archive category');
channel.setParent(available_archive)
}
if (latestCategory) {
channel.setParent(latestCategory);
} else {
// creating a new archive folder
const count = Math.max(
...archiveCategories.map((cat) => parseInt(cat.name.split("_")[1]))
);
latestCategory = await channel.guild.channels.create({
name: `📁ARCHIVES_${count + 1}`,
type: 4,
});
console.log("Created new archive latestCategory");
channel.setParent(available_archive);
}
}

module.exports = { archive };
module.exports = { archive };

0 comments on commit 452c4f4

Please sign in to comment.