Fixed quota reset

This commit is contained in:
Lukian 2024-12-24 17:48:09 +01:00
parent d7a9051f7d
commit 66dc111ea4
5 changed files with 19 additions and 51 deletions

5
.gitignore vendored
View file

@ -1,4 +1,3 @@
node_modules node_modules
package-lock.json .env
dist deno.lock
.env

24
package
View file

@ -1,24 +0,0 @@
{
"name": "chaise_bot_3.0",
"version": "3.1.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"dev": "tsx watch src",
"build": "tsc",
"start": "node dist"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@mistralai/mistralai": "^0.1.3",
"@types/mysql": "^2.15.26",
"@types/node": "^20.16.0",
"canvas": "^2.11.2",
"discord.js": "^14.14.1",
"dotenv": "^16.4.5",
"mysql": "^2.18.1"
}
}

View file

@ -162,7 +162,7 @@ export function setWelcomePropertiy(connection: mysql.Connection, guild_id: Stri
export function getLastReset(connection: mysql.Connection) { export function getLastReset(connection: mysql.Connection) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
connection.query("SELECT MAX(date) FROM resets", (error, result) => { connection.query("SELECT MAX(date) AS date FROM resets", (error, result) => {
if (error) { if (error) {
reject(error); reject(error);
} }

View file

@ -1,21 +1,26 @@
import { connectToDb, resetQuota, getLastReset, addReset } from "./mysql.ts"; import { connectToDb, resetQuota, getLastReset, addReset } from "./mysql.ts";
import { sendLog } from "./discord.ts";
export async function checkReset() { export async function checkReset() {
const connection = await connectToDb(); const connection = await connectToDb();
const lastReset = await getLastReset(connection); const lastReset = await getLastReset(connection);
const now = Date.now() / 1000; const now = Date.now()
// @ts-ignore
if (lastReset[0] && now - lastReset[0].date > 1000 * 60 * 60 * 24 * 30) {
await resetQuota(connection);
await addReset(connection, now)
connection.end();
if (!lastReset[0]) {
return; return;
} else { }
connection.end();
return false; if (lastReset[0].date == null) {
await resetQuota(connection);
await addReset(connection, now);
return connection.end();
}
if (now - lastReset[0].date > 1000 * 60 * 60 * 24 * 30) {
await resetQuota(connection);
await addReset(connection, now);
return connection.end();
} }
} }

View file

@ -1,12 +0,0 @@
{
"compilerOptions": {
"target": "ES5",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"resolveJsonModule": true,
"outDir": "./dist",
"skipLibCheck": true,
"noImplicitAny": true,
},
"include": ["src"],
}