Bot-BasicBot-Pluggable-Module-Pastebin
view release on metacpan or search on metacpan
lib/Bot/BasicBot/Pluggable/Module/PasteBin.pm view on Meta::CPAN
my $period = $self->get("user_tick");
$tick_counter++;
return if ( $tick_counter < $period);
$tick_counter = 0;
my $time = timelocal (localtime());
$self->_check_pastebin();
}
sub _check_nick{
my $self = shift;
my $nick = shift;
my $channel = shift;
return undef unless $nick;
my @nicks = keys %{ $self->{Bot}->{channel_data}->{$channel}};
for (@nicks){
next unless $_;
return 1 if /$nick/ ;
}
return undef;
}
sub _filter_link {
my $self = shift;
my $link = shift;
if ($link =~ /\w{1,9}\"/){
$link =~ />([\w|\s]*)</;
my $nick = $1;
$link =~ /"(.*)"/;
my $url = $1;
$url =~ m#com/(\w*)#;
my $id = $1;
return ($nick, $url, $id);
}else{
return undef;
}
}
sub _check_pastebin {
my $self = shift;
my $url = $self->get("user_pastebin_url");
my $ua = LWP::UserAgent->new;
$ua->agent("Bot/0.1");
my $req = HTTP::Request->new(POST => $url);
$req->content_type('application/x-www-form-urlencoded');
$req->content('query=libwww-perl&mode=dist');
my $res = $ua->request($req);
my $html = $res->content if $res->is_success;
my $LX = new HTML::LinkExtractor();
$LX->parse(\$html);
for my $link ( @{ $LX->links }){
next unless $link->{_TEXT};
my ($nick, $url, $id) = $self->_filter_link($link->{_TEXT});
for my $channel (keys %{ $self->{Bot}->{channel_data}} ){
next unless ($channel =~ /^\#/);
if ($self->_check_nick($nick,$channel)){
open my $fh , "<", "$self->{tmpfile}";
while(<$fh>){
chomp;
return 0 if ($_ =~ /$id/);
}
close $fh;
open $fh, ">>", "$self->{tmpfile}";
print $fh "$id\n";
close $fh;
$self->tell($channel, "$nick just paste in pastebin: $url\n");
}
}
}
}
1;
( run in 0.797 second using v1.01-cache-2.11-cpan-8644d7adfcd )