diff --git a/ch_index.js b/ch_index.js deleted file mode 100644 index 48b96c4..0000000 --- a/ch_index.js +++ /dev/null @@ -1,169 +0,0 @@ -require('./server'); - -const { token } = process.env; - -const fetch = require('node-fetch'); -const Discord = require('discord.js'); - -const client = new Discord.Client(); - -const Prefix = ';'; - -const moment = require('moment-timezone'); - -const got = require("got"); - -const mongo = require("mongodb"); -const { - Sequelize, - DataTypes -} = require('sequelize'); - - -const fs = require("fs"); - -const version = "1.0.0"; - -client.commands = new Discord.Collection(); - -function command(command) { - return `${Prefix}${command}` -} - -client.on("ready", () => { - console.log(`Logged in as ${client.user.tag}!`); - client.user.setActivity(';cmds | v1.0.1', { type: 'LISTENING' }) -}); - -client.on('message', message => { - if (!message.content.startsWith(prefix) || message.author.bot) return; - - const args = message.content.slice(prefix.length).trim().split(/ +/); - const command = args.shift().toLowerCase(); - - - switch (message.content) { - case command('cmds'): - let dateTime2 = message.createdAt - let d2 = moment(dateTime2); - let time2 = d2.tz("America/Chicago").format("LT"); - let embed2 = new Discord.MessageEmbed() - .setTitle("Here are a list of commands!") - .setDescription(">>> ```;avatar```\n```;invite```\n```;meme```\n```;owner```\n```;devs```\n```;support```") - .setColor("ORANGE") - .setFooter(`Moby • Today at ${time2}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) - message.channel.send(embed2) - break; - - case command('support'): - let dateTimeSup = message.createdAt - let dSup = moment(dateTimeSup); - let timeSup = dSup.tz("America/Chicago").format("LT"); - let embedSup = new Discord.MessageEmbed() - .setTitle("Moby's Support Server!") - .setDescription("Click on the link to join Moby's support server today! [Link](https://discord.gg/7zUD9vkDzN)") - .setColor("ORANGE") - .setFooter(`Moby • Today at ${timeSup}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) - message.channel.send(embedSup) - break; - - case command('femboy me daddy UwU'): - let dateTime3 = message.createdAt - let d3 = moment(dateTime3); - let time3 = d3.tz("America/Chicago").format("LT"); - let embed3 = new Discord.MessageEmbed() - .setTitle("no you demented burnt lentil") - .setDescription("hehe luv ya :D\nthis is the secret command :)") - .setColor("ORANGE") - .setFooter(`Moby • Today at ${time3}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) - message.channel.send(embed3) - break; - - case command('owner'): - let dateTime6 = message.createdAt - let d6 = moment(dateTime6); - let time6 = d6.tz("America/Chicago").format("LT"); - let embed6 = new Discord.MessageEmbed() - .setTitle("Who owns me?") - .setDescription("head;#8429") - .setColor("ORANGE") - .setFooter(`Moby • Today at ${time6}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) - message.channel.send(embed6) - break; - - case command('devs'): - let dateTime7 = message.createdAt - let d7 = moment(dateTime7); - let time7 = d7.tz("America/Chicago").format("LT"); - let embed7 = new Discord.MessageEmbed() - .setTitle("Heres a list of the devs!") - .setDescription("-_-#9799") - .setColor("ORANGE") - .setFooter(`Moby • Today at ${time7}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) - message.channel.send(embed7) - break; - - case command('avatar'): - let dateTime4 = message.createdAt - let d4 = moment(dateTime4); - let time4 = d4.tz("America/Chicago").format("LT"); - let embed4 = new Discord.MessageEmbed() - .setTitle("Heres your avatar!") - .setImage(message.author.displayAvatarURL({ dyanmic: true, format: 'png', size: 512 })) - .setColor("ORANGE") - .setFooter(`Moby • Today at ${time4}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) - message.channel.send(embed4) - break; - - case command('invite'): - let dateTime5 = message.createdAt - let d5 = moment(dateTime5); - let time5 = d5.tz("America/Chicago").format("LT"); - let embed5 = new Discord.MessageEmbed() - .setTitle("Invite Moby to your Server!") - .setDescription('Use this link to invite Moby to your servers! [Link](https://discord.com/oauth2/authorize?client_id=784210441622650920&scope=bot)') - .addField(`Version: 1.0.1`) - .setColor("ORANGE") - .setFooter(`Moby • Today at ${time5}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) - message.channel.send(embed5) - break; - - case command('kick'): - const kickMember = message.mentions.members.first() - kickMember.kick(); - break; - - case command('meme'): - let memeembed = new Discord.MessageEmbed() - got("https://www.reddit.com/r/dankmemes/random/.json").then(response => { - - let dateTime = message.createdAt - let d = moment(`${dateTime}`) - let time = d.tz("America/Chicago").format("LT"); - let content = JSON.parse(response.body); - let permalink = content[0].data.children[0].data.permalink; - let memeUrl = `https://reddit.com${permalink};` - let memeImage = content[0].data.children[0].data.url; - let memeTitle = content[0].data.children[0].data.title; - let memeUpvotes = content[0].data.children[0].data.ups; - let memeDownvotes = content[0].data.children[0].data.downs; - let memeNumComments = content[0].data.children[0].data.num_comments; - let memeSubreddit = content[0].data.children[0].data.subreddit; - memeembed.setTitle(`${memeTitle}`); - memeembed.setDescription(`r/${memeSubreddit}`) - memeembed.setURL(`${memeUrl}`); - memeembed.setImage(memeImage); - memeembed.setColor("ORANGE"); - memeembed.setFooter(`Moby • Today at ${time}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })); - message.channel.send(memeembed); - }); - } -}); - -client.on('guildMemberAdd', member => { - const channel = member.guild.channels.cache.find(ch => ch.name === 'member-log'); - if (!channel) return; - channel.send(`Howdy ${member}! Welcome to the server.`); -}); - -client.login(token); \ No newline at end of file diff --git a/commands/_template b/commands/_template new file mode 100644 index 0000000..f78911b --- /dev/null +++ b/commands/_template @@ -0,0 +1,23 @@ +module.exports = { + name: 'test', + aliases: ['test2', 't'], + + description: '', + + args: true, + //args required? + + usage: ' ', + //usage of command + + guildOnly: true, + + cooldown: 5, + //in secs + + permissions: 'ADMINISTRATOR', + + execute(message, args) { +//stuff + }, +}; \ No newline at end of file diff --git a/commands/avatar.js b/commands/avatar.js index fb09d54..e129e6d 100644 --- a/commands/avatar.js +++ b/commands/avatar.js @@ -2,21 +2,24 @@ const Discord = require('discord.js'); module.exports = { name: 'avatar', + aliases: ['icon', 'pfp'], description: 'Returns a users avatar', execute(message, args) { const embed = new Discord.MessageEmbed() if (!message.mentions.users.first()) { embed.setTitle("Your Avatar:") + embed.setURL(message.author.displayAvatarURL()) embed.setThumbnail(message.author.displayAvatarURL()) // embed.setDescription("This is your avatar.") - embed.setColor("RANDOM") + embed.setColor("ORANGE") return message.channel.send(embed) } else { const user = message.mentions.users.first() embed.setTitle(`${user.tag}'s Avatar:`) + embed.setURL(user.displayAvatarURL()) embed.setThumbnail(user.displayAvatarURL()) // embed.setDescription(`This is ${user.tag}'s avatar.`) - embed.setColor('RANDOM') + embed.setColor('ORANGE') // embed.setFooter("This is a test.") return message.channel.send(embed) } diff --git a/commands/devs.js b/commands/devs.js deleted file mode 100644 index 56ca0e5..0000000 --- a/commands/devs.js +++ /dev/null @@ -1,9 +0,0 @@ -const Discord = require('discord.js'); - -module.exports = { - name: 'ping', - description: 'Ping!', - execute(message, args) { - message.channel.send('Pong.'); - }, -}; \ No newline at end of file diff --git a/commands/help.js b/commands/help.js index 78579c8..2edfdf1 100644 --- a/commands/help.js +++ b/commands/help.js @@ -1,7 +1,47 @@ +const prefix = ';'; +//this will change with the custom prefix thing + module.exports = { name: 'help', - description: 'Help menu', + description: 'List all of my commands or info about a specific command.', + aliases: ['commands', 'cmds', 'info'], + usage: '[command name]', execute(message, args) { - //will work on this later as it is a "feature" of the command handling + const data = []; + const { commands } = message.client; + + if (!args.length) { + let nonhiddencmds = commands.filter(command => {if (!command.hidden) return command.name }); + data.push('Here\'s a list of all my commands:'); + data.push(nonhiddencmds.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!'); + }); + } + + 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/invite.js b/commands/invite.js index 03bb4da..828ee22 100644 --- a/commands/invite.js +++ b/commands/invite.js @@ -1,7 +1,16 @@ +const Discord = require('discord.js'); +const version = "v1.0.3" + module.exports = { - name: 'ping', - description: 'Ping!', + name: 'invite', + description: 'Get the invite link for the bot!', execute(message, args) { - message.channel.send('Pong.'); + let embed5 = new Discord.MessageEmbed() + .setTitle("Invite Moby to your Server!") + .setDescription('Use this link to invite Moby to your servers! [Link](https://discord.com/oauth2/authorize?client_id=784210441622650920&permissions=8&scope=bot)') + .addField(version) + .setColor("ORANGE") + .setFooter(`Moby`, message.client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) + message.channel.send(embed5) }, }; \ No newline at end of file diff --git a/commands/meme.js b/commands/meme.js index 59b5f77..fd0852e 100644 --- a/commands/meme.js +++ b/commands/meme.js @@ -20,7 +20,7 @@ module.exports = { embed.setTitle(`${memeTitle}`); embed.setURL(`${memeUrl}`); - embed.setColor('RANDOM'); + embed.setColor('ORANGE'); embed.setImage(memeImage); embed.setFooter(`👍 ${memeUpvotes} 💬 ${memeNumComments}`); diff --git a/commands/owner.js b/commands/owner.js deleted file mode 100644 index 56ca0e5..0000000 --- a/commands/owner.js +++ /dev/null @@ -1,9 +0,0 @@ -const Discord = require('discord.js'); - -module.exports = { - name: 'ping', - description: 'Ping!', - execute(message, args) { - message.channel.send('Pong.'); - }, -}; \ No newline at end of file diff --git a/commands/secretcommand.js b/commands/secretcommand.js index 56ca0e5..215702b 100644 --- a/commands/secretcommand.js +++ b/commands/secretcommand.js @@ -1,9 +1,15 @@ const Discord = require('discord.js'); module.exports = { - name: 'ping', - description: 'Ping!', + name: 'femboy me daddy UwU', + hidden: true, + description: '', execute(message, args) { - message.channel.send('Pong.'); + let embed3 = new Discord.MessageEmbed() + .setTitle("no you demented burnt lentil") + .setDescription("hehe luv ya :D\nthis is the secret command :)") + .setColor("ORANGE") + .setFooter(`Moby`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) + message.channel.send(embed3) }, }; \ No newline at end of file diff --git a/commands/support.js b/commands/support.js index f57cafc..6c5e8b4 100644 --- a/commands/support.js +++ b/commands/support.js @@ -8,7 +8,7 @@ module.exports = { .setTitle("Moby's Support Server!") .setDescription("Click on the link to join Moby's support server today! [Link](https://discord.gg/7zUD9vkDzN)") .setColor("ORANGE") - .setFooter(`Moby • Today at ${timeSup}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) + .setFooter(`Moby • Today at ${timeSup}`, message.client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) message.channel.send(embedSup) }, }; \ No newline at end of file diff --git a/index.js b/index.js index b6f7ae0..6e1f12d 100644 --- a/index.js +++ b/index.js @@ -7,7 +7,7 @@ const Discord = require('discord.js'); const client = new Discord.Client(); -const Prefix = ';'; +const prefix = ';'; const moment = require('moment-timezone'); @@ -15,143 +15,91 @@ const got = require("got"); const mongo = require("mongodb"); const { - Sequelize, - DataTypes + Sequelize, + DataTypes } = require('sequelize'); const fs = require("fs"); -const version = "1.0.3"; +const version = "1.0.0"; client.commands = new Discord.Collection(); -function command(command) { - return `${Prefix}${command}` + +client.commands = new Discord.Collection(); +const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); +for (const file of commandFiles) { + const command = require(`./commands/${file}`); + client.commands.set(command.name, command); } +const cooldowns = new Discord.Collection(); + client.on("ready", () => { console.log(`Logged in as ${client.user.tag}!`); - client.user.setActivity(';cmds | v1.0.3', { type: 'LISTENING' }) + client.user.setActivity(';help | v1.0.1', { type: 'LISTENING' }) }); client.on('message', message => { - switch (message.content) { - case command('cmds'): - let dateTime2 = message.createdAt - let d2 = moment(dateTime2); - let time2 = d2.tz("America/Chicago").format("LT"); - let embed2 = new Discord.MessageEmbed() - .setTitle("Here are a list of commands!") - .setDescription(">>> ```;avatar```\n```;invite```\n```;meme```\n```;owner```\n```;devs```\n```;support```") - .setColor("ORANGE") - .setFooter(`Moby • Today at ${time2}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) - message.channel.send(embed2) - break; - - case command('support'): - let dateTimeSup = message.createdAt - let dSup = moment(dateTimeSup); - let timeSup = dSup.tz("America/Chicago").format("LT"); - let embedSup = new Discord.MessageEmbed() - .setTitle("Moby's Support Server!") - .setDescription("Click on the link to join Moby's support server today! [Link](https://discord.gg/7zUD9vkDzN)") - .setColor("ORANGE") - .setFooter(`Moby • Today at ${timeSup}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) - message.channel.send(embedSup) - break; - - case command('femboy me daddy UwU'): - let dateTime3 = message.createdAt - let d3 = moment(dateTime3); - let time3 = d3.tz("America/Chicago").format("LT"); - let embed3 = new Discord.MessageEmbed() - .setTitle("no you demented burnt lentil") - .setDescription("hehe luv ya :D\nthis is the secret command :)") - .setColor("ORANGE") - .setFooter(`Moby • Today at ${time3}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) - message.channel.send(embed3) - break; - - case command('owner'): - let dateTime6 = message.createdAt - let d6 = moment(dateTime6); - let time6 = d6.tz("America/Chicago").format("LT"); - let embed6 = new Discord.MessageEmbed() - .setTitle("Who owns me?") - .setDescription("head;#8429") - .setColor("ORANGE") - .setFooter(`Moby • Today at ${time6}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) - message.channel.send(embed6) - break; - - case command('devs'): - let dateTime7 = message.createdAt - let d7 = moment(dateTime7); - let time7 = d7.tz("America/Chicago").format("LT"); - let embed7 = new Discord.MessageEmbed() - .setTitle("Heres a list of the devs!") - .setDescription("-_-#9799") - .setColor("ORANGE") - .setFooter(`Moby • Today at ${time7}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) - message.channel.send(embed7) - break; - - case command('avatar'): - let dateTime4 = message.createdAt - let d4 = moment(dateTime4); - let time4 = d4.tz("America/Chicago").format("LT"); - let embed4 = new Discord.MessageEmbed() - .setTitle("Heres your avatar!") - .setImage(message.author.displayAvatarURL({ dyanmic: true, format: 'png', size: 512 })) - .setColor("ORANGE") - .setFooter(`Moby • Today at ${time4}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) - message.channel.send(embed4) - break; - - case command('invite'): - let dateTime5 = message.createdAt - let d5 = moment(dateTime5); - let time5 = d5.tz("America/Chicago").format("LT"); - let embed5 = new Discord.MessageEmbed() - .setTitle("Invite Moby to your Server!") - .setDescription('Use this link to invite Moby to your servers! [Link](https://discord.com/oauth2/authorize?client_id=784210441622650920&permissions=8&scope=bot)') - .addField(version) - .setColor("ORANGE") - .setFooter(`Moby • Today at ${time5}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })) - message.channel.send(embed5) - break; - - case command('kick'): - const kickMember = message.mentions.members.first() - kickMember.kick(); - break; - - case command('meme'): - let memeembed = new Discord.MessageEmbed() - got("https://www.reddit.com/r/dankmemes/random/.json").then(response => { - - let dateTime = message.createdAt - let d = moment(`${dateTime}`) - let time = d.tz("America/Chicago").format("LT"); - let content = JSON.parse(response.body); - let permalink = content[0].data.children[0].data.permalink; - let memeUrl = `https://reddit.com${permalink};` - let memeImage = content[0].data.children[0].data.url; - let memeTitle = content[0].data.children[0].data.title; - let memeUpvotes = content[0].data.children[0].data.ups; - let memeDownvotes = content[0].data.children[0].data.downs; - let memeNumComments = content[0].data.children[0].data.num_comments; - let memeSubreddit = content[0].data.children[0].data.subreddit; - memeembed.setTitle(`${memeTitle}`); - memeembed.setDescription(`r/${memeSubreddit}`) - memeembed.setURL(`${memeUrl}`); - memeembed.setImage(memeImage); - memeembed.setColor("ORANGE"); - memeembed.setFooter(`Moby • Today at ${time}`, client.user.displayAvatarURL({ dynamic: true, format: 'png', size: 32 })); - message.channel.send(memeembed); - }); + if (!message.content.startsWith(prefix) || message.author.bot) return; + + const args = message.content.slice(prefix.length).trim().split(/ +/); + const commandName = args.shift().toLowerCase(); + const command = client.commands.get(commandName) + || client.commands.find(cmd => cmd.aliases && cmd.aliases.includes(commandName)); + + if (!command) return; + + if (command.guildOnly && message.channel.type === 'dm') { + return message.reply('I can\'t execute that command inside DMs!'); +} + + if (command.permissions) { + const authorPerms = message.channel.permissionsFor(message.author); + if (!authorPerms || !authorPerms.has(command.permissions)) { + return message.channel.reply('You can not do this!'); + } + } + + if (command.args && !args.length) { + let reply = `You didn't provide any arguments, ${message.author}!`; + + if (command.usage) { + reply += `\nThe proper usage would be: \`${prefix}${command.name} ${command.usage}\``; + } + + return message.channel.send(reply); + } + +if (!cooldowns.has(command.name)) { + cooldowns.set(command.name, new Discord.Collection()); +} + +const now = Date.now(); +const timestamps = cooldowns.get(command.name); +const cooldownAmount = (command.cooldown || 3) * 1000; + +if (timestamps.has(message.author.id)) { + const expirationTime = timestamps.get(message.author.id) + cooldownAmount; + + if (now < expirationTime) { + const timeLeft = (expirationTime - now) / 1000; + return message.reply(`please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`); + } +} +timestamps.set(message.author.id, now); +setTimeout(() => timestamps.delete(message.author.id), cooldownAmount); + + + try { + command.execute(message, args); + } catch (error) { + console.error(error); + message.reply('there was an error trying to execute that command!'); } + + }); client.on('guildMemberAdd', member => {