cakebot /vendors/php-irc/modules/bash/bash_mod.php

Language PHP Lines 179
MD5 Hash 7c5a8a785d17337c473994af20728e43 Estimated Cost $3,454 (why?)
Repository git://github.com/cakephp/cakebot.git View Raw File View Project SPDX
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
<?php
/* SVN FILE: $Id$ */
class bash_mod extends module {

	public $title = "Bash Parser";
	public $author = "Manick";
	public $version = "0.1";

	private $delay = 0;

	public function priv_bash($line, $args)
	{
		$channel = $line['to'];
		$random = false;

		if (strpos($channel, "#") === false)
		{
			return;
		}

		if ($this->ircClass->getStatusRaw() != STATUS_CONNECTED_REGISTERED)
		{
			return;
		}

		if (time() < $this->delay)
		{
			$this->ircClass->notice($line['fromNick'], "Please wait " . ($this->delay - time()) . " seconds before using this function again.", 0);
			return;
		}

		//?search=test&sort=0&show=25

		if ($args['nargs'] > 0)
		{
			if ($args['arg1'] == "+")
			{
				$random = true;
				$query = "random1&show=1";
			}
			else if ($args['arg1'] == "-")
			{
				$this->ircClass->notice($line['fromNick'], "This is an unsupported function.");
				return;
			}
			else
			{
				$num = $args['arg1'];
				if (substr($num, 0, 1) == "#")
				{
					$num = substr($num, 1);
				}
				$num = intval($num);

				if ($num <= 0)
				{
					$search = urlencode($args['query']);
					$random = true;
					$query = "search=".$search."&show=1&sort=0";
				}
				else
				{
					$query = "$num";
				}
			}
		}
		else
		{
			$random = true;
			$query = "random&show=1";
		}

		$line['channel'] = $channel;
		$line['random'] = $random;

		$host = "www.bash.org";
		$port = 80;
		$path = "/";

		$getQuery = socket::generateGetQuery($query, $host, $path, "1.0");

		$this->ircClass->addQuery($host, $port, $getQuery, $line, $this, "priv_bash_stageTwo");


	}

	public function priv_bash_stageTwo($line, $args, $result, $data)
	{
		if ($result == QUERY_ERROR)
		{
			$this->ircClass->notice($line['fromNick'], "An error was encountered: " . $data);
			return;
		}

		$channel = $line['channel'];
		$random = $line['random'];

		$data = preg_replace("/\r/i", "", $data);
		preg_match_all("/<p class=\"quote\">(.+?)<\/p><p class=\"qt\">(.+?)<\/p>/is", $data, $dataArray, PREG_PATTERN_ORDER);

		$num = 0;

		$t_count = count($dataArray[2]);

		$our = rand(0, $t_count - 1);

		for ($i = 0; $i < $our - 1; $i++)
		{
			array_shift($dataArray[2]);
			array_shift($dataArray[1]);
		}

		foreach ($dataArray[2] AS $index => $item)
		{
			if (trim($item) != "")
			{
				$item = str_replace("<br />", "", $item);
				$item = html_entity_decode($item, ENT_QUOTES);

				$newLines = substr_count($item, "\n");

				if ($random == true)
				{
					if ($newLines > 20)
					{
						continue;
					}
				}
				else
				{
					if ($newLines > 20)
					{
						$this->ircClass->notice($line['fromNick'], "The quote to be displayed was over the required 20 line limit. ($newLines lines)");
						return;
					}
				}

				$num = $dataArray[1][$index];
				$num = preg_replace("/<(.+?)>/i", "", $num);
				 $offsetA = strpos($num, "(");
				 $offsetB = strpos($num, ")");
				$rating = substr($num, $offsetA + 1, $offsetB - $offsetA - 1);
				$num = intval(trim(substr($num, 1, strpos($num, chr(32)))));

				break;

			}

		}
		if ($num == 0)
		{
			if ($random == true)
			{
				$this->ircClass->notice($line['fromNick'], "None of the data returned was short enough to display.  Try again.");

			}
			else
			{
				$this->ircClass->notice($line['fromNick'], "No Data was Returned.");
			}
		}
		else
		{
			$count = 0;
			$items = explode("\n", $item);
			foreach ($items AS $item)
			{
				$this->ircClass->privMsg($channel, BOLD . "Bash #" . $num . BOLD . " (Rating: " . $rating . "): " . $item);
				$count++;
			}
		}

		$this->delay = time() + $count + 3;
	}

}

?>
Back to Top