-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmessageFiltering.js
More file actions
48 lines (46 loc) · 1.73 KB
/
messageFiltering.js
File metadata and controls
48 lines (46 loc) · 1.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
const { clientId } = require('./config.json');
const { matchFormatString, FORMAT_PLACEHOLDER } = require('./stringParsing')
const Strings = require('./Strings')
module.exports = {
async getBotMessages(interaction) {
let botMessages
await interaction.channel.messages.fetch({ limit: 100 })
.then(messages => {
botMessages = Array.from(messages.filter(m => m.author.id === clientId).values())
}
)
return botMessages
},
getStandardTitle(botMessages) {
// To-do: Handle failure of no previous standard title
let standardTitle
botMessages.find(message => {
standardTitle = matchFormatString(message.content, Strings.BREW_WEEK.TEMPLATES.TITLE_LINE(FORMAT_PLACEHOLDER))
if (standardTitle.length > 0) {
return true
}
return false
})
return standardTitle
},
async getReactions(botMessages, formatString) {
let reactionEmojis
let reactionMap = []
let reactions
let reactionMessage = botMessages.find(message => {
reactionEmojis = matchFormatString(message.content, formatString)
return (reactionEmojis.length > 0)
})
if (reactionMessage != undefined) {
reactions = reactionMessage.reactions.cache
}
for (const reactionEmoji of reactionEmojis) {
await reactions.get(reactionEmoji).users.fetch()
.then(users => {
let filteredUsers = Array.from(users.values()).filter(user => user.id !== clientId)
reactionMap.push([reactionEmoji, filteredUsers])
})
}
return reactionMap
},
}