2 /********************************* PHP-P10 ******************************
3 * P10 uplink class by pk910 (c)2011 pk910 *
4 ************************************************************************
7 * PHP-P10 is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
17 * You should have received a copy of the GNU General Public License *
18 * along with PHP-P10; if not, write to the Free Software Foundation, *
19 * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 ************************************************************************
23 * Bots/ExampleBot.class.php
25 * a simple example bot...
29 class {$_NAME} extends Bot { // {$_NAME} will be replaced by our script later ;)
33 public function load($uplink, $old = false) { //load is called when the module gets included
34 $this->uplink = $uplink; //Reference to the P10 Uplink
36 //$old is only set, if the module is rehashed. It contains the return value of unload();
40 //Here you can define startup actions
41 //We'll add an user to the Server
42 // newuser($localid,$nick,$ident,$host,$realname,$uptime,$modes) returns an array with the result
43 // $localid is just an id you can set (whatever you want) - maybe you'll use it to identify the bot/user later?
45 $nick = "ExampleBot"; // Please note: If this user already exists on another Server it will be killed!
47 $host = "Example.Bot";
48 $realname = "Thats an example Bot :)";
49 $modes = "i"; //we don't need a leading + (that will be added automatically)
51 $this->example_bot = $this->uplink->addUser($nick,$ident,$host,$realname,$uptime,$modes); //addUser($nick, $ident, $host, $ip, $modes, $realname)
52 if(is_a($this->example_bot, "P10_User")) { // A new user was created :)
53 //ok let's join a channel
54 $this->uplink->join($this->example_bot, "#test");
55 //now we want to say something...
56 //but note: thats the startup procedure! the p10 server is not connected to an uplink, yet - so noone would recive our message (only the other bots on this server)
60 $this->example_bot = $old; //We've saved out Bot reference in $old so we can simply use it again...
63 //OK send something to the Server is easy...
64 //How to recive something from the IRC Server?
66 //I've copied the eggdrop way to do that - bind
67 ModCMD::bind($this, BIND_PRIVMSG, "recive_privmsg");
68 ModCMD::bind($this, BIND_QUIT, "recive_quit");
71 public function loop() { //this function is triggered as often as possible (at least one time per second!). Maybe you need it to do timed events
72 //please don't trigger any blocking functions here... that would cause an extreme lagg!
75 public function unload($rehash = false) { //this function is triggered, when the Bot is unloaded... If it's just a rehash the return value of this method is passed to $old in the load method.
76 return $this->example_bot;
79 public function recive_privmsg($user, $channel, $message) {
80 //We've got a privmsg...
81 $exp=explode(" ",$message);
83 $this->uplink->privmsg($this->example_bot, $channel, "Hallo ".$user->getNick()); // We send a message back - documentation is following
85 if($exp[0] == "-users") {
87 foreach($channel->getUsers() as $chan_user) {
89 $privs = $channel->getUserPrivs($chan_user);
90 if(($privs & P10_Channel::USERPRIV_VOICE)) $extra= '+';
91 if(($privs & P10_Channel::USERPRIV_OPED)) $extra= '@';
92 $user_str .= " " . $extra . $chan_user->getNick();
94 $this->uplink->notice($this->example_bot, $user, "User in ".$channel->getName().":".$user_str);
98 function recive_quit($user, $reason) {
99 if($user === $this->example_bot) { //maybe we got killed???
100 $this->load($this->uplink);