Skip to content

Wiadomość na wzmiankę @everyone #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,29 @@ client.on('ready', () => {
}
});
});
client.on('message', message => { //Ten event wykonuje się, gdy bot wykryje wiadomość
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tak ogólnie, to przeniósłbym ciało tego event handlera do osobnej nazwanej funkcji, np. handleEveryoneAndHereCommands (która mogła by być importowana z osobnego modułu), bo niewykluczone, że dojdzie w tym handlerze więcej kodu, a wtedy - przy obecnej formie - zrobi się bałagan.

const pingEmbed = new Discord.MessageEmbed()
.setColor('#eb1540')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrzuciłbym wartość koloru do zmiennej/stałej i jej tu użył. Być może w przyszłości będą w różnych miejscach używane jakieś kolory i wtedy przyda się mieć jedno miejsce, gdzie są one zadeklarowane i nazwane, wtedy łatwiej i wygodniej będzie tego używać.

.setTitle('Nie wołaj wszystkich!')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Na tłumaczenia jest plik commands.js. A jeśli to tłumaczenie tam kontekstowo nie pasuje, to warto zrobić nowy plik i tam wrzucić tłumaczenia - powód analogiczny jak w poprzednim komentarzu.

.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ć.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

J.w. odnośnie tekstu tłumaczenia.


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..")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Co ma w zasadzie robić ten catch?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zapomniałem usunąć 😅

}

} 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..")
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zbędna ifologia. Zamiast tego lepsze by było coś w rodzaju:

const mentionedEveryone = (message.content.includes("@everyone") || (message.content.includes("@here")
const hasPermission = message.member.hasPermission('MENTION_EVERYONE')
if (mentionedEveryone && !hasPermission) {
    message.author.send(pingEmbed)
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha, dzięki wielkie, zapomniałem o "||" w javascriptcie, potem naprawię

});
client.login(process.env.TOKEN);