mirror of
https://github.com/pragma-/pbot.git
synced 2024-10-01 17:16:39 +02:00
47 lines
1021 B
Perl
47 lines
1021 B
Perl
|
#!/usr/bin/env perl
|
||
|
|
||
|
use warnings;
|
||
|
use strict;
|
||
|
|
||
|
use Time::HiRes qw/gettimeofday/;
|
||
|
|
||
|
my $CJEOPARDY_FILE = 'cjeopardy.txt';
|
||
|
my $CJEOPARDY_DATA = 'cjeopardy.dat';
|
||
|
my $CJEOPARDY_SQL = 'cjeopardy.sqlite3';
|
||
|
|
||
|
my $channel = shift @ARGV;
|
||
|
my $text = join(' ', @ARGV);
|
||
|
|
||
|
if ($channel !~ /^#/) {
|
||
|
print "Sorry, C Jeopardy must be played in a channel.\n";
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
my @questions;
|
||
|
open my $fh, "<", $CJEOPARDY_FILE or die "Could not open $CJEOPARDY_FILE: $!";
|
||
|
while (my $question = <$fh>) {
|
||
|
my ($question_only) = split /\|/, $question, 2;
|
||
|
next if length $text and $question_only !~ /\Q$text\E/i;
|
||
|
push @questions, $question;
|
||
|
}
|
||
|
close $fh;
|
||
|
|
||
|
if (not @questions) {
|
||
|
print "No questions containing '$text' found.\n";
|
||
|
exit;
|
||
|
}
|
||
|
|
||
|
my $question = $questions[int rand(@questions)];
|
||
|
|
||
|
my ($q, $a) = split /\|/, $question, 2;
|
||
|
chomp $q;
|
||
|
chomp $a;
|
||
|
|
||
|
$q =~ s/^\[.*?\]\s+//;
|
||
|
print "$q\n";
|
||
|
|
||
|
open $fh, ">", "$CJEOPARDY_DATA-$channel" or die "Could not open $CJEOPARDY_DATA-$channel: $!";
|
||
|
print $fh "$a\n";
|
||
|
print $fh gettimeofday, "\n";
|
||
|
close $fh;
|