summaryrefslogtreecommitdiffstats
path: root/scripts/bgta.pl
blob: 3b388e3a766b4f71be34e91db337b877bdc05ddb (plain)
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/usr/local/bin/perl

# BgTA SCRIPT

use strict;
use vars qw($VERSION %IRSSI %FEATURES);

use Irssi;

# Define Script Version
$VERSION = '0.0.1';
%IRSSI = (
	authors		=> '[^BgTA^]',
	contact		=> 'raul@bgta.net',
	name		=> 'BgTA Script',
	description	=> 'Byte\'s Gallery of the TAilor Script',
	license		=> 'Public Domain',
);

# /bgversion command

sub cmd_bgversion {
	my ($data, $server, $witem) = @_;

	print("\cC4BgTA Script v. ".$VERSION);
	foreach my $key (sort keys %IRSSI) {
		print("\cC4$key: \cC0".$IRSSI{$key}) unless $key =~ /name/i;
	}
	return 1;
}

Irssi::command_bind bgversion => \&cmd_bgversion;

# /bghelp command
$FEATURES{'help'} = "/bghelp \c0 List the BgTA Script FEATURES";

sub cmd_bghelp {
	my ($data, $server, $witem) = @_;

	print("\cC4BgTA Script v. ".$VERSION);
	foreach my $key (sort keys %FEATURES) {
		print("\cC4$key: \cC0".$FEATURES{$key}) unless $key =~ /name/i;
	}
	return 1;
}

Irssi::command_bind bghelp => \&cmd_bghelp;
# GOOGLE
$FEATURES{'google'} = "/bggoogle \cC7search_string \t \cC5Search one result in Google.com";

sub cmd_bggoogle {
	my ($data, $server, $witem) = @_;

	return unless $witem;


	use Net::Google;
	
	# Put here the Google Key. See Google->Tools & Services
	use constant LOCAL_GOOGLE_KEY => "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";

	$witem->command("me Google Searching [$data]...");
	my $google = Net::Google->new(key=>LOCAL_GOOGLE_KEY);

	my $search = $google->search(max_results => 100);

	 $search->query($data);

	 my @tresults = @{$search->results()};

	if(!defined($tresults[0])) {
		$witem->command("me NO RESULTS");
		return;
	}
	my $title = $tresults[0]->title();
	$title =~ s/<[^<]*>//ig;
	$witem->command("me ".$title."\cC2: ".$tresults[0]->URL());
	return;
}

Irssi::command_bind bggoogle => \&cmd_bggoogle;

# PHP Documentation
$FEATURES{'php'} = "/bgphp \cC7function_name \t \cC5Search a PHP Function URL and Definition";
$FEATURES{'phpwb'} = "/bgphpwb \cC7function_name \t \cC5Search a PHP Function URL and Definition AND Kick BAN With the URL";
sub cmd_bgphp {

	my ($data, $server, $witem) = @_;

	return unless $witem;


	use LWP;

	my $Navigator = new LWP::UserAgent({
        "agent" => "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
        "timeout" => "180", 
        });

	$data =~ s/\_/\-/ig;

	my $Page = $Navigator->get('http://www.php.net/manual/es/function.'.$data.'.php');
	
	my $content = $Page->content if $Page->is_success;
	if($Page->is_success && $content =~ /([^<]*)<B\nCLASS=\"methodname\"\n>([^<]*)<\/B\n> ([^<]*)/i) {
		$witem->command("me PHP Function $data:");
		$witem->command("me Location: \cC5 http://www.php.net/manual/es/function.".$data.'.php');
		if($content =~ /<td><a href=\"ref.([^\.]*).php\">/i) {
			$witem->command("me Reference: \cC6 http://www.php.net/manual/es/ref.$1.php");
		}
		if($content =~ />([^<]*)<B\nCLASS=\"methodname\"\n>([^<]*)<\/B\n> ([^<]*)/i) {
			$witem->command("me $1\cC0$2\cC $3");
		}
		if($content =~ /--\&nbsp;([A-Za-z0-9\ �����\n]+)/i) {
			my $sal = $1;
			$sal =~ s/\ \ /\ /gi;
			$sal =~ s/\n/\ /gi;
			chomp($sal);
			$witem->command("me Description: $sal");
		}
	} else {
		$witem->command("me \cC5PHP Function $data: No Results.");
	}

	return;

}

sub cmd_bgphpwb {

	my ($data, $server, $witem) = @_;

	return unless $witem;


	use LWP;

	my $Navigator = new LWP::UserAgent({
        "agent" => "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
        "timeout" => "180", 
        });
	
	$data =~ /^([^\ ]*) (.*)$/i;
	my $nick = $1;
	$data = $2;
	$data =~ s/\_/\-/ig;

	my $Page = $Navigator->get('http://www.php.net/manual/es/function.'.$data.'.php');
	
	my $content = $Page->content if $Page->is_success;
	if($Page->is_success && $content =~ /([^<]*)<B\nCLASS=\"methodname\"\n>([^<]*)<\/B\n> ([^<]*)/i) {
		$witem->command("kickban $nick Mira el Jodido Manual: \cC5 http://www.php.net/manual/es/function.".$data.'.php');
	} 

	return;

}
sub bgphpevent {
	my ($server, $data, $nick, $address) = @_;
	my ($target, $text) = $data =~ /^(\S*)\s:(.*)/;

	#if($text =~ /bgphp:(.*)$/) {
	#}	

}
Irssi::signal_add("event notice", "bgphpevent");
Irssi::command_bind bgphp => \&cmd_bgphp;
Irssi::command_bind bgphpwb => \&cmd_bgphpwb;


#  WEB SEARCH TITLE
$FEATURES{'wwwd'} = "/bgwwwd \cC7http://some.web.com/ \t \cC5Look for title and Description of Web";
sub cmd_bgwwwd {

	my ($data, $server, $witem) = @_;

	return unless $witem;


	use LWP;

	my $Navigator = new LWP::UserAgent({
        "agent" => "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
        "timeout" => "180", 
        });

	my $Page = $Navigator->get($data);

	if($Page->is_success) {
		my $content = $Page->content;
		my $title = "No Title";
		my $description = "No Description Page";

		if($content =~ /TITLE>([^<]*)<\/TITLE>/i) {
			$title = $1;
		}

		if($content =~ /META NAME=\"DESCRIPTION\" CONTENT=\"([^\"]*)\"/i) {
			$description = $1;
		}
		$witem->command("me [ $data ]: ".$title);
		$witem->command("me \cC5 $description");
	} else {
		$witem->command("me [ $data ] Page Not Found");
	}
}

Irssi::command_bind bgwwwd => \&cmd_bgwwwd;


# Perl Documentation
$FEATURES{'perl'} = "/bgperl \cC7function_name \t \cC5Search a Perl Function URL and Definition";
sub cmd_bgperl {

	my ($data, $server, $witem) = @_;

	return unless $witem;


	use LWP;

	my $Navigator = new LWP::UserAgent({
        "agent" => "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
        "timeout" => "180", 
        });

	my $Page = $Navigator->get('http://www.perldoc.com/perl5.8.0/pod/func/'.$data.'.html');
	
	my $content = $Page->content if $Page->is_success;
	if($Page->is_success && $content =~ /<span class=\"docTitle\">([^<]*)<\/span>/i) {
		$witem->command("me Perl Function $data:");
		$witem->command("me Location: \cC5 http://www.perldoc.com/perl5.8.0/pod/func/".$data.'.html');
		if($content =~ /<DL><DT><A NAME=\"[^\"]*\">(.*)\n/i) {
			$witem->command("me \cC0$1");
		}
		if($content =~ /<DT><A NAME=\"$data\">$data\n\n<\/A><\/DT>\n<DD>\n([^\n]*)/i) {
			$witem->command("me $1");
		}
	} else {
		$witem->command("me \cC5Perl Function $data: No Results.");
	}

	return;

}
Irssi::command_bind bgperl => \&cmd_bgperl;

# Debian Search Packages
$FEATURES{'debian'} = "/bgdebian \cC7package name | \cC5Search a package in a Debian stable distribution";
sub cmd_bgdebian {

	my ($data, $server, $witem) = @_;

	return unless $witem;


	use LWP;

	my $Navigator = new LWP::UserAgent({
        "agent" => "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
        "timeout" => "180", 
        });

	$data =~ s/\ /\+/;
	my $Page = $Navigator->get('http://packages.debian.org/cgi-bin/search_packages.pl?keywords='.$data.'&searchon=names&subword=1&version=stable&release=all');
	
	my $content = $Page->content if $Page->is_success;
	if($Page->is_success && $content =~ /<TD><B><A HREF=\"http:\/\/packages\.debian\.org\/stable\/misc\/([^\.]*).html\"> $data/i) {
		$witem->command("me Debian \cC2$data\cC package:");
		$witem->command("me Location: \cC5 http://packages.debian.org/stable/misc/$1.html");
		if($content =~ /<TD COLSPAN=2>([^<]*)</i) {
			$witem->command("me Description: $1");
		}
	} else {
		$witem->command("me \cC5Debian $data package: No Results.");
	}

	return;

}
Irssi::command_bind bgdebian => \&cmd_bgdebian;
1;