diff --git a/handlers/mentionHandler.js b/handlers/mentionHandler.js new file mode 100644 index 0000000..ccc6992 --- /dev/null +++ b/handlers/mentionHandler.js @@ -0,0 +1,26 @@ +const Discord = require('discord.js'); +const MENTIONS_DICT = Object.freeze({ + EVERYONE: '@everyone', + HERE: '@here', +}); +const MENTION_PERMISSION = 'MENTION_EVERYONE'; +const EMBED_COLOR = '#eb1540'; +const EMBED_TITLE = 'Nie wołaj wszystkich!'; +const EMBED_THUMBNAIL = 'https://i.imgur.com/nREiJww.png'; +const EMBED_DESCRIPTION = '\nRozumiemy, że potrzebujesz pomocy, ale nie wszyscy chcą zostać o tym powiadomieni.\n Jest nas tutaj dużo i nie ma sensu, aby każdy dostał bezpośrednio taką informację.\n Nie trudno sobie wyobrazić jak irytujące byłoby, gdyby każdy wołał wszystkich do każdego tematu.\n Dlatego zadaj pytanie i po prostu poczekaj - jeśli ktoś będzie wiedział i mógł, to na pewno spróbuje odpowiedzieć.'; + +function mentionHandler(message){ + const pingEmbed = new Discord.MessageEmbed() + .setColor(EMBED_COLOR) + .setTitle(EMBED_TITLE) + .setThumbnail(EMBED_THUMBNAIL) + .setDescription(EMBED_DESCRIPTION); + const mentions = message.content.includes(MENTIONS_DICT.EVERYONE) || message.content.includes(MENTIONS_DICT.HERE); + const hasPermission = message.member.hasPermission(MENTION_PERMISSION); + + if (mentions && !hasPermission) { + message.reply(pingEmbed).catch(console.error); + } +} + +module.exports = mentionHandler; diff --git a/main.js b/main.js index 587e981..9e5fed1 100644 --- a/main.js +++ b/main.js @@ -1,7 +1,8 @@ const Discord = require('discord.js'); const commands = require('./commands'); -require('dotenv').config(); +const mentionHandler = require('./handlers/mentionHandler'); +require('dotenv').config(); const client = new Discord.Client(); client.on('ready', () => { @@ -30,5 +31,7 @@ client.on('ready', () => { } }); }); - +client.on('message', (message) => { + mentionHandler(message); +}); client.login(process.env.TOKEN);