tweet source & winners
This commit is contained in:
parent
4b2f1621dc
commit
8fc9425be3
|
@ -5,6 +5,7 @@
|
|||
"connect": ">=1.8.1",
|
||||
"ltx":">=0.1.1",
|
||||
"websocket":">=1.0.1",
|
||||
"mime": ">=1.2.4"
|
||||
"mime": ">=1.2.4",
|
||||
"twitter": ">=0.1.17"
|
||||
}
|
||||
}
|
24
quiz.js
24
quiz.js
|
@ -522,6 +522,9 @@ function switchToGame() {
|
|||
i++;
|
||||
});
|
||||
|
||||
// Tweet source
|
||||
sendToBackend({ tweet: q.text + (q.source ? (" " + q.source) : "") });
|
||||
|
||||
keyHandler = function(key) {
|
||||
if (key === " ") {
|
||||
// next question:
|
||||
|
@ -531,6 +534,27 @@ function switchToGame() {
|
|||
$('#game').fadeOut(500, function() {
|
||||
switchToScoreboard();
|
||||
});
|
||||
if (currentQuestion == questions.length) {
|
||||
var winners = [];
|
||||
for(var i = 0; i < playerNames.length; i++) {
|
||||
if (playerNames[i])
|
||||
winners.push({ name: playerNames[i],
|
||||
score: playerScores[i]
|
||||
});
|
||||
}
|
||||
winners.sort(function(a, b) {
|
||||
if (a.score < b.score)
|
||||
return 1;
|
||||
else if (a.score > b.score)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
});
|
||||
var tweet = winners.map(function(winner) {
|
||||
return winner.name + " (" + winner.score + ")";
|
||||
}).join(" > ");
|
||||
sendToBackend({ tweet: tweet });
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
22
server.js
22
server.js
|
@ -298,6 +298,8 @@ new wss({ httpServer: server }).on('request', function(req) {
|
|||
gamestate = msg.gamestate;
|
||||
} else if (msg.requestGamestate) {
|
||||
conn.sendUTF(JSON.stringify({ gamestate: gamestate }));
|
||||
} else if (msg.tweet) {
|
||||
tweet(msg.tweet);
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e.stack);
|
||||
|
@ -322,3 +324,23 @@ function sendToFrontend(obj) {
|
|||
server.listen(8081, "::1");
|
||||
|
||||
morse("c3d2");
|
||||
|
||||
var twit = new (require('twitter'))({
|
||||
consumer_key: 'sNWvbrAz11vVMwppORKA',
|
||||
consumer_secret: 'MzAhGlzz3qWUIxse8vcHc3zqkPOBuWKJgjazGkeOc',
|
||||
access_token_key: '108923470-KVfqQJc8oIhAYZj2RhL7ggrR5Y9eMGjTQD79Db12',
|
||||
access_token_secret: 'uQ9ljbh5L3NGEuHhKSrrnQv3KmL59d0nS2pJBjiqgL8'
|
||||
});
|
||||
function tweet(text) {
|
||||
// FIXME: remove next line for production!
|
||||
return;
|
||||
|
||||
twit.updateStatus(text, function(res) {
|
||||
if (res.statusCode && res.statusCode >= 400) {
|
||||
/* Failure */
|
||||
var m = text.match(/^(.+) /);
|
||||
if (m)
|
||||
tweet(m[1]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue