Adding timer
This commit is contained in:
parent
fffef84119
commit
b72875e744
@ -4,7 +4,7 @@ import { emptyResponses } from './assets/emptyMessages.js';
|
|||||||
import { resetResponses, userResetMessages } from './assets/resetMessages.js';
|
import { resetResponses, userResetMessages } from './assets/resetMessages.js';
|
||||||
import { errorMessages, busyResponses } from './assets/errorMessages.js';
|
import { errorMessages, busyResponses } from './assets/errorMessages.js';
|
||||||
import cpuStat from 'cpu-stat';
|
import cpuStat from 'cpu-stat';
|
||||||
import os from 'os';
|
import os, { tmpdir } from 'os';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
Client,
|
Client,
|
||||||
@ -180,10 +180,10 @@ async function generateResponse(conversation, message) {
|
|||||||
const messagesCopy = [...conversation.messages]; // create a copy of the messages array
|
const messagesCopy = [...conversation.messages]; // create a copy of the messages array
|
||||||
|
|
||||||
let botMessage; // define a variable to hold the message object
|
let botMessage; // define a variable to hold the message object
|
||||||
|
let time = 0
|
||||||
// define a function that shows the system load percentage and updates the message
|
// define a function that shows the system load percentage and updates the message
|
||||||
const showSystemLoad = async () => {
|
const showSystemLoad = async () => {
|
||||||
|
time = time + 7
|
||||||
cpuStat.usagePercent(function(err, percent, seconds) {
|
cpuStat.usagePercent(function(err, percent, seconds) {
|
||||||
if (err) {
|
if (err) {
|
||||||
return console.log(err);
|
return console.log(err);
|
||||||
@ -193,7 +193,7 @@ async function generateResponse(conversation, message) {
|
|||||||
const freeMemory = os.freemem() / 1024 / 1024 / 1024;
|
const freeMemory = os.freemem() / 1024 / 1024 / 1024;
|
||||||
const totalMemory = os.totalmem() / 1024 / 1024 / 1024;
|
const totalMemory = os.totalmem() / 1024 / 1024 / 1024;
|
||||||
const usedMemory = totalMemory - freeMemory;
|
const usedMemory = totalMemory - freeMemory;
|
||||||
const messageData = `Please wait, I am thinking...\nSystem Load Average: ${systemLoad.toFixed(2)}%\nMemory Usage: ${usedMemory.toFixed(2)} GB / ${totalMemory.toFixed(2)} GB`;
|
const messageData = `Please wait, I am thinking...\nSystem Load: ${systemLoad.toFixed(2)}%\nMemory Usage: ${usedMemory.toFixed(2)} GB / ${totalMemory.toFixed(2)} GB | Time: ${time} seconds.`;
|
||||||
|
|
||||||
// if the message object doesn't exist, create it
|
// if the message object doesn't exist, create it
|
||||||
if (!botMessage) {
|
if (!botMessage) {
|
||||||
@ -243,6 +243,7 @@ async function generateResponse(conversation, message) {
|
|||||||
throw err;
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
|
time = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user