Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Socket } = require('net');
- const moment = require('moment');
- module.exports = class Mus{
- constructor(host,port,client){
- this.client = client;
- this.host = host || '127.0.0.1';
- this.port = port || '30001';
- this.connect();
- }
- connect(){
- this.socket = new Socket().setEncoding('utf8')
- .connect(this.port, this.host, function() {
- if(!this.ping) console.log('[MUS] Conectado!');
- else console.log(`[MUS] Ping!`)
- this.ping = false;
- });
- if(!this.ping) this.init();
- }
- init(){
- this.socket.on('close', function() {
- if(!this.ping) console.log('[MUS] Conexão encerrada!');
- });
- this.socket.on('error', error => console.log(error.message));
- this.socket.on('data', async data => {
- let mus = await JSON.parse(data);
- if(mus.to != 'bot') return;
- let tipo = mus.command
- let args = mus.args
- switch(tipo) {
- case 'eha':
- this.client.channels.get('568572221258465306').send(`[${moment().format(`HH:mm`)}] \`Eha\` - ${args[0]} - ${args[1]}`)
- break;
- case 'premiar':
- this.client.channels.get('568572221258465306').send(`[${moment().format(`HH:mm`)}] \`Premiar\` - ${args[0]} premiou o usuário ${args[1]}`)
- break;
- case 'ban':
- 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]} `)
- break;
- case 'mip':
- this.client.channels.get('570299844686643200').send(`[${moment().format(`HH:mm`)}] \`MIP\` - ${args[0]} baniu o usuário ${args[1]}. MOTIVO: ${args[3]} `)
- break;
- case 'dc':
- this.client.channels.get('570299844686643200').send(`[${moment().format(`HH:mm`)}] \`DC\` - ${args[0]} desconectou o usuário ${args[1]}`)
- break;
- case 'give':
- this.client.channels.get('570299844686643200').send(`[${moment().format(`HH:mm`)}] \`Give\` - ${args[0]} deu ao usuário ${args[1]} ${args[2]} ${args[3]}`)
- break;
- }
- })
- //this.socket.setKeepAlive(true, 5000)
- this.socket.setTimeout(60 * 60 * 1000);
- this.socket.on('timeout', () => {
- this.socket.destroy();
- this.ping = true;
- this.connect();
- });
- }
- enviar(mensagem){
- if(this.socket.setKeepAlive(true, 5000))
- new Promise((resolve,reject) => resolve(this.socket.write(mensagem)))
- }
- receber(){
- return new Promise((resolve,reject) => this.socket.on('data', data => resolve(data)))
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement