From 4d46428862b936f6458570bde751a19128dd6714 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 | 28 +++++++++++++------ 2 files changed, 20 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..9b46cc1 100644 --- a/util/custom_commands/getOwnerOfCustomCommand.js +++ b/util/custom_commands/getOwnerOfCustomCommand.js @@ -1,10 +1,20 @@ -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; + let command = await new Promise((resolve, reject)=>{ + db.get("SELECT * FROM customCommands WHERE customName = ? AND isDeleted = 0", [customName], function(error){ + 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; } \ No newline at end of file