Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Commit

Permalink
Merge pull request #28 from matteoauger/feature/emoji-multiple-words
Browse files Browse the repository at this point in the history
Feature/emoji multiple words
  • Loading branch information
LucasCtrl committed Oct 4, 2020
2 parents afbf047 + 7801a1a commit 3b59516
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lang/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
emoji: '👻',
},
{
name: 'halloween',
name: ['halloween', 'pumpkin'],
emoji: '🎃',
},
{
Expand Down
14 changes: 11 additions & 3 deletions utils/reactMessage.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
const { getGuild } = require('../models/servers')

String.prototype.contains = function(toCheck) {
return this.indexOf(toCheck) >= 0;
String.prototype.contains = function (toCheck) {
return this.indexOf(toCheck) >= 0
}

const translationNameContainsWord = (translationName, fullMessage) => {
if (translationName instanceof Array) {
return translationName.map((n) => fullMessage.contains(n)).reduce((a, b) => a || b)
} else {
return fullMessage.contains(translationName)
}
}

module.exports = async (guildId, message) => {
Expand All @@ -10,6 +18,6 @@ module.exports = async (guildId, message) => {
const fullMessage = message.content.toLowerCase()

translation.words.forEach((w) => {
if (fullMessage.contains(w.name)) message.react(w.emoji)
if (translationNameContainsWord(w.name, fullMessage)) message.react(w.emoji)
})
}

0 comments on commit 3b59516

Please sign in to comment.