From 90fcdc4f585d6343c8a764054ca240cf46958fe3 Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Thu, 19 Dec 2024 19:52:02 +0100 Subject: [PATCH] Use SQL on owner custom command subcommand --- commands/misc/custom.js | 2 +- .../getOwnerOfCustomCommand.js | 30 +++++++++++++------ 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/commands/misc/custom.js b/commands/misc/custom.js index d31404f..71885df 100644 --- a/commands/misc/custom.js +++ b/commands/misc/custom.js @@ -42,7 +42,7 @@ module.exports = { break; } case "owner":{ - let author = getOwnerOfCustomCommand(customName); + let author = await getOwnerOfCustomCommand(customName); let user; if(!author) sendText = `${customName} does not exist` diff --git a/util/custom_commands/getOwnerOfCustomCommand.js b/util/custom_commands/getOwnerOfCustomCommand.js index f0106c0..fe82e66 100644 --- a/util/custom_commands/getOwnerOfCustomCommand.js +++ b/util/custom_commands/getOwnerOfCustomCommand.js @@ -1,10 +1,22 @@ -const fs = require('fs'); -module.exports = function(customName){ - const customPath = './data/customCommands.json'; - let json = fs.readFileSync(customPath, 'utf8'); - let customCommands = JSON.parse(json) - let author = customCommands.filter(customCommands => customCommands.customName === customName); - if(author.length === 0) return false; - return author[0].author; - + +const sqlite3 = require('sqlite3').verbose(); +module.exports = async function(customName){ + const db = new sqlite3.Database("data/database.db"); + + let author = await new Promise((resolve, reject)=>{ + db.get("SELECT * FROM customCommands WHERE customName = ? AND isDeleted = 0", [customName], + function(error, command){ + if(error){ + console.error(error) + author = "Error when getting the owner of this custom command. Check console."; + reject(author) + }else { + if(author) + author = command.author; + resolve(author) + } + }) + }) + + return author; } \ No newline at end of file