From 8e25f7f95fec81bcf4c7edc00a99080621119907 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Tue, 23 May 2017 22:27:03 +0000 Subject: [PATCH] Star Command --- XiaoBot.js | 15 +++----------- commands/random/star.js | 45 +++++++++++++++++++++++++++++++++++++++++ package.json | 2 +- 3 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 commands/random/star.js diff --git a/XiaoBot.js b/XiaoBot.js index 029658ec..cb5fe455 100644 --- a/XiaoBot.js +++ b/XiaoBot.js @@ -9,7 +9,6 @@ const client = new CommandoClient({ invite: INVITE, unknownCommandResponse: false }); -const { RichEmbed } = require('discord.js'); const { carbon, dBots } = require('./structures/Stats'); const SequelizeProvider = require('./providers/Sequelize'); @@ -82,23 +81,15 @@ client.on('message', async (msg) => { client.on('messageReactionAdd', (reaction, user) => { if (reaction.emoji.name !== '⭐') return; if (reaction.count > 1) return; - if (user.bot) return; const msg = reaction.message; - const channel = msg.guild.channels.get(msg.guild.settings.get('starboard')); + const channel = msg.guild.settings.get('starboard'); if (!channel) return; - if (!channel.permissionsFor(client.user).has(['SEND_MESSAGES', 'EMBED_LINKS'])) return; if (user.id === msg.author.id) { if (msg.channel.permissionsFor(client.user).has('MANAGE_MESSAGES')) reaction.remove(user); - return msg.reply('You cannot star your own messages, idiot.'); + return msg.reply('You cannot star your own messages, idiot'); } - const embed = new RichEmbed() - .setColor(0xFFFF00) - .setAuthor(msg.author.tag, msg.author.displayAvatarURL) - .setDescription(msg.content) - .setImage(msg.attachments.first() ? msg.attachments.first().url : null) - .setTimestamp(); - return channel.send({ embed }); + client.registry.resolveCommand('random:starboard').run(msg, { id: msg.id }, true); }); client.on('guildMemberAdd', (member) => { diff --git a/commands/random/star.js b/commands/random/star.js new file mode 100644 index 00000000..b4b484a4 --- /dev/null +++ b/commands/random/star.js @@ -0,0 +1,45 @@ +const { Command } = require('discord.js-commando'); +const { RichEmbed } = require('discord.js'); +const moment = require('moment'); + +module.exports = class StarCommand extends Command { + constructor(client) { + super(client, { + name: 'star', + group: 'random', + memberName: 'star', + description: 'Stars a message.', + args: [ + { + key: 'id', + prompt: 'What is the ID of the message you wish to star?', + type: 'string', + validate: id => { + if (id.length === 18) return true; + return 'Invalid ID.'; + } + } + ] + }); + } + + async run(msg, args, reaction) { + const { id } = args; + const channel = msg.guild.settings.get('starboard'); + if (!channel || !channel.permissionsFor(this.client.user).has('EMBED_LINKS')) return null; + try { + const message = await msg.channel.fetchMessage(id); + if (!reaction && msg.author.id === message.author.id) + return msg.reply('You cannot star your own messages, idiot.'); + const embed = new RichEmbed() + .setColor(0xFFFF00) + .setAuthor(message.author.tag, message.author.displayAvatarURL) + .setDescription(message.content) + .setImage(message.attachments.first() ? message.attachments.first().url : null) + .setFooter(moment(message.createdTimestamp).format('MMMM Do YYYY h:mm:ss A')); + return channel.send({ embed }); + } catch (err) { + return msg.say(`${err.name}: ${err.message}`); + } + } +}; diff --git a/package.json b/package.json index bdb5904d..e45e68e9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "20.0.0", + "version": "20.1.0", "description": "A Discord Bot", "main": "Shard.js", "scripts": {