forked from sabattle/CalypsoBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
141 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,98 @@ | ||
const { MessageEmbed } = require('discord.js'); | ||
const { verify } = require('../utils/emojis.json'); | ||
const { stripIndent } = require('common-tags'); | ||
|
||
module.exports = async (client, messageReaction, user) => { | ||
|
||
if (messageReaction.emoji.id != verify.split(':')[2].slice(0, -1) || client.user === user) return; | ||
if (client.user === user) return; | ||
|
||
const { verification_role_id: verificationRoleId, verification_message_id: verificationMessageId } = | ||
client.db.settings.selectVerification.get(messageReaction.message.guild.id); | ||
const verificationRole = messageReaction.message.guild.roles.cache.get(verificationRoleId); | ||
const { message, emoji } = messageReaction; | ||
|
||
if (!verificationRole || messageReaction.message.id != verificationMessageId) return; | ||
// Verification | ||
if (emoji.id === verify.split(':')[2].slice(0, -1)) { | ||
const { verification_role_id: verificationRoleId, verification_message_id: verificationMessageId } = | ||
client.db.settings.selectVerification.get(message.guild.id); | ||
const verificationRole = message.guild.roles.cache.get(verificationRoleId); | ||
|
||
const member = messageReaction.message.guild.members.cache.get(user.id); | ||
if (!member.roles.cache.has(verificationRole)) { | ||
try { | ||
await member.roles.add(verificationRole); | ||
} catch (err) { | ||
return client.sendSystemErrorMessage(member.guild, 'verification', stripIndent` | ||
Unable to assign verification role, please check the role hierarchy and ensure I have the Manage Roles permission | ||
`, err.message); | ||
if (!verificationRole || message.id != verificationMessageId) return; | ||
|
||
const member = message.guild.members.cache.get(user.id); | ||
if (!member.roles.cache.has(verificationRole)) { | ||
try { | ||
await member.roles.add(verificationRole); | ||
} catch (err) { | ||
return client.sendSystemErrorMessage(member.guild, 'verification', | ||
stripIndent`Unable to assign verification role,` + | ||
'please check the role hierarchy and ensure I have the Manage Roles permission' | ||
, err.message); | ||
} | ||
} | ||
} | ||
|
||
// Starboard | ||
if (emoji.name === '⭐' && message.author != user) { | ||
const starboardChannelId = client.db.settings.selectStarboardChannelId.pluck().get(message.guild.id); | ||
const starboardChannel = message.guild.channels.cache.get(starboardChannelId); | ||
if ( | ||
!starboardChannel || | ||
!starboardChannel.viewable || | ||
!starboardChannel.permissionsFor(message.guild.me).has(['SEND_MESSAGES', 'EMBED_LINKS']) || | ||
message.channel === starboardChannel | ||
) return; | ||
|
||
const emojis = ['⭐', '🌟', '✨', '💫', '☄️']; | ||
const messages = await starboardChannel.messages.fetch({ limit: 100 }); | ||
const starred = messages.find(m => { | ||
return emojis.some(e => { | ||
return m.content.startsWith(e) && | ||
m.embeds[0] && | ||
m.embeds[0].footer && | ||
m.embeds[0].footer.text == message.id; | ||
}); | ||
}); | ||
|
||
// If message already in starboard | ||
if (starred) { | ||
const starCount = parseInt(starred.content.split(' ')[1].slice(2)) + 1; | ||
|
||
// Determine emoji type | ||
let emojiType; | ||
if (starCount > 20) emojiType = emojis[4]; | ||
else if (starCount > 15) emojiType = emojis[3]; | ||
else if (starCount > 10) emojiType = emojis[2]; | ||
else if (starCount > 5) emojiType = emojis[1]; | ||
else emojiType = emojis[0]; | ||
|
||
const starMessage = await starboardChannel.messages.fetch(starred.id); | ||
await starMessage.edit(`${emojiType} **${starCount} |** ${message.channel}`) | ||
.catch(err => client.logger.error(err.stack)); | ||
|
||
// New starred message | ||
} else { | ||
|
||
// Check for attachment image | ||
let image = ''; | ||
const attachment = message.attachments.array()[0]; | ||
if (attachment && attachment.url) { | ||
const extension = attachment.url.split('.').pop(); | ||
if (/(jpg|jpeg|png|gif)/gi.test(extension)) image = attachment.url; | ||
} | ||
|
||
// Check for url | ||
if (!image && message.embeds[0] && message.embeds[0].url) { | ||
const extension = message.embeds[0].url.split('.').pop(); | ||
if (/(jpg|jpeg|png|gif)/gi.test(extension)) image = message.embeds[0].url; | ||
} | ||
|
||
const embed = new MessageEmbed() | ||
.setAuthor(message.author.tag, message.author.displayAvatarURL({ dynamic: true})) | ||
.setDescription(message.content) | ||
.addField('Original', `[Jump!](${message.url})`) | ||
.setImage(image) | ||
.setTimestamp() | ||
.setFooter(message.id) | ||
.setColor('#ffac33'); | ||
await starboardChannel.send(`⭐ **1 |** ${message.channel}`, embed); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module.exports = async (client, messageReaction, user) => { | ||
|
||
if (client.user === user) return; | ||
|
||
const { message, emoji } = messageReaction; | ||
|
||
// Starboard | ||
if (emoji.name === '⭐' && message.author != user) { | ||
const starboardChannelId = client.db.settings.selectStarboardChannelId.pluck().get(message.guild.id); | ||
const starboardChannel = message.guild.channels.cache.get(starboardChannelId); | ||
if ( | ||
!starboardChannel || | ||
!starboardChannel.viewable || | ||
!starboardChannel.permissionsFor(message.guild.me).has(['SEND_MESSAGES', 'EMBED_LINKS']) || | ||
message.channel === starboardChannel | ||
) return; | ||
|
||
const emojis = ['⭐', '🌟', '✨', '💫', '☄️']; | ||
const messages = await starboardChannel.messages.fetch({ limit: 100 }); | ||
|
||
const starred = messages.find(m => { | ||
return emojis.some(e => { | ||
return m.content.startsWith(e) && | ||
m.embeds[0] && | ||
m.embeds[0].footer && | ||
m.embeds[0].footer.text == message.id; | ||
}); | ||
}); | ||
|
||
// If message already in starboard | ||
if (starred) { | ||
|
||
const starCount = parseInt(starred.content.split(' ')[1].slice(2)) - 1; | ||
|
||
// Determine emoji type | ||
let emojiType; | ||
if (starCount > 20) emojiType = emojis[4]; | ||
else if (starCount > 15) emojiType = emojis[3]; | ||
else if (starCount > 10) emojiType = emojis[2]; | ||
else if (starCount > 5) emojiType = emojis[1]; | ||
else emojiType = emojis[0]; | ||
|
||
const starMessage = await starboardChannel.messages.fetch(starred.id); | ||
await starMessage.edit(`${emojiType} **${starCount} |** ${message.channel}`); | ||
|
||
if (starCount == 0) | ||
await starMessage.delete().catch(err => client.logger.error(err.stack)); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters