2 /******************************* PHP-P10 v2 *****************************
3 * Copyright (C) 2011 Philipp Kreil (pk910) *
5 * This program is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 ************************************************************************
20 * Bots/ExampleBot.class.php
22 * a simple example bot...
26 class {$_NAME} extends Bot { // {$_NAME} will be replaced by our script later ;)
30 public function load($uplink, $old = false) { //load is called when the module gets included
31 $this->uplink = $uplink; //Reference to the P10 Uplink
33 //$old is only set, if the module is rehashed. It contains the return value of unload();
37 //Here you can define startup actions
38 //We'll add an user to the Server
39 // newuser($localid,$nick,$ident,$host,$realname,$uptime,$modes) returns an array with the result
40 // $localid is just an id you can set (whatever you want) - maybe you'll use it to identify the bot/user later?
42 $nick = "ExampleBot"; // Please note: If this user already exists on another Server it will be killed!
44 $host = "Example.Bot";
45 $realname = "Thats an example Bot :)";
46 $modes = "i"; //we don't need a leading + (that will be added automatically)
48 $this->example_bot = $this->uplink->addUser($nick,$ident,$host,$realname,$uptime,$modes); //addUser($nick, $ident, $host, $ip, $modes, $realname)
49 if(is_a($this->example_bot, "P10_User")) { // A new user was created :)
50 //ok let's join a channel
51 $this->uplink->join($this->example_bot, "#test");
52 //now we want to say something...
53 //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)
57 $this->example_bot = $old; //We've saved out Bot reference in $old so we can simply use it again...
60 //OK send something to the Server is easy...
61 //How to recive something from the IRC Server?
63 //I've copied the eggdrop way to do that - bind
64 ModCMD::bind($this, BIND_PRIVMSG, "recive_privmsg");
65 ModCMD::bind($this, BIND_QUIT, "recive_quit");
68 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
69 //please don't trigger any blocking functions here... that would cause an extreme lagg!
72 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.
74 return $this->example_bot;
76 $this->uplink->delUser($this->example_bot, "Bye.");
80 public function recive_privmsg($user, $channel, $message) {
81 //We've got a privmsg...
82 $exp=explode(" ",$message);
84 $this->uplink->privmsg($this->example_bot, $channel, "Hallo ".$user->getNick()); // We send a message back - documentation is following
86 if($exp[0] == "-users" && is_a($channel, "P10_Channel")) {
88 foreach($channel->getUsers() as $chan_user) {
90 $privs = $channel->getUserPrivs($chan_user);
91 if(($privs & P10_Channel::USERPRIV_VOICE)) $extra= '+';
92 if(($privs & P10_Channel::USERPRIV_OPED)) $extra= '@';
93 $user_str .= " " . $extra . $chan_user->getNick();
95 $this->uplink->notice($this->example_bot, $user, "User in ".$channel->getName().":".$user_str);
99 function recive_quit($user, $reason) {
100 if($user === $this->example_bot) { //maybe we got killed???
101 $this->load($this->uplink);