home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
plum
/
2.x
/
plum2_28_2.lzh
/
module
/
auto
/
reply.plm
< prev
next >
Wrap
Text File
|
1998-10-15
|
10KB
|
336 lines
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><!-- $_ if 0; # -*- perl -*-
# $Id: reply.plm,v 2.8 1998/09/24 15:31:37 hasegawa Exp $
# copyright (c)1998 pupu_j <hasegawa@agusa.nuie.nagoya-u.ac.jp>
package auto_reply;
$_ = 'auto_reply';
sub ss_privmsg {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $mtime, $file, $idx, $name, $code, $req, $rep, $rate, @list, $regex, $to);
$userno = $'userno[$serverno];
$file = &'property($userno, 'file') || '';
if (($idx = rindex($file, ';')) != -1) {
$name = substr($file, 0, $idx);
$code = substr($file, $idx + 1);
} else {
$name = $file;
$code = '';
}
$name = &'expand($name);
if ($name) {
$mtime = (stat($name))[9];
if (defined($mtime) && ($modify[$userno] || 0) != $mtime) {
$modify[$userno] = $mtime;
&read_file($userno);
}
}
($req, @reply) = split(/\s+/, $params[1]);
if (@reply) {
foreach $add (&'property($userno, 'add')) {
next unless $req eq $add;
&add_file($userno, @reply);
return ($prefix, $cmd, @params);
}
foreach $remove (&'property($userno, 'remove')) {
next unless $req eq $remove;
&remove_file($userno, @reply);
return ($prefix, $cmd, @params);
}
foreach $change (&'property($userno, 'change')) {
next unless $req eq $change;
&change_file($userno, @reply);
return ($prefix, $cmd, @params);
}
}
$rate = &'property($userno, 'rate');
if (rand(100) < $rate) {
foreach $str (&'array($message[$userno])) {
($req, $rep) = &parse($str);
foreach $text (&'array($req)) {
$regex = &'regex(&'jis_euc($text));
next unless &'jis_euc($params[1]) =~ /$regex/;
if ($params[0] =~ /^[\#\&\+]/) {
$to = $params[0];
} else {
$to = &'prefix($prefix);
}
@list = &'array($rep);
&privmsg($serverno, $to, $list[rand(scalar(@list))]);
return ($prefix, $cmd, @params);
}
}
}
return ($prefix, $cmd, @params);
}
sub privmsg {
local($serverno, $to, $msg) = @_;
&'s_print($serverno, '', 'PRIVMSG', $to, $msg);
foreach $cno (&'array($'clientlist)) {
next unless $'avail[$cno];
next unless $'server[$cno] == $serverno;
&'c_print($cno, &'user($cno), 'PRIVMSG', $to, $msg);
}
}
sub parse {
local($str) = @_;
local($left, $right, $req, $rep);
($left, $right) = split(/\s+\:\s+/, $str);
$req = &'list(split(/\s+/, $left || ''));
$rep = &'list(split(/\s+/, $right || ''));
return ($req, $rep);
}
sub add_file {
local($userno, $req, @reply) = @_;
local(@array, $line, $recv, $send, $i);
@array = &'array($message[$userno]);
for ($i = 0; $i < scalar(@array); $i++) {
($recv, $send) = &parse($array[$i]);
next unless &'exist($recv, $req);
$array[$i] = join(' ', &'array($recv)) . ' : ' . join(' ', &'array(&'add($send, @reply)));
$message[$userno] = &'list(@array);
&write_file($userno);
return;
}
push(@array, $req . ' : ' . join(' ', @reply));
$message[$userno] = &'list(@array);
&write_file($userno);
}
sub remove_file {
local($userno, $req, @reply) = @_;
local(@array, $line, $recv, $send, $i);
@array = &'array($message[$userno]);
for ($i = 0; $i < scalar(@array); $i++) {
($recv, $send) = &parse($array[$i]);
next unless &'exist($recv, $req);
$send = &'remove($send, @reply);
if ($send) {
$array[$i] = join(' ', &'array($recv)) . ' : ' . join(' ', &'array($send));
} else {
splice(@array, $i, 1);
}
last;
}
$message[$userno] = &'list(@array);
&write_file($userno);
}
sub change_file {
local($userno, $req, @reply) = @_;
local(@array, $line, $recv, $send, $i);
@array = &'array($message[$userno]);
for ($i = 0; $i < scalar(@array); $i++) {
($recv, $send) = &parse($array[$i]);
next unless &'exist($recv, $req);
$array[$i] = join(' ', &'array($recv)) . ' : ' . join(' ', &'array(&'change($send, @reply)));
last;
}
$message[$userno] = &'list(@array);
&write_file($userno);
}
sub read_file {
local($userno) = @_;
local($file, $idx, $name, $code, $line);
$file = &'property($userno, 'file') || '';
if (($idx = rindex($file, ';')) != -1) {
$name = substr($file, 0, $idx);
$code = substr($file, $idx + 1);
} else {
$name = $file;
$code = '';
}
$name = &'expand($name);
if ($name && open(FILE, $name)) {
undef($message[$userno]);
while (defined($line = <FILE>)) {
$line =~ tr/\r\n//d;
next unless $line;
$line = &code_jis($line, $code) if $code;
$line = &read_line($userno, $line);
$message[$userno] = &'add($message[$userno], $line);
}
close(FILE);
}
}
sub write_file {
local($userno) = @_;
local($file, $idx, $name, $code);
$file = &'property($userno, 'file') || '';
if (($idx = rindex($file, ';')) != -1) {
$name = substr($file, 0, $idx);
$code = substr($file, $idx + 1);
} else {
$name = $file;
$code = '';
}
$name = &'expand($name);
if ($name && open(FILE, ">$name")) {
foreach $line (&'array($message[$userno])) {
$line = &jis_code($line, $code) if $code;
$line = &write_line($userno, $line);
print FILE $line, "\n";
}
close(FILE);
}
}
sub code_jis {
local($line, $list) = @_;
foreach $code (split(/\,/, "\L$list\E")) {
if ($code eq 'euc') {
$line = &'euc_jis($line);
} elsif ($code eq 'jis') {
$line = &'jis_jis($line);
} elsif ($code eq 'sjis') {
$line = &'sjis_jis($line);
}
}
return $line;
}
sub jis_code {
local($line, $list) = @_;
local($code);
$code = (split(/\,/, "\L$list\E"))[0];
if ($code eq 'euc') {
$line = &'jis_euc($line);
} elsif ($code eq 'jis') {
$line = &'jis_jis($line);
} elsif ($code eq 'sjis') {
$line = &'jis_sjis($line);
}
return $line;
}
sub read_line {
local($userno, $line) = @_;
foreach $kanji (&'property($userno, 'kanji')) {
foreach $code (split(/\,/, "\L$kanji\E")) {
if ($code eq 'euc') {
$line = &'euc_jis($line);
} elsif ($code eq 'jis') {
$line = &'jis_jis($line);
} elsif ($code eq 'sjis') {
$line = &'sjis_jis($line);
}
}
}
return $line;
}
sub write_line {
local($userno, $line) = @_;
local($kanji, $code);
$kanji = &'property($userno, 'kanji');
if ($kanji) {
$code = (split(/\,/, "\L$kanji\E"))[0];
if ($code eq 'euc') {
$line = &'jis_euc($line);
} elsif ($code eq 'jis') {
$line = &'jis_jis($line);
} elsif ($code eq 'sjis') {
$line = &'jis_sjis($line);
}
}
return $line;
}
__END__
--><HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-2022-JP">
<LINK REV="made" HREF="mailto:hasegawa@agusa.nuie.nagoya-u.ac.jp">
<TITLE>auto/reply.plm</TITLE></HEAD><BODY>
$B%*%s%i%$%s%I%-%e%a%s%H(B
<HR><H3>$BL>A0(B</H3>
auto/reply.plm - $BFCDj$NH/8@$KH?1~$7$?%a%C%;!<%8$rH/8@$9$k(B
<HR><H3>$B@bL@(B</H3>
$BFCDj$NH/8@$KH?1~$7$F!"$=$l$KBP$9$k%a%C%;!<%8$rH/8@$7$^$9!#(B
$B0l$D$NH/8@$KBP$7$FJ#?t$N%a%C%;!<%8$r;XDj$9$k$3$H$,$G$-!"(B
$B$=$NCf$+$i%i%s%@%`$G$I$l$+0l$D$N%a%C%;!<%8$rH/8@$7$^$9!#(B
$B%a%C%;!<%8$O%U%!%$%k$G;XDj$7!"%U%!%$%k$N%U%)!<%^%C%H$O(B
$B0J2<$N$h$&$K$J$C$F$$$^$9!#(B
<PRE>
$B$3$s$P$s$o(B : $B$3$s$P$s$o!A!y(B $B$3$s$P$s!&$o$s!A(B
$B$4$O$s(B* : $B$"$?$7$b9T$/!A(B
*$B$W$i$`(B* : $B$h$s$@$!(B? $B$O!<$$!y(B
</PRE>
$BH?1~$O0l9T$K0l$D5-=R$7!"H?1~$9$kH/8@$H$=$l$KBP$9$k%a%C%;!<%8$O(B
$B!V(B:$B!W$H$=$NA08e$K(B1$B$D0J>e$N6uGr$r$D$1$F6h@Z$C$F;XDj$7$^$9!#(B
$B$^$?!"H/8@$H%a%C%;!<%8$N$=$l$>$l$O(B1$B$D0J>e$N6uGr$G6h@Z$j$^$9!#(B
$BH?1~$9$kH/8@$K$O%o%$%k%I%+!<%I$H$7$F!V(B*$B!W$,;XDj$G$-$^$9!#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8@$H$=$l$KBP$9$k%a%C%;!<%8$r(B
$B6uGr$G6h@Z$C$F;XDj$7$^$9!#(B
</DD>
</DL>
<HR><H3>$B@_DjNc(B</H3>
<PRE>
+ auto/reply.plm
auto.reply.file: reply.txt;jis
auto.reply.rate: 100
auto.reply.add: $B%a%C%;!<%8DI2C(B
auto.reply.remove: $B%a%C%;!<%8:o=|(B
auto.reply.change: $B%a%C%;!<%8JQ99(B
</PRE>
$B!V(Breply.txt$B!W$K=q$+$l$?FbMF$K$b$H$E$$$F!"H/8@$KH?1~$7$F$=$l$KBP$9$k(B
$B%a%C%;!<%8$rH/8@$7$^$9!#(Breply.txt$B$O(Bjis$B$G=q$+$l$F$$$kI,MW$,$"$j$^$9!#(B
$B$^$?!"!V%a%C%;!<%8DI2C(B $B$3$s$K$A$O(B $B$3$s$K$A$O!A!y!W$N$h$&$KH/8@$9$l$P!"(B
$B?7$?$JH?1~$rDI2C$9$k$3$H$,$G$-$^$9!#(B
$BF1MM$K!"!V%a%C%;!<%8:o=|(B $B$3$s$K$A$O(B $B$3$s$K$A$O!A!y!W$d!"(B
$B!V%a%C%;!<%8JQ99(B $B$3$s$K$A$O(B $B$3$s$K$A!&$o$s!A!W$N$h$&$KH/8@$9$k$3$H$G!"(B
$BH?1~$r:o=|$7$?$jJQ99$9$k$3$H$,$G$-$^$9!#(B
</BODY></HTML>