Advertisement
Guest User

Untitled

a guest
Feb 16th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. const config = require('./config.json');
  2. const SkyChat = require('node-redsky').init({
  3. username: config.username,
  4. password: config.password
  5. });
  6.  
  7. let sondage = {
  8. voters: [],
  9. votes: [],
  10. total: 0
  11. };
  12.  
  13. SkyChat.on('newmessage', msg => {
  14. let nb = parseInt(msg.message_raw, 10);
  15. if(isNaN(nb)) return;
  16. if(sondage.voters.includes(msg.pseudo_lower)) return;
  17. sondage.voters.push(msg.pseudo_lower);
  18. sondage.votes[nb]++;
  19. sondage.total++;
  20. });
  21.  
  22. SkyChat.on('command', cmd => {
  23. if(cmd.name.toLowerCase() == 'resultats') {
  24. if(sondage.total < 1) return;
  25.  
  26. let out = '';
  27. for(let i in sondage.buttons) {
  28. if(i != 0) out += ' -';
  29. let res = Math.round(sondage.votes[i] / sondage.total * 100);
  30. out += ` [${sondage.buttons[i]}] ${res}%`
  31. }
  32.  
  33. SkyChat.send(`Résultats du sondage :` + out);
  34. }
  35. console.log(cmd);
  36. if(cmd.nbArgs < 2) return;
  37. if(cmd.name.toLowerCase() != 'sondage') return;
  38. sondage.buttons = cmd.args.split(' ');
  39. sondage.voters = [];
  40. sondage.votes = [];
  41. sondage.total = 0;
  42.  
  43. let out = '';
  44. for(let i in sondage.buttons) {
  45. sondage.votes[i] = 0;
  46. out += `[[${sondage.buttons[i]}/${i}]] `
  47. }
  48.  
  49. SkyChat.send(out);
  50. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement