And fixing... [DMC]


SUBMITTED BY: Guest

DATE: Oct. 18, 2013, 5:43 p.m.

FORMAT: JavaScript

SIZE: 3.1 kB

HITS: 995

  1. var io = require('socket.io-client');
  2. socket = io.connect("https://coinchat.org", {
  3. secure: true
  4. });
  5. var username = "DMCFaucetBot";
  6. var outputBuffer = [];
  7. socket.on('connect', function () {
  8. socket.emit('login', {
  9. session: "removed"
  10. });
  11. socket.on('loggedin', function (data) {
  12. username = data.username;
  13. setTimeout(function () {
  14. socket.emit("getcolors", {});
  15. }, 1000);
  16. setInterval(function () {
  17. if (outputBuffer.length > 0) {
  18. var chat = outputBuffer.splice(0, 1)[0];
  19. socket.emit("chat", {
  20. room: chat.room,
  21. message: chat.message
  22. });
  23. }
  24. }, 600);
  25. });
  26. console.log("----------")
  27. console.log("[DMC] Starting faucet component...")
  28. console.log("----------")
  29. console.log(" ")
  30. socket.emit('joinroom', {
  31. join: 'dmcfaucet'
  32. });
  33. console.log("Joined #dmcfaucet.")
  34. socket.emit('joinroom', {
  35. join: 'offtopic'
  36. });
  37. console.log("Joined #offtopic.")
  38. console.log("[DMC] Successfully launched faucet component.")
  39. socket.on('chat', function (data) {
  40. if (data.message === "!dmc admin terminate: faucet" && (data.room === "offtopic" || data.room === "dmcfaucet" ) && (data.user === "DiamondCardz" || data.user === "admin")) {
  41. console.log("[DMC] Received terminate command.")
  42. socket.emit('quitroom', {
  43. join: 'dmcfaucet'
  44. });
  45. console.log("Left #dmcfaucet.")
  46. socket.emit('quitroom', {
  47. join: 'offtopic'
  48. });
  49. console.log("Left #offtopic.")
  50. console.log("[DMC] Dying!")
  51. throw new Error();
  52. }
  53. if (contains(data.message, ["<span class='label label-success'>has tipped " + username])) {
  54. var amount = data.message.split("<span class='label label-success'>has tipped " + username + " ")[1].split(" ")[0];
  55. console.log("[DMC] Detected new " + amount + "mBTC tip.")
  56. outputBuffer.push({
  57. room: data.room,
  58. message: "Thanks for the " + amount + "mBTC donation to the faucet, " + data.user + "!"
  59. });
  60. }
  61. if (data.message === "!dmc admin test: faucet" && data.room === "dmcfaucet" && (data.user === "DiamondCardz" || data.user === "admin")) {
  62. console.log("[DMC] Received test command.")
  63. outputBuffer.push({
  64. room: dmcfaucet,
  65. message: "Currently alive."
  66. });
  67. }
  68. });
  69. socket.on('disconnect', function () {});
  70. });
  71. function contains(string, terms) {
  72. for (var i = 0; i < terms.length; i++) {
  73. if (string.toLowerCase().indexOf(terms[i].toLowerCase()) == -1) {
  74. return false;
  75. }
  76. }
  77. return true;
  78. }

comments powered by Disqus