change to connect db for each function as needed
This commit is contained in:
parent
faa5c161f7
commit
e67fd83b4d
23
functions.js
23
functions.js
@ -33,7 +33,6 @@ const db = new mysql.createConnection({
|
|||||||
database: dbName,
|
database: dbName,
|
||||||
port: dbPort,
|
port: dbPort,
|
||||||
});
|
});
|
||||||
db.connect();
|
|
||||||
|
|
||||||
const functions = {
|
const functions = {
|
||||||
collections: {
|
collections: {
|
||||||
@ -332,65 +331,82 @@ const functions = {
|
|||||||
upload: {
|
upload: {
|
||||||
request(commandData, client) {
|
request(commandData, client) {
|
||||||
const query = `INSERT INTO requests (author, request, status) VALUES ('${commandData.author}','${commandData.args}','Active')`;
|
const query = `INSERT INTO requests (author, request, status) VALUES ('${commandData.author}','${commandData.args}','Active')`;
|
||||||
|
db.connect();
|
||||||
db.query(query, (err, rows, fields) => {
|
db.query(query, (err, rows, fields) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
functions.download.requests(client);
|
functions.download.requests(client);
|
||||||
});
|
});
|
||||||
|
db.end();
|
||||||
},
|
},
|
||||||
pasta(pastaData, client) {
|
pasta(pastaData, client) {
|
||||||
const query = `INSERT INTO pastas (name, content) VALUES ('${pastaData.name}','${pastaData.content}')`;
|
const query = `INSERT INTO pastas (name, content) VALUES ('${pastaData.name}','${pastaData.content}')`;
|
||||||
|
db.connect();
|
||||||
db.query(query, (err, rows, fields) => {
|
db.query(query, (err, rows, fields) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
functions.download.pastas(client);
|
functions.download.pastas(client);
|
||||||
});
|
});
|
||||||
|
db.end();
|
||||||
},
|
},
|
||||||
joint(content, client) {
|
joint(content, client) {
|
||||||
const query = `INSERT INTO joints (content) VALUES ('${content}')`;
|
const query = `INSERT INTO joints (content) VALUES ('${content}')`;
|
||||||
|
db.connect();
|
||||||
db.query(query, (err, rows, fields) => {
|
db.query(query, (err, rows, fields) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
functions.download.joints(client);
|
functions.download.joints(client);
|
||||||
});
|
});
|
||||||
|
db.end();
|
||||||
},
|
},
|
||||||
gif(gifData, client) {
|
gif(gifData, client) {
|
||||||
const query = `INSERT INTO gifs (name, embed_url) VALUES ('${gifData.name}', '${gifData.embed_url}')`;
|
const query = `INSERT INTO gifs (name, embed_url) VALUES ('${gifData.name}', '${gifData.embed_url}')`;
|
||||||
|
db.connect();
|
||||||
db.query(query, (err, rows, fields) => {
|
db.query(query, (err, rows, fields) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
functions.download.gifs(client);
|
functions.download.gifs(client);
|
||||||
});
|
});
|
||||||
|
db.end();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
download: {
|
download: {
|
||||||
requests(client) {
|
requests(client) {
|
||||||
const query = 'SELECT * FROM requests WHERE status = \'Active\' ORDER BY id ASC';
|
const query = 'SELECT * FROM requests WHERE status = \'Active\' ORDER BY id ASC';
|
||||||
|
db.connect();
|
||||||
db.query(query, (err, rows, fields) => {
|
db.query(query, (err, rows, fields) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
functions.collections.requests(rows, client);
|
functions.collections.requests(rows, client);
|
||||||
});
|
});
|
||||||
|
db.end();
|
||||||
},
|
},
|
||||||
pastas(client) {
|
pastas(client) {
|
||||||
const query = 'SELECT * FROM pastas ORDER BY id ASC';
|
const query = 'SELECT * FROM pastas ORDER BY id ASC';
|
||||||
|
db.connect();
|
||||||
db.query(query, (err, rows, fields) => {
|
db.query(query, (err, rows, fields) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
functions.collections.pastas(rows, client);
|
functions.collections.pastas(rows, client);
|
||||||
});
|
});
|
||||||
|
db.end();
|
||||||
},
|
},
|
||||||
gifs(client) {
|
gifs(client) {
|
||||||
const query = 'SELECT * FROM gifs ORDER BY id ASC';
|
const query = 'SELECT * FROM gifs ORDER BY id ASC';
|
||||||
|
db.connect();
|
||||||
db.query(query, (err, rows, fields) => {
|
db.query(query, (err, rows, fields) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
functions.collections.gifs(rows, client);
|
functions.collections.gifs(rows, client);
|
||||||
});
|
});
|
||||||
|
db.end();
|
||||||
},
|
},
|
||||||
joints(client) {
|
joints(client) {
|
||||||
const query = 'SELECT * FROM joints ORDER BY id ASC';
|
const query = 'SELECT * FROM joints ORDER BY id ASC';
|
||||||
|
db.connect();
|
||||||
db.query(query, (err, rows, fields) => {
|
db.query(query, (err, rows, fields) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
functions.collections.joints(rows, client);
|
functions.collections.joints(rows, client);
|
||||||
});
|
});
|
||||||
|
db.end();
|
||||||
},
|
},
|
||||||
strain(commandData, message) {
|
strain(commandData, message) {
|
||||||
const { strainName } = commandData;
|
const { strainName } = commandData;
|
||||||
const query = `SELECT id, name, type, effects, ailment, flavor FROM strains WHERE name = '${strainName}'`;
|
const query = `SELECT id, name, type, effects, ailment, flavor FROM strains WHERE name = '${strainName}'`;
|
||||||
|
db.connect();
|
||||||
db.query(query, (err, rows, fields) => {
|
db.query(query, (err, rows, fields) => {
|
||||||
if (rows != undefined) {
|
if (rows != undefined) {
|
||||||
commandData.strainInfo = {
|
commandData.strainInfo = {
|
||||||
@ -404,13 +420,16 @@ const functions = {
|
|||||||
functions.embeds.strain(commandData, message);
|
functions.embeds.strain(commandData, message);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
db.end();
|
||||||
},
|
},
|
||||||
strains(client) {
|
strains(client) {
|
||||||
const query = 'SELECT id, name FROM strains';
|
const query = 'SELECT id, name FROM strains';
|
||||||
|
db.connect();
|
||||||
db.query(query, (err, rows, fields) => {
|
db.query(query, (err, rows, fields) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
functions.collections.strains(rows, client);
|
functions.collections.strains(rows, client);
|
||||||
});
|
});
|
||||||
|
db.end();
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
weed: {
|
weed: {
|
||||||
@ -432,10 +451,12 @@ const functions = {
|
|||||||
// Parent-Level functions (miscellaneuous)
|
// Parent-Level functions (miscellaneuous)
|
||||||
closeRequest(requestId, client) {
|
closeRequest(requestId, client) {
|
||||||
const query = `UPDATE requests SET status = 'Closed' WHERE id = ${requestId}`;
|
const query = `UPDATE requests SET status = 'Closed' WHERE id = ${requestId}`;
|
||||||
|
db.connect();
|
||||||
db.query(query, (err, rows, fields) => {
|
db.query(query, (err, rows, fields) => {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
functions.download.requests(client);
|
functions.download.requests(client);
|
||||||
});
|
});
|
||||||
|
db.end();
|
||||||
},
|
},
|
||||||
spongebob(commandData) {
|
spongebob(commandData) {
|
||||||
let flipper = 0;
|
let flipper = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user