Use SQL on owner custom command subcommand
All checks were successful
CI / CI (push) Successful in 21s
Lint Codebase / eslint (push) Successful in 15s

This commit is contained in:
SileNce5k 2024-12-19 19:52:02 +01:00
parent 345a03a3b0
commit 4d46428862
Signed by: SileNce
GPG key ID: B0A142BB4291B204
2 changed files with 20 additions and 10 deletions

View file

@ -42,7 +42,7 @@ module.exports = {
break; break;
} }
case "owner":{ case "owner":{
let author = getOwnerOfCustomCommand(customName); let author = await getOwnerOfCustomCommand(customName);
let user; let user;
if(!author) if(!author)
sendText = `${customName} does not exist` sendText = `${customName} does not exist`

View file

@ -1,10 +1,20 @@
const fs = require('fs');
module.exports = function(customName){ const sqlite3 = require('sqlite3').verbose();
const customPath = './data/customCommands.json'; module.exports = async function(customName){
let json = fs.readFileSync(customPath, 'utf8'); const db = new sqlite3.Database("data/database.db");
let customCommands = JSON.parse(json) let author;
let author = customCommands.filter(customCommands => customCommands.customName === customName); let command = await new Promise((resolve, reject)=>{
if(author.length === 0) return false; db.get("SELECT * FROM customCommands WHERE customName = ? AND isDeleted = 0", [customName], function(error){
return author[0].author; if(error){
console.error(error)
author = "Error when getting the owner of this custom command. Check console.";
reject(author)
}else {
author = command.author;
resolve(author)
}
})
})
return author;
} }