Use SQL on owner custom command subcommand
This commit is contained in:
parent
345a03a3b0
commit
0c45055e0f
2 changed files with 24 additions and 10 deletions
|
@ -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`
|
||||||
|
|
|
@ -1,10 +1,24 @@
|
||||||
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 = customCommands.filter(customCommands => customCommands.customName === customName);
|
let author = await new Promise((resolve, reject)=>{
|
||||||
if(author.length === 0) return false;
|
db.get("SELECT * FROM customCommands WHERE customName = ? AND isDeleted = 0", [customName],
|
||||||
return author[0].author;
|
function(error, command){
|
||||||
|
if(error){
|
||||||
|
console.error(error)
|
||||||
|
let author = "Error when getting the owner of this custom command. Check console.";
|
||||||
|
reject(author)
|
||||||
|
}else {
|
||||||
|
let author;
|
||||||
|
if(command){
|
||||||
|
author = command.author;
|
||||||
|
}
|
||||||
|
resolve(author)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
return author;
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue