buh
This commit is contained in:
parent
16014d6623
commit
cb309e8850
21
index.js
21
index.js
|
@ -9,6 +9,16 @@ const hook = new Discord.WebhookClient({ url: process.env.DISCORD_WEBHOOK_URL })
|
|||
|
||||
const JSON_FILE = process.env.JSON_FILE || "records.json";
|
||||
|
||||
|
||||
function getStartOfYesterdayTimestamp() {
|
||||
const today = new Date();
|
||||
// Set the date to yesterday
|
||||
today.setDate(today.getDate() - 1);
|
||||
// Create a new Date object for the start of yesterday
|
||||
const startOfYesterday = new Date(today.getFullYear(), today.getMonth(), today.getDate());
|
||||
return startOfYesterday.getTime(); // Returns the timestamp in milliseconds
|
||||
}
|
||||
|
||||
async function loadRecords() {
|
||||
try {
|
||||
const data = await fs.readFile(JSON_FILE, 'utf-8');
|
||||
|
@ -28,7 +38,7 @@ async function saveRecords(root) {
|
|||
|
||||
async function getPreviousDayData() {
|
||||
return new Promise(async (resolve, reject) => {
|
||||
const previousDay = new Date(Date.now() - 86400000); // 24 hours ago
|
||||
const previousDay = new Date(getStartOfYesterdayTimestamp()) // 24 hours ago
|
||||
const startTime = new Date(previousDay.setHours(0, 0, 0, 0));
|
||||
const endTime = new Date(previousDay.setHours(23, 59, 59, 999));
|
||||
const connection = await mysql.createConnection({
|
||||
|
@ -75,7 +85,7 @@ function getSystemUptime() {
|
|||
}
|
||||
|
||||
function updateRecords(data, root) {
|
||||
const currentDate = new Date(Date.now() - 86400000).toISOString().split('T')[0];
|
||||
const currentDate = new Date(getStartOfYesterdayTimestamp()).toISOString().split('T')[0];
|
||||
const month = currentDate.slice(0, 7);
|
||||
let isNewRecord = false;
|
||||
|
||||
|
@ -102,18 +112,13 @@ function updateRecords(data, root) {
|
|||
return data;
|
||||
}
|
||||
|
||||
function getStartOfDayTimestamp(date) {
|
||||
const startOfDay = new Date(date.getFullYear(), date.getMonth(), date.getDate());
|
||||
return startOfDay.getTime(); // Returns the timestamp in milliseconds
|
||||
}
|
||||
|
||||
async function sendSummary() {
|
||||
const data = await getPreviousDayData();
|
||||
const root = await loadRecords();
|
||||
const updatedData = await updateRecords(data, root);
|
||||
await saveRecords(root);
|
||||
|
||||
const previousDayStart = new Date(getStartOfDayTimestamp(new Date()));
|
||||
const previousDayStart = new Date(getStartOfYesterdayTimestamp());
|
||||
const previousDayEnd = new Date(previousDayStart);
|
||||
previousDayEnd.setHours(23, 59, 59, 999);
|
||||
|
||||
|
|
Loading…
Reference in a new issue