Created
March 20, 2014 13:43
-
-
Save cranic/9663995 to your computer and use it in GitHub Desktop.
Client de comandos por chat do Twitch.tv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var express = require('express'); | |
var app = express(); | |
var http = require('http').createServer(app); | |
var io = require('socket.io').listen(http); | |
var irc = require('irc'); | |
var commands = ['up', 'down', 'left', 'right', 'reset']; | |
// Conexão com o IRC do canal | |
var client = new irc.Client('irc.twitch.tv', 'cooplays', { | |
nick: 'cooplays', | |
userName: 'cooplays', | |
channels: ['#cooplays'], | |
password: 'oauth:meuoauth', | |
sasl: true, | |
port: 6667 | |
}); | |
client.addListener('error', function(err){ | |
throw err; | |
}); | |
// Ao receber uma msg verificamos se é um comando | |
client.addListener('message#cooplays', function (from, message) { | |
// O comando digitado é válido? | |
var cmd = commands.filter(function(val){ | |
return message.toLowerCase().indexOf(val) === 0; | |
})[0]; | |
// Se for um comando eviamos para o navegador | |
if(cmd) | |
io.sockets.emit('command', { | |
user: from, | |
command : cmd | |
}); | |
}); | |
// Nada de novo aqui, só o express | |
app.use(express.static('./public')); | |
// Servimos a página principal com um iframe e | |
// um painel lateral | |
app.get('/', function(req, res){ | |
res.sendfile(__dirname + '/view/index.html'); | |
}); | |
// O jogo mesmo, carrega dentro de um iframe, assim | |
// não precisamos mexer no CSS, hue hue br | |
app.get('/game', function(req, res){ | |
res.sendfile(__dirname + '/view/game.html'); | |
}); | |
// Iniciamos a aplicação e bindamos ela em um | |
// endereço local para ninguém ter acesso | |
http.listen(8085, '127.0.0.1'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment