Amethyst

 view release on metacpan or  search on metacpan

Amethyst/Brain/BarWench.pm  view on Meta::CPAN

package Amethyst::Brain::BarWench;

use strict;
use vars qw(@ISA);
use URI;
use Amethyst::Brain;
use Amethyst::Message;

@ISA = qw(Amethyst::Brain);

sub reply_to {
	my $self = shift;
	my $message = $self->SUPER::reply_to(@_);
	# $message->channel('spam');
	return $message;
}

sub init {
	my $self = shift;

	my %funcs = map { $_ => \&{"action_$_"} } qw(
					help beer caffeine coffee beat pebkac sex npi
					fuckup pissybeer base http hotornot jobs
					rtfs rtfm rtfc
						);

	$self->{Funcs} = \%funcs;

	$self->{Http} = [ ];
	$self->{Hotornot} = [ ];
	$self->{Jobs} = [ ];
	$self->{HttpHash} = { };
}

sub record_http {
	my ($self, $message) = @_;

	my $content = $message->content;

	return undef if $content =~ /Recorded/;

	my @http = ($content =~ m,(http(?:s)?://[^/]\S*),g);

	@http = map { URI->new($_)->canonical->as_string } @http;

	foreach my $url (@http) {
		next if $self->{HttpHash}->{$url};

		my $old = undef;
		my $new = [ $url, $message->user ];

		$self->{HttpHash}->{$url} = 1;

		if ($url =~ m/hotornot/) {
			push(@{ $self->{Hotornot} }, $new);
			$old = shift(@{ $self->{Hotornot} })
							if @{$self->{Hotornot}} > 10;
		}
		else {
			push(@{ $self->{Http} }, $new);
			$old = shift(@{ $self->{Http} })
							if @{$self->{Http}} > 10;
		}

		if ($content =~ m/job/i) {
			push(@{ $self->{Jobs} }, $new);
			$old = shift(@{ $self->{Jobs} })
							if @{$self->{Jobs}} > 10;
		}

		delete $self->{HttpHash}->{$old->[0]} if $old;
	}
}



( run in 2.810 seconds using v1.01-cache-2.11-cpan-364913b4093 )