diff --git a/commands/help.js b/commands/help.js new file mode 100644 index 0000000..26be304 --- /dev/null +++ b/commands/help.js @@ -0,0 +1,43 @@ +const { prefix } = require('../config.json'); + +module.exports = { + name: 'help', + description: 'Shows the help page.', + execute(message, args) { + const data = []; + const { commands } = message.client; + + if (!args.length) { + data.push('Here\'s a list of all my commands:'); + data.push(commands.map(command => command.name).join(', ')); + data.push(`\nYou can send \`${prefix}help [command name]\` to get info on a specific command!`); + + return message.author.send(data, { split: true }) + .then(() => { + if (message.channel.type === 'dm') return; + message.reply('I\'ve sent you a DM with all my commands!'); + }) + .catch(error => { + console.error(`Could not send help DM to ${message.author.tag}.\n`, error); + message.reply('it seems like I can\'t DM you! Do you have DMs disabled?'); + }); + } + + const name = args[0].toLowerCase(); + const command = commands.get(name) || commands.find(c => c.aliases && c.aliases.includes(name)); + + if (!command) { + return message.reply('that\'s not a valid command!'); + } + + data.push(`**Name:** ${command.name}`); + + if (command.aliases) data.push(`**Aliases:** ${command.aliases.join(', ')}`); + if (command.description) data.push(`**Description:** ${command.description}`); + if (command.usage) data.push(`**Usage:** ${prefix}${command.name} ${command.usage}`); + + data.push(`**Cooldown:** ${command.cooldown || 3} second(s)`); + + message.channel.send(data, { split: true }); + }, +}; \ No newline at end of file diff --git a/commands/log-message.js b/commands/log-message.js new file mode 100644 index 0000000..fbbb02a --- /dev/null +++ b/commands/log-message.js @@ -0,0 +1,7 @@ +module.exports = { + name: "log-message", + description: "Logs the message to console for debugging purposes.", + execute(message, args) { + console.log(message); + } +} \ No newline at end of file diff --git a/commands/ping.js b/commands/ping.js new file mode 100644 index 0000000..eb270b5 --- /dev/null +++ b/commands/ping.js @@ -0,0 +1,7 @@ +module.exports = { + name: 'ping', + description: 'Ping!', + execute(message, args) { + message.channel.send('Pong.'); + } +} \ No newline at end of file diff --git a/commands/request.js b/commands/request.js new file mode 100644 index 0000000..03696cb --- /dev/null +++ b/commands/request.js @@ -0,0 +1,9 @@ +module.exports = { + name: 'request', + description: 'Submit a request to the bot developer.', + execute(message, args) { + const request = args.join(' '); + message.channel.send('Your request has been submitted:\n```\n' + request + '\n```'); + message.client.users.fetch(process.env.ownerID).then(user => {user.send('New request or feedback:\n```\n' + request + '\n```');}).catch(error => { console.error(error);} ); + } +} \ No newline at end of file diff --git a/commands/template b/commands/template new file mode 100644 index 0000000..e87841d --- /dev/null +++ b/commands/template @@ -0,0 +1,7 @@ +module.exports = { + name: "", + description: "", + execute(message, args) { + message.channel.send(""); + } +} \ No newline at end of file diff --git a/commands/truth.js b/commands/truth.js new file mode 100644 index 0000000..fab5c0c --- /dev/null +++ b/commands/truth.js @@ -0,0 +1,7 @@ +module.exports = { + name: "truth", + description: "The truth about MHFS", + execute(message, args) { + message.channel.send("https://www.twitch.tv/hochmania/clip/EsteemedSlickDootStinkyCheese-hncmP8aIP8_WQb_a?filter=clips&range=all&sort=time"); + } +} \ No newline at end of file diff --git a/commands/wrongbad.js b/commands/wrongbad.js new file mode 100644 index 0000000..df735d6 --- /dev/null +++ b/commands/wrongbad.js @@ -0,0 +1,9 @@ +module.exports = { + name: "wrongbad", + description: "", + execute(message, args) { + + const wrongbad = "<:wrongbad:853304921969393684>"; + message.channel.send(""); + } +} \ No newline at end of file diff --git a/config.json b/config.json new file mode 100644 index 0000000..7b3bac1 --- /dev/null +++ b/config.json @@ -0,0 +1,4 @@ +{ + "prefix": "/", + "serverID": "760701839427108874" +} \ No newline at end of file diff --git a/index.js b/index.js index ff2dfdd..503eefb 100644 --- a/index.js +++ b/index.js @@ -1,80 +1,60 @@ /* eslint-disable brace-style */ // Variable Assignment +const fs = require('fs'); const dotenv = require('dotenv'); +dotenv.config(); const Discord = require('discord.js'); const client = new Discord.Client(); -const giphy = require('giphy-api')(process.env.giphyAPIKey); -const debug = false; -const links = require('./links.json'); +client.commands = new Discord.Collection(); +const debug = true; +const config = require('./config.json'); +const { prefix, serverID } = require('./config.json'); +const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); +// const owner = process.env.ownerID; -dotenv.config(); -const owner = process.env.ownerID; +function getCommandFiles() { + for (const file of commandFiles) { + const command = require(`./commands/${file}`); + client.commands.set(command.name, command); + } + if (debug) console.log(client.commands); +} -if (debug) { - console.log(links); +function extCheck(content) { + const lastFour = content.slice(-4); + switch (lastFour) { + case '.gif': + return 'gif'; + case '.jpg': + return 'jpg'; + default: + return false; + } } client.once('ready', () => { console.log('Ready'); + client.guilds.fetch(serverID) + .then(guild => client.user.setActivity('Nod Simulator 2021', {type: "PLAYING"})) + .catch(console.error); + getCommandFiles(); }); client.login(process.env.TOKEN); client.on('message', message => { - if (message.author.bot) return; + if (debug) console.log(extCheck(message.content)); + if (!message.content.startsWith(prefix) || message.author.bot || !extCheck(message.content)) return; - const pre = message.content.slice(0, -4); - const ext = message.content.slice(-4); - let gifFound = false; + const args = message.content.slice(prefix.length).trim().split(/ +/); + const command = args.shift().toLowerCase(); - switch (ext) { - case '.gif': - if (debug) { - console.log('pre: ' + pre); - console.log('ext: ' + ext); - } - for (let index = 0; index < links.gifs.length; index++) { - const gif = links.gifs[index]; - if (gif.name == pre) { - message.channel.send(gif.embed_url); - gifFound = true; - } - } - if (gifFound == false) { - try { - giphy.search(pre, function(err, res) { - if (res.data[0] != undefined) { - message.channel.send(res.data[0].embed_url); - } else { - message.channel.send('Sorry, I was unable to find a gif of ' + pre + '.'); - } - if (err) { - console.log(err); - } - }); - } catch (error) { - console.log(error); - } - } - break; - // Admin Commands - case '.adm': - if (message.member.id == process.env.ownerID) { - switch (pre) { - case 'kill': - client.destroy(); - process.exit(); - break; - default: - break; - } - } - break; - case '.req': - message.channel.send('Feedback Submitted: ' + pre); - client.users.fetch(owner).then(user => { user.send('Feedback/Request: ' + pre);}); - break; - default: - break; + if (!client.commands.has(command)) return; + + try { + client.commands.get(command).execute(message, args); + } catch (error) { + console.error(error); + message.reply('There was an error trying to execute that command.'); } }); \ No newline at end of file