Skip to content

Commit

Permalink
Added .ini file for better customization
Browse files Browse the repository at this point in the history
  • Loading branch information
rubencosta13 committed Dec 19, 2021
1 parent 2df84bf commit d79970e
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 60 deletions.
1 change: 0 additions & 1 deletion .github/funding.yaml

This file was deleted.

52 changes: 52 additions & 0 deletions config.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
[Author]
name="Ruben Lavos Costa"
discord="Ruben Costa#4242"

[PlaceHolders]
discordUsername="" #E.G. File Cleaner
embedTitle="" #E.G. Temporary File Cleaner
embedColor="" #Ckeck Colors on the bottom -> Use Int Value
os_placeholder="" #E.G. Operating System:
os_hostname="" #E.G. Hostname: [On my organization we chnaged the computer hostname for the internet switch port's number]
cpu_core="" #E.G CPU cores:
free_ram="" #E.G. Free RAM:
available_ram="" #E.G. Available RAM:
uptime="" #E.G. Uptime:
cpu_percentage="" #E.G. CPU usage [On the code it ads the percentatge symbol itself]
c_drive_usage="" #E.G. C drive usage: [On the code it ads the percentatge symbol itself]
disk_cleanup="" #E.G. C drive needs to be cleaned up: [It will only show if the drive is higher than 70% used]
temporary_files_cleaned ="" #E.G. Temporary files Cleaned!
error="" #E.G. Error:
computer="" #E.G. Computer:

[Variables]
discord_logger="" #Webhook where all the infos are logged on
discord_error="" #Webhook where all the errors are shown

[Colors]
Name | Int value | Hex Code |
----------------------------|:-----------:|:-----------:
DEFAULT | 0 | #000000
AQUA | 1752220 | #1ABC9C
DARK_AQUA | 1146986 | #11806A
GREEN | 3066993 | #2ECC71
DARK_GREEN | 2067276 | #1F8B4C
BLUE | 3447003 | #3498DB
DARK_BLUE | 2123412 | #206694
PURPLE | 10181046 | #9B59B6
DARK_PURPLE | 7419530 | #71368A
LUMINOUS_VIVID_PINK | 15277667 | #E91E63
DARK_VIVID_PINK | 11342935 | #AD1457
GOLD | 15844367 | #F1C40F
DARK_GOLD | 12745742 | #C27C0E
ORANGE | 15105570 | #E67E22
DARK_ORANGE | 11027200 | #A84300
RED | 15158332 | #E74C3C
DARK_RED | 10038562 | #992D22
GREY | 9807270 | #95A5A6
DARK_GREY | 9936031 | #979C9F
DARKER_GREY | 8359053 | #7F8C8D
LIGHT_GREY | 12370112 | #BCC0C0
NAVY | 3426654 | #34495E
DARK_NAVY | 2899536 | #2C3E50
YELLOW | 16776960 | #FFFF00
17 changes: 0 additions & 17 deletions config.json

This file was deleted.

42 changes: 24 additions & 18 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,22 @@ import os from 'os'
import axios from 'axios'
import rimraf from 'rimraf'
import nodeDiskInfo from 'node-disk-info'
import {} from 'dotenv/config'
import config from './config.json'

import fs from 'fs'
import ini from 'ini'
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
const location = __dirname + "\\config.ini"


const cpu = osu.cpu
const date = new Date()
const username = os.userInfo().username
const temp = `C:\\Windows\\Temp`
const temp2 = `C:\\Users\\${username}\\AppData\\Local\\Temp`
const prefetch = `C:\\Windows\\Prefetch`
const config = ini.parse(fs.readFileSync(location, 'utf-8'));



Expand All @@ -27,15 +33,15 @@ try {
rimraf(temp2, function () {});
rimraf(prefetch, function () {});
if ((100 * disks[0].used) / disks[0].blocks >= 70){
axios.post(config.dc_log, {
"username": config.discord_webhook_username,
axios.post(config.Variables.discord_logger, {
"username": config.PlaceHolders.discordUsername,
"avatar_url": "",
"content": "",
"embeds": [
{
"title": config.embed_title,
"color": config.embed_color,
"description": config.operating_sistem_placeholder +`${os.type()}\n`+config.operating_sistem_hostname+`${os.hostname()}\n`+config.cpu_core_number+`${os.cpus().length}\n`+config.free_ram+`${Math.floor(os.freemem().toFixed(2))} Mb\n`+config.available_ram+`${Math.floor(os.totalmem().toFixed(2))} Mb\n`+config.uptime+`${os.uptime()} seconds\n`+config.cpu_percentage+`${cpuPercentage}%\n`+config.c_drive_usage+`${disks[0].capacity}\n\n`+config.temporary_files_cleaned,
"title": config.PlaceHolders.embedTitle,
"color": config.PlaceHolders.embedColor,
"description": config.PlaceHolders.os_placeholder +`${os.type()}\n`+config.PlaceHolders.os_hostname+`${os.hostname()}\n`+config.PlaceHolders.cpu_core+`${os.cpus().length}\n`+config.PlaceHolders.free_ram+`${Math.floor(os.freemem().toFixed(2))} Mb\n`+config.PlaceHolders.available_ram+`${Math.floor(os.totalmem().toFixed(2))} Mb\n`+config.PlaceHolders.uptime+`${os.uptime()} seconds\n`+config.PlaceHolders.cpu_percentage+`${cpuPercentage}%\n`+config.PlaceHolders.c_drive_usage+`${disks[0].capacity}\n\n`+config.PlaceHolders.temporary_files_cleaned,
"timestamp": null,
"author": {},
"image": {},
Expand All @@ -50,14 +56,14 @@ try {
})
}else{
axios.post(process.env.DISCORD_LOGGER, {
"username": "Monitor de recursos",
"username": config.PlaceHolders.discordUsername,
"avatar_url": "",
"content": "",
"embeds": [
{
"title": "Limpeza de ficheiros temporarios e dados do computador:",
"color": 16711680,
"description": `Sistema operativo: ${os.type()}\nHostname: ${os.hostname()}\nNumero de cores: ${os.cpus().length}\nMemória Livre: ${Math.floor(os.freemem())} Mb\nMemoria total: ${Math.floor(os.totalmem())} Mb\nUptime: ${os.uptime()} Segundos\nPercentagem de CPU usada: ${cpuPercentage}%\nUso total do disco C: ${disks[0].capacity} \n\n**Ficheiros temporarios limpos!**`,
"title": config.PlaceHolders.embedTitle,
"color": config.PlaceHolders.embedColor,
"description": config.PlaceHolders.os_placeholder +`${os.type()}\n`+config.PlaceHolders.os_hostname+`${os.hostname()}\n`+config.PlaceHolders.cpu_core+`${os.cpus().length}\n`+config.PlaceHolders.free_ram+`${Math.floor(os.freemem().toFixed(2))} Mb\n`+config.PlaceHolders.available_ram+`${Math.floor(os.totalmem().toFixed(2))} Mb\n`+config.PlaceHolders.uptime+`${os.uptime()} seconds\n`+config.PlaceHolders.cpu_percentage+`${cpuPercentage}%\n`+config.PlaceHolders.c_drive_usage+`${disks[0].capacity}\n\n`+config.PlaceHolders.temporary_files_cleaned+"\n\n"+config.PlaceHolders.disk_cleanup,
"timestamp": null,
"author": {},
"image": {},
Expand All @@ -69,20 +75,20 @@ try {
}
],
"components": []
})
})
}
})
})
} catch (e) {
axios.post(config.dc_error , {
"username": "Monitor de recursos",
axios.post(config.Variables.discord_error , {
"username": config.PlaceHolders.discordUsername,
"avatar_url": "",
"content": "",
"embeds": [
{
"title": "Dados:",
"color": 16711680,
"description": `Erro: ${e.message}\n Computador: ${os.hostname()}`,
"title": config.PlaceHolders.embedTitle,
"color": config.PlaceHolders.embedColor,
"description": config.PlaceHolders.error+` ${e.message}\n`+ config.PlaceHolders.computer +`${os.hostname()}`,
"timestamp": null,
"author": {},
"image": {},
Expand Down
46 changes: 22 additions & 24 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,35 @@ This script, is being developed, so companies, don't have to worry about going t
- Memory utilization
- General computer specs

# To-do:
[ ] Auto updating;
[ ] Getting information about the disks
# 📃 To-do:
[] Getting information about CPU temperature
# 🛠️ Working on:
[] Auto updating;


# Configurations

## Pre-requisites:
# ✅ Done:
[] Getting information about the disks


- Recommended having a discord server, to receive the data;
- Create a webhook
- Go into .env and define the webhook URL
- Download all the packages using ``npm install``, use ``npm build`` to make an executable with nexe. (Caution: Some antivirus will flag it has virus. Why? You may ask. Response: It removes OS folders, specifically temporary folders: ["temp", "%temp%", "prefetch"], so don't worry!)
- Optional, but should be fixed in the next updates:
- Go to task scheduler:
- Click on: "Create Task"
- Name the task something knowledgeable: e.g. "Monitor computer task"
- Click on the "Triggers" tab
- Use the default: "On schedule"
- Change the start hour, so you are sure that on that time someone is using the computer, (if you want, use: "Repeat task every:", so the task will run itself). Click OK
- Then go to "Actions" tab, click on "New", leave everything as default, just change on: "Program / script" to the .exe file directory
- Then click "OK"
- Then click "OK" again and close task manager (The program should run on the defined schedule)
- Then you are going to receive the data to the discord!
# Configurations
- Create a webhook
- Go into config.ini file and assign the values, (inside the file there's an explanation about every setting)
- Download all the packages using `npm install`, use `npm build` to make an executable with nexe. (Caution: Some antivirus will flag it has virus. Why? You may ask. Response: It removes OS folders, specifically temporary folders: ["temp", "%temp%", "prefetch"], so don't worry!)
- Optional:
- Go to task scheduler:
- Click on: "Create Task"
- Name the task something knowledgeable: e.g. "Monitor computer task"
- Click on the "Triggers" tab
- Use the default: "On schedule"
- Change the start hour, so you are sure that on that time someone is using the computer, (if you want, use: "Repeat task every:", so the task will run itself). Click OK
- Then go to "Actions" tab, click on "New", leave everything as default, just change on: "Program / script" to the .exe file directory
- Then click "OK"
- Then click "OK" again and close task manager (The program should run on the defined schedule)## Pre-requisites:
- Recommended having a discord server, to receive the data;
- Then you are going to receive the data to the discord!


# Help!

If you need any help send me an [email](mailto:[email protected]). Use the subject as: "Temporary file cleaner"



Made with <3 by Ruben Costa

0 comments on commit d79970e

Please sign in to comment.