Moving requests to db with in chat management
This commit is contained in:
parent
986a3dd980
commit
47330d5760
11
commands/closereq.js
Normal file
11
commands/closereq.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
const fn = require('../functions.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'closereq',
|
||||||
|
description: 'Close a given request by ID',
|
||||||
|
usage: '<request_id>',
|
||||||
|
execute(message, file) {
|
||||||
|
fn.closeRequest(file.name);
|
||||||
|
message.channel.send(fn.textEmbed('Request closed.', message.author, file.extension));
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,13 @@
|
|||||||
|
const fn = require('../functions.js');
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
name: 'request',
|
name: 'request',
|
||||||
description: 'Submit a request to the bot developer.',
|
description: 'Submit a request to the bot developer.',
|
||||||
usage: '<request or feedback>',
|
usage: '<request or feedback>',
|
||||||
execute(message, file) {
|
execute(message, file) {
|
||||||
const request = file.name;
|
const request = file.name;
|
||||||
message.channel.send('Your request has been submitted:\n```\n' + request + '\n```');
|
message.channel.send(fn.textEmbed('Your request has been submitted!', message.author, file.extension));
|
||||||
message.client.users.fetch(process.env.ownerID).then(user => {user.send('New request or feedback:\n```\n' + request + '\n```');}).catch(error => { console.error(error);} );
|
message.client.users.fetch(process.env.ownerID).then(user => {user.send('New request or feedback:\n```\n' + request + '\n```');}).catch(error => { console.error(error);} );
|
||||||
|
fn.uploadRequest(message.author, file.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
9
commands/requests.js
Normal file
9
commands/requests.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
const fn = require('../functions.js');
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
name: 'requests',
|
||||||
|
description: 'Get a list of the currently active requests.',
|
||||||
|
execute(message, file) {
|
||||||
|
fn.getActiveRequests(message);
|
||||||
|
}
|
||||||
|
}
|
56
functions.js
56
functions.js
@ -95,8 +95,8 @@ module.exports = {
|
|||||||
const extension = content.slice(finalPeriod).replace('.','').toLowerCase();
|
const extension = content.slice(finalPeriod).replace('.','').toLowerCase();
|
||||||
const filename = content.slice(0,finalPeriod).toLowerCase();
|
const filename = content.slice(0,finalPeriod).toLowerCase();
|
||||||
const file = {
|
const file = {
|
||||||
'name': filename,
|
name: filename,
|
||||||
'extension': extension
|
extension: extension
|
||||||
};
|
};
|
||||||
return file;
|
return file;
|
||||||
},
|
},
|
||||||
@ -109,7 +109,7 @@ module.exports = {
|
|||||||
},
|
},
|
||||||
createGifEmbed(data, author, command) {
|
createGifEmbed(data, author, command) {
|
||||||
return new Discord.MessageEmbed()
|
return new Discord.MessageEmbed()
|
||||||
.setAuthor(command)
|
.setAuthor('Command: ' + command)
|
||||||
.setImage(data.embed_url)
|
.setImage(data.embed_url)
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setFooter(`@${author.username}#${author.discriminator}`);
|
.setFooter(`@${author.username}#${author.discriminator}`);
|
||||||
@ -137,7 +137,7 @@ module.exports = {
|
|||||||
createAirportEmbed(data, author, command) {
|
createAirportEmbed(data, author, command) {
|
||||||
const airport = data.airport[0];
|
const airport = data.airport[0];
|
||||||
return new Discord.MessageEmbed()
|
return new Discord.MessageEmbed()
|
||||||
.setAuthor(command)
|
.setAuthor('Command: ' + command)
|
||||||
.setTitle(airport.airport_name)
|
.setTitle(airport.airport_name)
|
||||||
.addFields(
|
.addFields(
|
||||||
{ name: 'Location', value: `${airport.city}, ${airport.state_abbrev}`, inline: true },
|
{ name: 'Location', value: `${airport.city}, ${airport.state_abbrev}`, inline: true },
|
||||||
@ -152,7 +152,7 @@ module.exports = {
|
|||||||
const loc = data.location;
|
const loc = data.location;
|
||||||
const weather = data.current;
|
const weather = data.current;
|
||||||
return new Discord.MessageEmbed()
|
return new Discord.MessageEmbed()
|
||||||
.setAuthor(command)
|
.setAuthor('Command: ' + command)
|
||||||
.setTitle(`${loc.name}, ${loc.region}, ${loc.country} Weather`)
|
.setTitle(`${loc.name}, ${loc.region}, ${loc.country} Weather`)
|
||||||
.setDescription(`The weather is currently ${weather.condition.text}`)
|
.setDescription(`The weather is currently ${weather.condition.text}`)
|
||||||
.addFields(
|
.addFields(
|
||||||
@ -165,16 +165,16 @@ module.exports = {
|
|||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setFooter(`@${author.username}#${author.discriminator}`);
|
.setFooter(`@${author.username}#${author.discriminator}`);
|
||||||
},
|
},
|
||||||
createTextEmbed(data, author, command) {
|
textEmbed(content, author, command) {
|
||||||
return new Discord.MessageEmbed()
|
return new Discord.MessageEmbed()
|
||||||
.setAuthor(command)
|
.setAuthor('Command: ' + command)
|
||||||
.setDescription(data.content)
|
.setDescription(content)
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setFooter(`@${author.username}#${author.discriminator}`);
|
.setFooter(`@${author.username}#${author.discriminator}`);
|
||||||
},
|
},
|
||||||
createStockEmbed(data, author, command) {
|
createStockEmbed(data, author, command) {
|
||||||
return new Discord.MessageEmbed()
|
return new Discord.MessageEmbed()
|
||||||
.setAuthor(command)
|
.setAuthor('Command: ' + command)
|
||||||
.setTitle()
|
.setTitle()
|
||||||
.setTimestamp()
|
.setTimestamp()
|
||||||
.setFooter(`@${author.username}#${author.discriminator}`);
|
.setFooter(`@${author.username}#${author.discriminator}`);
|
||||||
@ -253,5 +253,43 @@ module.exports = {
|
|||||||
db.query(query)
|
db.query(query)
|
||||||
.then()
|
.then()
|
||||||
.catch(e => console.error(e));
|
.catch(e => console.error(e));
|
||||||
|
},
|
||||||
|
uploadRequest(author, request) {
|
||||||
|
const query = `INSERT INTO requests (author, request, status) VALUES ('@${author.username}#${author.discriminator}','${request}','Active')`;
|
||||||
|
db.query(query)
|
||||||
|
.then()
|
||||||
|
.catch(e => console.error(e));
|
||||||
|
},
|
||||||
|
getActiveRequests(message) {
|
||||||
|
const query = "SELECT * FROM requests WHERE status = 'Active'";
|
||||||
|
let rows;
|
||||||
|
db.query(query)
|
||||||
|
.then(res => {
|
||||||
|
const embed = this.requestsEmbed(res.rows);
|
||||||
|
message.channel.send(embed);
|
||||||
|
})
|
||||||
|
.catch(e => console.error(e));
|
||||||
|
return rows;
|
||||||
|
},
|
||||||
|
requestsEmbed(rows) {
|
||||||
|
let fields = [];
|
||||||
|
for (const row of rows) {
|
||||||
|
fields.push({
|
||||||
|
name: '#' + row.id,
|
||||||
|
value: row.request + `\nSubmitted by ${row.author}`
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Discord.MessageEmbed()
|
||||||
|
.setAuthor('NodBot Requests')
|
||||||
|
.setTitle('Currently Active Requests')
|
||||||
|
.addFields(fields)
|
||||||
|
.setTimestamp();
|
||||||
|
},
|
||||||
|
closeRequest(id) {
|
||||||
|
const query = `UPDATE requests SET status = 'Closed' WHERE id = ${id}`;
|
||||||
|
db.query(query)
|
||||||
|
.then()
|
||||||
|
.catch(e => console.error(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user