From d0d65c298687bb178623b3a20770eb15a5e3fac4 Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Tue, 16 Jan 2024 17:26:26 +1100 Subject: [PATCH] Remove clock speed if virtualized Add dataSweeper cronjob Add Better Breakfast Day array Update @types/node --- .pnp.cjs | 18 +++++++++--------- package.json | 2 +- src/commands/statistics.ts | 8 ++++++-- src/index.ts | 8 +++++--- src/models/userLevels.ts | 15 +++++++++++++++ src/modules/ResponseModule.ts | 34 +++++++++++++++++++++++++++++++++- yarn.lock | 10 +++++----- 7 files changed, 74 insertions(+), 21 deletions(-) diff --git a/.pnp.cjs b/.pnp.cjs index 9f99438..bb653b6 100644 --- a/.pnp.cjs +++ b/.pnp.cjs @@ -30,7 +30,7 @@ const RAW_RUNTIME_STATE = ["@octokit/rest", "npm:20.0.2"],\ ["@toast/tokenservice-client", "npm:1.0.6::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.6%2Ftokenservice-client-1.0.6.tgz"],\ ["@types/ms", "npm:0.7.34"],\ - ["@types/node", "npm:20.11.0"],\ + ["@types/node", "npm:20.11.3"],\ ["@types/node-cron", "npm:3.0.11"],\ ["@types/pg", "npm:8.10.9"],\ ["@types/sequelize", "npm:4.28.20"],\ @@ -603,7 +603,7 @@ const RAW_RUNTIME_STATE = "packageLocation": "./.yarn/cache/@types-continuation-local-storage-npm-3.2.7-763e4dc12b-1f272b53bc.zip/node_modules/@types/continuation-local-storage/",\ "packageDependencies": [\ ["@types/continuation-local-storage", "npm:3.2.7"],\ - ["@types/node", "npm:20.11.0"]\ + ["@types/node", "npm:20.11.3"]\ ],\ "linkType": "HARD"\ }]\ @@ -637,10 +637,10 @@ const RAW_RUNTIME_STATE = }]\ ]],\ ["@types/node", [\ - ["npm:20.11.0", {\ - "packageLocation": "./.yarn/cache/@types-node-npm-20.11.0-cb757f0c2a-8da60a8ccb.zip/node_modules/@types/node/",\ + ["npm:20.11.3", {\ + "packageLocation": "./.yarn/cache/@types-node-npm-20.11.3-78cf05078e-dff6433343.zip/node_modules/@types/node/",\ "packageDependencies": [\ - ["@types/node", "npm:20.11.0"],\ + ["@types/node", "npm:20.11.3"],\ ["undici-types", "npm:5.26.5"]\ ],\ "linkType": "HARD"\ @@ -660,7 +660,7 @@ const RAW_RUNTIME_STATE = "packageLocation": "./.yarn/cache/@types-pg-npm-8.10.9-ee8620c8e7-787be5431a.zip/node_modules/@types/pg/",\ "packageDependencies": [\ ["@types/pg", "npm:8.10.9"],\ - ["@types/node", "npm:20.11.0"],\ + ["@types/node", "npm:20.11.3"],\ ["pg-protocol", "npm:1.6.0"],\ ["pg-types", "npm:4.0.1"]\ ],\ @@ -694,7 +694,7 @@ const RAW_RUNTIME_STATE = "packageLocation": "./.yarn/cache/@types-ws-npm-8.5.9-91d1b2ab07-7cf66383b8.zip/node_modules/@types/ws/",\ "packageDependencies": [\ ["@types/ws", "npm:8.5.9"],\ - ["@types/node", "npm:20.11.0"]\ + ["@types/node", "npm:20.11.3"]\ ],\ "linkType": "HARD"\ }]\ @@ -995,7 +995,7 @@ const RAW_RUNTIME_STATE = ["@octokit/rest", "npm:20.0.2"],\ ["@toast/tokenservice-client", "npm:1.0.6::__archiveUrl=https%3A%2F%2Fgit.toast-server.net%2Fapi%2Fpackages%2Ftoast%2Fnpm%2F%2540toast%252Ftokenservice-client%2F-%2F1.0.6%2Ftokenservice-client-1.0.6.tgz"],\ ["@types/ms", "npm:0.7.34"],\ - ["@types/node", "npm:20.11.0"],\ + ["@types/node", "npm:20.11.3"],\ ["@types/node-cron", "npm:3.0.11"],\ ["@types/pg", "npm:8.10.9"],\ ["@types/sequelize", "npm:4.28.20"],\ @@ -2733,7 +2733,7 @@ const RAW_RUNTIME_STATE = "packageLocation": "./.yarn/cache/wkx-npm-0.5.0-fca5152cd8-b8975e33f9.zip/node_modules/wkx/",\ "packageDependencies": [\ ["wkx", "npm:0.5.0"],\ - ["@types/node", "npm:20.11.0"]\ + ["@types/node", "npm:20.11.3"]\ ],\ "linkType": "HARD"\ }]\ diff --git a/package.json b/package.json index 0f130c8..4de2375 100644 --- a/package.json +++ b/package.json @@ -52,7 +52,7 @@ }, "devDependencies": { "@types/ms": "0.7.34", - "@types/node": "20.11.0", + "@types/node": "20.11.3", "@types/node-cron": "3.0.11", "@types/pg": "8.10.9", "@types/sequelize": "4.28.20", diff --git a/src/commands/statistics.ts b/src/commands/statistics.ts index 51533f4..74740ef 100644 --- a/src/commands/statistics.ts +++ b/src/commands/statistics.ts @@ -6,7 +6,7 @@ import GitHub from '../helpers/GitHub.js'; import si from 'systeminformation'; import os from 'node:os'; import ts from 'typescript'; -import {readFileSync} from 'node:fs'; +import {readFileSync, existsSync} from 'node:fs'; export default class Statistics { static async run(client:TClient, interaction:Discord.ChatInputCommandInteraction<'cached'>) { const initialMsg = await interaction.reply({content: '', fetchReply:true}); @@ -58,7 +58,7 @@ export default class Statistics { )}, {name: 'šŸ”¹ *Host*', value: MessageTool.concatMessage( `>>> **OS:** ${systemInfo.osInfo.distro} ${systemInfo.osInfo.release}`, - `**CPU:** ${systemInfo.cpu.manufacturer} ${systemInfo.cpu.brand} āˆ™ ${systemInfo.cpu.speed} GHz`, + `**CPU:** ${systemInfo.cpu.manufacturer} ${systemInfo.cpu.brand} ${this.isHostVirtualized() ? '' : `āˆ™ ${systemInfo.cpu.speed} GHz`}`, '**RAM**', `ā•° **Host:** ${this.progressBar(systemInfo.mem.used, systemInfo.mem.total)} (${Formatters.byteFormat(systemInfo.mem.used)}/${Formatters.byteFormat(systemInfo.mem.total)})`, `ā•° **Bot:** ${this.progressBar(process.memoryUsage().heapUsed, process.memoryUsage().heapTotal)} (${Formatters.byteFormat(process.memoryUsage().heapUsed)}/${Formatters.byteFormat(process.memoryUsage().heapTotal)})`, @@ -78,6 +78,10 @@ export default class Statistics { const bar = 'ā–“'.repeat(Math.round(percent*length)) + 'ā–‘'.repeat(length-Math.round(percent*length)); return `${bar} ${Math.round(percent*100)}%`; } + private static isHostVirtualized():boolean { + if (existsSync('/sys/firmware/qemu_fw_cfg') ?? existsSync('/sys/module/qemu_fw_cfg')) return true + return false; + } static data = new Discord.SlashCommandBuilder() .setName('statistics') .setDescription('List of commands used in current session and host statistics') diff --git a/src/index.ts b/src/index.ts index 1cf5eb9..a5d6946 100644 --- a/src/index.ts +++ b/src/index.ts @@ -57,6 +57,8 @@ setInterval(async()=>{ } }, 5000) -if (client.config.botSwitches.dailyMsgsBackup) client.userLevels.initSelfdestruct() -// Initiate the nuke on userLevels and dailyMsgs tables -// Also don't ask why it's outside the interval +if (client.config.botSwitches.dailyMsgsBackup) { + client.userLevels.initSelfdestruct(); + client.userLevels.dataSweeper(); +} +// Cronjob tasks diff --git a/src/models/userLevels.ts b/src/models/userLevels.ts index c40068c..f065af2 100644 --- a/src/models/userLevels.ts +++ b/src/models/userLevels.ts @@ -81,6 +81,21 @@ export class UserLevelsSvc { } } else await this.model.create({id: userId, messages: 1, level: 0, pingToggle: true}); } + async dataSweeper() { + // Every Monday at 12:00 (Sydney Time) + cron.schedule('0 12 * * 1', async()=>{ + Logger.console('log', 'Cron', 'Running job "dataSweeper", this is activated every Monday at 12:00'); + const fetchDiscordMembers = await this.client.guilds.cache.get(this.client.config.dcServer.id).members.fetch(); + const fetchUsers = await this.model.findAll(); + for (const user of fetchUsers) { + if (!fetchDiscordMembers.has(user.dataValues.id)) { + await this.deleteUser(user.dataValues.id); + Logger.console('log', 'Cron:dataSweeper', `Removing ${user.dataValues.id}`); + } + } + Logger.console('log', 'Cron:dataSweeper', 'Job completed'); + }) + } async initSelfdestruct() { // Every 1st of January at 11:00 (Midnight in London, Middayish in Sydney) cron.schedule('0 11 1 1 *', async()=>{ diff --git a/src/modules/ResponseModule.ts b/src/modules/ResponseModule.ts index 9df2239..1ed02de 100644 --- a/src/modules/ResponseModule.ts +++ b/src/modules/ResponseModule.ts @@ -32,9 +32,11 @@ export default class Response { if (new RegExp(`^(${this.incomingArrays[responseKeyword].prefix.join('|')})?\\s?${responseKeyword} (${this.incomingArrays[responseKeyword].suffix.join('|')})\\b`, 'i').test(message.content)) return message.reply(`${this.outgoingArrays(message)[responseKeyword][Math.floor(Math.random()*this.outgoingArrays(message)[responseKeyword].length)]}`).catch(()=>null) } protected static outgoingArrays(message:Discord.Message) { + const currDate = new Date(); const PersonnyMcPerson = `**${message.member.displayName}**`; // const responseCreator =(id:Discord.Snowflake)=>`\nā•°*Response made by <@${id}>*`; - return { + + const respArrays = { morning: [ `Morning ${PersonnyMcPerson}, did you sleep great?`, `Good morning ${PersonnyMcPerson}!`, `Hope you enjoyed your breakfast, ${PersonnyMcPerson}!`, `Gm ${PersonnyMcPerson}.`, `Uh.. What time is it? Oh yea, morning ${PersonnyMcPerson}.`, `Morning and hope you had a good dream last night, ${PersonnyMcPerson}.`, @@ -65,6 +67,36 @@ export default class Response { `Sleep well ${PersonnyMcPerson}.`, `Gn ${PersonnyMcPerson}.`, `Close your eyelids and sleep, ${PersonnyMcPerson}.`, `Good night ${PersonnyMcPerson} and hope your pillow is nice and cold!`, `# Night ${PersonnyMcPerson}!`, `You should try maintaining your sleep schedule if you're really that tired, ${PersonnyMcPerson}.` ] + }; + + // Better Breakfast Day (Sept. 26) + if (currDate.getUTCMonth() === 8 && currDate.getUTCDate() === 26) { + return { + morning: [ + `Hello ${PersonnyMcPerson}, have you tried avocado toast for breakfast?`, + `Hey and good morning ${PersonnyMcPerson}!\nDid you know that breakfast is the most important meal of the day?`, + `Morning ${PersonnyMcPerson}, having a balanced breakfast can help you feel more energized throughout the day.`, + `Good morning ${PersonnyMcPerson}, how about some eggs benedict for breakfast today?`, + `Morning ${PersonnyMcPerson}!\nDid you know that a high protein breakfast can help control your hunger throughout the day?`, + 'Have you tried a breakfast burrito? They\'re delicious and filling.', + `Morning ${PersonnyMcPerson}, remember that fruits are a great addition to your breakfast.`, + `Hello ${PersonnyMcPerson}!\nStart your morning with some French toast for a treat. They're easy to make and tastes delicious!`, + 'A breakfast sandwich or toast is a quick and easy option for busy mornings.', + `Good morning ${PersonnyMcPerson}, don't forget to add some veggies to your breakfast for extra nutrients.`, + `Morning ${PersonnyMcPerson}, have you tried a breakfast casserole? They're a great make-ahead option.`, + 'Cereal is the quickest option to start your busy day with!', + `Gooood morning ${PersonnyMcPerson}! How about some pancakes for breakfast today?`, + `Morning ${PersonnyMcPerson}, don't forget to have some milk with your breakfast.` + ], + afternoon: respArrays.afternoon, + evening: respArrays.evening, + night: respArrays.night + } + } else return { + morning: respArrays.morning, + afternoon: respArrays.afternoon, + evening: respArrays.evening, + night: respArrays.night } } } diff --git a/yarn.lock b/yarn.lock index c375994..fd24d08 100644 --- a/yarn.lock +++ b/yarn.lock @@ -441,12 +441,12 @@ __metadata: languageName: node linkType: hard -"@types/node@npm:*, @types/node@npm:20.11.0": - version: 20.11.0 - resolution: "@types/node@npm:20.11.0" +"@types/node@npm:*, @types/node@npm:20.11.3": + version: 20.11.3 + resolution: "@types/node@npm:20.11.3" dependencies: undici-types: "npm:~5.26.4" - checksum: 8da60a8ccb65181c3d6f7686ddc5f1b1616cafa14d9e520a866adff82c17cc99336a78dd7ce7bee8f54e2332946f678b0e3aa377fbaaf751d3c05b64600872c6 + checksum: dff64333435bbda87e200e24e2103f40692d0a01849db685ecb31db7c589f2556843a03dd351ddaee9981020263939c026557b36df49154efd910c610deefe78 languageName: node linkType: hard @@ -748,7 +748,7 @@ __metadata: "@octokit/rest": "npm:20.0.2" "@toast/tokenservice-client": "npm:1.0.6" "@types/ms": "npm:0.7.34" - "@types/node": "npm:20.11.0" + "@types/node": "npm:20.11.3" "@types/node-cron": "npm:3.0.11" "@types/pg": "npm:8.10.9" "@types/sequelize": "npm:4.28.20"