diff --git a/package.json b/package.json index 8d6cdf8..361344d 100644 --- a/package.json +++ b/package.json @@ -28,6 +28,7 @@ "discord.js": "14.7.1", "moment": "2.29.4", "ms": "2.1.3", + "node-cron": "3.0.2", "sequelize": "6.28.0", "sqlite3": "5.1.4", "systeminformation": "5.16.9", @@ -36,6 +37,7 @@ }, "devDependencies": { "@types/node": "18.11.18", + "@types/node-cron": "3.0.7", "ts-node": "10.9.1" } } diff --git a/src/index.ts b/src/index.ts index 3ffc000..737f8d1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -4,6 +4,8 @@ const client = new TClient; client.init(); import fs from 'node:fs'; import MPDB from './models/MPServer'; +//import cron from 'node-cron'; +//import {exec} from 'node:child_process'; import {Punishment, UserLevels, FSData, FSCareerSavegame} from './typings/interfaces'; client.on('ready', async()=>{ @@ -29,6 +31,7 @@ client.on('ready', async()=>{ }) }, 500000); console.log(`${client.user.tag} has logged into Discord API and now ready for operation`); + //console.log('Total cron tasks: ' + cron.getTasks().size); console.log(client.config.botSwitches); (client.channels.resolve(client.config.mainServer.channels.bot_status) as Discord.TextChannel).send(`${client.user.username} is active\n\`\`\`json\n${Object.entries(client.config.botSwitches).map((hi)=>`${hi[0]}: ${hi[1]}`).join('\n')}\`\`\``); @@ -174,3 +177,20 @@ setInterval(async()=>{ client.guilds.cache.get(client.config.mainServer.id).commands.fetch().then((commands)=>(client.channels.resolve(client.config.mainServer.channels.logs) as Discord.TextChannel).send(`:pencil: Pushed \`[${formattedDate}, ${total}]\` to x.name == 'rank').id}>`)) } }, 5000) + +// Check Windows Updates at 6PM Sydney Time every Tuesday and Thursday +// 0 18 * * 2,4 +/* +cron.schedule('* * * * *', async function(){ + const x = await (client.channels.resolve(client.config.mainServer.channels.thismeanswar) as Discord.TextChannel).send('Checking Windows Updates...') + exec('D:/Bots-Housing/wu.ps1', {'shell':'powershell.exe'}, (err:Error, stdout)=>{ + if (err){ + x.edit('Powershell script caught an error, see console.'); + console.log(err.stack) + } else if (stdout.includes('You\'re up to date')){ + x.edit('The system is up to date.') + } else if (stdout.includes('Updates available')){ + x.edit(`\`\`\`${stdout}\`\`\``) + } + }); +})*/ \ No newline at end of file