bradly.spicer 47 Posting Whiz in Training

Hi all,

Been trying to do this for a while, I have a .js script which utilises node.js and socket.io. I'm trying to make it so that when I have the page localhost:3000 open and I type !follow in an IRC chat it will change the web page.

Index.html:

<!doctype html>
<html>
  <head>
    <title>Family Fortunes</title>
    <style>
      * { margin: 0; padding: 0; box-sizing: border-box; }
      body { font: 13px Helvetica, Arial; }
      form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; }
      form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; }
      form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; }
      #messages { list-style-type: none; margin: 0; padding: 0; }
      #messages li { padding: 5px 10px; }
      #messages li:nth-child(odd) { background: #eee; }
    </style>
    <script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
    <script src="http://code.jquery.com/jquery-1.11.1.js"></script>
  </head>
  <body>

  <script src="/socket.io/socket.io.js"></script>  
  <script src="trigger.js"></script>
  <script src="example.js"></script>
<script>
  var socket = io();

</script>
<div id="welcome" style="display:none;"> WELCOME</div>

  </body>
</html>

example.js:

//http://www.schmoopiie.com/docs/twitch-irc/Commands/Action

//SOCKET.IO Setup
var io = require('socket.io')(http);
var app = require('express')();
var http = require('http').Server(app);

//Check if user accesses page
io.on('connection', function(socket){
  console.log('a user connected');
  socket.on('disconnect', function(){
    console.log('user disconnected');
  });
});
http.listen(3000, function(){
  console.log('listening on *:3000');
});

//Get index.html page
app.get('/', function(req, res){
  res.sendfile('index.html');
});

//Node.JS Setup & libraries
var irc = require('twitch-irc');
var api = require('twitch-irc-api');

//Declare Global Variable with NO attributes.
var Follower = {};
var LastFollower = {};

//API Callout
setInterval(function(){ 
    api.call({
        channel: null,
        method: 'GET',
        path: '/channels/greatbritishbg/follows',
        options: {
            limit: 1,
            offset: 0
        }
    }, function(err, statusCode, response) {
        if (err) {
            console.log(err);
            return;
        }
            Follower.response = String(response.follows[0].user.display_name);
            //console.log('Returning Current follower Loop: ' + Follower.response);
    });
}, 1000);

//IRC Connect
var clientOptions = {
    options: {
        debug: true,
        debugIgnore: ['ping', 'chat', 'action']
    },
    identity: {
        username: 'greatbritishbg',
        password: 'oauth:5y15lyv5t15rr9to0zrhz11rlgzw9r'
    },
    channels: ['greatbritishbg']
}
var client = new irc.client(clientOptions);
client.connect();


//show hidden Div called "welcome"
function showDiv() {
        document.getElementById('welcome').style.display = "visible";
}  

//Commands
client.addListener('chat', function (channel, user, message) {
    console.log(user.username + ': ' + message);
    if (message.toLowerCase() === '!follow') {
        client.say(channel, 'Latest Follower: ' + Follower.response).then(function() {
        showDiv();
        });
    }
});

So far, it does the client.say() part but if I have the wbe page open it doesn't trigger showDiv();

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.