Compare commits

...

10 Commits
master ... dev

  1. 14
      .gitignore
  2. 89
      lib/commands.js
  3. 738
      lib/currency.js
  4. 24
      lib/initialize.js
  5. 25
      lib/irc.js
  6. 20
      lib/mysql.js
  7. 115
      lib/web.js
  8. 1
      node_modules/body-parser/.npmignore
  9. 3
      node_modules/body-parser/.travis.yml
  10. 10
      node_modules/body-parser/HISTORY.md
  11. 9
      node_modules/body-parser/Makefile
  12. 60
      node_modules/body-parser/README.md
  13. 100
      node_modules/body-parser/index.js
  14. 6
      node_modules/body-parser/node_modules/qs/.gitmodules
  15. 7
      node_modules/body-parser/node_modules/qs/.npmignore
  16. 58
      node_modules/body-parser/node_modules/qs/Readme.md
  17. 366
      node_modules/body-parser/node_modules/qs/index.js
  18. 38
      node_modules/body-parser/node_modules/qs/package.json
  19. 1
      node_modules/body-parser/node_modules/raw-body/.npmignore
  20. 5
      node_modules/body-parser/node_modules/raw-body/.travis.yml
  21. 14
      node_modules/body-parser/node_modules/raw-body/Makefile
  22. 96
      node_modules/body-parser/node_modules/raw-body/README.md
  23. 164
      node_modules/body-parser/node_modules/raw-body/index.js
  24. 1
      node_modules/body-parser/node_modules/raw-body/node_modules/bytes/.npmignore
  25. 20
      node_modules/body-parser/node_modules/raw-body/node_modules/bytes/History.md
  26. 7
      node_modules/body-parser/node_modules/raw-body/node_modules/bytes/Makefile
  27. 54
      node_modules/body-parser/node_modules/raw-body/node_modules/bytes/Readme.md
  28. 7
      node_modules/body-parser/node_modules/raw-body/node_modules/bytes/component.json
  29. 41
      node_modules/body-parser/node_modules/raw-body/node_modules/bytes/index.js
  30. 37
      node_modules/body-parser/node_modules/raw-body/node_modules/bytes/package.json
  31. 45
      node_modules/body-parser/node_modules/raw-body/package.json
  32. 1
      node_modules/body-parser/node_modules/type-is/.npmignore
  33. 4
      node_modules/body-parser/node_modules/type-is/.travis.yml
  34. 16
      node_modules/body-parser/node_modules/type-is/HISTORY.md
  35. 87
      node_modules/body-parser/node_modules/type-is/README.md
  36. 148
      node_modules/body-parser/node_modules/type-is/index.js
  37. 19
      node_modules/body-parser/node_modules/type-is/node_modules/mime/LICENSE
  38. 66
      node_modules/body-parser/node_modules/type-is/node_modules/mime/README.md
  39. 114
      node_modules/body-parser/node_modules/type-is/node_modules/mime/mime.js
  40. 36
      node_modules/body-parser/node_modules/type-is/node_modules/mime/package.json
  41. 84
      node_modules/body-parser/node_modules/type-is/node_modules/mime/test.js
  42. 1588
      node_modules/body-parser/node_modules/type-is/node_modules/mime/types/mime.types
  43. 77
      node_modules/body-parser/node_modules/type-is/node_modules/mime/types/node.types
  44. 37
      node_modules/body-parser/node_modules/type-is/package.json
  45. 41
      node_modules/body-parser/package.json
  46. 24
      web/public/css/app.css
  47. 31
      web/public/help/instructions.txt
  48. 20
      web/templates/fanart.jade
  49. 138
      web/templates/index.jade
  50. 219
      web/templates/ladder.jade
  51. 61
      web/templates/layout.jade
  52. 14
      web/templates/stats.jade

14
.gitignore

@ -180,4 +180,16 @@ JsonParser.js
KarmaBot.js
Knowledge_Bot.js
WizardBot.js
XBucksBot.js
XBucksBot.js
#me me me
shaneomad.js
pyrionflax.js
testbot.js
2gd.js
*.png
*.jpg
web/public/browserconfig.xml
node_modules/.bin
web/public/favicon.ico
web/public/statistics

89
lib/commands.js

@ -20,6 +20,7 @@ function Commands(irc, db, options) {
__self.config = options || {};
__self.config.bot_name = options.bot_name || '';
__self.config.currency = options.currency || 'coins';
__self.config.exchange = options.exchange || {};
__self.command_list = [];
}
@ -36,8 +37,10 @@ Commands.prototype.start = function() {
};
Commands.prototype.commands = function(data) {
var __self = this,
command_check = data[3].slice(1).charAt(0),
var __self = this;
if (typeof data[3] === 'undefined') return;
var command_check = data[3].slice(1).charAt(0),
command = data[3].slice(2);
// check if potential command was called and match it with stored commands
@ -51,30 +54,92 @@ Commands.prototype.commands = function(data) {
for (var i = 0; i < rows.length; i++) {
// match db command with called command
if (rows[i].command = command) {
/*
// display based on viewer auth
if (rows[i].auth === 1) {
__self.irc.emit('message',{message:rows[i].text, options:{caller: __self.irc.caller(data[0]), auth: 1}});
__self.irc.emit('message',{message:'> '+rows[i].text, options:{caller: __self.irc.caller(data[0]), auth: 1}});
break;
} else if (rows[i].auth === 0) {
__self.irc.emit('message',{message:rows[i].text, options:null});
__self.irc.emit('message',{message:'> '+rows[i].text, options:null});
break;
}
*/
__self.irc.emit('message',{message:'> '+rows[i].text, options:null});
}
}
});
} else if (command_check === '!' && command === __self.config.bot_name.toLowerCase()) {
var commands = '> Commands: !' + __self.config.currency.toLowerCase() + ', ';
for (var i = 0; i < __self.command_list.length; i++) {
if (i !== __self.command_list.length - 1) {
commands += '!' + __self.command_list[i] + ', ';
} else {
commands += '!' + __self.command_list[i];
moderator_initiated = __self.irc.mods.indexOf(__self.irc.caller(data[0])) >= 0;
console.log(__self.irc.mods)
var commands = '> Commands: !' + __self.config.currency.toLowerCase() + ', !top, !rank, ';
if(Object.keys(__self.config.exchange).length != 0) commands += '!exchange, ';
if(moderator_initiated) {
for (var i = 0; i < __self.command_list.length; i++) {
if (i !== __self.command_list.length - 1) {
commands += '!' + __self.command_list[i] + ', ';
} else {
commands += '!' + __self.command_list[i];
}
}
__self.irc.emit('message',{message:commands, options:null});
}
__self.irc.emit('message',{message:commands, options:{caller: __self.irc.caller(data[0]), auth: 1}});
}
};
Commands.prototype.add = function(command, text) {
var __self = this;
// escape string for sql sanity
var txt = text.replace(/[\0\x08\x09\x1a\n\r"'\\\%]/g, function(char) {
switch (char) {
case "\0":
return "\\0";
case "\x08":
return "\\b";
case "\x09":
return "\\t";
case "\x1a":
return "\\z";
case "\n":
return "\\n";
case "\r":
return "\\r";
case "\"":
case "'":
case "\\":
case "%":
return "\\"+char;
}
});
var sql = 'INSERT INTO commands (command, text) VALUES (\''+command+'\', \''+txt+'\');';
// add the command to the database
__self.db.execute(sql, function(data) {
var message = '> Add Command: !' + command + ' has been added.';
__self.command_list.push(command);
__self.irc.emit('message',{message:message, options:null});
});
};
Commands.prototype.remove = function(command) {
var __self = this,
index = __self.command_list.indexOf(command);
if( index >= 0) {
var sql = 'DELETE FROM commands WHERE command=\''+command+'\';';
// remove the command from the database
__self.db.execute(sql, function(data) {
var message = '> Delete Command: !' + command + ' has been removed.';
__self.command_list.splice(index, 1);
__self.irc.emit('message',{message:message, options:null});
});
}
};
module.exports = function(irc, db, options) {
return new Commands(irc, db, options);
};
};

738
lib/currency.js

@ -59,14 +59,17 @@
var https = require('https'),
http = require('http'),
querystr = require('querystring'),
file = require('fs'),
utils = require('./utils.js');
//-------- Construct ---------
function Currency(irc, db, options) {
function Currency(irc, db, commands, options) {
var __self = this;
__self.irc = irc;
__self.db = db;
__self.custom_commands = commands;
// config
__self.config = options || {};
@ -75,6 +78,7 @@ function Currency(irc, db, options) {
__self.config.website = options.website || '';
__self.config.modpowers = options.modpowers || false;
__self.config.ignorelist = options.ignorelist || ['jtv'];
__self.config.exchanges = options.exchanges || {};
// general settings
__self.pre_text = '> ' + __self.config.currency + ': ';
@ -132,9 +136,29 @@ function Currency(irc, db, options) {
__self.bets_response_timer = 3000;
__self.bets_response_reset = true;
// voting settings
__self.votes_status = false;
__self.votes_board = [];
__self.votes_viewers = [];
__self.votes_payout = false;
__self.votes_total = 0;
__self.votes_flood = [];
__self.votes_response = null;
__self.votes_response_timer = 3000;
__self.votes_response_reset = true;
// high score table
__self.score_bet_pool = 0;
__self.score_bet_single = 0;
// commands add/rem settings
__self.command_add_string = options.add_command || 'addcmd';
__self.command_remove_string = options.remove_command || 'removecmd';
// message to new subscribers
__self.sub_ty_msg = options.sub_ty_msg || '';
// stored twitch stream data
}
//-------- Methods ---------
@ -172,6 +196,20 @@ Currency.prototype.commands = function (data) {
// broadcaster only commands
if (broadcaster_bot_initiated || (__self.config.modpowers && moderator_initiated)) {
//add / remove custom commands
if (data[4] === __self.command_add_string && data[5] !== undefined && data[6] !== undefined) {
var command = data[5];
var text = data.slice(6);
text = text.join(' ');
__self.custom_commands.add(command, text);
}
if (data[4] === __self.command_remove_string && data[5] !== undefined) {
var command = data[5];
__self.custom_commands.remove(command);
}
//open / close auction system
if (data[4] === 'auction') {
switch (data[5]) {
@ -198,7 +236,7 @@ Currency.prototype.commands = function (data) {
switch (data[5]) {
case 'open':
if (data[6] && data[7] && !__self.raffle_status) {
if(parseInt(data[6], 10) > 0 && parseInt(data[7], 10) > 0) {
if(parseInt(data[6], 10) >= 0 && parseInt(data[7], 10) > 0) {
// save default values
__self.temp.raffle_ticket_cost = __self.raffle_ticket_cost;
__self.temp.raffle_max_tickets = __self.raffle_max_tickets;
@ -261,6 +299,31 @@ Currency.prototype.commands = function (data) {
break;
}
}
// open / close voting system
if (data[4] === 'vote') {
switch (data[5]) {
case 'open':
if (data[6] && data[7]) {
__self.votes(true, data);
} else {
__self.irc.emit('message', {message:__self.pre_text + 'Unable to open voting, need at least two items to vote for'});
}
break;
case 'close':
__self.votes(false, null);
break;
case 'pool':
__self.votes('pool', null);
break;
case 'winner':
__self.votes('winner', data[6]);
break;
case 'cancel':
__self.votes('cancel');
break;
}
}
// TODO: create a log file that monitors just add/remove/push - greedy mods :D
// add currency
@ -289,6 +352,13 @@ Currency.prototype.commands = function (data) {
if (broadcaster_bot_initiated || moderator_initiated) {
// enable/disable currency requests
switch (data[4]) {
case 'status':
if (__self.streaming) {
__self.irc.emit('message', {message:__self.pre_text + "Stream is online, " + __self.config.currency + " are being distributed!"});
} else {
__self.irc.emit('message', {message:__self.pre_text + "Stream is offline :("});
}
break;
case 'on':
if (!__self.auction_status && !__self.raffle_status) {
__self.coin_toggle = false;
@ -395,8 +465,21 @@ Currency.prototype.commands = function (data) {
case '!rank':
__self.get_rank(__self.irc.caller(data[0]).toLowerCase());
break;
case '!exchange':
if(Object.keys(__self.config.exchanges).length != 0)
__self.currency_exchange(__self.irc.caller(data[0]), parseInt(data[4], 10), data[5]);
break;
case '!addquote':
__self.add_quotation(data);
break;
case '!delquote':
__self.remove_quotation(data);
break;
case '!quote':
__self.get_quotation();
}
// place a bet
if (__self.bets_status === true) {
for (var i = 0; i < __self.bets_board.length; i++) {
@ -410,6 +493,19 @@ Currency.prototype.commands = function (data) {
}
}
}
// cast a vote
if (__self.votes_status === true) {
for (var i = 0; i < __self.votes_board.length; i++) {
if (data[3].slice(1) === '!' + __self.votes_board[i].name) {
if (isNaN(parseInt(data[4], 10)) === false) {
if (data[4] >= 0 && data[4] % 1 === 0) {
__self.collect_votes(__self.irc.caller(data[0]), __self.votes_board[i], parseInt(data[4], 10));
break;
}
}
}
}
}
};
/**
@ -485,6 +581,67 @@ Currency.prototype.get_coins = function (caller) {
}
}
};
Currency.prototype.currency_exchange = function (name, amount, type) {
console.log('INSIDE CURR EXCHANGE');
var __self = this,
rate = 15,
cost = (amount * (rate / 100))
total = amount + cost;
if( name && amount && type ) {
console.log('ready to post');
if(Object.keys(__self.config.exchanges).indexOf(type) > -1) {
__self.query_coins(name.toLowerCase(), function (rows) {
var message = '',
response = new String();
if(rows[0].points >= total) {
// Prepare for POST
var data = querystr.stringify({'name': name, 'amount': amount});
var opts = {
port: __self.config.exchanges[type],
path: '/api/exchange',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(data)
}
};
var request = http.request(opts, function(res) {
res.setEncoding('utf-8');
res.on('data', function(chunk) {
response += chunk;
});
res.on('end', function() {
if(response == '1') {
// Exchanged succesfully, let's remove local currency
__self.adjust_currency('remove', total, name);
message = name+' exchanged '+amount+' for '+type+'. Cost '+total;
__self.irc.emit('message', {message:__self.pre_text + message, timer: 1});
}
});
});
request.write(data);
request.end();
}
});
}
} else {
message = '!exchange <amount> <type> [Valid types: ';
keys = Object.keys(__self.config.exchanges);
keys.forEach(function(element, index, array) {
message += keys[index]+', ';
});
message+=']';
__self.irc.emit('message', {message:__self.pre_text + message, timer: 1});
}
};
Currency.prototype.get_rank = function (data) {
var __self = this;
@ -526,7 +683,7 @@ Currency.prototype.get_rank = function (data) {
Currency.prototype.get_top = function (data) {
var __self = this;
var limit = 0;
var limit = 5;
function do_work() {
var response = '';
@ -547,12 +704,6 @@ Currency.prototype.get_top = function (data) {
__self.top_flood = [];
}
// check that we got a number
( isNaN(data) ) ? limit = 3 : limit = data;
// limit the number
if (limit > 6) limit = 3;
// add flood users to array
if (__self.top_flood.indexOf(limit) < 0) {
__self.top_flood.push(limit);
@ -704,32 +855,6 @@ Currency.prototype.handout_coins = function () {
// get subscribers
function subscribers() {
var time = utils.make_interval(__self.subscriber_check);
if (time === 0) {
// get stream status
http.get(__self.config.subscribers_json, function (response) {
var body = '';
// put together response
response.on('data', function (chunk) {
body += chunk;
});
// start / stop handing out coins based on stream status
response.on('end', function () {
var json = JSON.parse(body);
var entries = json.feed.entry, subs = '';
__self.subscribers = [];
for (var i = 0; i < entries.length; i++) {
__self.subscribers.push(entries[i].title['$t']);
subs += entries[i].title['$t'] + ' ';
}
__self.irc.emit('data', 'DATA - Subscriber Check - Returned: ' + subs);
setTimeout(subscribers, 1000);
});
});
} else {
setTimeout(subscribers, time);
}
}
// trigger coin handout
@ -816,7 +941,6 @@ Currency.prototype.handout_coins = function () {
if (viewer_idx >= 0) {
__self.viewer_list.splice(viewer_idx,1);
} else {
console.log("[*ERROR*] User "+viewer+" PART'ed but was not in viewer_list.");
}
}
@ -827,10 +951,48 @@ Currency.prototype.handout_coins = function () {
if (viewer != __self.irc.config.name.toLowerCase()) {
viewer = viewer.slice(1);
}
// add missing chatters to viewer_list
if (__self.viewer_list.indexOf(viewer) < 0 && __self.config.ignorelist.indexOf(viewer) < 0) {
__self.viewer_list.push(viewer);
console.log("[*ADD NAME*] "+viewer+" from CHAT");
}
// is this a new subscription notice?
if(viewer == 'twitchnotify') {
var subscriber = data_split[5].slice(1);
__self.irc.emit('message', {message:'> SUBHYPE: Thank you ' + subscriber + '. ' + __self.sub_ty_msg});
}
// log chat if enabled
if (__self.irc.store_chat && __self.config.ignorelist.indexOf(viewer) < 0) {
file.exists(__self.irc.chat_log, function (exists) {
if (exists) {
// get a timestamp
var date = new Date(),
hours = date.getHours() < 10 ? '0' + date.getHours() : date.getHours(),
min = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes(),
sec = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds(),
streaming_time = '';
// create start time string
streaming_time += hours.toString() + ':' + min.toString();
// craft message
data_split[5] = data_split[5].slice(1);
var message = data_split.slice(5).join(' ');
// put it all together
var logline = '[' + streaming_time + '] <' + viewer + '> ' + message + '\r\n';
file.appendFile(__self.irc.chat_log, logline, 'utf-8', function (err) {
if (err) {
throw err;
}
});
}
});
}
}
});
@ -902,48 +1064,50 @@ Currency.prototype.auction = function (status) {
switch (status) {
case true:
if (!__self.bets_status) {
if (!__self.raffle_status) {
if (!__self.auction_status) {
// open up the auction
__self.auction_status = true;
if (!__self.votes_status) {
if (!__self.bets_status) {
if (!__self.raffle_status) {
if (!__self.auction_status) {
// open up the auction
__self.auction_status = true;
// request toggle
if (__self.temp.raffle_toggle) {
__self.temp.auction_toggle = __self.temp.raffle_toggle;
} else {
__self.temp.auction_toggle = __self.coin_toggle;
}
__self.coin_toggle = false;
// request toggle
if (__self.temp.raffle_toggle) {
__self.temp.auction_toggle = __self.temp.raffle_toggle;
} else {
__self.temp.auction_toggle = __self.coin_toggle;
}
__self.coin_toggle = false;
// default request timer
if (__self.temp.raffle_timer && __self.temp.raffle_timer_reset) {
__self.temp.auction_timer = __self.temp.raffle_timer;
__self.temp.auction_timer_reset = __self.temp.raffle_timer_reset;
} else {
__self.temp.auction_timer = __self.coin_response_timer;
__self.temp.auction_timer_reset = __self.coin_response_reset;
}
__self.coin_response_timer = 3000;
__self.coin_response_reset = true;
// default request timer
if (__self.temp.raffle_timer && __self.temp.raffle_timer_reset) {
__self.temp.auction_timer = __self.temp.raffle_timer;
__self.temp.auction_timer_reset = __self.temp.raffle_timer_reset;
} else {
__self.temp.auction_timer = __self.coin_response_timer;
__self.temp.auction_timer_reset = __self.coin_response_reset;
}
__self.coin_response_timer = 3000;
__self.coin_response_reset = true;
// clear previous bids
__self.auction_bids = [];
__self.auction_previous_bid = {};
// clear previous bids
__self.auction_bids = [];
__self.auction_previous_bid = {};
// auction open response
__self.irc.emit('message', {message:__self.pre_text + 'Auction opened, accepting bids'})
// auction open response
__self.irc.emit('message', {message:__self.pre_text + 'Auction opened, accepting bids'})
} else {
// auction is already open response
__self.irc.emit('message', {message:__self.pre_text + 'Auction already in progress'});
}
} else {
// auction is already open response
__self.irc.emit('message', {message:__self.pre_text + 'Auction already in progress'});
// raffle currently running
__self.irc.emit('message', {message:__self.pre_text + 'You must close the raffle before you can open an auction'});
}
} else {
// raffle currently running
__self.irc.emit('message', {message:__self.pre_text + 'You must close the raffle before you can open an auction'});
// gambling currently running
__self.irc.emit('message', {message:__self.pre_text + 'Betting must be closed before you can open an auction'});
}
} else {
// gambling currently running
__self.irc.emit('message', {message:__self.pre_text + 'Betting must be closed before you can open an auction'});
}
break;
case false:
@ -1175,54 +1339,56 @@ Currency.prototype.raffle = function (status) {
switch (status) {
case true:
if (!__self.bets_status) {
if (!__self.auction_status) {
if (!__self.raffle_status) {
// open up a raffle
__self.raffle_status = true;
if (!__self.votes_status) {
if (!__self.bets_status) {
if (!__self.auction_status) {
if (!__self.raffle_status) {
// open up a raffle
__self.raffle_status = true;
// request toggle
if (__self.temp.auction_toggle) {
__self.temp.raffle_toggle = __self.temp.auction_toggle;
} else {
__self.temp.raffle_toggle = __self.coin_toggle;
}
__self.coin_toggle = false;
// request toggle
if (__self.temp.auction_toggle) {
__self.temp.raffle_toggle = __self.temp.auction_toggle;
} else {
__self.temp.raffle_toggle = __self.coin_toggle;
}
__self.coin_toggle = false;
// default request timer
if (__self.temp.auction_timer && __self.temp.auction_timer_reset) {
__self.temp.raffle_timer = __self.temp.auction_timer;
__self.temp.raffle_timer_reset = __self.temp.auction_timer_reset;
} else {
__self.temp.raffle_timer = __self.coin_response_timer;
__self.temp.raffle_timer_reset = __self.coin_response_reset;
}
__self.coin_response_timer = 3000;
__self.coin_response_reset = true;
// default request timer
if (__self.temp.auction_timer && __self.temp.auction_timer_reset) {
__self.temp.raffle_timer = __self.temp.auction_timer;
__self.temp.raffle_timer_reset = __self.temp.auction_timer_reset;
} else {
__self.temp.raffle_timer = __self.coin_response_timer;
__self.temp.raffle_timer_reset = __self.coin_response_reset;
}
__self.coin_response_timer = 3000;
__self.coin_response_reset = true;
// save previous raffle settings in case
// a new one is opened on accident
__self.raffle_restore_ticket_requests = __self.raffle_ticket_requests;
__self.raffle_restore_tickets = __self.raffle_tickets;
// save previous raffle settings in case
// a new one is opened on accident
__self.raffle_restore_ticket_requests = __self.raffle_ticket_requests;
__self.raffle_restore_tickets = __self.raffle_tickets;
// clear previous tickets
__self.raffle_ticket_requests = [];
__self.raffle_tickets = [];
// clear previous tickets
__self.raffle_ticket_requests = [];
__self.raffle_tickets = [];
// raffle open response
__self.irc.emit('message',{message:__self.pre_text + 'Raffle opened'});
__self.irc.emit('message',{message:'+ Tickets cost ' + __self.raffle_ticket_cost + ' ' + __self.config.currency.toLowerCase() + ' / Maximum of ' + __self.raffle_max_tickets + ' tickets per viewer'});
// raffle open response
__self.irc.emit('message',{message:__self.pre_text + 'Raffle opened'});
__self.irc.emit('message',{message:'+ Tickets cost ' + __self.raffle_ticket_cost + ' ' + __self.config.currency.toLowerCase() + ' / Maximum of ' + __self.raffle_max_tickets + ' tickets per viewer'});
} else {
// raffle in progress response
__self.irc.emit('message',{message:__self.pre_text + 'Raffle already in progress'});
}
} else {
// raffle in progress response
__self.irc.emit('message',{message:__self.pre_text + 'Raffle already in progress'});
// auction in progress
__self.irc.emit('message', {message:__self.pre_text + 'You must close the auction before you can open an a raffle'});
}
} else {
// auction in progress
__self.irc.emit('message', {message:__self.pre_text + 'You must close the auction before you can open an a raffle'});
// gambling currently running
__self.irc.emit('message', {message:__self.pre_text + 'Betting must be closed before you can open a raffle'});
}
} else {
// gambling currently running
__self.irc.emit('message', {message:__self.pre_text + 'Betting must be closed before you can open a raffle'});
}
break;
case false:
@ -1443,6 +1609,273 @@ Currency.prototype.next_raffle_winner = function () {
}
};
/*
* VOTING SYSTEM
* ------------
*/
Currency.prototype.votes = function(status, data) {
var __self = this;
switch(status){
case true:
if (!__self.bets_status) {
if (!__self.auction_status) {
if (!__self.raffle_status) {
if (!__self.votes_status && !__self.votes_payout) {
var wager_msg = '';
__self.votes_status = true;
__self.votes_payout = true;
__self.votes_board = [];
__self.votes_viewers = [];
__self.votes_total = 0;
__self.votes_board = data.join().split(',').filter(function(n){return n}).slice(6).map(function(n){return {name: n, num: 0, total: 0};});
for (var i = 0; i < __self.votes_board.length; i++) {
__self.votes_board[i].idx = i;
}
for (var i = 0; i < __self.votes_board.length; i++) {
if (i !== __self.votes_board.length - 1) {
wager_msg += '"!' + __self.votes_board[i].name + '" / ';
} else {
wager_msg += '"!' + __self.votes_board[i].name + '"';
}
}
// output to chat
__self.irc.emit('message', {message:__self.pre_text + 'Voting is now open'});
__self.irc.emit('message', {message:'+ Type ' + wager_msg + ' and the vote amount to enter'});
} else {
if (__self.votes_payout) {
// payout pending message
__self.irc.emit('message', {message:__self.pre_text + 'Unable to take new votes until the last has been decided'});
} else {
__self.irc.emit('message', {message:__self.pre_text + 'Voting already in progress'});
}
}
// FIXME: messages below should be "cant open a vote until X is over/closed" instead? test it
} else {
// raffle in progress
__self.irc.emit('message', {message:__self.pre_text + 'Voting must be closed before you can open a raffle'});
}
} else {
// auction currently running
__self.irc.emit('message', {message:__self.pre_text + 'Voting must be closed before you can open an auction'});
}
}
break;
case false:
if (__self.votes_status && __self.votes_payout) {
__self.votes_status = false;
__self.votes_deduct_votes();
// output to chat
if (__self.votes_viewers.length > 0) {
__self.irc.emit('message', {message:__self.pre_text + 'Voting is now closed'});
for (var i = 0; i < __self.votes_board.length; i++) {
__self.irc.emit('message', {message:'+ ' + __self.votes_board[i].name + ' with ' + __self.votes_board[i].num + ' supporters totaling ' + __self.votes_board[i].total + ' votes'});
}
//
} else {
__self.irc.emit('message', {message:__self.pre_text + 'Voting closed, no votes were cast.'});
}
}
break;
case 'pool':
function do_work() {
if (__self.votes_board.length > 0) {
__self.irc.emit('message', {message:__self.pre_text + 'Current voting pool is:'});
for (var i = 0; i < __self.votes_board.length; i++) {
__self.irc.emit('message', {message:'+ ' + __self.votes_board[i].name + ' with ' + __self.votes_board[i].num + ' supporters totaling ' + __self.votes_board[i].total + ' votes'});
}
} else {
__self.irc.emit('message', {message:__self.pre_text + 'No current vote.'});
}
}
if (__self.votes_response_reset) {
__self.votes_response = setTimeout(function () {do_work();}, __self.votes_response_timer);
} else {
setTimeout(function () {do_work();}, __self.votes_response_timer);
}
break;
case 'winner':
if (!__self.votes_status) {
if (__self.votes_payout) {
for (var i = 0; i < __self.votes_board.length; i++) {
if (data == __self.votes_board[i].name) {
__self.votes_award_winner(__self.votes_board[i]);
__self.irc.emit('message', {message:__self.pre_text + 'Winner:' + data + 'had the most votes!'});
}
}
} else {
__self.irc.emit('message', {message:__self.pre_text + 'A winner has already been decided.'});
}
} else {
__self.irc.emit('message', {message:__self.pre_text + 'Voting must be closed before you can have a winner'});
}
break;
case 'cancel':
if (!__self.votes_status) {
// Return all the currency back to original owners
if (__self.votes_payout) {
sql = '';
for (var i = 0; i < __self.votes_viewers.length; i++) {
if (__self.votes_viewers[i].amount > 0) {
if (sql.length > 0) {
sql += '; ';
}
sql += 'UPDATE viewers ';
sql += 'SET points = points + ' + __self.votes_viewers[i].amount + ' ';
sql += 'WHERE user = \'' + __self.votes_viewers[i].viewer + '\'';
}
}
__self.db.execute(sql, function() {
__self.irc.emit('message', {message:__self.pre_text + 'Vote was canceled, all ' + __self.config.currency.toLowerCase() + ' returned.'});
});
__self.votes_payout = false;
} else {
__self.irc.emit('message', {message:__self.pre_text + 'No vote to cancel.'});
}
} else {
__self.votes_status = false;
__self.votes_payout = false;
__self.irc.emit('message', {message:__self.pre_text + 'Current vote was canceled.'});
}
break;
}
};
Currency.prototype.collect_votes = function (caller, vote, amount) {
var __self = this, has_vote = false;
function do_work() {
var multi_response = [];
for (var i = 0; i < __self.votes_board.length; i++) {
multi_response.push([]);
}
if (__self.votes_flood.length > 0) {// send flood requests
var vote;
// setup vote response
for (var i = 0; i < __self.votes_flood.length; i++) {
vote = __self.votes_viewers[__self.votes_flood[i]];
multi_response[vote.vote].push(vote.viewer + ' (' + vote.amount + ')');
}
for (var i = 0; i < __self.votes_board.length; i++) {
if (multi_response[i].length > 0) {
__self.irc.emit('message', {message:'New votes for ' + __self.votes_board[i].name + ': ' + multi_response[i].join(', '), timer: 1});
}
}
}
// clear flood requests
__self.votes_flood = [];
}
// Bound amount by positive currency
__self.query_coins(caller, function (rows) {
for (var i = 0; i < rows.length; i++) {
amount = Math.min(amount, rows[i].points);
}
if (__self.votes_viewers.length > 0) {
for (var i = 0; i < __self.votes_viewers.length; i++) {
if (__self.votes_viewers[i].viewer === caller) {
has_vote = true;
if (amount > __self.votes_viewers[i].amount) {
__self.votes_board[__self.votes_viewers[i].vote].num -= 1;
__self.votes_board[__self.votes_viewers[i].vote].total -= __self.votes_viewers[i].amount;
__self.votes_viewers[i].vote = vote.idx;
__self.votes_viewers[i].amount = amount;
__self.votes_board[vote.idx].num += 1;
__self.votes_board[vote.idx].total += amount;
// add flood users to array
if (__self.votes_flood.indexOf(i) < 0) {
__self.votes_flood.push(i);
}
}
break;
}
}
if (!has_vote && amount >= 1 && amount !== 0) {
__self.votes_viewers.push({viewer: caller, vote: vote.idx, amount: amount});
__self.votes_board[vote.idx].num += 1;
__self.votes_board[vote.idx].total += amount;
__self.votes_flood.push(__self.votes_viewers.length - 1);
}
} else {
if (amount >= 1 && amount !== 0) {
__self.votes_viewers.push({viewer: caller, vote: vote.idx, amount: amount});
__self.votes_board[vote.idx].num += 1;
__self.votes_board[vote.idx].total += amount;
__self.votes_flood.push(__self.votes_viewers.length - 1);
}
}
// check if flood has a set amount of requests and output
// if not, set the output timer
if (__self.votes_flood.length === __self.max_requests) {
do_work();
} else {
if (__self.votes_response_reset) {
__self.votes_response = setTimeout(function () {do_work();}, __self.votes_response_timer);
} else {
setTimeout(function () {do_work();}, __self.votes_response_timer);
}
}
});
};
Currency.prototype.votes_deduct_votes = function () {
var __self = this;
if (__self.votes_viewers.length > 0) {
// Don't trust the on-the-fly numbers
for (var i = 0; i < __self.votes_board.length; i++) {
__self.votes_board[i].num = 0;
__self.votes_board[i].total = 0;
}
__self.votes_total = 0;
// Remove the points and add them to an escrow
sql = '';
for (var i = 0; i < __self.votes_viewers.length; i++) {
if (__self.votes_viewers[i].amount > 0) {
if (sql.length > 0) {
sql += '; ';
}
sql += 'UPDATE viewers ';
sql += 'SET points = points - ' + __self.votes_viewers[i].amount + ' ';
sql += 'WHERE user = \'' + __self.votes_viewers[i].viewer + '\'';
__self.votes_board[__self.votes_viewers[i].vote].num += 1;
__self.votes_board[__self.votes_viewers[i].vote].total += __self.votes_viewers[i].amount;
__self.votes_total += __self.votes_viewers[i].amount;
}
}
__self.db.execute(sql, function() {});
}
};
Currency.prototype.votes_award_winner = function (winner) {
var __self = this;
if (__self.votes_payout) {
// set payout to complete
__self.votes_payout = false;
}
// Clear the board
__self.votes_board = [];
__self.votes_viewers = [];
__self.votes_total = 0;
};
/**
* ============================================
* BETTING SYSTEM
@ -1516,8 +1949,17 @@ Currency.prototype.bets = function(status, data) {
if (__self.bets_viewers.length > 0) {
__self.irc.emit('message', {message:__self.pre_text + 'Betting is now closed'});
for (var i = 0; i < __self.bets_board.length; i++) {
__self.irc.emit('message', {message:'+ ' + __self.bets_board[i].name + ' with ' + __self.bets_board[i].num + ' bets totaling ' + __self.bets_board[i].total});
if(parseInt(__self.bets_board[i].total,10) > parseInt(__self.score_bet_pool, 10)) {
__self.score_bet_pool = __self.bets_board[i].total;
sql = 'INSERT INTO highscores (`value`, `name`) VALUES (\'' + __self.bets_board[i].total + '\', \'bet_pool\') ON DUPLICATE KEY UPDATE value=values(value);';
__self.db.execute(sql, function() {});
__self.irc.emit('message', {message:'+ ' + __self.bets_board[i].name + ' with ' + __self.bets_board[i].num + ' bets totaling ' + __self.bets_board[i].total + '. New record set!!'});
} else {
__self.irc.emit('message', {message:'+ ' + __self.bets_board[i].name + ' with ' + __self.bets_board[i].num + ' bets totaling ' + __self.bets_board[i].total});
}
}
//
} else {
__self.irc.emit('message', {message:__self.pre_text + 'Betting closed, no bets were placed'});
}
@ -1546,15 +1988,7 @@ Currency.prototype.bets = function(status, data) {
for (var i = 0; i < __self.bets_board.length; i++) {
if (data == __self.bets_board[i].name) {
__self.bets_award_winner(__self.bets_board[i]);
if(__self.bets_board[i].total > __self.score_bet_pool) {
sql = 'UPDATE highscores SET value = ' + __self.bets_board[i].total + ' WHERE name = \'bet_pool\'';
__self.db.execute(sql, function() {
__self.score_bet_pool = __self.bets_board[i].total;
__self.irc.emit('message', {message:__self.pre_text + 'Betting payed out to ' + data + '. New record set!!'});
});
} else {
__self.irc.emit('message', {message:__self.pre_text + 'Betting payed out to ' + data});
}
__self.irc.emit('message', {message:__self.pre_text + 'Betting payed out to ' + data});
}
}
} else {
@ -1611,12 +2045,22 @@ Currency.prototype.collect_bets = function (caller, bet, amount) {
for (var i = 0; i < __self.bets_flood.length; i++) {
bet = __self.bets_viewers[__self.bets_flood[i]];
multi_response[bet.bet].push(bet.viewer + ' (' + bet.amount + ')');
// check for hiscore and set db appropriately
if ( parseInt(bet.amount, 10) > parseInt(__self.score_bet_single, 10) ) {
sql = 'INSERT INTO highscores (`value`, `user`, `name`) VALUES (\'' + amount + '\', \'' + caller + '\', \'bet_single\') ON DUPLICATE KEY UPDATE user=values(user), value=values(value);';
__self.db.execute(sql, function() {
__self.score_bet_single = amount;
__self.irc.emit('message', {message:__self.pre_text + ' ' + caller + ' set new record bet at ' + amount + '!'});
});
}
}
for (var i = 0; i < __self.bets_board.length; i++) {
if (multi_response[i].length > 0) {
__self.irc.emit('message', {message:'New bets for ' + __self.bets_board[i].name + ': ' + multi_response[i].join(', '), timer: 1});
}
}
}
// clear flood requests
@ -1629,15 +2073,6 @@ Currency.prototype.collect_bets = function (caller, bet, amount) {
amount = Math.min(amount, rows[i].points);
}
// check for hiscore and set db appropriately
if(amount > __self.score_bet_single) {
sql = 'UPDATE highscores SET value = ' + amount + ' WHERE name = \'bet_single\'';
__self.db.execute(sql, function() {
__self.score_bet_single = amount;
__self.irc.emit('message', {message:__self.pre_text + ' ' + caller + ' set new record bet at ' + amount + '!'});
});
}
if (__self.bets_viewers.length > 0) {
for (var i = 0; i < __self.bets_viewers.length; i++) {
if (__self.bets_viewers[i].viewer === caller) {
@ -1671,7 +2106,6 @@ Currency.prototype.collect_bets = function (caller, bet, amount) {
__self.bets_flood.push(__self.bets_viewers.length - 1);
}
}
console.log(__self.bets_viewers);
// check if flood has a set amount of requests and output
// if not, set the output timer
@ -1744,6 +2178,48 @@ Currency.prototype.bets_award_winner = function (winner) {
__self.bets_total = 0;
};
module.exports = function (irc, db, options) {
return new Currency(irc, db, options);
// NEW STUFF
Currency.prototype.add_quotation = function (data) {
var __self = this;
broadcaster_bot_initiated = __self.irc.caller(data[0]).toLowerCase() === __self.irc.config.broadcaster.toLowerCase() || __self.irc.caller(data[0]).toLowerCase() === __self.irc.config.name.toLowerCase(),
moderator_initiated = __self.irc.mods.indexOf(__self.irc.caller(data[0])) >= 0;
if (broadcaster_bot_initiated || moderator_initiated) {
// Chop all the shit out
data.splice(0, 4);
data = data.join(' ')
sql = 'INSERT INTO quotes (`text`) VALUES (' + __self.db.string_escape(data) + ');';
__self.db.execute(sql, function(rows, fields) {
__self.irc.emit('message', {message:__self.pre_text + ' New quote added!' + ' ['+rows.insertId+']'});
});
}
};
Currency.prototype.remove_quotation = function(data) {
var __self = this;
broadcaster_bot_initiated = __self.irc.caller(data[0]).toLowerCase() === __self.irc.config.broadcaster.toLowerCase() || __self.irc.caller(data[0]).toLowerCase() === __self.irc.config.name.toLowerCase(),
moderator_initiated = __self.irc.mods.indexOf(__self.irc.caller(data[0])) >= 0;
if (broadcaster_bot_initiated || moderator_initiated) {
// Chop all the shit out
data.splice(0, 4);
if (data == parseInt(data, 10)) {
__self.db.execute('DELETE FROM quotes WHERE id=\''+parseInt(data, 10)+'\';', function(rows) {
__self.irc.emit('message', {message:__self.pre_text + 'Quote #'+data+' deleted!'});
});
}
}
};
Currency.prototype.get_quotation = function() {
var __self = this;
__self.db.execute('SELECT * FROM quotes ORDER BY RAND() LIMIT 1;', function(rows) {
__self.irc.emit('message', {message:__self.pre_text + rows[0].id + ': ' + rows[0].text});
});
};
module.exports = function (irc, db, commands, options) {
return new Currency(irc, db, commands, options);
};

24
lib/initialize.js

@ -18,7 +18,8 @@ exports.initialize = function(options) {
irc = require('./irc.js')({
name : config.twitch.bot.name,
pass : config.twitch.bot.password,
channel : '#' + config.twitch.channel
channel : '#' + config.twitch.channel,
chatlog : config.web.chatlog
});
db = require('./mysql.js')({
host : config.currency.host,
@ -28,22 +29,27 @@ exports.initialize = function(options) {
});
commands = require('./commands.js')(irc, db, {
bot_name : config.twitch.bot.name,
exchange : config.exchanges,
currency : config.currency.name
});
currency = require('./currency.js')(irc, db, {
currency = require('./currency.js')(irc, db, commands, {
currency : config.currency.name,
payrate : config.currency.payrate,
subscribers : config.twitch.subscribers,
website : config.currency.website,
modpowers : config.currency.modpowers,
ignorelist : config.ignorelist
ignorelist : config.ignorelist,
exchanges : config.exchanges,
sub_ty_msg : config.currency.sub_ty_msg
});
web = require('./web.js')(db, {
port : config.web.port,
title : config.twitch.channel,
slogan : config.web.slogan,
logo : config.web.logo,
twitter : config.web.twitter
web = require('./web.js')(db, currency, {
port : config.web.port,
title : config.twitch.channel,
currency : config.currency.name,
logo : config.web.logo,
twitter : config.web.twitter,
fanart : config.web.fanart,
statdir : config.twitch.channel
});
//-------- Start -------

25
lib/irc.js

@ -77,7 +77,7 @@ function IRC(options) {
addr : 'irc.twitch.tv', //__self.options.name.toLowerCase() + '.jtvirc.com',
port : 6667,
channel : __self.options.channel.toLowerCase(),
encoding : 'ascii'
encoding : 'utf-8'
};
__self.mods = [];
@ -93,6 +93,11 @@ function IRC(options) {
__self.streaming = false;
__self.new_file = false;
__self.log = '';
// chat logging
__self.first_check = true;
__self.store_chat = __self.options.chatlog || false;
__self.chat_log = '';
}
IRC.prototype = new events.EventEmitter();
@ -104,7 +109,9 @@ IRC.prototype.start = function () {
// check stream status
function stream_status() {
var time = utils.make_interval(__self.check_streaming);
if (time === 0) {
if (time === 0 || __self.first_check) {
// Important to log chat right away, so lets skip the first 4 minute wait
if (__self.first_check) __self.first_check = false;
https.get('https://api.twitch.tv/kraken/streams/' + __self.config.channel.slice(1), function (response) {
var body = '';
@ -140,6 +147,12 @@ IRC.prototype.start = function () {
// create new log file
__self.log = './../logs/' + __self.config.channel.slice(1) + '_' + streaming_time.toString() + '.txt';
file.open(__self.log, 'w');
// create chat log
if (__self.store_chat) {
__self.chat_log = './../logs/chat/' + __self.config.channel.slice(1) + '_' + streaming_time.toString() + '.txt';
file.open(__self.chat_log, 'w');
}
} else if (!__self.streaming) {
__self.new_file = false;
__self.log = '';
@ -191,6 +204,8 @@ IRC.prototype.connect = function () {
__self.raw('PASS ' + __self.config.pass, true);
__self.raw('NICK ' + __self.config.name);
__self.raw('USER ' + __self.config.nick + ' ' + __self.config.nick + '.com ' + __self.config.nick + ' :' + __self.config.name);
__self.raw('TWITCHCLIENT 1');
__self.raw('CAP REQ :twitch.tv/membership');
});
// handle incoming socket data
@ -260,7 +275,7 @@ IRC.prototype.moderators = function (data) {
if (data[1] === 'MODE') {
if (data[4] !== undefined) {
var user = data[4].charAt(0).toUpperCase() + data[4].slice(1);
var user = data[4].toLowerCase();
switch (data[3]) {
case '+o':
if (__self.mods.indexOf(user) < 0) {
@ -302,7 +317,7 @@ IRC.prototype.raw = function (data, hide) {
IRC.prototype.caller = function (data) {
var caller = data.split('!');
return caller[0].charAt(1).toUpperCase() + caller[0].slice(2);
return caller[0].slice(1).toLowerCase();
};
// send message to twitch chat
@ -314,7 +329,7 @@ IRC.prototype.msg = function (msg, options) {
__self.raw('PRIVMSG ' + __self.config.channel + ' :' + msg);
break;
case 1:
if (__self.mods.indexOf(opts.caller) >= 0) {
if (__self.mods.indexOf(opts.caller.toLowerCase()) >= 0) {
__self.raw('PRIVMSG ' + __self.config.channel + ' :' + msg);
}
break;

20
lib/mysql.js

@ -24,11 +24,14 @@ function DB(options) {
__self.user = options.user || '';
__self.password = options.password || '';
__self.database = options.database || '';
// Open escape method to other modules
__self.string_escape = mysql.escape;
}
//-------- Methods ---------
DB.prototype.start = function() {
var __self = this, commands ='', viewers = '', scores = '';
var __self = this, commands ='', viewers = '', scores = '', quotes = '';
// table structure for table commands
commands += 'CREATE TABLE IF NOT EXISTS `commands` (';
@ -49,14 +52,21 @@ DB.prototype.start = function() {
// table structure for table highscores
scores += 'CREATE TABLE IF NOT EXISTS `highscores` (';
scores += '`name` varchar(64) COLLATE utf8_unicode_ci NOT NULL,';
scores += '`user` varchar(64) COLLATE utf8_unicode_ci,';
scores += '`value` int(11) NOT NULL,';
scores += '`date` timestamp ON UPDATE current_timestamp,';
scores += 'PRIMARY KEY (`name`)';
scores += ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;';
scores += 'INSERT INTO `highscores` (`name`, `value`) VALUES(\'bet_single\', 0);';
scores += 'INSERT INTO `highscores` (`name`, `value`) VALUES(\'bet_pool\', 0);';
scores += ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci';
// table structure for QUOTES
quotes += 'CREATE TABLE IF NOT EXISTS `quotes` (';
quotes += '`id` int(11) NOT NULL AUTO_INCREMENT,';
quotes += '`text` longtext COLLATE utf8_unicode_ci NOT NULL,';
quotes += 'PRIMARY KEY (`id`)';
quotes += ') ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1;';
// execute sql, create tables if they don't exist
__self.execute(commands + '; ' + viewers + '; ' + scores, function(){});
__self.execute(commands + '; ' + viewers + '; ' + scores + '; ' + quotes, function(){});
};
DB.prototype.execute = function(sql, callback) {

115
lib/web.js

@ -1,17 +1,25 @@
var express = require('express'),
bodyParser = require('body-parser'),
utils = require('./utils.js'),
https = require('https');
//---- Construct ----
function WEB(db, options) {
function WEB(db, currency, options) {
var __self = this;
__self.db = db;
__self.currency = currency;
__self.port = options.port || 9000;
__self.title = options.title;
__self.slogan = options.slogan;
__self.currency_name = options.currency;
__self.logo = options.logo;
__self.twitter = options.twitter;
__self.fanart = options.fanart;
__self.statdir = options.statdir;
__self.check_data = 4;//minutes
__self.first_check = true;
__self.slogan = '';
}
// ---- Methods ----
@ -20,40 +28,95 @@ WEB.prototype.start = function () {
__self.srv = express();
__self.srv.set('view engine', 'jade');
__self.srv.set('views', 'web/templates');
__self.srv.use(bodyParser());
__self.srv.use(express.static('./web/public'));
__self.render_opts = {
title: __self.title,
slogan: __self.slogan,
logo: __self.logo,
twitter: __self.twitter,
fanart: __self.fanart,
currency: __self.currency_name,
};
// get twitch/twitter data
function update_data() {
var time = utils.make_interval(__self.check_data);
if (time === 0 || __self.first_check) {
if(__self.first_check) __self.first_check = false;
https.get('https://api.twitch.tv/kraken/channels/' + __self.title, function (response) {
var body = '';
// put together response
response.on('data', function (chunk) {
body += chunk;
});
// log file creation
response.on('end', function () {
var json = null;
try {
json = JSON.parse(body);
__self.slogan = json.status;
__self.render_opts.slogan = json.status;
} catch (err) {
console.log('Error grabbing Twitch data in Web.JS: '+err);
}
setTimeout(update_data, 1000);
});
});
} else {
setTimeout(update_data, time);
}
}
// ---- Helpers ----
__self.srv.locals.ucfirst = function(value){
return value.charAt(0).toUpperCase() + value.slice(1);
};
__self.srv.locals.slicelast = function(value){
return value.slice(0, -1);
};
// ---- Routes -----
__self.srv.get('/', function(req, res) {
//lets get the top 5
sql = 'SELECT * FROM viewers ORDER BY points DESC LIMIT 10;';
__self.db.execute(sql, function(rows) {
res.render('index', {
title: __self.title,
slogan: __self.slogan,
logo: __self.logo,
twitter: __self.twitter,
rows: rows,
});
var opts = __self.render_opts;
opts.rows = rows;
opts.bet_status = __self.currency.bets_status;
opts.bet_board = __self.currency.bets_board;
opts.bet_viewers = __self.currency.bets_viewers;
res.render('index', opts);
});
});
__self.srv.get('/ladder', function(req, res) {
//get the whole viewer list
sql = 'SELECT * FROM viewers ORDER BY points DESC;';
__self.db.execute(sql, function(rows) {
res.render('ladder', {
title: __self.title,
slogan: __self.slogan,
logo: __self.logo,
twitter: __self.twitter,
rows: rows,
});
var opts = __self.render_opts;
opts.rows = rows;
res.render('ladder', opts);
});
});
__self.srv.get('/stats', function(req, res) {
var opts = __self.render_opts;
opts.statdir = __self.statdir;
res.render('stats', opts);
});
__self.srv.get('/fanart', function(req, res) {
res.render('fanart', __self.render_opts);
});
/* Raw data for android app */
__self.srv.get('/api/test', function(req, res) {
res.send("Hey, its Potatr. This data was pulled from the web.");
});
__self.srv.all('/api/data', function(req, res) {
__self.srv.get('/api/viewer_dump', function(req, res) {
sql = 'SELECT * FROM viewers ORDER BY points DESC;';
__self.db.execute(sql, function(rows) {
ladder_data = new Object();
@ -63,12 +126,26 @@ WEB.prototype.start = function () {
res.send(ladder_data);
});
});
__self.srv.post('/api/exchange', function(req, res) {
var name = req.body.name.toLowerCase(),
amount = parseInt(req.body.amount, 10);
if (req.ip == '127.0.0.1') {
if ( __self.currency.viewer_list.indexOf(name) > -1 ) {
__self.currency.adjust_currency('add', amount, name);
res.send('1');
} else {
res.send('0');
}
}
});
__self.srv.listen(__self.port);
update_data();
console.log('Started website at '+__self.port);
};
module.exports = function (db, options) {
return new WEB(db, options);
module.exports = function (db, currency, options) {
return new WEB(db, currency, options);
};

1
node_modules/body-parser/.npmignore

@ -0,0 +1 @@
test/

3
node_modules/body-parser/.travis.yml

@ -0,0 +1,3 @@
node_js:
- "0.10"
language: node_js

10
node_modules/body-parser/HISTORY.md

@ -0,0 +1,10 @@
1.0.1 / 2014-04-14
==================
* use `type-is` module
1.0.1 / 2014-03-20
==================
* lower default limits to 100kb

9
node_modules/body-parser/Makefile

@ -0,0 +1,9 @@
BIN = ./node_modules/.bin/
test:
@$(BIN)mocha \
--require should \
--reporter spec \
--bail
.PHONY: test

60
node_modules/body-parser/README.md

@ -0,0 +1,60 @@
# Body Parser [![Build Status](https://travis-ci.org/expressjs/body-parser.png)](https://travis-ci.org/expressjs/body-parser)
Connect's body parsing middleware.
## API
```js
var bodyParser = require('body-parser');
var app = connect();
app.use(bodyParser());
app.use(function (req, res, next) {
console.log(req.body) // populated!
next();
})
```
### bodyParser([options])
Returns middleware that parses both `json` and `urlencoded`. The `options` are passed to both middleware.
### bodyParser.json([options])
Returns middleware that only parses `json`. The options are:
- `strict` <true> - only parse objects and arrays
- `limit` <1mb> - maximum request body size
- `reviver` - passed to `JSON.parse()`
### bodyParser.urlencoded([options])
Returns middleware that only parses `urlencoded` with the [qs](https://github.com/visionmedia/node-querystring) module. The options are:
- `limit` <1mb> - maximum request body size
## License
The MIT License (MIT)
Copyright (c) 2014 Jonathan Ong me@jongleberry.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

100
node_modules/body-parser/index.js

@ -0,0 +1,100 @@
var getBody = require('raw-body');
var typeis = require('type-is');
var http = require('http');
var qs = require('qs');
exports = module.exports = bodyParser;
exports.json = json;
exports.urlencoded = urlencoded;
function bodyParser(options){
var _urlencoded = urlencoded(options);
var _json = json(options);
return function bodyParser(req, res, next) {
_json(req, res, function(err){
if (err) return next(err);
_urlencoded(req, res, next);
});
}
}
function json(options){
options = options || {};
var strict = options.strict !== false;
return function jsonParser(req, res, next) {
if (req._body) return next();
req.body = req.body || {};
if (!typeis(req, 'json')) return next();
// flag as parsed
req._body = true;
// parse
getBody(req, {
limit: options.limit || '100kb',
length: req.headers['content-length'],
encoding: 'utf8'
}, function (err, buf) {
if (err) return next(err);
var first = buf.trim()[0];
if (0 == buf.length) {
return next(error(400, 'invalid json, empty body'));
}
if (strict && '{' != first && '[' != first) return next(error(400, 'invalid json'));
try {
req.body = JSON.parse(buf, options.reviver);
} catch (err){
err.body = buf;
err.status = 400;
return next(err);
}
next();
})
};
}
function urlencoded(options){
options = options || {};
return function urlencodedParser(req, res, next) {
if (req._body) return next();
req.body = req.body || {};
if (!typeis(req, 'urlencoded')) return next();
// flag as parsed
req._body = true;
// parse
getBody(req, {
limit: options.limit || '100kb',
length: req.headers['content-length'],
encoding: 'utf8'
}, function (err, buf) {
if (err) return next(err);
try {
req.body = buf.length
? qs.parse(buf)
: {};
} catch (err){
err.body = buf;
return next(err);
}
next();
})
}
}
function error(code, msg) {
var err = new Error(msg || http.STATUS_CODES[code]);
err.status = code;
return err;
}

6
node_modules/body-parser/node_modules/qs/.gitmodules

@ -0,0 +1,6 @@
[submodule "support/expresso"]
path = support/expresso
url = git://github.com/visionmedia/expresso.git
[submodule "support/should"]
path = support/should
url = git://github.com/visionmedia/should.js.git

7
node_modules/body-parser/node_modules/qs/.npmignore

@ -0,0 +1,7 @@
test
.travis.yml
benchmark.js
component.json
examples.js
History.md
Makefile

58
node_modules/body-parser/node_modules/qs/Readme.md

@ -0,0 +1,58 @@
# node-querystring
query string parser for node and the browser supporting nesting, as it was removed from `0.3.x`, so this library provides the previous and commonly desired behaviour (and twice as fast). Used by [express](http://expressjs.com), [connect](http://senchalabs.github.com/connect) and others.
## Installation
$ npm install qs
## Examples
```js
var qs = require('qs');
qs.parse('user[name][first]=Tobi&user[email]=tobi@learnboost.com');
// => { user: { name: { first: 'Tobi' }, email: 'tobi@learnboost.com' } }
qs.stringify({ user: { name: 'Tobi', email: 'tobi@learnboost.com' }})
// => user[name]=Tobi&user[email]=tobi%40learnboost.com
```
## Testing
Install dev dependencies:
$ npm install -d
and execute:
$ make test
browser:
$ open test/browser/index.html
## License
(The MIT License)
Copyright (c) 2010 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

366
node_modules/body-parser/node_modules/qs/index.js

@ -0,0 +1,366 @@
/**
* Object#toString() ref for stringify().
*/
var toString = Object.prototype.toString;
/**
* Object#hasOwnProperty ref
*/
var hasOwnProperty = Object.prototype.hasOwnProperty;
/**
* Array#indexOf shim.
*/
var indexOf = typeof Array.prototype.indexOf === 'function'
? function(arr, el) { return arr.indexOf(el); }
: function(arr, el) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === el) return i;
}
return -1;
};
/**
* Array.isArray shim.
*/
var isArray = Array.isArray || function(arr) {
return toString.call(arr) == '[object Array]';
};
/**
* Object.keys shim.
*/
var objectKeys = Object.keys || function(obj) {
var ret = [];
for (var key in obj) {
if (obj.hasOwnProperty(key)) {
ret.push(key);
}
}
return ret;
};
/**
* Array#forEach shim.
*/
var forEach = typeof Array.prototype.forEach === 'function'
? function(arr, fn) { return arr.forEach(fn); }
: function(arr, fn) {
for (var i = 0; i < arr.length; i++) fn(arr[i]);
};
/**
* Array#reduce shim.
*/
var reduce = function(arr, fn, initial) {
if (typeof arr.reduce === 'function') return arr.reduce(fn, initial);
var res = initial;
for (var i = 0; i < arr.length; i++) res = fn(res, arr[i]);
return res;
};
/**
* Cache non-integer test regexp.
*/
var isint = /^[0-9]+$/;
function promote(parent, key) {
if (parent[key].length == 0) return parent[key] = {}
var t = {};
for (var i in parent[key]) {
if (hasOwnProperty.call(parent[key], i)) {
t[i] = parent[key][i];
}
}
parent[key] = t;
return t;
}
function parse(parts, parent, key, val) {
var part = parts.shift();
// illegal
if (Object.getOwnPropertyDescriptor(Object.prototype, key)) return;
// end
if (!part) {
if (isArray(parent[key])) {
parent[key].push(val);
} else if ('object' == typeof parent[key]) {
parent[key] = val;
} else if ('undefined' == typeof parent[key]) {
parent[key] = val;
} else {
parent[key] = [parent[key], val];
}
// array
} else {
var obj = parent[key] = parent[key] || [];
if (']' == part) {
if (isArray(obj)) {
if ('' != val) obj.push(val);
} else if ('object' == typeof obj) {
obj[objectKeys(obj).length] = val;
} else {
obj = parent[key] = [parent[key], val];
}
// prop
} else if (~indexOf(part, ']')) {
part = part.substr(0, part.length - 1);
if (!isint.test(part) && isArray(obj)) obj = promote(parent, key);
parse(parts, obj, part, val);
// key
} else {
if (!isint.test(part) && isArray(obj)) obj = promote(parent, key);
parse(parts, obj, part, val);
}
}
}
/**
* Merge parent key/val pair.
*/
function merge(parent, key, val){
if (~indexOf(key, ']')) {
var parts = key.split('[')
, len = parts.length
, last = len - 1;
parse(parts, parent, 'base', val);
// optimize
} else {
if (!isint.test(key) && isArray(parent.base)) {
var t = {};
for (var k in parent.base) t[k] = parent.base[k];
parent.base = t;
}
set(parent.base, key, val);
}
return parent;
}
/**
* Compact sparse arrays.
*/
function compact(obj) {
if ('object' != typeof obj) return obj;
if (isArray(obj)) {
var ret = [];
for (var i in obj) {
if (hasOwnProperty.call(obj, i)) {
ret.push(obj[i]);
}
}
return ret;
}
for (var key in obj) {
obj[key] = compact(obj[key]);
}
return obj;
}
/**
* Parse the given obj.
*/
function parseObject(obj){
var ret = { base: {} };
forEach(objectKeys(obj), function(name){
merge(ret, name, obj[name]);
});
return compact(ret.base);
}
/**
* Parse the given str.
*/
function parseString(str){
var ret = reduce(String(str).split('&'), function(ret, pair){
var eql = indexOf(pair, '=')
, brace = lastBraceInKey(pair)
, key = pair.substr(0, brace || eql)
, val = pair.substr(brace || eql, pair.length)
, val = val.substr(indexOf(val, '=') + 1, val.length);
// ?foo
if ('' == key) key = pair, val = '';
if ('' == key) return ret;
return merge(ret, decode(key), decode(val));
}, { base: {} }).base;
return compact(ret);
}
/**
* Parse the given query `str` or `obj`, returning an object.
*
* @param {String} str | {Object} obj
* @return {Object}
* @api public
*/
exports.parse = function(str){
if (null == str || '' == str) return {};
return 'object' == typeof str
? parseObject(str)
: parseString(str);
};
/**
* Turn the given `obj` into a query string
*
* @param {Object} obj
* @return {String}
* @api public
*/
var stringify = exports.stringify = function(obj, prefix) {
if (isArray(obj)) {
return stringifyArray(obj, prefix);
} else if ('[object Object]' == toString.call(obj)) {
return stringifyObject(obj, prefix);
} else if ('string' == typeof obj) {
return stringifyString(obj, prefix);
} else {
return prefix + '=' + encodeURIComponent(String(obj));
}
};
/**
* Stringify the given `str`.
*
* @param {String} str
* @param {String} prefix
* @return {String}
* @api private
*/
function stringifyString(str, prefix) {
if (!prefix) throw new TypeError('stringify expects an object');
return prefix + '=' + encodeURIComponent(str);
}
/**
* Stringify the given `arr`.
*
* @param {Array} arr
* @param {String} prefix
* @return {String}
* @api private
*/
function stringifyArray(arr, prefix) {
var ret = [];
if (!prefix) throw new TypeError('stringify expects an object');
for (var i = 0; i < arr.length; i++) {
ret.push(stringify(arr[i], prefix + '[' + i + ']'));
}
return ret.join('&');
}
/**
* Stringify the given `obj`.
*
* @param {Object} obj
* @param {String} prefix
* @return {String}
* @api private
*/
function stringifyObject(obj, prefix) {
var ret = []
, keys = objectKeys(obj)
, key;
for (var i = 0, len = keys.length; i < len; ++i) {
key = keys[i];
if ('' == key) continue;
if (null == obj[key]) {
ret.push(encodeURIComponent(key) + '=');
} else {
ret.push(stringify(obj[key], prefix
? prefix + '[' + encodeURIComponent(key) + ']'
: encodeURIComponent(key)));
}
}
return ret.join('&');
}
/**
* Set `obj`'s `key` to `val` respecting
* the weird and wonderful syntax of a qs,
* where "foo=bar&foo=baz" becomes an array.
*
* @param {Object} obj
* @param {String} key
* @param {String} val
* @api private
*/
function set(obj, key, val) {
var v = obj[key];
if (Object.getOwnPropertyDescriptor(Object.prototype, key)) return;
if (undefined === v) {
obj[key] = val;
} else if (isArray(v)) {
v.push(val);
} else {
obj[key] = [v, val];
}
}
/**
* Locate last brace in `str` within the key.
*
* @param {String} str
* @return {Number}
* @api private
*/
function lastBraceInKey(str) {
var len = str.length
, brace
, c;
for (var i = 0; i < len; ++i) {
c = str[i];
if (']' == c) brace = false;
if ('[' == c) brace = true;
if ('=' == c && !brace) return i;
}
}
/**
* Decode `str`.
*
* @param {String} str
* @return {String}
* @api private
*/
function decode(str) {
try {
return decodeURIComponent(str.replace(/\+/g, ' '));
} catch (err) {
return str;
}
}

38
node_modules/body-parser/node_modules/qs/package.json

@ -0,0 +1,38 @@
{
"name": "qs",
"description": "querystring parser",
"version": "0.6.6",
"keywords": [
"query string",
"parser",
"component"
],
"repository": {
"type": "git",
"url": "git://github.com/visionmedia/node-querystring.git"
},
"devDependencies": {
"mocha": "*",
"expect.js": "*"
},
"scripts": {
"test": "make test"
},
"author": {
"name": "TJ Holowaychuk",
"email": "tj@vision-media.ca",
"url": "http://tjholowaychuk.com"
},
"main": "index",
"engines": {
"node": "*"
},
"readme": "# node-querystring\n\n query string parser for node and the browser supporting nesting, as it was removed from `0.3.x`, so this library provides the previous and commonly desired behaviour (and twice as fast). Used by [express](http://expressjs.com), [connect](http://senchalabs.github.com/connect) and others.\n\n## Installation\n\n $ npm install qs\n\n## Examples\n\n```js\nvar qs = require('qs');\n\nqs.parse('user[name][first]=Tobi&user[email]=tobi@learnboost.com');\n// => { user: { name: { first: 'Tobi' }, email: 'tobi@learnboost.com' } }\n\nqs.stringify({ user: { name: 'Tobi', email: 'tobi@learnboost.com' }})\n// => user[name]=Tobi&user[email]=tobi%40learnboost.com\n```\n\n## Testing\n\nInstall dev dependencies:\n\n $ npm install -d\n\nand execute:\n\n $ make test\n\nbrowser:\n\n $ open test/browser/index.html\n\n## License \n\n(The MIT License)\n\nCopyright (c) 2010 TJ Holowaychuk &lt;tj@vision-media.ca&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.",
"readmeFilename": "Readme.md",
"bugs": {
"url": "https://github.com/visionmedia/node-querystring/issues"
},
"homepage": "https://github.com/visionmedia/node-querystring",
"_id": "qs@0.6.6",
"_from": "qs@~0.6.6"
}

1
node_modules/body-parser/node_modules/raw-body/.npmignore

@ -0,0 +1 @@
test/

5
node_modules/body-parser/node_modules/raw-body/.travis.yml

@ -0,0 +1,5 @@
node_js:
- "0.8"
- "0.10"
- "0.11"
language: node_js

14
node_modules/body-parser/node_modules/raw-body/Makefile

@ -0,0 +1,14 @@
NODE ?= node
BIN = ./node_modules/.bin/
test:
@${NODE} ${BIN}mocha \
--harmony-generators \
--reporter spec \
--bail \
./test/index.js
clean:
@rm -rf node_modules
.PHONY: test clean

96
node_modules/body-parser/node_modules/raw-body/README.md

@ -0,0 +1,96 @@
# Raw Body [![Build Status](https://travis-ci.org/stream-utils/raw-body.svg?branch=master)](https://travis-ci.org/stream-utils/raw-body)
Gets the entire buffer of a stream either as a `Buffer` or a string.
Validates the stream's length against an expected length and maximum limit.
Ideal for parsing request bodies.
## API
```js
var getRawBody = require('raw-body')
app.use(function (req, res, next) {
getRawBody(req, {
length: req.headers['content-length'],
limit: '1mb',
encoding: 'utf8'
}, function (err, string) {
if (err)
return next(err)
req.text = string
next()
})
})
```
or in a Koa generator:
```js
app.use(function* (next) {
var string = yield getRawBody(this.req, {
length: this.length,
limit: '1mb',
encoding: 'utf8'
})
})
```
### getRawBody(stream, [options], [callback])
Returns a thunk for yielding with generators.
Options:
- `length` - The length length of the stream.
If the contents of the stream do not add up to this length,
an `400` error code is returned.
- `limit` - The byte limit of the body.
If the body ends up being larger than this limit,
a `413` error code is returned.
- `encoding` - The requested encoding.
By default, a `Buffer` instance will be returned.
Most likely, you want `utf8`.
You can use any type of encoding supported by [StringDecoder](http://nodejs.org/api/string_decoder.html).
You can also pass `true` which sets it to the default `utf8`
`callback(err, res)`:
- `err` - the following attributes will be defined if applicable:
- `limit` - the limit in bytes
- `length` and `expected` - the expected length of the stream
- `received` - the received bytes
- `status` and `statusCode` - the corresponding status code for the error
- `type` - either `entity.too.large`, `request.size.invalid`, or `stream.encoding.set`
- `res` - the result, either as a `String` if an encoding was set or a `Buffer` otherwise.
If an error occurs, the stream will be paused,
and you are responsible for correctly disposing the stream.
For HTTP requests, no handling is required if you send a response.
For streams that use file descriptors, you should `stream.destroy()` or `stream.close()` to prevent leaks.
## License
The MIT License (MIT)
Copyright (c) 2013 Jonathan Ong me@jongleberry.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

164
node_modules/body-parser/node_modules/raw-body/index.js

@ -0,0 +1,164 @@
var StringDecoder = require('string_decoder').StringDecoder
var bytes = require('bytes')
module.exports = function (stream, options, done) {
if (typeof options === 'function') {
done = options
options = {}
} else if (!options) {
options = {}
} else if (options === true) {
options = {
encoding: 'utf8'
}
}
// convert the limit to an integer
var limit = null
if (typeof options.limit === 'number')
limit = options.limit
if (typeof options.limit === 'string')
limit = bytes(options.limit)
// convert the expected length to an integer
var length = null
if (options.length != null && !isNaN(options.length))
length = parseInt(options.length, 10)
// check the length and limit options.
// note: we intentionally leave the stream paused,
// so users should handle the stream themselves.
if (limit !== null && length !== null && length > limit) {
if (typeof stream.pause === 'function')
stream.pause()
process.nextTick(function () {
var err = makeError('request entity too large', 'entity.too.large')
err.status = err.statusCode = 413
err.length = err.expected = length
err.limit = limit
done(err)
})
return defer
}
var state = stream._readableState
// streams2+: assert the stream encoding is buffer.
if (state && state.encoding != null) {
if (typeof stream.pause === 'function')
stream.pause()
process.nextTick(function () {
var err = makeError('stream encoding should not be set',
'stream.encoding.set')
// developer error
err.status = err.statusCode = 500
done(err)
})
return defer
}
var received = 0
// note: we delegate any invalid encodings to the constructor
var decoder = options.encoding
? new StringDecoder(options.encoding === true ? 'utf8' : options.encoding)
: null
var buffer = decoder
? ''
: []
stream.on('data', onData)
stream.once('end', onEnd)
stream.once('error', onEnd)
stream.once('close', cleanup)
return defer
// yieldable support
function defer(fn) {
done = fn
}
function onData(chunk) {
received += chunk.length
decoder
? buffer += decoder.write(chunk)
: buffer.push(chunk)
if (limit !== null && received > limit) {
if (typeof stream.pause === 'function')
stream.pause()
var err = makeError('request entity too large', 'entity.too.large')
err.status = err.statusCode = 413
err.received = received
err.limit = limit
done(err)
cleanup()
}
}
function onEnd(err) {
if (err) {
if (typeof stream.pause === 'function')
stream.pause()
done(err)
} else if (length !== null && received !== length) {
err = makeError('request size did not match content length',
'request.size.invalid')
err.status = err.statusCode = 400
err.received = received
err.length = err.expected = length
done(err)
} else {
done(null, decoder
? buffer + endStringDecoder(decoder)
: Buffer.concat(buffer)
)
}
cleanup()
}
function cleanup() {
received = buffer = null
stream.removeListener('data', onData)
stream.removeListener('end', onEnd)
stream.removeListener('error', onEnd)
stream.removeListener('close', cleanup)
}
}
// to create serializable errors you must re-set message so
// that it is enumerable and you must re configure the type
// property so that is writable and enumerable
function makeError(message, type) {
var error = new Error()
error.message = message
Object.defineProperty(error, 'type', {
value: type,
enumerable: true,
writable: true,
configurable: true
})
return error
}
// https://github.com/Raynos/body/blob/2512ced39e31776e5a2f7492b907330badac3a40/index.js#L72
// bug fix for missing `StringDecoder.end` in v0.8.x
function endStringDecoder(decoder) {
if (decoder.end) {
return decoder.end()
}
var res = ""
if (decoder.charReceived) {
var cr = decoder.charReceived
var buf = decoder.charBuffer
var enc = decoder.encoding
res += buf.slice(0, cr).toString(enc)
}
return res
}

1
node_modules/body-parser/node_modules/raw-body/node_modules/bytes/.npmignore

@ -0,0 +1 @@
test

20
node_modules/body-parser/node_modules/raw-body/node_modules/bytes/History.md

@ -0,0 +1,20 @@
0.3.0 / 2014-03-19
==================
* added terabyte support
0.2.1 / 2013-04-01
==================
* add .component
0.2.0 / 2012-10-28
==================
* bytes(200).should.eql('200b')
0.1.0 / 2012-07-04
==================
* add bytes to string conversion [yields]

7
node_modules/body-parser/node_modules/raw-body/node_modules/bytes/Makefile

@ -0,0 +1,7 @@
test:
@./node_modules/.bin/mocha \
--reporter spec \
--require should
.PHONY: test

54
node_modules/body-parser/node_modules/raw-body/node_modules/bytes/Readme.md

@ -0,0 +1,54 @@
# node-bytes
Byte string parser / formatter.
## Example:
```js
bytes('1kb')
// => 1024
bytes('2mb')
// => 2097152
bytes('1gb')
// => 1073741824
bytes(1073741824)
// => 1gb
bytes(1099511627776)
// => 1tb
```
## Installation
```
$ npm install bytes
$ component install visionmedia/bytes.js
```
## License
(The MIT License)
Copyright (c) 2012 TJ Holowaychuk &lt;tj@vision-media.ca&gt;
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

7
node_modules/body-parser/node_modules/raw-body/node_modules/bytes/component.json

@ -0,0 +1,7 @@
{
"name": "bytes",
"description": "byte size string parser / serializer",
"keywords": ["bytes", "utility"],
"version": "0.2.1",
"scripts": ["index.js"]
}

41
node_modules/body-parser/node_modules/raw-body/node_modules/bytes/index.js

@ -0,0 +1,41 @@
/**
* Parse byte `size` string.
*
* @param {String} size
* @return {Number}
* @api public
*/
module.exports = function(size) {
if ('number' == typeof size) return convert(size);
var parts = size.match(/^(\d+(?:\.\d+)?) *(kb|mb|gb|tb)$/)
, n = parseFloat(parts[1])
, type = parts[2];
var map = {
kb: 1 << 10
, mb: 1 << 20
, gb: 1 << 30
, tb: ((1 << 30) * 1024)
};
return map[type] * n;
};
/**
* convert bytes into string.
*
* @param {Number} b - bytes to convert
* @return {String}
* @api public
*/
function convert (b) {
var tb = ((1 << 30) * 1024), gb = 1 << 30, mb = 1 << 20, kb = 1 << 10;
if (b >= tb) return (Math.round(b / tb * 100) / 100) + 'tb';
if (b >= gb) return (Math.round(b / gb * 100) / 100) + 'gb';
if (b >= mb) return (Math.round(b / mb * 100) / 100) + 'mb';
if (b >= kb) return (Math.round(b / kb * 100) / 100) + 'kb';
return b + 'b';
}

37
node_modules/body-parser/node_modules/raw-body/node_modules/bytes/package.json

@ -0,0 +1,37 @@
{
"name": "bytes",
"author": {
"name": "TJ Holowaychuk",
"email": "tj@vision-media.ca",
"url": "http://tjholowaychuk.com"
},
"description": "byte size string parser / serializer",
"repository": {
"type": "git",
"url": "https://github.com/visionmedia/bytes.js.git"
},
"version": "0.3.0",
"main": "index.js",
"dependencies": {},
"devDependencies": {
"mocha": "*",
"should": "*"
},
"component": {
"scripts": {
"bytes/index.js": "index.js"
}
},
"readme": "# node-bytes\n\n Byte string parser / formatter.\n\n## Example:\n\n```js\nbytes('1kb')\n// => 1024\n\nbytes('2mb')\n// => 2097152\n\nbytes('1gb')\n// => 1073741824\n\nbytes(1073741824)\n// => 1gb\n\nbytes(1099511627776)\n// => 1tb\n```\n\n## Installation\n\n```\n$ npm install bytes\n$ component install visionmedia/bytes.js\n```\n\n## License \n\n(The MIT License)\n\nCopyright (c) 2012 TJ Holowaychuk &lt;tj@vision-media.ca&gt;\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n",
"readmeFilename": "Readme.md",
"bugs": {
"url": "https://github.com/visionmedia/bytes.js/issues"
},
"homepage": "https://github.com/visionmedia/bytes.js",
"_id": "bytes@0.3.0",
"dist": {
"shasum": "741ac2cc6fdac3cd7ee104196aaad35b6d4c8ee5"
},
"_from": "bytes@~0.3.0",
"_resolved": "https://registry.npmjs.org/bytes/-/bytes-0.3.0.tgz"
}

45
node_modules/body-parser/node_modules/raw-body/package.json

@ -0,0 +1,45 @@
{
"name": "raw-body",
"description": "Get and validate the raw body of a readable stream.",
"version": "1.1.4",
"author": {
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/stream-utils/raw-body.git"
},
"bugs": {
"url": "https://github.com/stream-utils/raw-body/issues"
},
"dependencies": {
"bytes": "~0.3.0"
},
"devDependencies": {
"readable-stream": "~1.0.17",
"co": "3",
"gnode": "~0.0.4",
"mocha": "^1.14.0",
"through2": "~0.4.1",
"request": "^2.27.0",
"assert-tap": "~0.1.4"
},
"scripts": {
"test": "NODE=gnode make test && node ./test/acceptance.js"
},
"engines": {
"node": ">= 0.8.0"
},
"readme": "# Raw Body [![Build Status](https://travis-ci.org/stream-utils/raw-body.svg?branch=master)](https://travis-ci.org/stream-utils/raw-body)\n\nGets the entire buffer of a stream either as a `Buffer` or a string.\nValidates the stream's length against an expected length and maximum limit.\nIdeal for parsing request bodies.\n\n## API\n\n```js\nvar getRawBody = require('raw-body')\n\napp.use(function (req, res, next) {\n getRawBody(req, {\n length: req.headers['content-length'],\n limit: '1mb',\n encoding: 'utf8'\n }, function (err, string) {\n if (err)\n return next(err)\n\n req.text = string\n next()\n })\n})\n```\n\nor in a Koa generator:\n\n```js\napp.use(function* (next) {\n var string = yield getRawBody(this.req, {\n length: this.length,\n limit: '1mb',\n encoding: 'utf8'\n })\n})\n```\n\n### getRawBody(stream, [options], [callback])\n\nReturns a thunk for yielding with generators.\n\nOptions:\n\n- `length` - The length length of the stream.\n If the contents of the stream do not add up to this length,\n an `400` error code is returned.\n- `limit` - The byte limit of the body.\n If the body ends up being larger than this limit,\n a `413` error code is returned.\n- `encoding` - The requested encoding.\n By default, a `Buffer` instance will be returned.\n Most likely, you want `utf8`.\n You can use any type of encoding supported by [StringDecoder](http://nodejs.org/api/string_decoder.html).\n You can also pass `true` which sets it to the default `utf8`\n\n`callback(err, res)`:\n\n- `err` - the following attributes will be defined if applicable:\n\n - `limit` - the limit in bytes\n - `length` and `expected` - the expected length of the stream\n - `received` - the received bytes\n - `status` and `statusCode` - the corresponding status code for the error\n - `type` - either `entity.too.large`, `request.size.invalid`, or `stream.encoding.set`\n\n- `res` - the result, either as a `String` if an encoding was set or a `Buffer` otherwise.\n\nIf an error occurs, the stream will be paused,\nand you are responsible for correctly disposing the stream.\nFor HTTP requests, no handling is required if you send a response.\nFor streams that use file descriptors, you should `stream.destroy()` or `stream.close()` to prevent leaks.\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2013 Jonathan Ong me@jongleberry.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n",
"readmeFilename": "README.md",
"homepage": "https://github.com/stream-utils/raw-body",
"_id": "raw-body@1.1.4",
"dist": {
"shasum": "6bc522a645d7c9939fe2ba2be3bd5ddf29f7f89f"
},
"_from": "raw-body@~1.1.2",
"_resolved": "https://registry.npmjs.org/raw-body/-/raw-body-1.1.4.tgz"
}

1
node_modules/body-parser/node_modules/type-is/.npmignore

@ -0,0 +1 @@
test.js

4
node_modules/body-parser/node_modules/type-is/.travis.yml

@ -0,0 +1,4 @@
node_js:
- "0.10"
- "0.11"
language: node_js

16
node_modules/body-parser/node_modules/type-is/HISTORY.md

@ -0,0 +1,16 @@
1.1.0 / 2014-04-12
==================
* add non-array values support
* expose internal utilities:
- `.is()`
- `.hasBody()`
- `.normalize()`
- `.match()`
1.0.1 / 2014-03-30
==================
* add `multipart` as a shorthand

87
node_modules/body-parser/node_modules/type-is/README.md

@ -0,0 +1,87 @@
# Type Is [![Build Status](https://travis-ci.org/expressjs/type-is.png)](https://travis-ci.org/expressjs/type-is)
Infer the content type of a request.
Extracted from [koa](https://github.com/koajs/koa) for general use.
Here's an example body parser:
```js
var is = require('type-is');
var parse = require('body');
var busboy = require('busboy');
function bodyParser(req, res, next) {
var hasRequestBody = 'content-type' in req.headers
|| 'transfer-encoding' in req.headers;
if (!hasRequestBody) return next();
switch (is(req, ['urlencoded', 'json', 'multipart'])) {
case 'urlencoded':
// parse urlencoded body
break
case 'json':
// parse json body
break
case 'multipart':
// parse multipart body
break
default:
// 415 error code
}
}
```
## API
### var type = is(request, types)
```js
var is = require('type-is')
http.createServer(function (req, res) {
is(req, ['text/*'])
})
```
`request` is the node HTTP request. `types` is an array of types. Each type can be:
- An extension name such as `json`. This name will be returned if matched.
- A mime type such as `application/json`.
- A mime type with a wildcard such as `*/json` or `application/*`. The full mime type will be returned if matched
`false` will be returned if no type matches.
Examples:
```js
// req.headers.content-type = 'application/json'
is(req, ['json']) // -> 'json'
is(req, ['html', 'json']) // -> 'json'
is(req, ['application/*']) // -> 'application/json'
is(req, ['application/json']) // -> 'application/json'
is(req, ['html']) // -> false
```
## License
The MIT License (MIT)
Copyright (c) 2013 Jonathan Ong me@jongleberry.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

148
node_modules/body-parser/node_modules/type-is/index.js

@ -0,0 +1,148 @@
var mime = require('mime');
var slice = [].slice;
module.exports = typeofrequest;
typeofrequest.is = typeis;
typeofrequest.hasBody = hasbody;
typeofrequest.normalize = normalize;
typeofrequest.match = mimeMatch;
/**
* Compare a `value` content-type with `types`.
* Each `type` can be an extension like `html`,
* a special shortcut like `multipart` or `urlencoded`,
* or a mime type.
*
* If no types match, `false` is returned.
* Otherwise, the first `type` that matches is returned.
*
* @param {String} value
* @param {Array} types
* @return String
*/
function typeis(value, types) {
if (!value) return false;
if (types && !Array.isArray(types)) types = slice.call(arguments, 1);
// remove stuff like charsets
var index = value.indexOf(';')
value = ~index ? value.slice(0, index) : value
// no types, return the content type
if (!types || !types.length) return value;
var type;
for (var i = 0; i < types.length; i++)
if (mimeMatch(normalize(type = types[i]), value))
return ~type.indexOf('*') ? value : type;
// no matches
return false;
}
/**
* Check if a request has a request body.
* A request with a body __must__ either have `transfer-encoding`
* or `content-length` headers set.
* http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.3
*
* @param {Object} request
* @return {Boolean}
* @api public
*/
function hasbody(req) {
var headers = req.headers;
if ('transfer-encoding' in headers) return true;
var length = headers['content-length'];
if (!length) return false;
// no idea when this would happen, but `isNaN(null) === false`
if (isNaN(length)) return false;
return !!parseInt(length, 10);
}
/**
* Check if the incoming request contains the "Content-Type"
* header field, and it contains any of the give mime `type`s.
* If there is no request body, `null` is returned.
* If there is no content type, `false` is returned.
* Otherwise, it returns the first `type` that matches.
*
* Examples:
*
* // With Content-Type: text/html; charset=utf-8
* this.is('html'); // => 'html'
* this.is('text/html'); // => 'text/html'
* this.is('text/*', 'application/json'); // => 'text/html'
*
* // When Content-Type is application/json
* this.is('json', 'urlencoded'); // => 'json'
* this.is('application/json'); // => 'application/json'
* this.is('html', 'application/*'); // => 'application/json'
*
* this.is('html'); // => false
*
* @param {String|Array} types...
* @return {String|false|null}
* @api public
*/
function typeofrequest(req, types) {
if (!hasbody(req)) return null;
if (types && !Array.isArray(types)) types = slice.call(arguments, 1);
return typeis(req.headers['content-type'], types);
}
/**
* Normalize a mime type.
* If it's a shorthand, expand it to a valid mime type.
*
* In general, you probably want:
*
* var type = is(req, ['urlencoded', 'json', 'multipart']);
*
* Then use the appropriate body parsers.
* These three are the most common request body types
* and are thus ensured to work.
*
* @param {String} type
* @api private
*/
function normalize(type) {
switch (type) {
case 'urlencoded': return 'application/x-www-form-urlencoded';
case 'multipart':
type = 'multipart/*';
break;
}
return ~type.indexOf('/') ? type : mime.lookup(type);
}
/**
* Check if `exected` mime type
* matches `actual` mime type with
* wildcard support.
*
* @param {String} expected
* @param {String} actual
* @return {Boolean}
* @api private
*/
function mimeMatch(expected, actual) {
if (expected === actual) return true;
if (!~expected.indexOf('*')) return false;
actual = actual.split('/');
expected = expected.split('/');
if ('*' === expected[0] && expected[1] === actual[1]) return true;
if ('*' === expected[1] && expected[0] === actual[0]) return true;
return false;
}

19
node_modules/body-parser/node_modules/type-is/node_modules/mime/LICENSE

@ -0,0 +1,19 @@
Copyright (c) 2010 Benjamin Thomas, Robert Kieffer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

66
node_modules/body-parser/node_modules/type-is/node_modules/mime/README.md

@ -0,0 +1,66 @@
# mime
Comprehensive MIME type mapping API. Includes all 600+ types and 800+ extensions defined by the Apache project, plus additional types submitted by the node.js community.
## Install
Install with [npm](http://github.com/isaacs/npm):
npm install mime
## API - Queries
### mime.lookup(path)
Get the mime type associated with a file, if no mime type is found `application/octet-stream` is returned. Performs a case-insensitive lookup using the extension in `path` (the substring after the last '/' or '.'). E.g.
var mime = require('mime');
mime.lookup('/path/to/file.txt'); // => 'text/plain'
mime.lookup('file.txt'); // => 'text/plain'
mime.lookup('.TXT'); // => 'text/plain'
mime.lookup('htm'); // => 'text/html'
### mime.default_type
Sets the mime type returned when `mime.lookup` fails to find the extension searched for. (Default is `application/octet-stream`.)
### mime.extension(type)
Get the default extension for `type`
mime.extension('text/html'); // => 'html'
mime.extension('application/octet-stream'); // => 'bin'
### mime.charsets.lookup()
Map mime-type to charset
mime.charsets.lookup('text/plain'); // => 'UTF-8'
(The logic for charset lookups is pretty rudimentary. Feel free to suggest improvements.)
## API - Defining Custom Types
The following APIs allow you to add your own type mappings within your project. If you feel a type should be included as part of node-mime, see [requesting new types](https://github.com/broofa/node-mime/wiki/Requesting-New-Types).
### mime.define()
Add custom mime/extension mappings
mime.define({
'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],
'application/x-my-type': ['x-mt', 'x-mtt'],
// etc ...
});
mime.lookup('x-sft'); // => 'text/x-some-format'
The first entry in the extensions array is returned by `mime.extension()`. E.g.
mime.extension('text/x-some-format'); // => 'x-sf'
### mime.load(filepath)
Load mappings from an Apache ".types" format file
mime.load('./my_project.types');
The .types file format is simple - See the `types` dir for examples.

114
node_modules/body-parser/node_modules/type-is/node_modules/mime/mime.js

@ -0,0 +1,114 @@
var path = require('path');
var fs = require('fs');
function Mime() {
// Map of extension -> mime type
this.types = Object.create(null);
// Map of mime type -> extension
this.extensions = Object.create(null);
}
/**
* Define mimetype -> extension mappings. Each key is a mime-type that maps
* to an array of extensions associated with the type. The first extension is
* used as the default extension for the type.
*
* e.g. mime.define({'audio/ogg', ['oga', 'ogg', 'spx']});
*
* @param map (Object) type definitions
*/
Mime.prototype.define = function (map) {
for (var type in map) {
var exts = map[type];
for (var i = 0; i < exts.length; i++) {
if (process.env.DEBUG_MIME && this.types[exts]) {
console.warn(this._loading.replace(/.*\//, ''), 'changes "' + exts[i] + '" extension type from ' +
this.types[exts] + ' to ' + type);
}
this.types[exts[i]] = type;
}
// Default extension is the first one we encounter
if (!this.extensions[type]) {
this.extensions[type] = exts[0];
}
}
};
/**
* Load an Apache2-style ".types" file
*
* This may be called multiple times (it's expected). Where files declare
* overlapping types/extensions, the last file wins.
*
* @param file (String) path of file to load.
*/
Mime.prototype.load = function(file) {
this._loading = file;
// Read file and split into lines
var map = {},
content = fs.readFileSync(file, 'ascii'),
lines = content.split(/[\r\n]+/);
lines.forEach(function(line) {
// Clean up whitespace/comments, and split into fields
var fields = line.replace(/\s*#.*|^\s*|\s*$/g, '').split(/\s+/);
map[fields.shift()] = fields;
});
this.define(map);
this._loading = null;
};
/**
* Lookup a mime type based on extension
*/
Mime.prototype.lookup = function(path, fallback) {
var ext = path.replace(/.*[\.\/\\]/, '').toLowerCase();
return this.types[ext] || fallback || this.default_type;
};
/**
* Return file extension associated with a mime type
*/
Mime.prototype.extension = function(mimeType) {
var type = mimeType.match(/^\s*([^;\s]*)(?:;|\s|$)/)[1].toLowerCase();
return this.extensions[type];
};
// Default instance
var mime = new Mime();
// Load local copy of
// http://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types
mime.load(path.join(__dirname, 'types/mime.types'));
// Load additional types from node.js community
mime.load(path.join(__dirname, 'types/node.types'));
// Default type
mime.default_type = mime.lookup('bin');
//
// Additional API specific to the default instance
//
mime.Mime = Mime;
/**
* Lookup a charset based on mime type.
*/
mime.charsets = {
lookup: function(mimeType, fallback) {
// Assume text types are utf8
return (/^text\//).test(mimeType) ? 'UTF-8' : fallback;
}
};
module.exports = mime;

36
node_modules/body-parser/node_modules/type-is/node_modules/mime/package.json

@ -0,0 +1,36 @@
{
"author": {
"name": "Robert Kieffer",
"email": "robert@broofa.com",
"url": "http://github.com/broofa"
},
"contributors": [
{
"name": "Benjamin Thomas",
"email": "benjamin@benjaminthomas.org",
"url": "http://github.com/bentomas"
}
],
"dependencies": {},
"description": "A comprehensive library for mime-type mapping",
"devDependencies": {},
"keywords": [
"util",
"mime"
],
"main": "mime.js",
"name": "mime",
"repository": {
"url": "https://github.com/broofa/node-mime",
"type": "git"
},
"version": "1.2.11",
"readme": "# mime\n\nComprehensive MIME type mapping API. Includes all 600+ types and 800+ extensions defined by the Apache project, plus additional types submitted by the node.js community.\n\n## Install\n\nInstall with [npm](http://github.com/isaacs/npm):\n\n npm install mime\n\n## API - Queries\n\n### mime.lookup(path)\nGet the mime type associated with a file, if no mime type is found `application/octet-stream` is returned. Performs a case-insensitive lookup using the extension in `path` (the substring after the last '/' or '.'). E.g.\n\n var mime = require('mime');\n\n mime.lookup('/path/to/file.txt'); // => 'text/plain'\n mime.lookup('file.txt'); // => 'text/plain'\n mime.lookup('.TXT'); // => 'text/plain'\n mime.lookup('htm'); // => 'text/html'\n\n### mime.default_type\nSets the mime type returned when `mime.lookup` fails to find the extension searched for. (Default is `application/octet-stream`.)\n\n### mime.extension(type)\nGet the default extension for `type`\n\n mime.extension('text/html'); // => 'html'\n mime.extension('application/octet-stream'); // => 'bin'\n\n### mime.charsets.lookup()\n\nMap mime-type to charset\n\n mime.charsets.lookup('text/plain'); // => 'UTF-8'\n\n(The logic for charset lookups is pretty rudimentary. Feel free to suggest improvements.)\n\n## API - Defining Custom Types\n\nThe following APIs allow you to add your own type mappings within your project. If you feel a type should be included as part of node-mime, see [requesting new types](https://github.com/broofa/node-mime/wiki/Requesting-New-Types).\n\n### mime.define()\n\nAdd custom mime/extension mappings\n\n mime.define({\n 'text/x-some-format': ['x-sf', 'x-sft', 'x-sfml'],\n 'application/x-my-type': ['x-mt', 'x-mtt'],\n // etc ...\n });\n\n mime.lookup('x-sft'); // => 'text/x-some-format'\n\nThe first entry in the extensions array is returned by `mime.extension()`. E.g.\n\n mime.extension('text/x-some-format'); // => 'x-sf'\n\n### mime.load(filepath)\n\nLoad mappings from an Apache \".types\" format file\n\n mime.load('./my_project.types');\n\nThe .types file format is simple - See the `types` dir for examples.\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/broofa/node-mime/issues"
},
"homepage": "https://github.com/broofa/node-mime",
"_id": "mime@1.2.11",
"_from": "mime@~1.2.11"
}

84
node_modules/body-parser/node_modules/type-is/node_modules/mime/test.js

@ -0,0 +1,84 @@
/**
* Usage: node test.js
*/
var mime = require('./mime');
var assert = require('assert');
var path = require('path');
function eq(a, b) {
console.log('Test: ' + a + ' === ' + b);
assert.strictEqual.apply(null, arguments);
}
console.log(Object.keys(mime.extensions).length + ' types');
console.log(Object.keys(mime.types).length + ' extensions\n');
//
// Test mime lookups
//
eq('text/plain', mime.lookup('text.txt')); // normal file
eq('text/plain', mime.lookup('TEXT.TXT')); // uppercase
eq('text/plain', mime.lookup('dir/text.txt')); // dir + file
eq('text/plain', mime.lookup('.text.txt')); // hidden file
eq('text/plain', mime.lookup('.txt')); // nameless
eq('text/plain', mime.lookup('txt')); // extension-only
eq('text/plain', mime.lookup('/txt')); // extension-less ()
eq('text/plain', mime.lookup('\\txt')); // Windows, extension-less
eq('application/octet-stream', mime.lookup('text.nope')); // unrecognized
eq('fallback', mime.lookup('text.fallback', 'fallback')); // alternate default
//
// Test extensions
//
eq('txt', mime.extension(mime.types.text));
eq('html', mime.extension(mime.types.htm));
eq('bin', mime.extension('application/octet-stream'));
eq('bin', mime.extension('application/octet-stream '));
eq('html', mime.extension(' text/html; charset=UTF-8'));
eq('html', mime.extension('text/html; charset=UTF-8 '));
eq('html', mime.extension('text/html; charset=UTF-8'));
eq('html', mime.extension('text/html ; charset=UTF-8'));
eq('html', mime.extension('text/html;charset=UTF-8'));
eq('html', mime.extension('text/Html;charset=UTF-8'));
eq(undefined, mime.extension('unrecognized'));
//
// Test node.types lookups
//
eq('application/font-woff', mime.lookup('file.woff'));
eq('application/octet-stream', mime.lookup('file.buffer'));
eq('audio/mp4', mime.lookup('file.m4a'));
eq('font/opentype', mime.lookup('file.otf'));
//
// Test charsets
//
eq('UTF-8', mime.charsets.lookup('text/plain'));
eq(undefined, mime.charsets.lookup(mime.types.js));
eq('fallback', mime.charsets.lookup('application/octet-stream', 'fallback'));
//
// Test for overlaps between mime.types and node.types
//
var apacheTypes = new mime.Mime(), nodeTypes = new mime.Mime();
apacheTypes.load(path.join(__dirname, 'types/mime.types'));
nodeTypes.load(path.join(__dirname, 'types/node.types'));
var keys = [].concat(Object.keys(apacheTypes.types))
.concat(Object.keys(nodeTypes.types));
keys.sort();
for (var i = 1; i < keys.length; i++) {
if (keys[i] == keys[i-1]) {
console.warn('Warning: ' +
'node.types defines ' + keys[i] + '->' + nodeTypes.types[keys[i]] +
', mime.types defines ' + keys[i] + '->' + apacheTypes.types[keys[i]]);
}
}
console.log('\nOK');

1588
node_modules/body-parser/node_modules/type-is/node_modules/mime/types/mime.types
File diff suppressed because it is too large
View File

77
node_modules/body-parser/node_modules/type-is/node_modules/mime/types/node.types

@ -0,0 +1,77 @@
# What: WebVTT
# Why: To allow formats intended for marking up external text track resources.
# http://dev.w3.org/html5/webvtt/
# Added by: niftylettuce
text/vtt vtt
# What: Google Chrome Extension
# Why: To allow apps to (work) be served with the right content type header.
# http://codereview.chromium.org/2830017
# Added by: niftylettuce
application/x-chrome-extension crx
# What: HTC support
# Why: To properly render .htc files such as CSS3PIE
# Added by: niftylettuce
text/x-component htc
# What: HTML5 application cache manifes ('.manifest' extension)
# Why: De-facto standard. Required by Mozilla browser when serving HTML5 apps
# per https://developer.mozilla.org/en/offline_resources_in_firefox
# Added by: louisremi
text/cache-manifest manifest
# What: node binary buffer format
# Why: semi-standard extension w/in the node community
# Added by: tootallnate
application/octet-stream buffer
# What: The "protected" MP-4 formats used by iTunes.
# Why: Required for streaming music to browsers (?)
# Added by: broofa
application/mp4 m4p
audio/mp4 m4a
# What: Video format, Part of RFC1890
# Why: See https://github.com/bentomas/node-mime/pull/6
# Added by: mjrusso
video/MP2T ts
# What: EventSource mime type
# Why: mime type of Server-Sent Events stream
# http://www.w3.org/TR/eventsource/#text-event-stream
# Added by: francois2metz
text/event-stream event-stream
# What: Mozilla App manifest mime type
# Why: https://developer.mozilla.org/en/Apps/Manifest#Serving_manifests
# Added by: ednapiranha
application/x-web-app-manifest+json webapp
# What: Lua file types
# Why: Googling around shows de-facto consensus on these
# Added by: creationix (Issue #45)
text/x-lua lua
application/x-lua-bytecode luac
# What: Markdown files, as per http://daringfireball.net/projects/markdown/syntax
# Why: http://stackoverflow.com/questions/10701983/what-is-the-mime-type-for-markdown
# Added by: avoidwork
text/x-markdown markdown md mkd
# What: ini files
# Why: because they're just text files
# Added by: Matthew Kastor
text/plain ini
# What: DASH Adaptive Streaming manifest
# Why: https://developer.mozilla.org/en-US/docs/DASH_Adaptive_Streaming_for_HTML_5_Video
# Added by: eelcocramer
application/dash+xml mdp
# What: OpenType font files - http://www.microsoft.com/typography/otspec/
# Why: Browsers usually ignore the font MIME types and sniff the content,
# but Chrome, shows a warning if OpenType fonts aren't served with
# the `font/opentype` MIME type: http://i.imgur.com/8c5RN8M.png.
# Added by: alrra
font/opentype otf

37
node_modules/body-parser/node_modules/type-is/package.json

@ -0,0 +1,37 @@
{
"name": "type-is",
"description": "Infer the content type if a request",
"version": "1.1.0",
"author": {
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/expressjs/type-is"
},
"dependencies": {
"mime": "~1.2.11"
},
"devDependencies": {
"mocha": "*",
"should": "*"
},
"scripts": {
"test": "mocha --require should --reporter spec --bail"
},
"readme": "# Type Is [![Build Status](https://travis-ci.org/expressjs/type-is.png)](https://travis-ci.org/expressjs/type-is)\n\nInfer the content type of a request. \nExtracted from [koa](https://github.com/koajs/koa) for general use.\n\nHere's an example body parser:\n\n```js\nvar is = require('type-is');\nvar parse = require('body');\nvar busboy = require('busboy');\n\nfunction bodyParser(req, res, next) {\n var hasRequestBody = 'content-type' in req.headers\n || 'transfer-encoding' in req.headers;\n if (!hasRequestBody) return next();\n \n switch (is(req, ['urlencoded', 'json', 'multipart'])) {\n case 'urlencoded':\n // parse urlencoded body\n break\n case 'json':\n // parse json body\n break\n case 'multipart':\n // parse multipart body\n break\n default:\n // 415 error code\n }\n}\n```\n\n## API\n\n### var type = is(request, types)\n\n```js\nvar is = require('type-is')\n\nhttp.createServer(function (req, res) {\n is(req, ['text/*'])\n})\n```\n\n`request` is the node HTTP request. `types` is an array of types. Each type can be:\n\n- An extension name such as `json`. This name will be returned if matched.\n- A mime type such as `application/json`.\n- A mime type with a wildcard such as `*/json` or `application/*`. The full mime type will be returned if matched\n\n`false` will be returned if no type matches.\n\nExamples:\n\n```js\n// req.headers.content-type = 'application/json'\nis(req, ['json']) // -> 'json'\nis(req, ['html', 'json']) // -> 'json'\nis(req, ['application/*']) // -> 'application/json'\nis(req, ['application/json']) // -> 'application/json'\nis(req, ['html']) // -> false\n```\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2013 Jonathan Ong me@jongleberry.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/expressjs/type-is/issues"
},
"homepage": "https://github.com/expressjs/type-is",
"_id": "type-is@1.1.0",
"dist": {
"shasum": "013fbfeb3955944bae8bf3b632df4ed807aefbbd"
},
"_from": "type-is@~1.1.0",
"_resolved": "https://registry.npmjs.org/type-is/-/type-is-1.1.0.tgz"
}

41
node_modules/body-parser/package.json

@ -0,0 +1,41 @@
{
"name": "body-parser",
"description": "Connect's body parsing middleware",
"version": "1.0.2",
"author": {
"name": "Jonathan Ong",
"email": "me@jongleberry.com",
"url": "http://jongleberry.com"
},
"license": "MIT",
"repository": {
"type": "git",
"url": "git://github.com/expressjs/body-parser"
},
"dependencies": {
"type-is": "~1.1.0",
"raw-body": "~1.1.2",
"qs": "~0.6.6"
},
"devDependencies": {
"connect": "*",
"mocha": "*",
"should": "*",
"supertest": "*"
},
"scripts": {
"test": "make test"
},
"readme": "# Body Parser [![Build Status](https://travis-ci.org/expressjs/body-parser.png)](https://travis-ci.org/expressjs/body-parser)\n\nConnect's body parsing middleware.\n\n## API\n\n```js\nvar bodyParser = require('body-parser');\n\nvar app = connect();\n\napp.use(bodyParser());\n\napp.use(function (req, res, next) {\n console.log(req.body) // populated!\n next();\n})\n```\n\n### bodyParser([options])\n\nReturns middleware that parses both `json` and `urlencoded`. The `options` are passed to both middleware.\n\n### bodyParser.json([options])\n\nReturns middleware that only parses `json`. The options are:\n\n- `strict` <true> - only parse objects and arrays\n- `limit` <1mb> - maximum request body size\n- `reviver` - passed to `JSON.parse()`\n\n### bodyParser.urlencoded([options])\n\nReturns middleware that only parses `urlencoded` with the [qs](https://github.com/visionmedia/node-querystring) module. The options are:\n\n- `limit` <1mb> - maximum request body size\n\n## License\n\nThe MIT License (MIT)\n\nCopyright (c) 2014 Jonathan Ong me@jongleberry.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n",
"readmeFilename": "README.md",
"bugs": {
"url": "https://github.com/expressjs/body-parser/issues"
},
"homepage": "https://github.com/expressjs/body-parser",
"_id": "body-parser@1.0.2",
"dist": {
"shasum": "a5ef66df81af3d2a204ac2c03f1b44c630a70643"
},
"_from": "body-parser@",
"_resolved": "https://registry.npmjs.org/body-parser/-/body-parser-1.0.2.tgz"
}

24
web/public/css/app.css

@ -0,0 +1,24 @@
.uk-navbar-nav > li {
display: inline-block;
float: none;
}
.uk-navbar-nav > li > a > img {
width: 20px;
}
.flip {
-moz-transform: scaleX(-1);
-o-transform: scaleX(-1);
-webkit-transform: scaleX(-1);
transform: scaleX(-1);
filter: FlipH;
-ms-filter: "FlipH";
}
.uk-search-field, .uk-search-field::-moz-placeholder {
color: #FFFFFF;
}
#fan-art > a {
margin: 8px;
}

31
web/public/help/instructions.txt

@ -0,0 +1,31 @@
TwitchBot Commands List
=======================
Public Commands:
!<currency> Displays how many <currency> you have
!bid <amount> Bid <amount> <currency> on the current auction
!ticket <amount> Buy <amount> tickets for the current raffle
!<option> <amount> Used for voting and betting
!<bot_name> List of available custom commands
!<currency> bet pool Display current betting pool
!<currency> vote pool Display current vote standings
Mod only commands:
!<currency> (on/off) Enables or disables currency requests
!<currency> auction open Opens a new auction
!<currency> auction close Closes the auction and announces winner
!<currency> auction cancel Cancels auction, returns <currency> to users
!<currency> raffle open <price> <max> Opens a raffle, tickets cost <price>, users can buy a max of <max> tickets
!<currency> raffle close/cancel Same as auction functions
!<currency> raffle draw Draws a second ticket (second place or need a new winner)
!<currency> bet open (opt1 opt2 etc) Opens a bet with options !opt1 !opt2 (can have up to 10)
!<currency> bet close Stop accepting new bets
!<currency> bet cancel Cancel bet, give <currency> back to users
!<currency> bet winner (opt1) Makes (!opt1) the winner, pays out to users
!<currency> vote open (opt1 opt2 etc) Opens a vote with options !opt1 !opt2 (can have up to 10)
!<currency> vote close Stop accepting new votes
!<currency> vote cancel Cancel vote, give <currency> back to users
!<currency> vote winner (opt1) Makes (!opt1) the winner (will make this calculate the winner soon)

20
web/templates/fanart.jade

@ -0,0 +1,20 @@
extends layout
block content
div.uk-grid
br
br
div.uk-width-1-1.uk-text-center
h1 #{ucfirst(title)} Fan Art
div.uk-width-1-1
div#fan-art.uk-panel.uk-panel-box
block postscript
script.
var art = !{JSON.stringify(fanart)};
var $holder = $(".uk-panel-box");
art.forEach(function(elem) {
var $thumb = $("<a href='"+elem.url+"' class='uk-thumbnail uk-thumbnail-small'></a>");
$thumb.append("<img src='"+elem.url+"' />");
$thumb.append("<div class='uk-thumbnail-caption'>Artist: <a href='"+elem.user_link+"'>"+elem.user+"</a></div>");
$holder.append($thumb);
});

138
web/templates/index.jade

@ -1,82 +1,60 @@
doctype html
html(lang="en")
head
title= title
link(rel='stylesheet', href='/lib/uikit/css/uikit.almost-flat.min.css')
link(rel='stylesheet', href='/css/app.css')
script(src='/lib/jquery.js')
script(src='/lib/uikit/js/uikit.min.js')
// Favicon stuff
link(rel='apple-touch-icon', sizes='57x57', href='/apple-touch-icon-57x57.png')
link(rel='apple-touch-icon', sizes='114x114', href='/apple-touch-icon-114x114.png')
link(rel='apple-touch-icon', sizes='72x72', href='/apple-touch-icon-72x72.png')
link(rel='apple-touch-icon', sizes='144x144', href='/apple-touch-icon-144x144.png')
link(rel='apple-touch-icon', sizes='60x60', href='/apple-touch-icon-60x60.png')
link(rel='apple-touch-icon', sizes='120x120', href='/apple-touch-icon-120x120.png')
link(rel='apple-touch-icon', sizes='76x76', href='/apple-touch-icon-76x76.png')
link(rel='apple-touch-icon', sizes='152x152', href='/apple-touch-icon-152x152.png')
link(rel='icon', type='image/png', href='/favicon-196x196.png', sizes='196x196')
link(rel='icon', type='image/png', href='/favicon-160x160.png', sizes='160x160')
link(rel='icon', type='image/png', href='/favicon-96x96.png', sizes='96x96')
link(rel='icon', type='image/png', href='/favicon-16x16.png', sizes='16x16')
link(rel='icon', type='image/png', href='/favicon-32x32.png', sizes='32x32')
meta(name='msapplication-TileColor', content='#da532c')
meta(name='msapplication-TileImage', content='/mstile-144x144.png')
body
div.uk-grid
div.uk-width-1-1
div.uk-grid
div.uk-width-1-4
img(src='/img/#{logo}')
div.uk-width-2-4
// bigimagelogo
h1.uk-text-center #{title}<br/>#{slogan}
div.uk-width-1-4
img.flip(src='/img/#{logo}')
div.uk-width-1-1
nav.uk-navbar
ul.uk-navbar-nav.uk-navbar-center
li: a(href='http://www.twitch.tv/#{title}'): img(src='/img/twitch.png', alt='Stream')
li: a(href='/') Home
li: a(href='/ladder') Ladder
li: a(href='#') Chat Stats
li: a(href='http://www.twitter.com/#{twitter}'): img(src='/img/twitter.gif', alt='Twitter')
div.uk-width-1-1
div.uk-container.uk-container-center
div.uk-grid
br
br
div.uk-width-1-2
div.uk-panel.uk-panel-box
h2 #{title} is
span#status offline.
div#streambox
div.uk-width-1-2
div.uk-panel.uk-panel-box
table.uk-table.uk-table-hover.uk-table-striped
caption Top 10 Potato Farmers
thead
tr
th Viewer
th Potatoes
tbody
each row in rows
tr
td #{row.user}
td #{row.points}
extends layout
block content
div.uk-grid
br
br
div.uk-width-1-2
div.uk-panel.uk-panel-box
h2 #{title} is
span#status offline.
div#streambox
br
div#betstats
span.uk-text-bold Betting is currently:
#{bet_status}
if bet_status === true
span.uk-text-bold.uk-text-success &nbsp;Active
else
span.uk-text-bold.uk-text-danger &nbsp;Inactive
if bet_board
table.uk-table
caption Current Betting Pool
thead
tr
th Option
th Total
tbody
each option in bet_board
tr
td !#{option.name}
td #{option.total}
br
div.uk-width-1-2
div.uk-panel.uk-panel-box
table.uk-table.uk-table-hover.uk-table-striped
caption Top 10 #{ucfirst(currency)} Farmers
thead
tr
th Viewer
th #{ucfirst(currency)}
tbody
each row in rows
tr
td #{row.user}
td #{row.points}
script.
$(document).ready(function(){
$.getJSON('https://api.twitch.tv/kraken/streams/#{title}?callback=?', function(data){
if(data.stream) {
$('#status').empty().append('online!');
$("#streambox").append("<span>Game:</span> <span class='uk-text-bold uk-text-success'>"+data.stream.game+"</span><br/>");
$("#streambox").append("<span>Viewers:</span> <span class='uk-text-bold uk-text-warning'>"+data.stream.viewers+"</span><br/>");
$("#streambox").append("<br/><br/><img src='"+data.stream.preview.medium+"' />");;
} else {
$("#streambox").append("<h3 class='uk-text-danger'>Offline</h3>");
}
});
block postscript
script.
$(document).ready(function(){
$.getJSON('https://api.twitch.tv/kraken/streams/#{title}?callback=?', function(data){
if(data.stream) {
$('#status').empty().append('online!');
$("#streambox").append("<span>Game:</span> <span class='uk-text-bold uk-text-success'>"+data.stream.game+"</span><br/>");
$("#streambox").append("<span>Viewers:</span> <span class='uk-text-bold uk-text-warning'>"+data.stream.viewers+"</span><br/>");
$("#streambox").append("<br/><br/><img src='"+data.stream.preview.medium+"' />");;
} else {
$("#streambox").append("<h3 class='uk-text-danger'>Offline</h3>");
$("#betstats").hide();
}
});
});

219
web/templates/ladder.jade

@ -1,122 +1,113 @@
doctype html
html(lang="en")
head
title= title
link(rel='stylesheet', href='/lib/uikit/css/uikit.almost-flat.min.css')
link(rel='stylesheet', href='/css/app.css')
script(src='/lib/jquery.js')
script(src='/lib/uikit/js/uikit.min.js')
// Favicon stuff
link(rel='apple-touch-icon', sizes='57x57', href='/apple-touch-icon-57x57.png')
link(rel='apple-touch-icon', sizes='114x114', href='/apple-touch-icon-114x114.png')
link(rel='apple-touch-icon', sizes='72x72', href='/apple-touch-icon-72x72.png')
link(rel='apple-touch-icon', sizes='144x144', href='/apple-touch-icon-144x144.png')
link(rel='apple-touch-icon', sizes='60x60', href='/apple-touch-icon-60x60.png')
link(rel='apple-touch-icon', sizes='120x120', href='/apple-touch-icon-120x120.png')
link(rel='apple-touch-icon', sizes='76x76', href='/apple-touch-icon-76x76.png')
link(rel='apple-touch-icon', sizes='152x152', href='/apple-touch-icon-152x152.png')
link(rel='icon', type='image/png', href='/favicon-196x196.png', sizes='196x196')
link(rel='icon', type='image/png', href='/favicon-160x160.png', sizes='160x160')
link(rel='icon', type='image/png', href='/favicon-96x96.png', sizes='96x96')
link(rel='icon', type='image/png', href='/favicon-16x16.png', sizes='16x16')
link(rel='icon', type='image/png', href='/favicon-32x32.png', sizes='32x32')
meta(name='msapplication-TileColor', content='#da532c')
meta(name='msapplication-TileImage', content='/mstile-144x144.png')
body
div.uk-grid
div.uk-width-1-1
div.uk-grid
div.uk-width-1-4
img(src='/img/#{logo}')
div.uk-width-2-4
// bigimagelogo
h1.uk-text-center #{title}<br/>#{slogan}
div.uk-width-1-4
img.flip(src='/img/#{logo}')
div.uk-width-1-1
nav.uk-navbar
ul.uk-navbar-nav.uk-navbar-center
li: a(href='http://www.twitch.tv/#{title}'): img(src='/img/twitch.png', alt='Stream')
li: a(href='/') Home
li: a(href='/ladder') Ladder
li: a(href='#') Chat Stats
li: a(href='http://www.twitter.com/#{twitter}'): img(src='/img/twitter.gif', alt='Twitter')
div.uk-width-1-1
div.uk-container.uk-container-center
div.uk-grid
br
br
div.uk-width-1-1
div.uk-panel.uk-panel-box
div.uk-badge.uk-float-right
form.uk-search
input(class='uk-search-field', type='search', placeholder='Search...')
button(class='uk-close', type='reset')
table.uk-table.uk-table-hover.uk-table-striped
caption Potato Farmer Ladder Rankings
thead
tr
th Rank
th Viewer
th Potatoes
tbody
ul.uk-pagination
script.
var perPage = 50,
data = !{JSON.stringify(rows)};
$(document).ready(function(){
// Live search of the ladder listings
$('.uk-search-field').keyup(function() {
var query = $(this).val();
if(query.length > 2) {
var temp = $('.uk-active').attr('page');
$('.uk-active').removeClass('uk-active').empty().append('<a>'+temp+'</a>');
$('table > tbody').empty();
data.forEach(function(element, index, array) {
if(element.user.search(new RegExp(query, 'i')) != -1) {
$('table > tbody').append($('<tr></tr>').append('<td>'+index+'</td><td>'+element.user+'</td><td>'+element.points+'</td>'));
}
});
}
});
extends layout
block content
div.uk-grid
br
br
div.uk-width-1-1
div.uk-panel.uk-panel-box
div.uk-badge.uk-float-right
form.uk-search
input(class='uk-search-field', type='search', placeholder='Search...')
button(class='uk-close', type='reset')
table.uk-table.uk-table-hover.uk-table-striped
caption #{ucfirst(currency)} Farmer Ladder Rankings (<span id="total_farmers"></span> farmers total)
thead
tr
th Rank
th Viewer
th #{ucfirst(currency)}
tbody
ul.uk-pagination
// Create pagination buttons
for(var i = 1; i <= Math.ceil(data.length/perPage); i++) {
var button = $('<li page='+i+'></li>').append('<a>'+i+'</a>');
button.on('click', function(){
//get page
var z = $(this).attr('page');
// cleanup
var temp = $('.uk-active').attr('page');
$('.uk-active').removeClass('uk-active').empty().append('<a>'+temp+'</a>');
$('table > tbody').empty();
$(this).addClass('uk-active').empty().append('<span>'+z+'</span>');
// slice(a, b): a = (n*(x-1))+1, b = n*x where n = perPage and x=curerntPage (skip +1 at end of a for splice)
var a = (perPage*(z-1)),
b = perPage*z;
data.slice(a, b).forEach(function(element, index, array){
$('table > tbody').append($('<tr></tr>').append('<td>'+(a+index+1)+'</td><td>'+element.user+'</td><td>'+element.points+'</td>'));
});
});
block postscript
script.
var perPage = 20,
data = !{JSON.stringify(rows)},
lastPage = Math.ceil(data.length/perPage);
function minifyPagination() {
var current = parseInt($('li.uk-active').attr('page')),
min = Math.max(current-3, 1),
max = current+3;
$('#page_first, #page_last').remove();
$('ul.uk-pagination > li').addClass('uk-hidden');
for(var x = min; x <= max; x++) {
$('li#'+x).removeClass('uk-hidden');
}
if (min > 1)
$('li#'+min).before("<button id='page_first' class='uk-button'>&lt;&lt;</button>");
if (max < lastPage)
$('li#'+max).after("<button id='page_last' class='uk-button'>&gt;&gt;</button>");
$('.uk-pagination').append(button);
$('#page_first').click(function(){
$('li#'+1).click();
});
$('#page_last').click(function(){
$('li#'+lastPage).click();
});
};
$(document).ready(function(){
// Live search of the ladder listings
$('.uk-search-field').keyup(function() {
var query = $(this).val();
if(query.length > 2) {
var temp = $('.uk-active').attr('page');
$('.uk-active').removeClass('uk-active').empty().append('<a>'+temp+'</a>');
$('table > tbody').empty();
data.forEach(function(element, index, array) {
if(element.user.search(new RegExp(query, 'i')) != -1) {
$('table > tbody').append($('<tr></tr>').append('<td>'+index+'</td><td>'+element.user+'</td><td>'+element.points+'</td>'));
}
});
}
});
// Create pagination buttons
for(var i = 1; i <= lastPage; i++) {
var button = $('<li page='+i+' id='+i+'></li>').append('<a>'+i+'</a>');
button.on('click', function(){
//get page
var z = $(this).attr('page');
// cleanup
var temp = $('.uk-active').attr('page');
$('.uk-active').removeClass('uk-active').empty().append('<a>'+temp+'</a>');
$('table > tbody').empty();
$(this).addClass('uk-active').empty().append('<span>'+z+'</span>');
// When search input is cleared, go back to first page
$('.uk-close').on('click', function(){
$('ul.uk-pagination > li').first().click();
// slice(a, b): a = (n*(x-1))+1, b = n*x where n = perPage and x=curerntPage (skip +1 at end of a for splice)
var a = (perPage*(z-1)),
b = perPage*z;
data.slice(a, b).forEach(function(element, index, array){
$('table > tbody').append($('<tr></tr>').append('<td>'+(Number(a+index+1).toLocaleString('en'))+'</td><td>'+element.user+'</td><td>'+element.points+'</td>'));
});
});
// Show the first page when we load up
$('.uk-pagination').append(button);
}
// When search input is cleared, go back to first page
$('.uk-close').on('click', function(){
$('ul.uk-pagination > li').first().click();
});
// Show the first page when we load up
$('ul.uk-pagination > li').first().click();
minifyPagination();
$('ul.uk-pagination > li').on('click', function(){
minifyPagination();
});
$('#total_farmers').append(Number(data.length).toLocaleString('en'));
});

61
web/templates/layout.jade

@ -0,0 +1,61 @@
doctype html
html(lang="en")
head
title= title
link(rel='stylesheet', href='/lib/uikit/css/uikit.almost-flat.min.css')
link(rel='stylesheet', href='/css/app.css')
script(src='/lib/jquery.js')
script(src='/lib/uikit/js/uikit.min.js')
// Favicon stuff
link(rel='icon', type='image/png', href='/favicon.ico', sizes='32x32')
meta(name='msapplication-TileColor', content='#da532c')
meta(name='msapplication-TileImage', content='/mstile-144x144.png')
body
div.uk-grid
div.uk-width-1-1
div.uk-grid
div.uk-width-1-4
img(src='/img/#{logo}', style='max-height:180px;')
div.uk-width-2-4
// bigimagelogo
h1.uk-text-center #{title}<br/>#{slogan}
div.uk-width-1-4
img.flip.uk-float-right(src='/img/#{logo}', style='max-height:180px;')
div.uk-width-1-1
nav.uk-navbar
ul.uk-navbar-nav.uk-navbar-center
li: a(href='http://www.twitch.tv/#{title}'): img(src='/img/twitch.png', alt='Stream')
li: a(href='/') Home
li: a(href='/ladder') Ladder
li: a(href='/stats') Chat Stats
li: a(href='/fanart') Fan Art
li: a(href='http://www.twitter.com/#{twitter}'): img(src='/img/twitter.png', alt='Twitter')
div.uk-width-1-1
div.uk-container.uk-container-center
block content
div.uk-width-1-1
footer.uk-text-center
br
span.tag Visit the #{ucfirst(currency)} Lord @
a(href='http://www.twitch.tv/#{title}') #{title}
br
span.copyright &nbsp;&copy; DotaNoobs & #{title}. All rights reserved.
block postscript
script.
$(document).ready(function() {
$('span.copyright').prepend(new Date().getFullYear());
});
script.
window._idl = {};
_idl.variant = "modal";
(function() {
var idl = document.createElement('script');
idl.type = 'text/javascript';
idl.async = true;
idl.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'members.internetdefenseleague.org/include/?url=' + (_idl.url || '') + '&campaign=' + (_idl.campaign || '') + '&variant=' + (_idl.variant || 'modal');
document.getElementsByTagName('body')[0].appendChild(idl);
})();

14
web/templates/stats.jade

@ -0,0 +1,14 @@
extends layout
block content
iframe#stats_content.uk-width-1-1(onload="resizeStats(this)")
block postscript
script.
$(document).ready( function() {
$("#stats_content").attr("src", "statistics/#{statdir}/index.html");
});
function resizeStats(iframe) {
iframe.height = iframe.contentWindow.document.body.scrollHeight + "px";
$('div.uk-container.uk-container-center').attr("style", "max-width: 100%!important; padding: 15px 5px;");
}
Loading…
Cancel
Save