1 #**************************************************************************
2 # Copyright (C) 2006 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 #**************************************************************************/
19 package NDIRC::Quotes;
27 our @ISA = qw/Exporter/;
29 our @EXPORT = qw/quote addQuote lastQuote findQuote delQuote/;
31 tie our @FILE, 'Tie::File', "/home/ndawn/.eos/scripts/quote.txt";
32 tie our @OLDFILE, 'Tie::File',"/home/ndawn/.eos/scripts/oldquotes.txt" or die "test";
36 if (defined $n && $n =~ /(\d+)/){
42 $n = $n-1 if defined $n;
43 $n = int(rand($#FILE)) unless defined $n;
45 $text =~ s/(.*?)[\r\n]*$/$1/;
48 $ND::server->command("msg $ND::target Quote $ND::B$n$ND::B of $ND::B$num:$ND::B $text");
53 unless (defined $quote){
54 $ND::server->command("notice $ND::nick Usage: .addquote quote");
59 $ND::server->command("msg $ND::target Quote $ND::B$num$ND::B added");
64 $text =~ s/(.*?)[\r\n]*$/$1/;
66 $ND::server->command("msg $ND::target Quote $ND::B$n$ND::B of $ND::B$n:$ND::B $text");
69 my ($pattern,$type) = @_;
71 unless (defined $pattern){
72 $ND::server->command("notice $ND::nick $type query | findqre uses regexes as query, findquote a substring match. Both are case insensitive");
75 if ($type eq 'findqre'){
76 if (defined (eval 'm/$pattern/ix')){
77 $matcher = 'm/$pattern/ix';
79 $ND::server->command("msg $ND::target bad regexp");
84 $matcher = '(index uc($_), uc($pattern)) != -1';
87 #my $file = "/tmp/quotes/$ND::address.txt";
88 #open(FILE,'>',"$file");
89 my $file = new File::Temp( SUFFIX => '.txt' );
96 print $file "$n: $_\n";
101 $ND::server->command("dcc send $ND::nick $file");
103 $ND::server->command("msg $ND::target $ND::nick: No quotes matching that.");
109 if ($n =~ /^(\d+)$/){
115 if (exists $FILE[$n]){
116 my ($uid,$username) = $ND::DBH->selectrow_array(q{SELECT uid,username FROM users where hostmask ILIKE ?}
117 ,undef,$ND::address);
118 my $text = $FILE[$n];
119 push @OLDFILE,"Removed by $username ($uid): $text";
123 $ND::server->command("msg $ND::target Quote $ND::B$n$ND::B {$text} removed, number of quotes now: $ND::B$num$ND::B");
125 $ND::server->command("msg $ND::target No such quote.");
128 $ND::server->command("msg $ND::target You don't have access to that!");