Created
February 12, 2020 08:35
-
-
Save conanak99/fb9dfa210886f4c08826504514d3412c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async processHook(hookObject) { | |
for (const entry of hookObject.entry) { | |
for (const change of entry.changes) { | |
this.processEntryChange(change); | |
} | |
} | |
} | |
async processEntryChange(change) { | |
if (change.field !== 'feed') return; | |
// New comment only | |
const changeValue = change.value; | |
if (changeValue.post_id !== this.postId) return; | |
if (changeValue.item !== 'comment' || changeValue.verb !== 'add') return; | |
var { sender_id, sender_name, message } = changeValue; | |
const bets = this.getBetFromComment(message); | |
console.log(bets); | |
if (bets.length === 0) return; | |
const avatar = await api.getAvatar(sender_id); | |
for (const bet of bets) { | |
const playerAndBet = { | |
id: sender_id, | |
name: sender_name, | |
avatar, | |
bet: bet.bet, | |
choice: bet.choice | |
}; | |
console.log(playerAndBet); | |
this.emitter.emit('newBet', playerAndBet); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment