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