From 2f3bb7e5640ef69a569e6c21a5d8c24a2bb61720 Mon Sep 17 00:00:00 2001 From: CodeKid0 <65465165+CodeKid0@users.noreply.github.com> Date: Fri, 11 Jun 2021 14:51:12 +0200 Subject: [PATCH 1/6] Update main.js --- main.js | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/main.js b/main.js index 587e981..64c2696 100644 --- a/main.js +++ b/main.js @@ -30,5 +30,29 @@ client.on('ready', () => { } }); }); +client.on('message', message => { //Ten event wykonuje się, gdy bot wykryje wiadomość + const pingEmbed = new Discord.MessageEmbed() + .setColor('#eb1540') + .setTitle('Nie wołaj wszystkich!') + .setThumbnail('https://cdn.discordapp.com/attachments/617673807213232128/852887484542615572/Pingsock.png') + .setDescription('\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ć.'); + if (message.content.includes("@everyone")) { //Jeśli wiadomość zawiera @everyone.. + try{ + if(!message.member.hasPermission('MENTION_EVERYONE')) //Sprawdzamy, czy wysyłający ma uprawnienia do wzmianki @everyone, jeśli nie to bot wysyła wiadomość + message.author.send(pingEmbed) + }catch{ + console.log(message.author.username + " wysłał ping w wiadomości prywatnej do bota, hmm..") + } + + } else { + if(message.content.includes("@here")) //Jeśli wiadomość zawiera @here.. + try{ + if(!message.member.hasPermission('MENTION_EVERYONE')) //Sprawdzamy, czy wysyłający ma uprawnienia do wzmianki @everyone, jeśli nie to bot wysyła wiadomość + message.author.send(pingEmbed) + }catch{ + console.log(message.author.username + " wysłał ping w wiadomości prywatnej do bota, hmm..") + } + } + }); client.login(process.env.TOKEN); From 11a72d5d8519660c7ba637f272fa1419ac0dd2d4 Mon Sep 17 00:00:00 2001 From: CodeKid0 <65465165+CodeKid0@users.noreply.github.com> Date: Fri, 11 Jun 2021 20:24:34 +0200 Subject: [PATCH 2/6] Update --- handlers/EveryoneAndHereMentionMessage.js | 24 +++++++++++++++++++ main.js | 29 ++++------------------- 2 files changed, 28 insertions(+), 25 deletions(-) create mode 100644 handlers/EveryoneAndHereMentionMessage.js diff --git a/handlers/EveryoneAndHereMentionMessage.js b/handlers/EveryoneAndHereMentionMessage.js new file mode 100644 index 0000000..b3a8fd6 --- /dev/null +++ b/handlers/EveryoneAndHereMentionMessage.js @@ -0,0 +1,24 @@ +const Discord = require('discord.js'); + +const color = '#eb1540'; +const title = 'Nie wołaj wszystkich!'; +const thumbnail = 'LINK' +const 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ć.' + +export function mentionHandler(){ + const pingEmbed = new Discord.MessageEmbed() + .setColor(color) + .setTitle(title) + .setThumbnail(thumbnail) + .setDescription(description); + + const mentionedEveryone = message.content.includes("@everyone") || message.content.includes("@here") + const hasPermission = message.member.hasPermission('MENTION_EVERYONE') + if (mentionedEveryone && !hasPermission) { + try{ + message.author.send(pingEmbed) + } catch { + + } + } +} \ No newline at end of file diff --git a/main.js b/main.js index 64c2696..4ae1b52 100644 --- a/main.js +++ b/main.js @@ -1,3 +1,4 @@ +import mentionHandler from './handlers/EveryoneAndHereMentionMessage' const Discord = require('discord.js'); const commands = require('./commands'); require('dotenv').config(); @@ -30,29 +31,7 @@ client.on('ready', () => { } }); }); -client.on('message', message => { //Ten event wykonuje się, gdy bot wykryje wiadomość - const pingEmbed = new Discord.MessageEmbed() - .setColor('#eb1540') - .setTitle('Nie wołaj wszystkich!') - .setThumbnail('https://cdn.discordapp.com/attachments/617673807213232128/852887484542615572/Pingsock.png') - .setDescription('\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ć.'); - - if (message.content.includes("@everyone")) { //Jeśli wiadomość zawiera @everyone.. - try{ - if(!message.member.hasPermission('MENTION_EVERYONE')) //Sprawdzamy, czy wysyłający ma uprawnienia do wzmianki @everyone, jeśli nie to bot wysyła wiadomość - message.author.send(pingEmbed) - }catch{ - console.log(message.author.username + " wysłał ping w wiadomości prywatnej do bota, hmm..") - } - - } else { - if(message.content.includes("@here")) //Jeśli wiadomość zawiera @here.. - try{ - if(!message.member.hasPermission('MENTION_EVERYONE')) //Sprawdzamy, czy wysyłający ma uprawnienia do wzmianki @everyone, jeśli nie to bot wysyła wiadomość - message.author.send(pingEmbed) - }catch{ - console.log(message.author.username + " wysłał ping w wiadomości prywatnej do bota, hmm..") - } - } - }); +client.on('message', message => { + mentionHandler(); +}); client.login(process.env.TOKEN); From 4a953beac3243a6c00952d379132722a034bbd57 Mon Sep 17 00:00:00 2001 From: CodeKid0 <65465165+CodeKid0@users.noreply.github.com> Date: Sat, 12 Jun 2021 07:17:52 +0200 Subject: [PATCH 3/6] Fix --- handlers/EveryoneAndHereMentionMessage.js | 46 +++++++++++++---------- main.js | 4 +- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/handlers/EveryoneAndHereMentionMessage.js b/handlers/EveryoneAndHereMentionMessage.js index b3a8fd6..375ff51 100644 --- a/handlers/EveryoneAndHereMentionMessage.js +++ b/handlers/EveryoneAndHereMentionMessage.js @@ -1,24 +1,30 @@ const Discord = require('discord.js'); +const MentionsList = [ + '@everyone', + '@here' +]; +const MentionPermission = 'MENTION_EVERYONE'; +const MentionEmbedColor = '#eb1540'; +const MentionEmbedTitle = 'Nie wołaj wszystkich!'; +const MentionEmbedThumb = 'https://i.imgur.com/nREiJww.png'; +const MentionEmbedDesc = '\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ć.'; -const color = '#eb1540'; -const title = 'Nie wołaj wszystkich!'; -const thumbnail = 'LINK' -const 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ć.' +module.exports = { + + mentionHandler: function (message){ + const pingEmbed = new Discord.MessageEmbed() + .setColor(MentionEmbedColor) + .setTitle(MentionEmbedTitle) + .setThumbnail(MentionEmbedThumb) + .setDescription(MentionEmbedDesc); + const mentions = message.content.includes(MentionsList[0]) || message.content.includes(MentionsList[1]); + if (mentions) { + try{ + const hasPermission = message.member.hasPermission(MentionPermission); + message.author.send(pingEmbed); + } catch { -export function mentionHandler(){ - const pingEmbed = new Discord.MessageEmbed() - .setColor(color) - .setTitle(title) - .setThumbnail(thumbnail) - .setDescription(description); - - const mentionedEveryone = message.content.includes("@everyone") || message.content.includes("@here") - const hasPermission = message.member.hasPermission('MENTION_EVERYONE') - if (mentionedEveryone && !hasPermission) { - try{ - message.author.send(pingEmbed) - } catch { - - } + } + } } -} \ No newline at end of file +} diff --git a/main.js b/main.js index 4ae1b52..fcee464 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,6 @@ -import mentionHandler from './handlers/EveryoneAndHereMentionMessage' const Discord = require('discord.js'); const commands = require('./commands'); +const EveryoneAndHereMentionMessage = require('./handlers/EveryoneAndHereMentionMessage'); require('dotenv').config(); const client = new Discord.Client(); @@ -32,6 +32,6 @@ client.on('ready', () => { }); }); client.on('message', message => { - mentionHandler(); + EveryoneAndHereMentionMessage.mentionHandler(message); }); client.login(process.env.TOKEN); From 00999233107dbeab5ea0450699d0c8394ce78b5e Mon Sep 17 00:00:00 2001 From: CodeKid0 <65465165+CodeKid0@users.noreply.github.com> Date: Sat, 12 Jun 2021 13:27:30 +0200 Subject: [PATCH 4/6] =?UTF-8?q?Poprawiono=20nazewnictwo,=20polepszono=20wy?= =?UTF-8?q?=C5=82apywanie=20b=C5=82=C4=99d=C3=B3w?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handlers/EveryoneAndHereMentionMessage.js | 30 ----------------------- handlers/mentionHandler.js | 30 +++++++++++++++++++++++ main.js | 5 ++-- 3 files changed, 32 insertions(+), 33 deletions(-) delete mode 100644 handlers/EveryoneAndHereMentionMessage.js create mode 100644 handlers/mentionHandler.js diff --git a/handlers/EveryoneAndHereMentionMessage.js b/handlers/EveryoneAndHereMentionMessage.js deleted file mode 100644 index 375ff51..0000000 --- a/handlers/EveryoneAndHereMentionMessage.js +++ /dev/null @@ -1,30 +0,0 @@ -const Discord = require('discord.js'); -const MentionsList = [ - '@everyone', - '@here' -]; -const MentionPermission = 'MENTION_EVERYONE'; -const MentionEmbedColor = '#eb1540'; -const MentionEmbedTitle = 'Nie wołaj wszystkich!'; -const MentionEmbedThumb = 'https://i.imgur.com/nREiJww.png'; -const MentionEmbedDesc = '\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ć.'; - -module.exports = { - - mentionHandler: function (message){ - const pingEmbed = new Discord.MessageEmbed() - .setColor(MentionEmbedColor) - .setTitle(MentionEmbedTitle) - .setThumbnail(MentionEmbedThumb) - .setDescription(MentionEmbedDesc); - const mentions = message.content.includes(MentionsList[0]) || message.content.includes(MentionsList[1]); - if (mentions) { - try{ - const hasPermission = message.member.hasPermission(MentionPermission); - message.author.send(pingEmbed); - } catch { - - } - } - } -} diff --git a/handlers/mentionHandler.js b/handlers/mentionHandler.js new file mode 100644 index 0000000..e824f1c --- /dev/null +++ b/handlers/mentionHandler.js @@ -0,0 +1,30 @@ +const Discord = require('discord.js'); +const MentionsList = { + 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ć.'; + +module.exports = { + + handler: function (message){ + const pingEmbed = new Discord.MessageEmbed() + .setColor(EMBED_COLOR) + .setTitle(EMBED_TITLE) + .setThumbnail(EMBED_THUMBNAIL) + .setDescription(EMBED_DESCRIPTION); + const mentions = message.content.includes(MentionsList.EVERYONE) || message.content.includes(MentionsList.HERE); + try { + const hasPermission = message.member.hasPermission(MENTION_PERMISSION); + if (mentions && !hasPermission) { + message.author.send(pingEmbed); + } + } catch(error) { + console.log(error); + } + } +} diff --git a/main.js b/main.js index fcee464..c90fcc2 100644 --- a/main.js +++ b/main.js @@ -1,8 +1,7 @@ const Discord = require('discord.js'); const commands = require('./commands'); -const EveryoneAndHereMentionMessage = require('./handlers/EveryoneAndHereMentionMessage'); +require('./handlers/mentionHandler'); require('dotenv').config(); - const client = new Discord.Client(); client.on('ready', () => { @@ -32,6 +31,6 @@ client.on('ready', () => { }); }); client.on('message', message => { - EveryoneAndHereMentionMessage.mentionHandler(message); + mentionHandler.handler(message); }); client.login(process.env.TOKEN); From f9f3a298a3c9747586616f34084f895eeb6a5737 Mon Sep 17 00:00:00 2001 From: Krzysztof Pawelec Date: Fri, 9 Jul 2021 22:51:30 +0200 Subject: [PATCH 5/6] Apply fixes from PR comments; --- handlers/mentionHandler.js | 34 +++++++++++++++------------------- main.js | 7 ++++--- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/handlers/mentionHandler.js b/handlers/mentionHandler.js index e824f1c..9a203aa 100644 --- a/handlers/mentionHandler.js +++ b/handlers/mentionHandler.js @@ -1,30 +1,26 @@ const Discord = require('discord.js'); -const MentionsList = { +const MENTIONS_DICT = Object.freeze({ EVERYONE: '@everyone', - HERE: '@here' -} + 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ć.'; -module.exports = { +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); - handler: function (message){ - const pingEmbed = new Discord.MessageEmbed() - .setColor(EMBED_COLOR) - .setTitle(EMBED_TITLE) - .setThumbnail(EMBED_THUMBNAIL) - .setDescription(EMBED_DESCRIPTION); - const mentions = message.content.includes(MentionsList.EVERYONE) || message.content.includes(MentionsList.HERE); - try { - const hasPermission = message.member.hasPermission(MENTION_PERMISSION); - if (mentions && !hasPermission) { - message.author.send(pingEmbed); - } - } catch(error) { - console.log(error); - } + if (mentions && !hasPermission) { + message.author.send(pingEmbed).catch(console.error); } } + +module.exports = mentionHandler; diff --git a/main.js b/main.js index c90fcc2..9e5fed1 100644 --- a/main.js +++ b/main.js @@ -1,6 +1,7 @@ const Discord = require('discord.js'); const commands = require('./commands'); -require('./handlers/mentionHandler'); +const mentionHandler = require('./handlers/mentionHandler'); + require('dotenv').config(); const client = new Discord.Client(); @@ -30,7 +31,7 @@ client.on('ready', () => { } }); }); -client.on('message', message => { - mentionHandler.handler(message); +client.on('message', (message) => { + mentionHandler(message); }); client.login(process.env.TOKEN); From 3cc4fc40fb13b4ddcc6bdad6c32e7295defb2fb8 Mon Sep 17 00:00:00 2001 From: Arkadiusz Waluk Date: Sat, 10 Jul 2021 00:09:00 +0200 Subject: [PATCH 6/6] Fix - sending reply to channel --- handlers/mentionHandler.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/handlers/mentionHandler.js b/handlers/mentionHandler.js index 9a203aa..ccc6992 100644 --- a/handlers/mentionHandler.js +++ b/handlers/mentionHandler.js @@ -17,9 +17,9 @@ function mentionHandler(message){ .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.author.send(pingEmbed).catch(console.error); + message.reply(pingEmbed).catch(console.error); } }