9826c509e2c7eee67dcb71dc2bc5f35a3111b76c
[PHP-P10.git] / Bots / Quote.class.php
1 <?php
2 class {$_NAME} extends Bot {
3         private $uplink;
4         private $quote;
5         private $topic = false;
6         
7         public function load($uplink, $old = false) {
8                 $this->uplink = $uplink;
9                 if(!$old) {
10                         $nick = "quote";
11                         $ident = "QuoteBot";
12                         $host = "Services.NextIRC.net";
13                         $ip = "127.0.0.1";
14                         $realname = "QuoteBot";
15                         $modes = "ioknISD";
16                         $this->quote = $this->uplink->addUser($nick,$ident,$host,$ip,$modes,$realname);
17                         if(is_a($this->quote, "P10_User")) {
18                                 $this->uplink->join($this->quote, "#lobby", P10_Channel::USERPRIV_OPED);
19                         }
20                 } else {
21                         $this->quote = $old;
22                 }
23                 
24                 ModCMD::bind($this, BIND_CHANMSG, "recive_privmsg");
25                 ModCMD::bind($this, BIND_QUIT, "recive_quit");
26         }
27         
28         public function unload($rehash = false) {
29                 if($rehash) {
30                         return $this->quote;
31                 } else {
32                         $this->uplink->delUser($this->quote, "Bye.");
33                 }
34         }
35         
36         public function loop() {
37                 
38         }
39         
40         public function recive_privmsg($user, $channel, $message) {
41                 $exp=explode(" ", $message, 3);
42                 switch (strtolower($exp[0])) {
43                         case "~bash":
44                                 $quelltext = file_get_contents('http://german-bash.org/action/random');
45                                 preg_match('#<span class="id">(.*?)</span>#is', $quelltext, $t);
46                                 preg_match('#<a(.*?)>(.*?)</a>#is', $t[1], $z);
47                                 preg_match('#<div class="zitat">(.*?)</div>#is', $quelltext, $m);
48                                 $string = nl2br(strip_tags($m[1]));
49                                 $array = explode("<br />", $string);
50                                 $length = count($array)-1;
51                                 $url = file_get_contents('http://tinyurl.com/api-create.php?url=http://german-bash.org/index.php?action=show&id='.str_replace('#', '', $z[2]));
52                                 
53                 foreach($array AS $index=>$value) {
54                                         $array[$index] = trim($value);
55                                 }
56                                 $this->uplink->privmsg($this->quote, $channel, "\ 2\ 39Zitatnummer:\ 2\ 30 ".$z[2]." ".$url);
57                                 for($i = 1; $i <= $length; $i++) {
58                                         if($array[$i] != '' && $array[$i] != '<br />') {
59                                                 $this->uplink->privmsg($this->quote, $channel, html_entity_decode($array[$i]));
60                                         }
61                                 }
62                                 break;
63                         case "~ibash":
64                                 $doc = new DOMDocument();
65                                 @$doc->loadHTMLFile("http://mobil.ibash.de/zitate.php?order=random");
66                                 $tags = $doc->getElementsByTagName('code');
67                                 $codes = $tags->item($id)->childNodes;
68                                 $nas = "90";
69                                 $bash='';
70                                 for ($i = 1; $i < $codes->length; $i++)
71                                 {
72                                         //$text = utf8_decode(htmlspecialchars($codes->item($i)->nodeValue));
73                                         $text = utf8_decode($codes->item($i)->nodeValue);
74                                         $bash = $bash.$text;
75                                 }
76                                 $bash = str_replace("  ", " ", $bash);
77                                 $bash = explode("\n", $bash);
78                                 #sendserv("PRIVMSG $e[2] :\002iBashDE\002");
79                                 $this->uplink->privmsg($this->quote, $channel, "\002iBashDE\002");
80
81                                 $i = 0;
82                                 #$this->uplink->privmsg($this->quote, $channel, print_r($bash));
83                                 foreach($bash as $line) {
84                                         $line = trim($line);
85                                         if(!empty($line)) {
86                                                 $line = str_replace("&lt;", "<", $line);
87                                                 $line = str_replace("&gt;", ">", $line);
88                                                 $line = str_replace("&quot;", '"', $line);
89                                                 #sendserv("PRIVMSG $e[2] :".$line);
90                                                 if($line != '') {
91                                                         $this->uplink->privmsg($this->quote, $channel, $line);
92                                                 } else break;
93                                         }
94                                 }
95                                 break;
96                 }
97         }
98         
99         public function recive_quit($user, $reason) {
100                 if($user === $this->quote) {
101                         $this->load($this->uplink);
102                 }
103         }
104
105 }
106 ?>