<commit_before>// Import the discord.js module
const Discord = require('discord.js');
// Import the checker functionality
const ApplyChecker = require('./checker.js');
// Import covfefify
const covfefify = require('./covfefify.js');
// Import configuracion
var CONFIG = require('./config.json');

// Import twitter
var Twitter = require('twitter-node-client').Twitter;
//Callback functions para twitter
var error = function (err, response, body) {
  	console.log('\nERROR: ' + err + "\nResponse: " + response + "\nBody: " + body);
};
var success = function (data) {
    //Nada
    //console.log('Data [%s]', data);
};

// Token para la conexion y asociacion al bot
var temporalToken = CONFIG.discordToken;
if(temporalToken == ""){
  temporalToken = process.env.discordToken;
}
const token = temporalToken;


//Tokens para twitter
var twitter = new Twitter({
  "consumerKey": CONFIG.twitterConsumerKey,
  "consumerSecret": CONFIG.twitterConsumerSecret,
  "accessToken": CONFIG.twitterAccessToken,
  "accessTokenSecret": CONFIG.twitterAccessTokenSecret,
  "callBackUrl": CONFIG.twitterCallBackUrl
});

// Instancia de cliente Discord
const client = new Discord.Client();

// Declaro constantes para las regex de interpretación de mensajes
// La i final implica case insensitiveness
const regexSupp = /(support)|(supp)/i
const regexDuplicates = /repetid[oa]/i
const regexRein = /rein/i
const regexPing = /(ping)|(lag)/i
const regexSaludos = /(Hola a todos)|(gente)|(buenas)|(señores)/i
const regexCarga = /(carga)|(punto)|(payload)|(proteg)/i
const regexPeplo = /(pero)|(orisa)|(support)/i
const regexAsco = /(asco)|(c[aá]ncer)|(sida)|(zanker)|(asquer)|(pharah?)|(yasuo)|(hanzo)/i
const regexRate = /^(?!http).*[0-9]+\/[0-9]+/
const regexPansal1 = /(hola)|(buenas)|(gente)/i
const regexPansal2 = /(Que tal)/
const regexKek = /kek/i
const regexPuton = /(que gracioso)|(hahaha)|(puto tonto)/i
const regexChancla = /(chancla)|(chancla mortal) nid jilin/i
const regexNegrito = /(felipe)|(negritoriko)/i
const regexBamboo = /(bambú)|(bambu)|(bamboo)/i
const regexJiros = /jiro+u*s+/i
const regexCallMe = /(c[ao]ll)|(cell)|(selfon)|(avis)/i
const regexBorja = /(borj)|(Hagrov)/i
const regexQuejaBot = /((c[aá]llate)|(que te calles)|(ktkys)|(puto)).*bot/i
const regexStaph = /(bot staph)|(para bot)/i
const regexNoLink = /^(?!http).*/
const regexTTSMal = /^(\/TTS).*/
const regexTorb = /(torb)|(enano)|(upgrade)/i
const regexRekt = /rekt/i

//LOCAL PERSISTENCE
var listeningAudioPetitions = true;
var cumpleBolas = false;
var hablarDelJuego = false;

var http = require("http");

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Get response\n');
}).listen(process.env.PORT || 5000)

setInterval(function() {
    http.get("http://eszobot.herokuapp.com");
    console.log("Sent keepalive request");
}, 200000); // every 5 minutes (300000)

setInterval(function() {
    hablarDelJuego = true;
}, 86400000); // every day (86400000)



//Cuando el bot hace sus cosas pasa esto:
client.on('ready', () => {
  console.log("Doing some gud' ol' barrel rolls...");
});

//Desconecta del canal de voz si lo hay, luego ejecuta el callback
var disconectVoiceThenExecute = function(callback){
  var conexiones = client.voiceConnections.array();
  if(conexiones.length > 0){
    conexiones[0].channel.leave();
  }
  callback()
}

//Refactorizacion de reproduccion de audio
var playAudioFile = function(uri, user){
  if(listeningAudioPetitions){
    listeningAudioPetitions = false;
    disconectVoiceThenExecute(function(){
      //Conexion al canal del user o de bots en su defecto
      let channel = user.voiceChannel
      if(channel == null){
        channel = client.channels.get('336838964004651008');
      }
      channel.join().then(
        conexion => {
          const dispatcheru = conexion.playArbitraryInput(uri);
          dispatcheru.on('end', () =>{
            conexion.channel.leave();
            listeningAudioPetitions = true;
          });
        }).catch(console.log)
      })
    }
}



// Listeners para pabla
client.on('voiceStateUpdate', (oldMemberState, newMemberState) => {
  if(newMemberState.id == 161138305189150720 && newMemberState.voiceChannel != null){
    playAudioFile("audio/mniac.mp3", newMemberState)
  }
});

//  Listener para Daviz
client.on('voiceStateUpdate', (oldMemberState, newMemberState) => {
  if(newMemberState.id == 328906982675185664 && newMemberState.voiceChannel != null){
    playAudioFile("audio/daviz.mp3", newMemberState)
  }
});


// Listeners para mensajes
client.on('message', message => {
  ApplyChecker(message)

  if(message.channel.id == 346796946393923584){
    var adjuntos = message.attachments.array()
    if(adjuntos.length > 0){
      var adjunto = adjuntos[0] //TODO ponerse a hacer esto en multiples archivos algun día
      console.log("URL: " + adjunto.url);
      /*
      twitter.postMedia({'media' : adjunto.attachment}, error, function(response){
        console.log("LLEGUE HASTA AQUI");
        twitter.postTweet({'status': message.content, 'media_ids': [response.media_id_string] }, error, success);
      })
      */
    }else {
      twitter.postTweet({'status': message.content}, error, success);
    }


  }else{
    // Si el mensaje no lo escribe el bot
    if( message.author.username != 'EstrellaZorro'){
      // Listener para reproduccion
      if ("!bling" == message.content || "!panda" == message.content
          || "!airhorn" == message.content || "!joeputa" == message.content
          || "!fgilipollas" == message.content || "!laloli" == message.content
          || "!salchichonio" == message.content || "!daviz" == message.content
          || "!subnormal" == message.content || "!janso" == message.content
          || "!yaves" == message.content || "!elagua" == message.content 
          || "!augale" == message.content ) {
        playAudioFile("audio/"+message.content.slice(1,message.content.length)+".mp3", message.member)
        message.delete()
      }
      // Desactivar audio
      if (regexStaph.test(message.content) || "!stop" == message.content) {
        disconectVoiceThenExecute(function(){message.reply('JOOOOOOBAAAAAAA');
          listeningAudioPetitions = true;});
      }

      //TORBJORN
      if (regexTorb.test(message.content) ) {
        playAudioFile("audio/torb.mp3", message.member)
      }

      if (regexRekt.test(message.content) ) {
        playAudioFile("audio/rekt.mp3", message.member)
      }

      // Listener para walker
      if (cumpleBolas && message.author.username === 'DarkWalker') {
        message.reply("¡¡¡¡¡¡¡¡¡FELI<NAME>!!!1!UNO!");
      }
      if (message.content == '!cumple') {
        cumpleBolas = !cumpleBolas;
        if(cumpleBolas){<commit_msg>duah&mishon 1/2<commit_after>// Import the discord.js module
const Discord = require('discord.js');
// Import the checker functionality
const ApplyChecker = require('./checker.js');
// Import covfefify
const covfefify = require('./covfefify.js');
// Import configuracion
var CONFIG = require('./config.json');

// Import twitter
var Twitter = require('twitter-node-client').Twitter;
//Callback functions para twitter
var error = function (err, response, body) {
  	console.log('\nERROR: ' + err + "\nResponse: " + response + "\nBody: " + body);
};
var success = function (data) {
    //Nada
    //console.log('Data [%s]', data);
};

// Token para la conexion y asociacion al bot
var temporalToken = CONFIG.discordToken;
if(temporalToken == ""){
  temporalToken = process.env.discordToken;
}
const token = temporalToken;


//Tokens para twitter
var twitter = new Twitter({
  "consumerKey": CONFIG.twitterConsumerKey,
  "consumerSecret": CONFIG.twitterConsumerSecret,
  "accessToken": CONFIG.twitterAccessToken,
  "accessTokenSecret": CONFIG.twitterAccessTokenSecret,
  "callBackUrl": CONFIG.twitterCallBackUrl
});

// Instancia de cliente Discord
const client = new Discord.Client();

// Declaro constantes para las regex de interpretación de mensajes
// La i final implica case insensitiveness
const regexSupp = /(support)|(supp)/i
const regexDuplicates = /repetid[oa]/i
const regexRein = /rein/i
const regexPing = /(ping)|(lag)/i
const regexSaludos = /(Hola a todos)|(gente)|(buenas)|(señores)/i
const regexCarga = /(carga)|(punto)|(payload)|(proteg)/i
const regexPeplo = /(pero)|(orisa)|(support)/i
const regexAsco = /(asco)|(c[aá]ncer)|(sida)|(zanker)|(asquer)|(pharah?)|(yasuo)|(hanzo)/i
const regexRate = /^(?!http).*[0-9]+\/[0-9]+/
const regexPansal1 = /(hola)|(buenas)|(gente)/i
const regexPansal2 = /(Que tal)/
const regexKek = /kek/i
const regexPuton = /(que gracioso)|(hahaha)|(puto tonto)/i
const regexChancla = /(chancla)|(chancla mortal) nid jilin/i
const regexNegrito = /(felipe)|(negritoriko)/i
const regexBamboo = /(bambú)|(bambu)|(bamboo)/i
const regexJiros = /jiro+u*s+/i
const regexCallMe = /(c[ao]ll)|(cell)|(selfon)|(avis)/i
const regexBorja = /(borj)|(Hagrov)/i
const regexQuejaBot = /((c[aá]llate)|(que te calles)|(ktkys)|(puto)).*bot/i
const regexStaph = /(bot staph)|(para bot)/i
const regexNoLink = /^(?!http).*/
const regexTTSMal = /^(\/TTS).*/
const regexTorb = /(torb)|(enano)|(upgrade)/i
const regexRekt = /rekt/i

//LOCAL PERSISTENCE
var listeningAudioPetitions = true;
var cumpleBolas = false;
var hablarDelJuego = false;

var http = require("http");

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'text/plain');
  res.end('Get response\n');
}).listen(process.env.PORT || 5000)

setInterval(function() {
    http.get("http://eszobot.herokuapp.com");
    console.log("Sent keepalive request");
}, 200000); // every 5 minutes (300000)

setInterval(function() {
    hablarDelJuego = true;
}, 86400000); // every day (86400000)



//Cuando el bot hace sus cosas pasa esto:
client.on('ready', () => {
  console.log("Doing some gud' ol' barrel rolls...");
});

//Desconecta del canal de voz si lo hay, luego ejecuta el callback
var disconectVoiceThenExecute = function(callback){
  var conexiones = client.voiceConnections.array();
  if(conexiones.length > 0){
    conexiones[0].channel.leave();
  }
  callback()
}

//Refactorizacion de reproduccion de audio
var playAudioFile = function(uri, user){
  if(listeningAudioPetitions){
    listeningAudioPetitions = false;
    disconectVoiceThenExecute(function(){
      //Conexion al canal del user o de bots en su defecto
      let channel = user.voiceChannel
      if(channel == null){
        channel = client.channels.get('336838964004651008');
      }
      channel.join().then(
        conexion => {
          const dispatcheru = conexion.playArbitraryInput(uri);
          dispatcheru.on('end', () =>{
            conexion.channel.leave();
            listeningAudioPetitions = true;
          });
        }).catch(console.log)
      })
    }
}



// Listeners para pabla
client.on('voiceStateUpdate', (oldMemberState, newMemberState) => {
  if(newMemberState.id == 161138305189150720 && newMemberState.voiceChannel != null){
    playAudioFile("audio/mniac.mp3", newMemberState)
  }
});

//  Listener para Daviz
client.on('voiceStateUpdate', (oldMemberState, newMemberState) => {
  if(newMemberState.id == 328906982675185664 && newMemberState.voiceChannel != null){
    playAudioFile("audio/daviz.mp3", newMemberState)
  }
});


// Listeners para mensajes
client.on('message', message => {
  ApplyChecker(message)

  if(message.channel.id == 346796946393923584){
    var adjuntos = message.attachments.array()
    if(adjuntos.length > 0){
      var adjunto = adjuntos[0] //TODO ponerse a hacer esto en multiples archivos algun día
      console.log("URL: " + adjunto.url);
      /*
      twitter.postMedia({'media' : adjunto.attachment}, error, function(response){
        console.log("LLEGUE HASTA AQUI");
        twitter.postTweet({'status': message.content, 'media_ids': [response.media_id_string] }, error, success);
      })
      */
    }else {
      twitter.postTweet({'status': message.content}, error, success);
    }


  }else{
    // Si el mensaje no lo escribe el bot
    if( message.author.username != 'EstrellaZorro'){
      // Listener para reproduccion
      if ("!bling" == message.content || "!panda" == message.content
          || "!airhorn" == message.content || "!joeputa" == message.content
          || "!fgilipollas" == message.content || "!laloli" == message.content
          || "!salchichonio" == message.content || "!daviz" == message.content
          || "!subnormal" == message.content || "!janso" == message.content
          || "!yaves" == message.content || "!elagua" == message.content 
          || "!augale" == message.content || "!duah" == message.content 
          || "!mishon" == message.content ) {
        playAudioFile("audio/"+message.content.slice(1,message.content.length)+".mp3", message.member)
        message.delete()
      }
      // Desactivar audio
      if (regexStaph.test(message.content) || "!stop" == message.content) {
        disconectVoiceThenExecute(function(){message.reply('JOOOOOOBAAAAAAA');
          listeningAudioPetitions = true;});
      }

      //TORBJORN
      if (regexTorb.test(message.content) ) {
        playAudioFile("audio/torb.mp3", message.member)
      }

      if (regexRekt.test(message.content) ) {
        playAudioFile("audio/rekt.mp3", message.member)
      }

      // Listener para walker
      if (cumpleBolas && message.author.username === 'DarkWalker') {
        message.reply("¡¡¡¡¡¡¡¡¡FELIZ CUMPLEAÑOS WALKER!!!1!UNO!");
      }
      if (message.content == '!cumple') {
        cumpleBolas = !cumpleBolas;
        if(cumpleBolas){
{'fraction_non_alphanumeric': 0.16153620639108765, 'fraction_numerical': 0.018469656992084433, 'mean_word_length': 3.685782967032967, 'pattern_counts': {'":': 10, '<': 4, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '25667', 'n_tokens_mistral': 4804, 'n_tokens_neox': 4557, 'n_words': 938}