🏰 TradeFortress 🏰 (OP)
Bitcoin Veteran
VIP
Legendary
Offline
Activity: 1316
Merit: 1043
👻
|
|
April 27, 2013, 09:27:44 AM Last edit: August 23, 2013, 11:16:22 AM by TradeFortress |
|
Want to write your own bot for CoinChat, a fast web based chat network integrated with bitcoin? 1. Install node.js and socket.io-client (npm install socket.io-client). 2. Register a new account for your bot by using a new browser or clearing your cookies. It must end in bot. Grab the session key from your cookies. This is how you'll sign in. 3. Use this code to get started: var io = require('socket.io-client'); socket = io.connect("https://coinchat.org", { secure: true });
var username = ""; var outputBuffer = [];
socket.on('connect', function () { //Your session key (aka API key) //Get this from your browser's cookies. socket.emit('login', { session: "YOUR_SESSION_KEY_HERE" }); socket.on('loggedin', function (data) { username = data.username; setTimeout(function () { socket.emit("getcolors", {});
}, 1000); setInterval(function () { //CoinChat has a 550ms anti spam prevention. You can't send a chat message more than once every 550ms. if (outputBuffer.length > 0) { var chat = outputBuffer.splice(0, 1)[0]; socket.emit("chat", { room: chat.room, message: chat.message }); } }, 600); });
socket.on('chat', function (data) { if (contains(data.message, ["hi", username])) { outputBuffer.push({ room: data.room, message: 'Hi ' + data.user + "!" }); } if (contains(data.message, ["slaps", "ccbot"])) { outputBuffer.push({ room: data.room, message: "/me slaps " + data.user + " around a bit with a large trout." }); } 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]; outputBuffer.push({ room: data.room, message: "Thanks for the " + amount + " mBTC tip " + data.user + "!" }); } if (contains(data.message, ["!flip"])) { var res = (Math.random() > 0.5 ? "heads" : "tails"); socket.emit("chat", { room: data.room, message: "Flipping coin: " + res + "!" }); } });
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; } There isn't any formal documentation for the API yet, but look through the chat client code here to reverse-engineer it (it's really simple if you know socket.io). Feel free to ask any questions here, or /pm admin
|
|
|
|
vlees
|
|
June 01, 2013, 10:48:17 PM |
|
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]; outputBuffer.push({room: data.room, message: "Thanks for the " + amount + " mBTC tip " + data.user + "!"}); }
Wouldn't it make more sense to send a 'tip' event instead of parsing the text from a chat message?
|
BEEP BEP
|
|
|
🏰 TradeFortress 🏰 (OP)
Bitcoin Veteran
VIP
Legendary
Offline
Activity: 1316
Merit: 1043
👻
|
|
June 02, 2013, 08:23:49 AM |
|
It would, but this is how it works now on the server.
|
|
|
|
ondratra
|
|
June 02, 2013, 11:43:12 AM |
|
Can you explain me in short what it is supposed to do? And the code is JS?
|
|
|
|
ondratra
|
|
June 02, 2013, 11:43:55 AM |
|
I take off JS question :D i checked topic label too late
|
|
|
|
bayu41
Newbie
Offline
Activity: 39
Merit: 0
|
|
June 29, 2013, 09:00:26 AM |
|
can you give me tutorial to create Bot...? please.... PM me... i want create
|
|
|
|
Shinodan
Member
Offline
Activity: 63
Merit: 10
|
|
June 29, 2013, 08:13:20 PM |
|
I cant get this to run without an error, probably doing it wrong, any more advice? it says error on line 1 or something :/
|
Lisk
|
|
|
whydifficult
|
|
June 30, 2013, 03:02:57 PM |
|
I cant get this to run without an error, probably doing it wrong, any more advice? it says error on line 1 or something :/
Could you post the error? That way we can see what's wrong.
|
Gekko a nodejs bitcoin trading bot! Realtime Bitcoin Globe - visualizing all transactions and blocks Tip jar (BTC): 1KyQdQ9ctjCrGjGRCWSBhPKcj5omy4gv5S
|
|
|
🏰 TradeFortress 🏰 (OP)
Bitcoin Veteran
VIP
Legendary
Offline
Activity: 1316
Merit: 1043
👻
|
|
July 01, 2013, 01:03:48 AM |
|
I cant get this to run without an error, probably doing it wrong, any more advice? it says error on line 1 or something :/
You probably need socket.io client.
|
|
|
|
Shinodan
Member
Offline
Activity: 63
Merit: 10
|
|
July 01, 2013, 12:19:45 PM |
|
|
Lisk
|
|
|
whydifficult
|
|
July 01, 2013, 05:23:55 PM Last edit: July 01, 2013, 09:07:36 PM by whydifficult |
|
Windows doesn´t understand what you are trying to do with the command `socket io-client`, neither am I for that matter.
You can run a node script by typing in `node [scriptname]` instead of just the name of the script.
EDIT: so you can use the script provided by the OP, this means: copy and paste the script in a file, call it something.js and put it in the same directory. After that you can run it using node in your terminal.
|
Gekko a nodejs bitcoin trading bot! Realtime Bitcoin Globe - visualizing all transactions and blocks Tip jar (BTC): 1KyQdQ9ctjCrGjGRCWSBhPKcj5omy4gv5S
|
|
|
bayu41
Newbie
Offline
Activity: 39
Merit: 0
|
|
July 08, 2013, 11:05:28 PM |
|
How to Install node.js and socket.io-client? give tutor please
|
|
|
|
assortmentofsorts
Member
Offline
Activity: 91
Merit: 10
|
|
July 09, 2013, 06:00:32 PM |
|
Create a JS file with the code provided by tradefortress (lets call it botkit.js). Then from your command prompt, run: "node botkit.js"
|
If you want to tip: BTC 1KbjTUEfcziwMv7BMXcjmvNAKEpTJbZCsF
|
|
|
assortmentofsorts
Member
Offline
Activity: 91
Merit: 10
|
|
July 09, 2013, 06:01:57 PM |
|
How to Install node.js and socket.io-client? give tutor please
Whats your OS?
|
If you want to tip: BTC 1KbjTUEfcziwMv7BMXcjmvNAKEpTJbZCsF
|
|
|
whiskers75
|
|
July 10, 2013, 06:27:14 AM Last edit: July 10, 2013, 08:37:52 AM by whiskers75 |
|
Argh, I'll make an API later EDIT: If you want a REAL functioning example of a bot, check out the source code of WhiskDiceBot (a bot like SatoshiDice): https://github.com/whiskers75/coinchat-bot
|
|
|
|
cronopio
Newbie
Offline
Activity: 55
Merit: 0
|
|
July 24, 2013, 05:12:02 AM |
|
THank you all!
All this was so helpful!!
|
|
|
|
faiza1990
Sr. Member
Offline
Activity: 420
Merit: 250
★☆★777Coin★☆★
|
|
August 16, 2013, 03:16:27 PM |
|
How to Install node.js and socket.io-client?
|
|
|
|
tspacepilot
Legendary
Offline
Activity: 1456
Merit: 1081
I may write code in exchange for bitcoins.
|
|
August 17, 2013, 06:07:00 AM |
|
I've really enjoyed making and testing bots on coinchat. It's taught me a lot about node.js and socket.io I really appreciate the opportunity!
|
|
|
|
tspacepilot
Legendary
Offline
Activity: 1456
Merit: 1081
I may write code in exchange for bitcoins.
|
|
August 17, 2013, 06:16:55 AM |
|
How to Install node.js and socket.io-client?
Depends on your OS. I'm running debian wheezy. I just got the source and did ./configure && make && make install (basically).
|
|
|
|
🏰 TradeFortress 🏰 (OP)
Bitcoin Veteran
VIP
Legendary
Offline
Activity: 1316
Merit: 1043
👻
|
|
August 18, 2013, 12:37:31 PM |
|
I've really enjoyed making and testing bots on coinchat. It's taught me a lot about node.js and socket.io I really appreciate the opportunity!
Glad to hear that
|
|
|
|
|