1 ################################
3 ################################
5 # The canonical filters should be installed on your path somewhere.
6 # You can get the source from these from your local distributor.
8 package BotModules::Filter;
11 @ISA = qw(BotModules);
32 '' => 'This module is an interface to the text filter applications.',
35 $reply->{$_} = "Pass the text through the $_ filter. Syntax: $_ <text>";
37 if ($self->isAdmin($event)) {
38 $reply->{'filtersay'} = "Pass text through a filter and send it to a channel. Syntax: filtersay <filter> <channel> <text>";
45 my ($event, $message) = @_;
47 if ($message =~ /^\s*\Q$_\E\s+(.+?)\s*$/si) {
48 $self->spawnChild($event, sub { return $self->Filter(@_); }, [$_, $1], 'filter', []);
49 return 0; # we've dealt with it, no need to do anything else.
50 } elsif (($message =~ /^\s*filtersay\s+\Q$_\E\s+(\S+)\s+(.+?)\s*$/si) and ($self->isAdmin($event))) {
51 $self->spawnChild($event, sub { return $self->Filter(@_); }, [$_, $2], 'filter', [$1]);
52 return 0; # we've dealt with it, no need to do anything else.
55 return $self->SUPER::Told(@_);
60 my($filter, $text) = @_;
64 my $pid = open2($reader, $writer, $filter);
67 my $reply = <$reader>;
73 # ChildCompleted - Called when a child process has quit
76 my ($event, $type, $output, @data) = @_;
77 if ($type eq 'filter') {
78 local $event->{'target'} = $data[0] if defined($data[0]);
79 $self->say($event, $output);
81 return $self->SUPER::ChildCompleted(@_);