Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const config = require('./config.json');
- const SkyChat = require('node-redsky').init({
- username: config.username,
- password: config.password
- });
- let sondage = {
- voters: [],
- votes: [],
- total: 0
- };
- SkyChat.on('newmessage', msg => {
- let nb = parseInt(msg.message_raw, 10);
- if(isNaN(nb)) return;
- if(sondage.voters.includes(msg.pseudo_lower)) return;
- sondage.voters.push(msg.pseudo_lower);
- sondage.votes[nb]++;
- sondage.total++;
- });
- SkyChat.on('command', cmd => {
- if(cmd.name.toLowerCase() == 'resultats') {
- if(sondage.total < 1) return;
- let out = '';
- for(let i in sondage.buttons) {
- if(i != 0) out += ' -';
- let res = Math.round(sondage.votes[i] / sondage.total * 100);
- out += ` [${sondage.buttons[i]}] ${res}%`
- }
- SkyChat.send(`Résultats du sondage :` + out);
- }
- console.log(cmd);
- if(cmd.nbArgs < 2) return;
- if(cmd.name.toLowerCase() != 'sondage') return;
- sondage.buttons = cmd.args.split(' ');
- sondage.voters = [];
- sondage.votes = [];
- sondage.total = 0;
- let out = '';
- for(let i in sondage.buttons) {
- sondage.votes[i] = 0;
- out += `[[${sondage.buttons[i]}/${i}]] `
- }
- SkyChat.send(out);
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement