1 #**************************************************************************
2 # Copyright (C) 2009 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
25 use NDIRC::Dispatcher;
29 help => q(syntax .quote [number|search term] | if number/search term isn't given, then a random quote is used),
30 alias => q(lastquote),
31 }, class extends NDIRC::Command {
32 method execute($c,$msg) {
35 if ($msg =~ /(\d+)/) {
36 my $quote = $dbh->selectrow_hashref(q{SELECT qid,quote FROM quotes WHERE qid = ?}, undef, $1);
38 $c->reply("Quote <b>$quote->{qid}</b>: $quote->{quote}");
40 $c->reply("No quote with id <b>$1</b>");
42 } elsif ($msg =~ /^\s*(.+?)\s*$/) {
44 my $quote = $dbh->selectrow_hashref(q{
45 SELECT qid,quote FROM quotes
46 WHERE quote ILIKE '%' || $1 || '%' ORDER BY random() limit 1
49 $c->reply("Quote <b>$quote->{qid}</b>: $quote->{quote}");
51 $c->reply("No quote matching <b>$1</b>");
55 my $quote = $dbh->selectrow_hashref(q{
56 SELECT qid,quote FROM quotes tablesample system(5) ORDER BY random() LIMIT 1
58 $c->reply("Quote <b>$quote->{qid}</b>: $quote->{quote}");
64 help => q(syntax .addquote quote),
65 }, class extends NDIRC::Command {
66 method execute($c,$msg) {
68 my ($quote) = $msg =~ /^\s*(.+?)\s*$/ or die 'ARGS';
71 my ($qid) = $dbh->selectrow_array(q{
72 INSERT INTO quotes (uid,quote) VALUES($1,$2) RETURNING qid
73 }, undef, $c->uid, $quote);
74 $c->reply("Quote <b>$qid</b> '$quote' added");
79 help => q(syntax: .delquote number),
80 acl => q(irc_delquote),
81 }, class extends NDIRC::Command {
82 method execute($c,$msg) {
83 my ($n) = $msg =~ /(\d+)/ or die 'ARGS';
85 my $quote = $dbh->selectrow_hashref(q{
86 WITH q AS (DELETE FROM quotes WHERE qid = $1 RETURNING qid,time,uid,quote)
87 INSERT INTO removed_quotes (qid,time,uid,quote,removed_by)
88 SELECT *, $2 AS removed_by FROM q RETURNING quote;
89 }, undef, $n, $c->uid);
91 $c->reply("Quote <b>$n</b> {$quote->{quote}} removed");
93 $c->reply("No such quote.");