Bitcoin Forum
April 19, 2024, 08:54:04 AM *
News: Latest Bitcoin Core release: 26.0 [Torrent]
 
   Home   Help Search Login Register More  
Warning: One or more bitcointalk.org users have reported that they strongly believe that the creator of this topic is a scammer. (Login to see the detailed trust ratings.) While the bitcointalk.org administration does not verify such claims, you should proceed with extreme caution.
Pages: [1]
  Print  
Author Topic: (Node.js) Build your own bot kit for CoinChat  (Read 4524 times)
🏰 TradeFortress 🏰 (OP)
Bitcoin Veteran
VIP
Legendary
*
Offline Offline

Activity: 1316
Merit: 1043

👻


View Profile
April 27, 2013, 09:27:44 AM
Last edit: August 23, 2013, 11:16:22 AM by TradeFortress
 #1

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:

Code:
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
1713516844
Hero Member
*
Offline Offline

Posts: 1713516844

View Profile Personal Message (Offline)

Ignore
1713516844
Reply with quote  #2

1713516844
Report to moderator
1713516844
Hero Member
*
Offline Offline

Posts: 1713516844

View Profile Personal Message (Offline)

Ignore
1713516844
Reply with quote  #2

1713516844
Report to moderator
1713516844
Hero Member
*
Offline Offline

Posts: 1713516844

View Profile Personal Message (Offline)

Ignore
1713516844
Reply with quote  #2

1713516844
Report to moderator
"There should not be any signed int. If you've found a signed int somewhere, please tell me (within the next 25 years please) and I'll change it to unsigned int." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1713516844
Hero Member
*
Offline Offline

Posts: 1713516844

View Profile Personal Message (Offline)

Ignore
1713516844
Reply with quote  #2

1713516844
Report to moderator
1713516844
Hero Member
*
Offline Offline

Posts: 1713516844

View Profile Personal Message (Offline)

Ignore
1713516844
Reply with quote  #2

1713516844
Report to moderator
vlees
Full Member
***
Offline Offline

Activity: 196
Merit: 100



View Profile
June 01, 2013, 10:48:17 PM
 #2

Code:
						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 Offline

Activity: 1316
Merit: 1043

👻


View Profile
June 02, 2013, 08:23:49 AM
 #3

It would, but this is how it works now on the server.
ondratra
Sr. Member
****
Offline Offline

Activity: 350
Merit: 250



View Profile
June 02, 2013, 11:43:12 AM
 #4

Can you explain me in short what it is supposed to do? And the code is JS?
ondratra
Sr. Member
****
Offline Offline

Activity: 350
Merit: 250



View Profile
June 02, 2013, 11:43:55 AM
 #5

I take off JS question Cheesy:D i checked topic label too late Cheesy
bayu41
Newbie
*
Offline Offline

Activity: 39
Merit: 0



View Profile
June 29, 2013, 09:00:26 AM
 #6

can you give me tutorial to create Bot...?
please.... PM me...
i want create
Shinodan
Member
**
Offline Offline

Activity: 63
Merit: 10



View Profile
June 29, 2013, 08:13:20 PM
 #7

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
Sr. Member
****
Offline Offline

Activity: 287
Merit: 250



View Profile WWW
June 30, 2013, 03:02:57 PM
 #8

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 Offline

Activity: 1316
Merit: 1043

👻


View Profile
July 01, 2013, 01:03:48 AM
 #9

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 Offline

Activity: 63
Merit: 10



View Profile
July 01, 2013, 12:19:45 PM
 #10

http://gyazo.com/ad19b327d55d22729e7c14b43fe2ecae <screenshot

Lisk
whydifficult
Sr. Member
****
Offline Offline

Activity: 287
Merit: 250



View Profile WWW
July 01, 2013, 05:23:55 PM
Last edit: July 01, 2013, 09:07:36 PM by whydifficult
 #11

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 Offline

Activity: 39
Merit: 0



View Profile
July 08, 2013, 11:05:28 PM
 #12

How to Install node.js and socket.io-client?
give tutor please
assortmentofsorts
Member
**
Offline Offline

Activity: 91
Merit: 10



View Profile
July 09, 2013, 06:00:32 PM
 #13


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 Offline

Activity: 91
Merit: 10



View Profile
July 09, 2013, 06:01:57 PM
 #14

How to Install node.js and socket.io-client?
give tutor please

Whats your OS?

If you want to tip: BTC 1KbjTUEfcziwMv7BMXcjmvNAKEpTJbZCsF
whiskers75
Hero Member
*****
Offline Offline

Activity: 658
Merit: 502


Doesn't use these forums that often.


View Profile
July 10, 2013, 06:27:14 AM
Last edit: July 10, 2013, 08:37:52 AM by whiskers75
 #15

Argh, I'll make an API later Tongue

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

Elastic.pw Elastic - The Decentralized Supercomputer
ELASTIC ANNOUNCEMENT THREAD | ELASTIC SLACK | ELASTIC FORUM
cronopio
Newbie
*
Offline Offline

Activity: 55
Merit: 0


View Profile
July 24, 2013, 05:12:02 AM
 #16

THank you all!

All this was so helpful!!
faiza1990
Sr. Member
****
Offline Offline

Activity: 420
Merit: 250


★☆★777Coin★☆★


View Profile
August 16, 2013, 03:16:27 PM
 #17

How to Install node.js and socket.io-client?

tspacepilot
Legendary
*
Offline Offline

Activity: 1456
Merit: 1076


I may write code in exchange for bitcoins.


View Profile
August 17, 2013, 06:07:00 AM
 #18

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 Offline

Activity: 1456
Merit: 1076


I may write code in exchange for bitcoins.


View Profile
August 17, 2013, 06:16:55 AM
 #19

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 Offline

Activity: 1316
Merit: 1043

👻


View Profile
August 18, 2013, 12:37:31 PM
 #20

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 Smiley
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!