nodbot/functions.js

137 lines
4.9 KiB
JavaScript
Raw Normal View History

2021-06-28 03:20:21 +00:00
const Discord = require('discord.js');
const fs = require('fs');
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
const gifFiles = fs.readdirSync('./gifs').filter(file => file.endsWith('.js'));
2021-06-28 19:29:35 +00:00
const pastaFiles = fs.readdirSync('./pastas').filter(file => file.endsWith('.js'));
2021-06-28 03:20:21 +00:00
module.exports = {
getCommandFiles(client) {
client.commands = new Discord.Collection();
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
},
getGifFiles(client) {
client.gifs = new Discord.Collection();
for (const file of gifFiles) {
const gif = require(`./gifs/${file}`);
client.gifs.set(gif.name, gif);
}
},
2021-06-28 19:29:35 +00:00
getPastaFiles(client) {
2021-06-28 22:11:32 +00:00
client.pastas = new Discord.Collection();
2021-06-28 19:29:35 +00:00
for (const file of pastaFiles) {
2021-06-28 22:11:32 +00:00
const pasta = require(`./pastas/${file}`);
2021-06-28 19:29:35 +00:00
client.pastas.set(pasta.name, pasta);
}
},
2021-06-30 22:59:24 +00:00
getFileInfo(content) {
2021-07-01 22:12:21 +00:00
// const finalPeriod = content.search(/\.(?:.(?!\\))+$/gim);
const finalPeriod = content.lastIndexOf('.');
2021-06-30 22:59:24 +00:00
if (finalPeriod < 0) return false;
const extension = content.slice(finalPeriod).replace('.','').toLowerCase();
const filename = content.slice(0,finalPeriod).toLowerCase();
const file = {
'name': filename,
'extension': extension
};
2021-06-28 22:11:32 +00:00
return file;
2021-06-28 19:29:35 +00:00
},
2021-06-30 22:59:24 +00:00
extIsValid(extension) {
2021-07-01 22:12:21 +00:00
const extensions = require('./config.json').validExtensions;
return extensions.includes(extension);
2021-07-06 21:37:29 +00:00
},
cleanInput(input) {
return input.replace(/'/g, '\\\'').replace(/\n/g, '\\n');
},
createGifEmbed(data, author, command) {
2021-07-06 21:37:29 +00:00
return new Discord.MessageEmbed()
2021-07-14 00:57:37 +00:00
.setAuthor(command)
2021-07-16 15:50:54 +00:00
.setDescription(data.embed_url)
2021-07-06 21:37:29 +00:00
.setImage(data.embed_url)
.setTimestamp()
.setFooter(`@${author.username}#${author.discriminator}`);
},
saveGif(message, name, embed_url) {
fs.writeFile(`./gifs/${name}.js`, `module.exports = {\n\tname: '${name}',\n\tembed_url: '${embed_url}'\n}`, function(err) {
if (err) throw err;
console.log('Saved file!');
2021-07-10 03:34:16 +00:00
const gif = require(`./gifs/${name}.js`);
message.client.gifs.set(gif.name, gif);
});
2021-07-14 00:15:57 +00:00
},
2021-07-16 14:01:44 +00:00
savePasta(message, name, content) {
fs.writeFile(`./pastas/${name}.js`, `module.exports = {\n\tname: '${name}',\n\tcontent: '${content}'\n}`, function(err) {
if (err) {
return `There was a problem saving the copypasta.`;
}
const pasta = require(`./pastas/${name}.js`);
message.client.pastas.set(pasta.name, pasta);
});
return `Copypasta saved successfully as ${name}.pasta`;
},
createAirportEmbed(data, author, command) {
2021-07-14 00:15:57 +00:00
const airport = data.airport[0];
return new Discord.MessageEmbed()
.setAuthor(command)
2021-07-14 00:15:57 +00:00
.setTitle(airport.airport_name)
.addFields(
{ name: 'Location', value: `${airport.city}, ${airport.state_abbrev}`, inline: true },
{ name: 'Coordinates', value: `${airport.latitude}, ${airport.longitude}`, inline: true },
{ name: 'Elevation', value: `${airport.elevation}ft`, inline: true },
{ name: 'More Information', value: airport.link_path }
)
.setTimestamp()
.setFooter(`@${author.username}#${author.discriminator}`);
},
createWeatherEmbed(data, author, command) {
const loc = data.location;
const weather = data.current;
return new Discord.MessageEmbed()
.setAuthor(command)
.setTitle(`${loc.name}, ${loc.region}, ${loc.country} Weather`)
.setDescription(`The weather is currently ${weather.condition.text}`)
.addFields(
{ name: 'Temperature', value: `${weather.temp_f}°F (Feels like: ${weather.feelslike_f}°F)`, inline: true },
{ name: 'Winds', value: `${weather.wind_mph} ${weather.wind_dir}`, inline: true },
{ name: 'Pressure', value: `${weather.pressure_in}inHg`, inline: true },
{ name: 'Relative Humidity', value: `${weather.humidity}%`, inline: true }
)
2021-07-14 01:02:29 +00:00
.setThumbnail(`https:${weather.condition.icon}`)
.setTimestamp()
.setFooter(`@${author.username}#${author.discriminator}`);
2021-07-14 01:13:46 +00:00
},
createTextEmbed(data, author, command) {
return new Discord.MessageEmbed()
.setAuthor(command)
.setDescription(data.content)
.setTimestamp()
.setFooter(`@${author.username}#${author.discriminator}`);
2021-07-14 01:55:14 +00:00
},
createStockEmbed(data, author, command) {
return new Discord.MessageEmbed()
.setAuthor(command)
.setTitle()
.setTimestamp()
.setFooter(`@${author.username}#${author.discriminator}`);
2021-07-18 18:56:45 +00:00
},
mapCommands(client) {
const { commands } = client;
// return new Promise((resolve, reject) => {
// let commandMap = []
// for (const [key, value] of commands.map()) {
// // commandMap.push({
// // name: command.name,
// // aliases: command.aliases,
// // description: command.description,
// // usage: command.usage,
// // cooldown: 0 // Set to 0 for now for the sake of simple code, will add cooldowns later
// // });
// }
// });
for (const entry of commands.map(command => [command.name, command.description, command.syntax])) {
console.log(entry);
}
2021-07-14 01:13:46 +00:00
}
2021-06-28 03:20:21 +00:00
}