Skip to content

Instantly share code, notes, and snippets.

@conanak99
Created February 12, 2020 08:35
Show Gist options
  • Save conanak99/fb9dfa210886f4c08826504514d3412c to your computer and use it in GitHub Desktop.
Save conanak99/fb9dfa210886f4c08826504514d3412c to your computer and use it in GitHub Desktop.
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