It was the Bitcointalk forum that inspired us to create Bitcointalksearch.org - Bitcointalk is an excellent site that should be the default page for anybody dealing in cryptocurrency, since it is a virtual gold-mine of data. However, our experience and user feedback led us create our site; Bitcointalk's search is slow, and difficult to get the results you need, because you need to log in first to find anything useful - furthermore, there are rate limiters for their search functionality.
The aim of our project is to create a faster website that yields more results and faster without having to create an account and eliminate the need to log in - your personal data, therefore, will never be in jeopardy since we are not asking for any of your data and you don't need to provide them to use our site with all of its capabilities.
We created this website with the sole purpose of users being able to search quickly and efficiently in the field of cryptocurrency so they will have access to the latest and most accurate information and thereby assisting the crypto-community at large.
mkdir dicebot && cd dicebot
npm install coinchat-client
var CoinChatClient = require('coinchat-client');
var client = new CoinChatClient({
username: 'foo',
password: 'bar'
});
console.log('Connecting to coinchat...');
client.connect(function() {
console.log('Connected. Logging in...');
client.login(function() {
console.log("WOOHOO! We're logged in!");
});
});
function messageParser(msg) {
console.log("Received a message from "+msg.user+" in "+msg.room+" and the first word he said was "+msg.params[0]+". He received "+msg.tip+"mBTC for this.");
}
...
client.login(function() {
client.register(messageParser);
});
...
client.join('foobar')
client.pushMessage(roomName, message, [color]);
client.pushTip(roomName, userName, tipAmount, [message]);
client.pushPrivateMessage(userName, message);
var DiceBot = function(client) {
// save a local instance of the client
this.client = client;
// enter all admin names in lowercase here
this.admins = ['yourname']; // Save all admin names here
// this is used to save our balance
this.balance = 0;
// This should contain a mapping of your commands in all lowercase
this.commands = {
'!help': this.printHelp,
'!roll': this.rollDice
};
// It is a good practice to separate admin
// commands from normal commands by using
// another prefix so here's the shutdown command
this.adminCommands = {
'!#shutdown': this.shutdown
};
this.helpText = "Here goes your helptext";
};
/**
* Prints out the help when !help is received by a user
*/
DiceBot.prototype.printHelp = function(msg) {
this.client.pushMessage(msg.room, msg.user+": "+this.helpText);
return false;
};
/**
* This is what gets called by our client instance when
* registering it by using client.register
*/
DiceBot.prototype.handleMessage = function(msg) {
// First lets check if an admin wrote this
var admin = (this.admins.indexOf(msg.user.toLowerCase) != -1)
// Lets see if the message is a tip
if (msg.isTip) {
// ok, we don't need to actually do more here in this case
this.balance = msg.tipAmount;
this.client.pushMessage(msg.room, msg.user+': Thank you for your tip. Your contribution is greatly welcomed!');
return false;
}
// ok, here's the tricky part. We check the first parameter of the message
// and check if we have a command there. If we have one we call it and
// pass it the message as a parameter.
if (typeof this.commands[msg.params[0]] == 'function') {
return this.commands[msg.params[0]].call(this, msg);
}
// Then finally we do the same with the admin commands
// if it was an admin typing the message.
if (admin && typeof this.adminCommands[msg.params[0]] == 'function') {
return this.adminCommands[msg.params[0]].call(this, msg);
}
};
/**
* This checks the msg parameters and sets defaults if something isn't given.
*/
DiceBot.prototype.rollDice = function(msg) {
var nrDice = Number(msg.params[1]) || 1,
sides = Number(msg.params[2]) || 6,
rolls = [];
for (var i=0; irolls.push(1+Math.floor(Math.random()*sides));
}
// Give the user his dice roll
this.client.pushMessage(msg.room, msg.user+": You rolled "+nrDice+"D"+sides+" and got " + rolls.reduce(function(pv, cv) { return pv + cv; }, 0) + ". "+rolls.join(', '));
}
/**
* This shuts down the bot
*/
DiceBot.prototype.shutdown = function(msg) {
console.log('shutting down..');
process.exit();
return false;
};
module.exports = DiceBot;
var CoinChatClient = require('coinchat-client'),
DiceBot = require('./dicebot.js'),
client, bot;
client = new CoinChatClient({
username: 'foo',
password: 'bar'
});
// create a new bot instance and handover the client instance
// so we have access to the push methods.
bot = new DiceBot(client);
console.log('Connecting...');
client.connect(function() {
console.log('Connected. Logging in...');
client.login(function() {
console.log('Logged in. Joining room...');
// now we join a room
client.join('throwingdice');
// we implement a delay
setTimeout(function() {
client.register(bot);
}, 3000);
});
});