函数不执行和跳过if语句

时间:2018-07-01 14:08:57

标签: javascript mysql node.js twitch

我试图让此代码重复运行,所以我可以在我的抽搐频道上为观众添加分。同样在工作时,它会跳过该函数中的第一个if语句,即使它应该通过它运行代码。

updatePoints函数不能与此代码一起运行

随机数的一长串是我的加密密码和mysql登录名

var request = require("request")
var sql = require("mssql")

var _0x7005=["\x6D\x79\x73\x71\x6C","","\x72\x6F\x6F\x74","","\x70\x6F\x69\x6E\x74\x73","\x63\x72\x65\x61\x74\x65\x43\x6F\x6E\x6E\x65\x63\x74\x69\x6F\x6E"];var mysql=require(_0x7005[0]);var connection=mysql[_0x7005[5]]({host:_0x7005[1],user:_0x7005[2],password:_0x7005[3],database:_0x7005[4]})


var Found = false;
var url = "https://tmi.twitch.tv/group/user/kong_plays/chatters"
var viewerAmount = 0;
var viewers = [];
var val = 0;

connection.connect((err) => {
  if (err) {
    console.log("Error connecting to database")
  }
  console.log('Connected to database!');
});


request({
    url: url,
    json: true
}, function (error, response, body) {
    if (!error && response.statusCode === 200) {
        viewers = body.chatters.viewers;
        console.log(viewers);
        viewerAmount = viewers.length;
        console.log(viewerAmount)

    }
});

    function updatePoints(){
      console.log("6")
      for (viewerCount = viewerAmount; viewerCount >= 0; viewerCount--) {
            currentViewer = viewers[viewerCount];
            connection.query("SELECT * FROM points WHERE twitchName = '" +currentViewer +"'", (err, result) => {
              if (result === ''){
                connection.query("INSERT INTO points (twitchName, points) VALUES ('" + currentViewer +"', '10')", (err, result) => {
                  if(err) throw err;
                  console.log("Inserted into table")
            });
    }else{
          for (viewerCount = viewerAmount; viewerCount >= 0; viewerCount--) {
            currentViewer = viewers[viewerCount];
            connection.query("SELECT * FROM points WHERE twitchName = '" +currentViewer +"'", (err, result) => {
              connection.query("UPDATE points SET points= points+10 WHERE twitchName = '" + currentViewer + "'", (err, result) => {
                if(err) throw err;
                console.log("updated points")
              });
            });
          };
        }
      });

    setInterval(function(){
    updatePoints()}, 3000)
    }
}

0 个答案:

没有答案