Advertisement
Guest User

MUS

a guest
May 26th, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. const { Socket } = require('net');
  2. const moment = require('moment');
  3. module.exports = class Mus{
  4. constructor(host,port,client){
  5. this.client = client;
  6. this.host = host || '127.0.0.1';
  7. this.port = port || '30001';
  8. this.connect();
  9. }
  10. connect(){
  11. this.socket = new Socket().setEncoding('utf8')
  12. .connect(this.port, this.host, function() {
  13. if(!this.ping) console.log('[MUS] Conectado!');
  14. else console.log(`[MUS] Ping!`)
  15. this.ping = false;
  16. });
  17. if(!this.ping) this.init();
  18. }
  19. init(){
  20. this.socket.on('close', function() {
  21. if(!this.ping) console.log('[MUS] Conexão encerrada!');
  22. });
  23. this.socket.on('error', error => console.log(error.message));
  24. this.socket.on('data', async data => {
  25. let mus = await JSON.parse(data);
  26. if(mus.to != 'bot') return;
  27. let tipo = mus.command
  28. let args = mus.args
  29.  
  30. switch(tipo) {
  31. case 'eha':
  32. this.client.channels.get('568572221258465306').send(`[${moment().format(`HH:mm`)}] \`Eha\` - ${args[0]} - ${args[1]}`)
  33. break;
  34. case 'premiar':
  35. this.client.channels.get('568572221258465306').send(`[${moment().format(`HH:mm`)}] \`Premiar\` - ${args[0]} premiou o usuário ${args[1]}`)
  36. break;
  37. case 'ban':
  38. this.client.channels.get('570299844686643200').send(`[${moment().format(`HH:mm`)}] \`Ban\` - ${args[0]} baniu o usuário ${args[1]} por ${args[2]} minutos, MOTIVO: ${args[3]} `)
  39. break;
  40. case 'mip':
  41. this.client.channels.get('570299844686643200').send(`[${moment().format(`HH:mm`)}] \`MIP\` - ${args[0]} baniu o usuário ${args[1]}. MOTIVO: ${args[3]} `)
  42. break;
  43. case 'dc':
  44. this.client.channels.get('570299844686643200').send(`[${moment().format(`HH:mm`)}] \`DC\` - ${args[0]} desconectou o usuário ${args[1]}`)
  45. break;
  46. case 'give':
  47. this.client.channels.get('570299844686643200').send(`[${moment().format(`HH:mm`)}] \`Give\` - ${args[0]} deu ao usuário ${args[1]} ${args[2]} ${args[3]}`)
  48. break;
  49.  
  50. }
  51. })
  52. //this.socket.setKeepAlive(true, 5000)
  53. this.socket.setTimeout(60 * 60 * 1000);
  54. this.socket.on('timeout', () => {
  55. this.socket.destroy();
  56. this.ping = true;
  57. this.connect();
  58. });
  59. }
  60. enviar(mensagem){
  61. if(this.socket.setKeepAlive(true, 5000))
  62. new Promise((resolve,reject) => resolve(this.socket.write(mensagem)))
  63. }
  64. receber(){
  65. return new Promise((resolve,reject) => this.socket.on('data', data => resolve(data)))
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement