3
0
mirror of https://github.com/pragma-/pbot.git synced 2024-11-30 07:59:42 +01:00
pbot/modules/getcfact.pl

23 lines
412 B
Perl
Raw Normal View History

2014-07-22 03:46:16 +02:00
#!/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";
}