a integrated plurk bot written with php-plurk-api
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.



It's an integrated class that you can design you plurk bot easily with shark. I'm still working on it and try to make it more user-friendly. In this way, you can happily design your own bot to keep watch any plurk posted by your friends and make a instant response to it!


You have to download php-plurk-api from Here and then require plurk_api.php and shark.php shark.core.php together in your_bot.php. After some configurations set , it's time to swim with it !

Here comes the demo of installation (your_bot.php) flow:


    $apikey = 'xxx';
    $username = 'test';
    $password = 'test';

    /*Shark Instance 1*/
    $plurk = new shark();
    $plurk->set_responses('I detect "token" and leave the response by Shark');

    /*Shark Instance 2*/
    $plurk2 = new shark();
    $plurk2->set_responses('Im shark, I can automatically plurk on 2010-03-06 at 14:01:10');
    $plurk2->set_mode(2,array("2010-03-06 14:01:10"));

    $sharkCore = new SharkCore();
    $sharkCore -> add($plurk);
    $sharkCore -> add($plurk2);
    $sharkCore -> run();

Usage for sharkCore class


(Optional) $infi: to swim with shark infinitely or not. The defalut is true.
(Optional) $timezone: the timezone for shark. The default is 'Asia/Taipei'.
(Optional) $logname: It is shark's log name but it's not used now. The default is 'sharklog'
    new sharkCore($infi,$timezone,$logname)


Add instances of shark.

$sharkInstance: you can specify plenty of shark instances if you want.
$this->add(shark $sharkInstance)


SharkCore will call each run() method in each shark instance.


Usage for shark class


(Optional) $logname: It is shark's log name that can memorize the permanent link of the plurk. The default is 'sharklog'

    new shark($logname)


it's default action designed in php-plurk-api. You have to pass 3 parameters as follows:

$api: Your API key
$username: Your username
$password: Your password



You can choose which word to match.
Because I use mb_ereg here(to support multi-byte words),you can use any regular expression which is POSIX extended.

$token: Your specific matching word (or "POSIX Regex" here)
(Optional) $qualifier: When match this qualifier, Shark will respond. The default is 'Thinks'.





You can decide what the responses will be.
If you use a relative path for a JSON-type list for responses (separated by '\n'), you can just put the link here!
Shark will automatically check whether the file exists or not  then do the proper action.

$response: Your response (string or array is fine) or a file or a specific link with prefix "http://"
(Optional) $qualifier: It is the qualifier that will be used when you respond. The default is 'says'.



    $this->set_responses("Hello! Im a shark!","thinks");





The most important thing I have to remind is that you have to use the JSON type for storing the file like this:

    {"Hi, ":"this ","is ":"shark."}

    Shark will automatically turn the key and value into your response in Plurk like this:

    >> Hi, this is shark.

It is easy , isn't it !?

You can decide whether random your responses or not.
$trueOrFalse: Your decision, true or false.



You can choose to save the shark's log or not. BTW, two records are saved as "sharlog" for each plurk. 
One is "posted time" and the other is "permanent link". And all of them are wrapped in JSON format at the same time.

$choice: true or false. The default is true



You can set the time limitations to decrease the API calls so that you will not run over the 50000 calls per day.
BTW, it's optional method. The default time limitation is 1 second.

$limit: It's your time limitations . The unit is "Second"



Run the program
It's recommended to run Shark through SharkCore!!

h.Modes (it's increasing)

It's a new design for Shark. You can design your own modes or use the written modes by me.

0) Mode0: "It's a special mode reserved for you if you want to design your style!"
You just have to inherit the Shark class then design!!

1) Mode1: "When matching words appear, you can reponde it once ."
You have to set your rules and response files correctly. and then use the sharkCore to run it.

    $shark = new shark();
    $shark->login($api_key[1], $username, $password);

2) Mode2: "You can plurk specific content when time's up ."
You have to set your content(for convenince, I choose set_responses method here, but dont be confused) and the time.
! The most important thing is that you have to set time limitation to "1", otherwise Shark wont count correctly.
! Content 1 matches task 1 and content 2 matches task 2 and vice versa. (matching in sequence)
! Mode 2 supports two formats of time. One is "HH:mm:ss" while the other one is "YY-MM-DD HH:mm:ss"

    $shark2 = new shark();
    $shark2->login($api_key[1], $username, $password);
    $shark2->set_mode(2,array("19:33:00","2010-03-08 19:32:50"));

You can put many shark instances in one sharkCore to run together!!

    $sharkCore = new sharkCore();

That's it!! Everythin is done ! time to swim with our sharks now!!

!One thing I have to remind you is not to put mode1 and mode2 together, it will make mode2 count time wrongly.
!The reason why this will happen is because mode1 will spend more than 1 sec matching tokens then make mode2 wrong.


In order to extend the flexibility of shark, I inherit the class from php-plurk-api. 
This means that you can use any method from the class as you wish! Here comes some useful methods from the class:


If you want to know more methods about this, just go to the official site of php-plurk-api to check it !


This program is advised to run on Command Line Interface(CLI).


EragonJ@hax4.in 陳佳隆

Email: jack.xxlong@gmail.com

Blog: Here