Function not excecuting and skipping if statement
Function not excecuting and skipping if statement
im trying to get this code to run on repeat, so i can add points for my viewers on my twitch channel. Also when it was working, it was skipping the first if statement in the function even though it should be running the code through it.
The updatePoints function does not run with this code
The long bits of random numbers is my encrypted passwords and mysql logins
var request = require("request")
var sql = require("mssql")
var _0x7005=["x6Dx79x73x71x6C","","x72x6Fx6Fx74","","x70x6Fx69x6Ex74x73","x63x72x65x61x74x65x43x6Fx6Ex6Ex65x63x74x69x6Fx6E"];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)
}
}
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
do not repost your question
– lucumt
Jul 1 at 14:23