From 6d9c3bf73aca74eccce74ef170fc61a23c6d1b9b Mon Sep 17 00:00:00 2001 From: toast-ts <96593068+toast-ts@users.noreply.github.com> Date: Sun, 21 Jan 2024 22:30:52 +1100 Subject: [PATCH] Add cronjob task for previous commit. --- src/index.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/index.ts b/src/index.ts index 43284cf..f84ed3d 100644 --- a/src/index.ts +++ b/src/index.ts @@ -2,12 +2,14 @@ import Discord from 'discord.js'; import TClient from './client.js'; const client = new TClient; client.init(); +import cron from 'node-cron'; import Logger from './helpers/Logger.js'; import YTModule from './modules/YTModule.js'; import MPModule, {refreshTimerSecs} from './modules/MPModule.js'; import UsernameHelper from './helpers/UsernameHelper.js'; import {Punishment} from 'src/interfaces'; import {readFileSync} from 'node:fs'; +import {exec} from 'node:child_process'; // Error handler function _(error:Error, type:string) { @@ -69,3 +71,12 @@ if (client.config.botSwitches.dailyMsgsBackup) { client.userLevels.dataSweeper(); } // Cronjob tasks + +// UFW reject cronjob - every minute through 30 to 50. +cron.schedule('30-50 * * * *', async()=>{ + exec('sudo ./ufwReject.sh', {shell: 'bash'}, (error, stdout, stderr)=>{ + if (error) return Logger.console('error', 'Cron:ufwReject', `Job ran into an error: ${error.message}`); + if (stderr) return Logger.console('error', 'Cron:ufwReject', `Process ran into an error: ${stderr}`); + else if (stdout.includes('Done populating UFW reject rule')) return Logger.console('log', 'Cron:ufwReject', 'Job completed'); + }); +})