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 ND::IRC::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 $n = $n-1 if defined $n;
37 $n = int(rand($#FILE)) unless defined $n;
39 $text =~ s/(.*?)[\r\n]*$/$1/;
42 $ND::server->command("msg $ND::target Quote $ND::B$n$ND::B of $ND::B$num:$ND::B $text");
49 $ND::server->command("msg $ND::target Quote $ND::B$num$ND::B added");
54 $text =~ s/(.*?)[\r\n]*$/$1/;
56 $ND::server->command("msg $ND::target Quote $ND::B$n$ND::B of $ND::B$n:$ND::B $text");
59 my ($type,$pattern) = @_;
62 if (defined (eval 'm/$pattern/ix')){
63 $matcher = 'm/$pattern/ix';
65 $ND::server->command("msg $ND::target bad regexp");
70 $matcher = '(index uc($_), uc($pattern)) != -1';
73 #my $file = "/tmp/quotes/$ND::address.txt";
74 #open(FILE,'>',"$file");
75 my $file = new File::Temp( SUFFIX => '.txt' );
82 print $file "$n: $_\n";
87 $ND::server->command("dcc send $ND::nick $file");
89 $ND::server->command("msg $ND::target $ND::nick: No quotes matching that.");
96 if (exists $FILE[$n]){
97 my ($uid,$username) = $ND::DBH->selectrow_array(q{SELECT uid,username FROM users where hostmask ILIKE ?}
100 push @OLDFILE,"Removed by $username ($uid): $text";
104 $ND::server->command("msg $ND::target Quote $ND::B$n$ND::B {$text} removed, number of quotes now: $ND::B$num$ND::B");
106 $ND::server->command("msg $ND::target No such quote.");
109 $ND::server->command("msg $ND::target You don't have access to that!");