mirror of
https://github.com/cheveguerra/whatsapp-web.js.git
synced 2026-04-18 03:29:14 +00:00
PART 2: ESLINT, EXAMPLES & MORE
This commit is contained in:
25
example.js
25
example.js
@@ -197,6 +197,27 @@ client.on('message', async msg => {
|
||||
client.sendMessage(msg.from, list);
|
||||
} else if (msg.body === '!reaction') {
|
||||
msg.react('👍');
|
||||
} else if (msg.body.startsWith('!vote ')) {
|
||||
if (msg.hasQuotedMsg) {
|
||||
const quotedMsg = await msg.getQuotedMessage();
|
||||
if (quotedMsg.type === 'poll_creation') {
|
||||
const options = msg.body.slice(6).split('//');
|
||||
const voteCount = {};
|
||||
for (const pollVote of quotedMsg.pollVotes) {
|
||||
for (const selectedOption of pollVote.selectedOptions) {
|
||||
if (!voteCount[selectedOption]) voteCount[selectedOption] = 0;
|
||||
voteCount[selectedOption]++;
|
||||
}
|
||||
}
|
||||
const voteCountStr = Object.entries(voteCount).map(([vote, number]) => ` -${vote}: ${number}`).join('\n');
|
||||
quotedMsg.reply(
|
||||
`Voting to poll ${quotedMsg.body}, with options: ${options.join(', ')}\ncurrent vote count:\n${voteCountStr}`
|
||||
);
|
||||
quotedMsg.vote(options);
|
||||
} else {
|
||||
msg.reply('Usage: !vote TEST1//TEST2');
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -253,6 +274,10 @@ client.on('group_update', (notification) => {
|
||||
console.log('update', notification);
|
||||
});
|
||||
|
||||
client.on('poll_vote', (vote) => {
|
||||
console.log(`Vote received, from ${vote.sender}, ${vote.selectedOptions.map(a => ` - ${a}`).join('\n')}`);
|
||||
});
|
||||
|
||||
client.on('change_state', state => {
|
||||
console.log('CHANGE STATE', state );
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user