-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
archive method now sends channel to latest archive category to allow …
…correct rotation between auto-archive/auto-delete
- Loading branch information
1 parent
cf4d4c7
commit 452c4f4
Showing
1 changed file
with
28 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |