- my $text = $FILE[$n];
- $text =~ s/(.*?)[\r\n]*$/$1/;
- $n++;
- my $num = $#FILE+1;
- $c->reply("Quote <b>$n</b> of <b>$num</b>: $text");
-}
-
-sub addquote
- : Help(syntax .addquote quote)
-{
- my ($self,$c,$quote) = @_;
+command quote => {
+ help => q(syntax .quote [number|search term] | if number/search term isn't given, then a random quote is used),
+ alias => q(lastquote),
+}, class extends NDIRC::Command {
+ method execute($c,$msg) {
+ my $dbh = $c->model;
+ my $quote;
+ if ($msg =~ /(\d+)/) {
+ my $quote = $dbh->selectrow_hashref(q{SELECT qid,quote FROM quotes WHERE qid = ?}, undef, $1);
+ if ($quote) {
+ $c->reply("Quote <b>$quote->{qid}</b>: $quote->{quote}");
+ } else {
+ $c->reply("No quote with id <b>$1</b>");
+ }
+ } elsif ($msg =~ /^\s*(.+?)\s*$/) {
+ say $1;
+ my $quote = $dbh->selectrow_hashref(q{
+SELECT qid,quote FROM quotes
+WHERE quote ILIKE '%' || $1 || '%' ORDER BY random() limit 1
+ }, undef, $1);
+ if ($quote) {
+ $c->reply("Quote <b>$quote->{qid}</b>: $quote->{quote}");
+ } else {
+ $c->reply("No quote matching <b>$1</b>");
+ }
+ } else {
+ say "default";
+ my $quote = $dbh->selectrow_hashref(q{
+SELECT qid,quote FROM quotes tablesample system(5) ORDER BY random() LIMIT 1
+ });
+ $c->reply("Quote <b>$quote->{qid}</b>: $quote->{quote}");
+ }
+ }
+};