A Twitch.tv viewer reward and games system.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.6 KiB

11 years ago
  1. var file = require('fs');
  2. //create logs directory
  3. file.exists('./../logs', function (exists) {
  4. if (!exists) {
  5. file.mkdir('./../logs');
  6. }
  7. });
  8. process.on('uncaughtException', function(err) {
  9. file.appendFile('./../logs/error-log.txt', err.message + '\r\n' + err.stack + '\r\n', function() {});
  10. });
  11. exports.initialize = function(options) {
  12. var config = options || {}, db, irc, commands, dashboard, currency;
  13. //-------- Setup -------
  14. irc = require('./irc.js')({
  15. name : config.twitch.bot.name,
  16. pass : config.twitch.bot.password,
  17. channel : '#' + config.twitch.channel
  18. });
  19. db = require('./mysql.js')({
  20. host : config.currency.host,
  21. user : config.currency.user,
  22. password : config.currency.password,
  23. database : config.currency.database
  24. });
  25. commands = require('./commands.js')(irc, db, {
  26. bot_name : config.twitch.bot.name,
  27. currency : config.currency.name
  28. });
  29. currency = require('./currency.js')(irc, db, {
  30. currency : config.currency.name,
  31. payrate : config.currency.payrate,
  32. subscribers : config.twitch.subscribers,
  33. website : config.currency.website
  34. });
  35. //-------- Start -------
  36. irc.start();
  37. db.start();
  38. currency.start();
  39. if (config.commands === true) commands.start();
  40. irc.on('data', function (data) {
  41. console.log(data);
  42. irc.realtime(data);
  43. });
  44. irc.on('command', function (data) {
  45. currency.commands(data);
  46. if (config.commands === true) commands.commands(data);
  47. });
  48. irc.on('message', function (msg) {
  49. irc.queue(msg);
  50. });
  51. };