Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
✨ 🔧 added showPlan/PollDetails
Browse files Browse the repository at this point in the history
fixes #364
fixes #365
  • Loading branch information
Bjornskjald committed Dec 26, 2018
1 parent 65e86e4 commit be08fa2
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
5 changes: 4 additions & 1 deletion config.example.json
Expand Up @@ -14,7 +14,10 @@

"handleEvents": true,
"handlePlans": true,
"handlePolls": true
"handlePolls": true,

"showPlanDetails": true,
"showPollDetails": true
},
"discord": {
"token": "",
Expand Down
4 changes: 3 additions & 1 deletion lib/config/getConfig.js
Expand Up @@ -15,7 +15,9 @@ const defaultConfig = {
attachmentTooLargeError: true,
handleEvents: true,
handlePlans: true,
handlePolls: true
handlePolls: true,
showPlanDetails: true,
showPollDetails: true
},
discord: {
renameChannels: true,
Expand Down
2 changes: 1 addition & 1 deletion lib/messenger/handlePlan.js
Expand Up @@ -20,7 +20,7 @@ module.exports = async _event => {
const going = (await Promise.all(people.filter(el => el.state === 'GOING').map(el => getSender(el.id)))).map(el => el.name)
const declined = (await Promise.all(people.filter(el => el.state === 'DECLINED').map(el => getSender(el.id)))).map(el => el.name)

const description = type === 'eventRsvpEvent' || type === 'eventCreateEvent'
const description = ((type === 'eventRsvpEvent' || type === 'eventCreateEvent') && config.messenger.showPlanDetails)
? `*${plan.message}*
Time: ${plan.time.toLocaleString('en-GB', {
Expand Down
17 changes: 14 additions & 3 deletions lib/messenger/handlePoll.js
@@ -1,6 +1,7 @@
const log = logger.withScope('messenger:handlePoll')

const { getThread } = require('./index')
const { getThread, getSender } = require('./index')
const { truncatePeople } = require('../utils')

module.exports = async _poll => {
log.trace('poll', _poll)
Expand All @@ -15,15 +16,25 @@ module.exports = async _poll => {
let connection = await connections.getWithCreateFallback(poll.threadId, thread.cleanName)
if (!connection) return

poll.options = await Promise.all(poll.options.map(async option => {
option.voters = (await Promise.all(option.voters.map(voter => getSender(voter)))).map(el => el.name)
return option
}))

const description = config.messenger.showPollDetails
? `*${poll.message}*
${poll.options.map(option => `${option.title} (${option.voteCount}): ${truncatePeople(option.voters)}`).join('\n')}
` : poll.message

const channels = await connection.getWritableChannels()
channels.forEach(async ({ channel }) => {
channel.send({ embed: { title: `Poll: **${poll.title}**`, description: poll.message } })
channel.send({ embed: { title: `Poll: **${poll.title}**`, description } })
})

const threads = connection.getOtherWritableThreads(poll.threadId)
threads.forEach(async _thread => {
log.debug('Sending Messenger message')
const info = await messenger.client.sendMessage(Number(_thread.id), `_${thread.name} - ${poll.title}_:\n${poll.message}`)
const info = await messenger.client.sendMessage(Number(_thread.id), `_${thread.name} - ${poll.title}_:\n${description}`)
log.trace('sent message info', info)
log.debug('Sent message on Messenger')
})
Expand Down

0 comments on commit be08fa2

Please sign in to comment.