<commit_before>const WebSocket = require('ws');
const axios = require('axios');
const qs = require('qs');

let key = process.env.TT_KEY;

axios.post('https://slack.com/api/auth.test', qs.stringify({token: key})).then(res =>{
  let data = res.data;
  let dest = data.url;
  console.dir(data);
  if (dest) {
    let socket = new WebSocket(dest);
  
    socket.on('message', (data) => {
      console.log(data.message);
    });
  }
  else {
    console.log('error');
  }
});<commit_msg>Run and respond to player info<commit_after>const WebSocket = require('ws');
const axios = require('axios');
const qs = require('qs');

let key = process.env.TT_KEY;
let wg = process.env.WG_KEY;

axios.post('https://slack.com/api/rtm.connect', qs.stringify({token: key})).then(res =>{
  let body = res.data;
  let dest = body.url;
  if (dest) {
    let socket = new WebSocket(dest);
    
    let id = 1;
    
    socket.on('message', (json) => {
      let data = JSON.parse(json);
      //console.log(data);
      if (data.type === 'message') {
        let text = data.text || '';
        let say = 'wotbot say';
        let channel = data.channel;
        if (text.startsWith(say)) {
          let ans = text.slice(say.length + 1);
          let res = {
            id: id++,
            type: 'message',
            channel: channel,
            text: ans
          };
          socket.send(JSON.stringify(res));
        }
  
        let info = 'player info';
        if (text.startsWith(info)) {
          let playerName = text.slice(info.length + 1);
          let params = {
            application_id: wg,
            type: 'exact',
            search: playerName
          };
          axios.get(`https://api.worldoftanks.com/wot/account/list/?application_id=${wg}&type=exact&search=${playerName}`).then(res => {
            console.dir(res.data);
            let player = res.data.data[0];
            let text = 'Player not found';
            if (player) {
              text = 'https://clantools.us/servers/na/players?id=' + player.account_id;
            }
            let slack = {
              id: id++,
              type: 'message',
              channel: channel,
              text: text
            };
            socket.send(JSON.stringify(slack));
          });
        }
        //https://api.worldoftanks.com/wot/account/list/?application_id=25197ff770476528cf3f98c4715287bf&type=exact&search=Pizar
      }
    });
  }
  else {
    console.log('error');
  }
});
{'fraction_non_alphanumeric': 0.16045380875202594, 'fraction_numerical': 0.011345218800648298, 'mean_word_length': 1.9746987951807229, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6007433', 'n_tokens_mistral': 815, 'n_tokens_neox': 793, 'n_words': 154}