var io = require('socket.io-client');
socket = io.connect("https://coinchat.org", {
secure: true
});
var username = "DMCFaucetBot";
var outputBuffer = [];
socket.on('connect', function () {
socket.emit('login', {
session: "removed"
});
socket.on('loggedin', function (data) {
username = data.username;
setTimeout(function () {
socket.emit("getcolors", {});
}, 1000);
setInterval(function () {
if (outputBuffer.length > 0) {
var chat = outputBuffer.splice(0, 1)[0];
socket.emit("chat", {
room: chat.room,
message: chat.message
});
}
}, 600);
});
console.log("----------")
console.log("[DMC] Starting faucet component...")
console.log("----------")
console.log(" ")
socket.emit('joinroom', {
join: 'dmcfaucet'
});
console.log("Joined #dmcfaucet.")
socket.emit('joinroom', {
join: 'offtopic'
});
console.log("Joined #offtopic.")
console.log("[DMC] Successfully launched faucet component.")
socket.on('chat', function (data) {
if (data.message === "!dmc admin terminate: faucet" && (data.room === "offtopic" || data.room === "dmcfaucet" ) && (data.user === "DiamondCardz" || data.user === "admin")) {
console.log("[DMC] Received terminate command.")
socket.emit('quitroom', {
join: 'dmcfaucet'
});
console.log("Left #dmcfaucet.")
socket.emit('quitroom', {
join: 'offtopic'
});
console.log("Left #offtopic.")
console.log("[DMC] Dying!")
throw new Error();
}
if (contains(data.message, ["<span class='label label-success'>has tipped " + username])) {
var amount = data.message.split("<span class='label label-success'>has tipped " + username + " ")[1].split(" ")[0];
console.log("[DMC] Detected new " + amount + "mBTC tip.")
outputBuffer.push({
room: data.room,
message: "Thanks for the " + amount + "mBTC donation to the faucet, " + data.user + "!"
});
}
if (data.message === "!dmc admin test: faucet" && data.room === "dmcfaucet" && (data.user === "DiamondCardz" || data.user === "admin")) {
console.log("[DMC] Received test command.")
outputBuffer.push({
room: dmcfaucet,
message: "Currently alive."
});
}
});
socket.on('disconnect', function () {});
});
function contains(string, terms) {
for (var i = 0; i < terms.length; i++) {
if (string.toLowerCase().indexOf(terms[i].toLowerCase()) == -1) {
return false;
}
}
return true;
}