Use SQL on owner custom command subcommand
This commit is contained in:
parent
345a03a3b0
commit
45ebf91e4d
2 changed files with 22 additions and 10 deletions
|
@ -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`
|
||||
|
|
|
@ -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(command)
|
||||
author = command.author;
|
||||
resolve(author)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return author;
|
||||
}
|
Loading…
Add table
Reference in a new issue