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;
30 tie my @FILE, 'Tie::File', "quote.txt";
31 tie my @OLDFILE, 'Tie::File',"oldquotes.txt" or die "test";
34 help => q(syntax .quote [number] | if number isn't given, then a random quote is used),
35 alias => q(lastquote),
36 }, class extends NDIRC::Command {
37 method execute($c,$msg) {
38 my ($n) = $msg =~ /(\d+)/;
40 $n = $n-1 if defined $n;
41 $n //= int(rand($#FILE));
42 $n = $#FILE if $self->name eq 'lastquote';
45 $text =~ s/(.*?)[\r\n]*$/$1/;
48 $c->reply("Quote <b>$n</b> of <b>$num</b>: $text");
53 help => q(syntax .addquote quote),
54 }, class extends NDIRC::Command {
55 method execute($c,$quote) {
57 die 'ARGS' unless $quote;
61 $c->reply("Quote <b>$num</b> added");
65 command findquote => {
66 help => q(syntax .findquote pattern | findqre lets you use a regex pattern),
68 }, class extends NDIRC::Command {
69 method execute($c,$pattern) {
70 die 'ARGS' unless $pattern;
73 if ($self->name eq 'findqre'){
74 if (defined (eval 'm/$pattern/ix')){
75 $matcher = 'm/$pattern/ix';
77 $c->reply("bad regexp");
81 $matcher = '(index uc($_), uc($pattern)) != -1';
83 my $file = new File::Temp( SUFFIX => '.txt' );
90 print $file "$n: $_\n";
96 $c->command(dcc => $c->nick => SEND => $file);
98 $c->reply("No quotes matching <b>$pattern.</b>");
103 command delquote => {
104 help => q(syntax: .delquote number),
105 acl => q(irc_delquote),
106 }, class extends NDIRC::Command {
107 method execute($c,$msg) {
108 my ($n) = $msg =~ /(\d+)/ or die 'ARGS';
110 if (exists $FILE[$n]){
111 my ($uid,$username) = $c->model->selectrow_array(q{
112 SELECT uid,username FROM users where uid = ?
115 my $text = $FILE[$n];
116 push @OLDFILE,"Removed by $username ($uid): $text";
120 $c->reply("Quote <b>$n</b> {$text} removed, number of quotes now: <b>$num</b>");
122 $c->reply("No such quote.");