2019-01-01 03:49:46 +01:00
const { Listener } = require ( 'discord-akairo' ) ;
2019-01-02 10:21:21 +01:00
const { MessageEmbed } = require ( 'discord.js' ) ;
2019-01-02 05:51:09 +01:00
const reload = require ( 'auto-reload' ) ;
2019-01-10 09:00:30 +01:00
let messageID = require ( '../../json/starboard.json' ) ;
2019-01-01 03:49:46 +01:00
class MessageReactionAddListener extends Listener {
2019-01-02 08:09:45 +01:00
constructor ( ) {
super ( 'messagereactionadd' , {
emitter : 'client' ,
2019-01-02 21:46:12 +01:00
event : 'messageReactionAdd'
2019-01-02 08:09:45 +01:00
} ) ;
}
2019-03-25 08:17:32 +01:00
async exec ( reaction , user ) {
2019-03-19 21:05:47 +01:00
if ( reaction . message . author == user ) return ;
2019-01-02 08:09:45 +01:00
let messageContent = reaction . message . content ;
2019-03-15 23:43:37 +01:00
let messageAttachments = reaction . message . attachments . map ( u => u . url ) ;
2019-02-14 18:44:21 +01:00
2019-02-15 01:09:08 +01:00
let starboardChannel ;
let staremote ;
let starcount ;
try {
starboardChannel = reload ( ` ../../board/star ${ reaction . message . guild . id } .json ` ) ;
staremote = starboardChannel [ 'emote' ] ;
starcount = starboardChannel [ 'count' ] ;
} catch ( err ) {
return null ;
}
2019-01-02 08:09:45 +01:00
2019-01-11 12:47:04 +01:00
// Starboard
2019-02-14 18:44:21 +01:00
if ( reaction . emoji . name == staremote && reaction . count == starcount ) {
2019-01-03 17:18:29 +01:00
if ( messageID . includes ( reaction . message . id ) )
return console . log ( 'Message already in starboard!' ) ;
messageID . push ( reaction . message . id ) ;
2019-01-02 08:09:45 +01:00
const channel = this . client . channels . get ( starboardChannel [ 'starboard' ] ) ;
2019-03-13 18:57:54 +01:00
if ( ! messageContent ) {
2019-03-26 02:46:36 +01:00
const starEmbed = new MessageEmbed ( )
. setColor ( reaction . message . member . displayHexColor )
. setAuthor ( reaction . message . author . username , reaction . message . author . displayAvatarURL ( ) )
. setDescription ( ` [Jump to message](https://discordapp.com/channels/ ${ reaction . message . guild . id } / ${ reaction . message . channel . id } / ${ reaction . message . id } ) ` )
. setFooter ( reaction . count + ' ' + staremote )
. setTimestamp ( ) ;
return channel . send ( { files : messageAttachments , embed : starEmbed } )
. catch ( ( ) => channel . send ( messageAttachments , { embed : starEmbed } ) ) ;
2019-03-13 18:57:54 +01:00
}
2019-01-15 19:22:23 +01:00
2019-01-02 10:21:21 +01:00
const starEmbed = new MessageEmbed ( )
2019-01-04 19:43:10 +01:00
. setColor ( reaction . message . member . displayHexColor )
2019-01-14 20:27:27 +01:00
. setAuthor ( reaction . message . author . username , reaction . message . author . displayAvatarURL ( ) )
2019-03-25 08:17:32 +01:00
. setDescription ( messageContent )
2019-03-25 20:37:38 +01:00
. addField ( 'Jump to' , ` [message](https://discordapp.com/channels/ ${ reaction . message . guild . id } / ${ reaction . message . channel . id } / ${ reaction . message . id } ) ` )
2019-03-25 08:17:32 +01:00
. setFooter ( reaction . count + ' ' + staremote )
2019-01-02 10:21:21 +01:00
. setTimestamp ( ) ;
2019-01-02 08:09:45 +01:00
2019-03-13 19:19:30 +01:00
return channel . send ( ` in: ${ reaction . message . channel } ` , { files : messageAttachments , embed : starEmbed } )
. catch ( ( ) => channel . send ( ` ${ reaction . message . author . username } , in: ${ reaction . message . channel } ` , { embed : starEmbed } ) ) ;
2019-01-02 08:09:45 +01:00
}
2019-02-14 18:44:21 +01:00
2019-02-15 01:09:08 +01:00
let shameboardChannel ;
let shameemote ;
let shamecount ;
try {
shameboardChannel = reload ( ` ../../board/shame ${ reaction . message . guild . id } .json ` ) ;
2019-02-14 18:44:21 +01:00
2019-02-15 01:09:08 +01:00
shameemote = shameboardChannel [ 'emote' ] ;
shamecount = shameboardChannel [ 'count' ] ;
} catch ( err ) {
return null ;
}
2019-02-14 18:44:21 +01:00
2019-01-11 12:47:04 +01:00
//Shameboard
2019-02-14 18:44:21 +01:00
if ( reaction . emoji . name == shameemote && reaction . count == shamecount ) {
2019-01-03 17:18:29 +01:00
if ( messageID . includes ( reaction . message . id ) )
return console . log ( 'Message already in starboard!' ) ;
2019-01-03 17:52:54 +01:00
2019-01-03 17:18:29 +01:00
messageID . push ( reaction . message . id ) ;
2019-01-03 17:52:54 +01:00
const channel = this . client . channels . get ( shameboardChannel [ 'shameboard' ] ) ;
2019-01-02 08:09:45 +01:00
2019-03-13 18:57:54 +01:00
if ( ! messageContent ) {
2019-03-26 02:46:36 +01:00
const shameEmbed = new MessageEmbed ( )
. setColor ( reaction . message . member . displayHexColor )
. setAuthor ( reaction . message . author . username , reaction . message . author . displayAvatarURL ( ) )
. setDescription ( ` [Jump to message](https://discordapp.com/channels/ ${ reaction . message . guild . id } / ${ reaction . message . channel . id } / ${ reaction . message . id } ) ` )
. setFooter ( reaction . count + ' ' + shameemote )
. setTimestamp ( ) ;
return channel . send ( { files : messageAttachments , embed : shameEmbed } )
. catch ( ( ) => channel . send ( messageAttachments , { embed : shameEmbed } ) ) ;
2019-03-13 18:57:54 +01:00
}
2019-01-15 19:22:23 +01:00
2019-01-03 17:52:54 +01:00
const shameEmbed = new MessageEmbed ( )
2019-01-04 19:43:10 +01:00
. setColor ( reaction . message . member . displayHexColor )
2019-01-14 20:27:27 +01:00
. setAuthor ( reaction . message . author . username , reaction . message . author . displayAvatarURL ( ) )
2019-03-25 08:17:32 +01:00
. setDescription ( messageContent )
2019-03-25 20:37:38 +01:00
. addField ( 'Jump to' , ` [message](https://discordapp.com/channels/ ${ reaction . message . guild . id } / ${ reaction . message . channel . id } / ${ reaction . message . id } ) ` )
2019-03-25 08:17:32 +01:00
. setFooter ( reaction . count + ' ' + shameemote )
2019-01-02 10:21:21 +01:00
. setTimestamp ( ) ;
2019-01-02 08:09:45 +01:00
2019-03-13 19:19:30 +01:00
return channel . send ( ` in: ${ reaction . message . channel } ` , { files : messageAttachments , embed : shameEmbed } )
. catch ( ( ) => channel . send ( ` ${ reaction . message . author . username } , in: ${ reaction . message . channel } ` , { embed : shameEmbed } ) ) ;
2019-01-02 08:09:45 +01:00
}
}
2019-01-01 03:49:46 +01:00
}
module . exports = MessageReactionAddListener ;