-
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.
improve archive and channel cleanup function
- Loading branch information
1 parent
461e235
commit abcaad2
Showing
4 changed files
with
41 additions
and
47 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,15 +1,17 @@ | ||
name: Deploy to Production | ||
|
||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
branches: | ||
- master | ||
jobs: | ||
deploy: | ||
name: Deploy | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: executing remote ssh commands using ssh key | ||
- name: deploy | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ secrets.HOST }} | ||
|
@@ -18,11 +20,7 @@ jobs: | |
port: ${{ secrets.PORT }} | ||
script: | | ||
cd ~/bot-discord-duck | ||
echo "Pulling code" | ||
git pull | ||
echo "Pruning docker" | ||
docker system prune -f | ||
echo "Restarting docker" | ||
docker compose down | ||
docker compose -f compose.yaml -f compose.prod.yaml up --build | ||
docker compose -f compose.yaml -f compose.prod.yaml up --build -d |
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
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,38 +1,35 @@ | ||
import archive from '../utils/archive.js'; | ||
import {archive, allowedCategories} from '../utils/archive.js'; | ||
|
||
export function channelCleanup(client) { | ||
const guild = client.guilds.cache.get(process.env.GUILD_ID); | ||
const category = guild.channels.cache.find(channel => channel.type === 4 && channel.name === '🪂 SORTIES'); | ||
|
||
if (category) { | ||
|
||
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 | ||
|
||
const today = new Date() | ||
let channels = category.children.cache | ||
channels.forEach(channel => { | ||
|
||
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)) { | ||
console.log(`format invalide ${channel.name}`); | ||
return | ||
} | ||
|
||
let channel_date = new Date(today.getFullYear(), (parseInt(match[2]) - 1), (parseInt(match[1]) + 1)); | ||
|
||
if (today > channel_date) { | ||
console.log(`${channel.name} too old, archiving !`); | ||
archive(channel) | ||
} else { | ||
console.log(`${channel.name} OK`); | ||
} | ||
}); | ||
} else { | ||
console.log('category not found'); | ||
} | ||
const guild = client.guilds.cache.get(process.env.GUILD_ID); | ||
const categories = guild.channels.cache.filter(channel => allowedCategories.includes(channel.name)) | ||
|
||
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 | ||
|
||
categories.forEach(category => { | ||
const today = new Date() | ||
let channels = category.children.cache | ||
channels.forEach(channel => { | ||
|
||
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)) { | ||
console.log(`format invalide ${channel.name}`); | ||
return | ||
} | ||
|
||
let channel_date = new Date(today.getFullYear(), (parseInt(match[2]) - 1), (parseInt(match[1]) + 1)); | ||
|
||
if (today > channel_date) { | ||
console.log(`${channel.name} too old, archiving !`); | ||
archive(channel) | ||
} else { | ||
console.log(`${channel.name} OK`); | ||
} | ||
}); | ||
}); | ||
} |
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