2 /******************************* PHP-P10 v2 *****************************
3 * Copyright (C) 2011-2012 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";
46 $realname = "Thats an example Bot :)";
47 $modes = "i"; //we don't need a leading + (that will be added automatically)
49 $this->example_bot = $this->uplink->addUser($nick, $ident, $host, $ip, $modes, $realname); //addUser($nick, $ident, $host, $ip, $modes, $realname)
50 if(is_a($this->example_bot, "P10_User")) { // A new user was created :)
51 //ok let's join a channel
52 $this->uplink->join($this->example_bot, "#test");
53 //now we want to say something...
54 //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)
58 $this->example_bot = $old; //We've saved out Bot reference in $old so we can simply use it again...
61 //OK send something to the Server is easy...
62 //How to recive something from the IRC Server?
64 //I've copied the eggdrop way to do that - bind
65 ModCMD::bind($this, BIND_PRIVMSG, "recive_privmsg");
66 ModCMD::bind($this, BIND_QUIT, "recive_quit");
69 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
70 //please don't trigger any blocking functions here... that would cause an extreme lagg!
73 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.
75 return $this->example_bot;
77 $this->uplink->delUser($this->example_bot, "Bye.");
81 public function recive_privmsg($user, $channel, $message) {
82 //We've got a privmsg...
83 $exp=explode(" ",$message);
85 $this->uplink->privmsg($this->example_bot, $channel, "Hallo ".$user->getNick()); // We send a message back - documentation is following
87 if($exp[0] == "-users" && is_a($channel, "P10_Channel")) {
89 foreach($channel->getUsers() as $chan_user) {
91 $privs = $channel->getUserPrivs($chan_user);
92 if(($privs & P10_Channel::USERPRIV_VOICE)) $extra= '+';
93 if(($privs & P10_Channel::USERPRIV_OPED)) $extra= '@';
94 $user_str .= " " . $extra . $chan_user->getNick();
96 $this->uplink->notice($this->example_bot, $user, "User in ".$channel->getName().":".$user_str);
100 function recive_quit($user, $reason) {
101 if($user === $this->example_bot) { //maybe we got killed???
102 $this->load($this->uplink);