3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-26 22:09:26 +01:00
pbot/modules/getcfact.pl
Pragmatic Software bcf76471c8 Add cfact module
2014-07-22 01:46:16 +00:00

23 lines
412 B
Perl
Executable File

#!/usr/bin/env perl
use warnings;
use strict;
my $CFACTS = 'cfacts.txt';
my $text = join(' ', @ARGV);
my @facts;
open my $fh, "<", $CFACTS or die "Could not open $CFACTS: $!";
while (my $fact = <$fh>) {
next if length $text and $fact !~ /\Q$text\E/i;
push @facts, $fact;
}
close $fh;
if (not @facts) {
print "No fact containing text $text found.\n";
} else {
print $facts[int rand(@facts)], "\n";
}