-
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.
- Loading branch information
1 parent
d71379f
commit 3ea9c3d
Showing
3 changed files
with
74 additions
and
52 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,42 +1,53 @@ | ||
const { archive } = require('../utils/archive.js'); | ||
const { archive } = require("../utils/archive.js"); | ||
|
||
function channelCleanup(client) { | ||
async function channelCleanup(client) { | ||
console.log("===== starting scheduled channel cleanup ====="); | ||
|
||
|
||
console.log('===== starting scheduled channel cleanup ====='); | ||
const allowedCategories = ['🪂 SORTIES', '🏃Sorties pas rapente']; | ||
const allowedCategories = ["🪂 SORTIES", "🏃Sorties pas rapente"]; | ||
const guild = client.guilds.cache.get(process.env.GUILD_ID); | ||
const categories = guild.channels.cache.filter(channel => allowedCategories.includes(channel.name)) | ||
const categories = guild.channels.cache.filter((channel) => | ||
allowedCategories.includes(channel.name) | ||
); | ||
|
||
const allowed = /(\d{1,2})-(\d{1,2})/ | ||
const allowed = /(\d{1,2})-(\d{1,2})/; | ||
|
||
// do nothing for these format for now, too risky | ||
const forbidden1 = /(\d{1,2})-(\d{1,2})-(\d{1,2})/ // 04-05-06 | ||
const forbidden2 = /-(janvier|fevrier|mars|avril|mai|juin|juillet|septembre|octobre|novembre|decembre)-/ // 04-05-juin-word | ||
const forbidden1 = /(\d{1,2})-(\d{1,2})-(\d{1,2})/; // 04-05-06 | ||
const forbidden2 = | ||
/-(janvier|fevrier|mars|avril|mai|juin|juillet|septembre|octobre|novembre|decembre)-/; // 04-05-juin | ||
|
||
for (const category of categories.values()) { | ||
const today = new Date(); | ||
const channels = category.children.cache; | ||
|
||
categories.forEach(category => { | ||
const today = new Date() | ||
let channels = category.children.cache | ||
channels.forEach(channel => { | ||
for (const channel of channels.values()) { | ||
const match = allowed.exec(channel.name); | ||
|
||
let match = allowed.exec(channel.name) | ||
// if month is found as a string (e.g. "juin"), do nothing for now, too risky | ||
if (!allowed.exec(channel.name) || forbidden1.exec(channel.name) || forbidden2.exec(channel.name)) { | ||
if ( | ||
!match || | ||
forbidden1.exec(channel.name) || | ||
forbidden2.exec(channel.name) | ||
) { | ||
console.log(`format invalide ${channel.name}`); | ||
return | ||
continue; | ||
} | ||
|
||
// archive channel 24 hours after actual expiry date. E.g. 18-05-plop will be archived on 20-05 at 1am | ||
let channel_date = new Date(today.getFullYear(), (parseInt(match[2]) - 1), (parseInt(match[1]) + 2)); | ||
const channel_date = new Date( | ||
today.getFullYear(), | ||
parseInt(match[2]) - 1, | ||
parseInt(match[1]) + 2 | ||
); | ||
|
||
if (today > channel_date) { | ||
console.log(`${channel.name} too old, archiving !`); | ||
archive(channel) | ||
console.log(`${channel.name} too old, archiving!`); | ||
await archive(channel); | ||
} else { | ||
console.log(`${channel.name} OK`); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
} | ||
|
||
module.exports = { channelCleanup }; |
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,65 +1,76 @@ | ||
const { EmbedBuilder } = require('discord.js'); | ||
const { EmbedBuilder } = require("discord.js"); | ||
|
||
async function serverStats(client) { | ||
console.log('===== starting scheduled server stats update ====='); | ||
console.log("===== starting scheduled server stats update ====="); | ||
const guild = client.guilds.cache.get(process.env.GUILD_ID); | ||
|
||
// fetch members first, otherwise guild.roles.cache.get('1232623387965132820').members.size will be empty | ||
let members = await guild.members.fetch(); | ||
const time = (new Date).toLocaleString( | ||
'fr-FR', | ||
{ | ||
weekday: 'long', | ||
year: 'numeric', | ||
month: 'long', | ||
day: 'numeric', | ||
hour: 'numeric', | ||
minute: 'numeric', | ||
second: 'numeric', | ||
timeZone: 'Europe/Paris', | ||
}) | ||
const time = new Date().toLocaleString("fr-FR", { | ||
weekday: "long", | ||
year: "numeric", | ||
month: "long", | ||
day: "numeric", | ||
hour: "numeric", | ||
minute: "numeric", | ||
second: "numeric", | ||
timeZone: "Europe/Paris", | ||
}); | ||
|
||
const embed = new EmbedBuilder() | ||
.setTitle('Statistiques du serveur') | ||
.setTitle("Statistiques du serveur") | ||
.setColor(0x0099ff) | ||
.setThumbnail('https://cdn.discordapp.com/icons/943454897431523349/cadb5ff769c962489b5dd144acb1e2e3.webp?size=96') | ||
.setThumbnail( | ||
"https://cdn.discordapp.com/icons/943454897431523349/cadb5ff769c962489b5dd144acb1e2e3.webp?size=96" | ||
) | ||
.setFooter({ text: `Dernière mise à jour : ${time}` }) | ||
.addFields([ | ||
{ | ||
name: 'Membres total', | ||
name: "Membres total", | ||
value: guild.memberCount.toString(), | ||
}, | ||
{ | ||
name: 'Admins', | ||
value: guild.roles.cache.find(role => role.name === 'admins')?.members?.size?.toString() || '0', | ||
name: "Admins", | ||
value: | ||
guild.roles.cache | ||
.find((role) => role.name === "admins") | ||
?.members?.size?.toString() || "0", | ||
inline: true, | ||
}, | ||
{ | ||
name: 'Staff', | ||
value: guild.roles.cache.find(role => role.name === 'staff')?.members?.size?.toString() || '0', | ||
name: "Staff", | ||
value: | ||
guild.roles.cache | ||
.find((role) => role.name === "staff") | ||
?.members?.size?.toString() || "0", | ||
inline: true, | ||
}, | ||
{ | ||
name: 'Biplaceurs', | ||
value: guild.roles.cache.find(role => role.name === 'biplaceurs')?.members?.size?.toString() || '0', | ||
name: "Biplaceurs", | ||
value: | ||
guild.roles.cache | ||
.find((role) => role.name === "biplaceurs") | ||
?.members?.size?.toString() || "0", | ||
inline: true, | ||
}, | ||
{ | ||
name: 'Nombre de salons', | ||
name: "Nombre de salons", | ||
value: guild.channels.cache.size.toString(), | ||
}, | ||
]); | ||
|
||
const statsChannel = client.channels.cache.find(channel => channel.name === 'stats'); | ||
const statsChannel = client.channels.cache.find( | ||
(channel) => channel.name === "stats" | ||
); | ||
let messages = await statsChannel.messages.fetch({ limit: 1 }); | ||
|
||
// Create or edit existing embed | ||
if (messages.size === 0) { | ||
statsChannel.send({ embeds: [embed] }); | ||
} else { | ||
messages.first().edit({ embeds: [embed] }); | ||
}; | ||
console.log('Server stats updated'); | ||
} | ||
console.log("Server stats updated"); | ||
} | ||
|
||
module.exports = { serverStats }; | ||
module.exports = { serverStats }; |
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