Advertisement
Guest User

Untitled

a guest
Jan 1st, 2018
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.21 KB | None | 0 0
  1. var DubAPI = require('dubapi');
  2.  
  3. new DubAPI({username: 'Putinha-Bot', password: '123456789'}, function(err, bot) {
  4. if (err) return console.error(err);
  5.  
  6. var resp=0;
  7. var count_fila=0;
  8. var count_downs = { "downdubs":"0"};
  9. var teste = 0;
  10. var chamada = 0;
  11. var fila = [];
  12. var fila_user = [];
  13. var presentes = [];
  14. var skip = 0;
  15.  
  16.  
  17. console.log('Running DubAPI v' + bot.version);
  18.  
  19. function connect() {bot.connect('radioanao');}
  20.  
  21.  
  22.  
  23. bot.on('connected', function(name) {
  24. console.log('Connected to ' + name);
  25.  
  26. // while(1)
  27. // {
  28. // count_downs = bot.getScore();
  29. // while(count_downs == null);
  30. // count_downs = count_downs.downdubs;
  31. // console.log(count_downs);
  32. // //myPromise.then(console.log(count_downs));
  33. // //count_downs// = resp.downdubs;
  34. // //console.log("count_downs");
  35. // if(count_downs !== 0 && count_downs != null)
  36. // {
  37. // resp = bot.getQueue();
  38. // count_fila = resp.length;
  39. // console.log(count_downs + " " + count_fila);
  40. // if(count_fila <= 2 && count_downs >=3)
  41. // bot.moderateSkip();
  42. // else if (count_downs >= count_fila/2)
  43. // bot.moderateSkip();
  44. // }
  45. // //wait(5000);
  46. // }
  47.  
  48.  
  49. });
  50.  
  51. function wait(ms){
  52. var start = new Date().getTime();
  53. var end = start;
  54. while(end < start + ms) {
  55. end = new Date().getTime();
  56. }
  57. }
  58.  
  59. bot.on('disconnected', function(name) {
  60. console.log('Disconnected from ' + name);
  61.  
  62. setTimeout(connect, 15000);
  63. });
  64.  
  65. bot.on('error', function(err) {
  66. console.error(err);
  67. });
  68.  
  69. bot.on(bot.events.userJoin, function(name)
  70. {
  71. console.log(name);
  72. //bot.sendChat(resp.length + " pessoas na fila :3");
  73. });
  74.  
  75. bot.on(bot.events.chatMessage, function(data) {
  76. if(data.message.indexOf("@Putinha-Bot") !== -1)
  77. {
  78. //else if(data.message.indexOf("qual o sentido da vida?") !== -1)
  79. // bot.sendChat("Leitar e ser leitado.");
  80. //else
  81. //{
  82. //bot.sendChat("@" + data.user.username + " Oin :3");
  83. //}
  84.  
  85. if(data.message.indexOf("sk") !== -1)
  86. {
  87. count_downs = bot.getScore();
  88.  
  89. bot.sendChat("resultado do GET: " + count_downs);
  90.  
  91. if(count_downs == null)
  92. {
  93. bot.getQueue();
  94. bot.sendChat("Não consigo ler os downvotes.");
  95. //count_downs = bot.getScore();
  96. //console.log(count_downs);
  97. count_downs = 0;
  98.  
  99. }
  100. else
  101. {
  102. count_downs = count_downs.downdubs;
  103. if(count_downs !== 0)
  104. {
  105. //console.log("3skip: " + skip);
  106. resp = bot.getQueue();
  107. count_fila = resp.length;
  108. bot.sendChat(count_fila + " na fila e " + count_downs + " downvotes.");
  109. //console.log(count_downs + " " + count_fila);
  110. if(count_fila <= 2 && count_downs >=3)
  111. bot.moderateSkip();
  112. else if ((count_downs >= count_fila/2) && count_fila > 2)
  113. bot.moderateSkip();
  114. }
  115. }
  116. }
  117.  
  118. else if(bot.isMod(data.user) || bot.isManager(data.user) || bot.isOwner(data.user) || bot.isCreator(data.user))
  119. {
  120. //bot.sendChat("@" + data.user.username + " é da Staff.");
  121. if(data.message.indexOf("chamada") !== -1 && chamada == 0)
  122. {
  123. resp = bot.getQueue();
  124. console.log(resp);
  125. //resp = JSON.parse(resp);
  126. for(var i = 0; i < resp.length; i++)
  127. {
  128. //console.log(resp[i].user.username);
  129. //bot.sendChat(resp[i].user.username);
  130. fila.push(resp[i].user.username);
  131. fila_user.push(resp[i].uid);
  132. console.log("fila[" + i + "] = " + fila[i]);
  133. }
  134.  
  135. chamada = 1;
  136.  
  137. for(var i =0; i < 5; i++)
  138. bot.sendChat("@djs CHAMADA " + (i+1) + "/5");// CHAMADA RESPONDAM APENAS UMA VEZ " + (i+1) + "/5");
  139. }
  140. else if(data.message.indexOf("finalizar") && chamada == 1)
  141. {
  142. //count_downs = bot.getScore();
  143. chamada = 0;
  144. for(var i = 0; i < fila.length; i++)
  145. console.log("fila: " + fila[i]);
  146. for(var i = 0; i < presentes.length; i++)
  147. console.log("presentes: " + presentes[i]);
  148. //{
  149. for(var j = 0; j < fila.length; j++)
  150. if(presentes.indexOf(fila[j]) == -1)
  151. {
  152. //bot.moderateRemoveDJ(fila_user[j]);
  153. bot.sendChat("@mods `retirem o " + fila[j] + "`");
  154. }
  155. fila = [];
  156. fila_user = [];
  157. presentes = [];
  158. //console.log("fila: " + fila[i]);
  159. //}
  160.  
  161. //console.log("presentes: " + presentes[i]);
  162. }
  163. }
  164. //else
  165. // bot.sendChat("@" + data.user.username + " não é da Staff.");
  166.  
  167. }
  168. else if(chamada == 1)
  169. {
  170. console.log(data.user.username + ': ' + data.message);
  171. // for(var i = 0; i < resp.length; i++)
  172. // {
  173. // console.log( "fila[" + i + "] = " + fila[i] + " " + data.user.username);
  174. // if(fila[i] == data.user.username)
  175. // {
  176. // //bot.sendChat("@" + data.user.username + " presente");
  177. // console.log( "fila[" + i + "] = " + fila[i] + " presente");
  178. // fila[i] = 0;
  179. // //console.log( fila[fila.indexOf(data.user.username)] + " presente");
  180. // console.log( "fila[" + i + "] = " + fila[i] + " zerado");
  181. // break;
  182. // }
  183. // }
  184. if(presentes.indexOf(data.user.username) == -1)
  185. {
  186. presentes.push(data.user.username);
  187. }
  188. }
  189. // else if ((skip == 0))
  190. // {
  191. // //skip = 1;
  192. // count_downs = bot.getScore();
  193. // //while(count_downs == null)
  194. // //{
  195. // count_downs = bot.getScore();
  196. // console.log(count_downs);
  197. // }
  198. // console.log("1skip: " + skip);
  199. // console.log(count_downs);
  200. // if(count_downs == null)
  201. // skip = 0;
  202. // else
  203. // skip = 4;
  204. // }
  205. // else if(skip == 1)
  206. // skip = 2;
  207. // else if(skip == 2)
  208. // skip = 3;
  209. // else if(skip == 3)
  210. // {
  211. // if(count_downs == null)
  212. // skip = 0;
  213. // else
  214. // skip = 4;
  215. // }
  216. // else if(skip == 4)
  217. // {
  218. // skip = 0;
  219. // console.log(" antes do while skip: " + skip);
  220. // console.log(" depois do while skip: " + skip);
  221. // //count_downs = { "downdubs":"0"};
  222. // count_downs = count_downs.downdubs;
  223. // console.log("2skip: " + skip);
  224. // if(count_downs !== 0 && count_downs != null)
  225. // {
  226. // console.log("3skip: " + skip);
  227. // resp = bot.getQueue();
  228. // count_fila = resp.length;
  229. // console.log(count_downs + " " + count_fila);
  230. // if(count_fila <= 2 && count_downs >=3)
  231. // bot.moderateSkip();
  232. // else if ((count_downs >= count_fila/2) && count_fila > 2)
  233. // bot.moderateSkip();
  234. // }
  235. // }
  236. //else
  237. // console.log(data.user.username + ': ' + data.message);
  238.  
  239. //console.log(data.user.username + ': ' + data.message);
  240. });
  241.  
  242. connect();
  243.  
  244.  
  245.  
  246. // while(1)
  247. // {
  248. // resp = bot.getScore();
  249. // console.log(resp);
  250. // //myPromise.then(console.log(count_downs));
  251. // count_downs = resp.downdubs;
  252. // console.log(count_downs);
  253. // if(count_downs !== 0)
  254. // {
  255. // resp = bot.getQueue();
  256. // count_fila = resp.length;
  257. // //console.log(count_downs + " " + count_fila);
  258. // if(count_fila <= 2 && count_downs >=3)
  259. // bot.moderateSkip();
  260. // else if (count_downs >= count_fila/2)
  261. // bot.moderateSkip();
  262. // }
  263. // }
  264.  
  265. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement