home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
plum
/
2.x
/
plum2_32_1.lzh
/
module
/
auto
/
reply.plm
< prev
next >
Wrap
Text File
|
1999-02-20
|
12KB
|
427 lines
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><!-- $_ if 0; # -*- perl -*-
# $Id: reply.plm,v 2.29 1999/01/28 14:56:27 hasegawa Exp $
# copyright (c)1998-1999 Yoshinori Hasegawa <hasegawa@madoka.org>
package auto_reply;
$FORMAT = '#(message)';
$_ = 'auto_reply';
sub ss_privmsg {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $mtime, $file, $idx, $name, $code, $req, $rep, $rate, @list, %alias, $regex, $to, $str, @format);
$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_data($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/;
@list = &'array($rep);
$str = $list[rand(@list)];
%alias = &get_alias_user($userno, $prefix);
$alias{'nick.now'} = (&'prefix($prefix))[0];
$alias{'message'} = &'format($str, %alias);
if (&'channel($params[0])) {
$alias{'channel'} = $params[0];
$to = $params[0];
} else {
$to = &'prefix($prefix);
}
@format = &'property($userno, 'format');
if (@format) {
foreach $reply (@format) {
&privmsg($serverno, $to, &'format($reply, %alias));
}
} else {
&privmsg($serverno, $to, &'format($FORMAT, %alias));
}
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 < @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 < @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 < @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_data {
local($userno) = @_;
local($name, $code, $line);
($name, $code) = &filename(&'property($userno, 'file'));
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;
$message[$userno] = &'add($message[$userno], $line);
}
close(FILE);
}
}
sub write_file {
local($userno) = @_;
local($name, $code);
($name, $code) = &filename(&'property($userno, 'file'));
if ($name && open(FILE, ">$name")) {
foreach $line (&'array($message[$userno])) {
$line = &jis_code($line, $code) if $code;
print FILE $line, "\n";
}
close(FILE);
}
}
sub get_alias_user {
local($userno, $from, $prefix) = @_;
local($file, @list);
$file = &'property($userno, 'alias');
foreach $list (&split_list('nick', &read_file($file))) {
@list = &'array($list);
if (&match_alias_user($from, @list)) {
return &parse_alias($prefix, @list);
}
}
return ();
}
sub match_alias_user {
local($from, @list) = @_;
local($var, $arg, $regex);
foreach $line (@list) {
($var, $arg) = split(/\s+/, $line, 2);
next unless "\L$var\E" eq 'user';
$regex = &'regex($arg);
next unless $from =~ /$regex/i;
return 1;
}
return 0;
}
sub parse_alias {
local($prefix, @list) = @_;
local(%alias, $var, $arg, $key);
%alias = ();
foreach $line (@list) {
($var, $arg) = split(/\s+/, $line, 2);
$var = "\L$var\E";
if ($prefix) {
$key = $prefix . '.' . $var;
} else {
$key = $var;
}
next if defined($alias{$key});
if ($var eq 'nick') {
$alias{$key} = (split(/\,/, $arg))[0];
} elsif ($var eq 'name') {
$alias{$key} = (split(/\s+/, $arg))[0];
} else {
$alias{$key} = $arg;
}
}
return %alias;
}
sub split_list {
local($field, @list) = @_;
local($var, $arg, @array, @entry);
$field = "\L$field\E";
@array = ();
@entry = ();
foreach $line (@list) {
($var, $arg) = split(/\s*\:\s*/, $line, 2);
if ($field eq "\L$var\E") {
push(@array, &'list(@entry)) if @entry;
@entry = ();
}
push(@entry, $var . ' ' . $arg);
}
push(@array, &'list(@entry)) if @entry;
return @array;
}
sub read_file {
local($file) = @_;
local($name, $code, $mtime, @data, $line);
($name, $code) = &filename($file);
$mtime = (stat($name))[9];
if (defined($mtime)) {
$modify{$name} = -1 unless defined($modify{$name});
if ($modify{$name} != $mtime) {
if (open(TMP, $name)) {
@data = ();
while (defined($line = <TMP>)) {
$line =~ s/^\s+//;
next if $line =~ /^[\#\;]/;
$line =~ tr/\r\n//d;
next unless $line;
$line =~ s/\s+$//;
$line = &code_jis($line, $code) if $code;
push(@data, $line);
}
close(TMP);
$modify{$name} = $mtime;
$cache{$name} = &'list(@data);
return @data;
}
} else {
return &'array($cache{$name});
}
}
return ();
}
sub filename {
local($file) = @_;
local($idx, $name, $code);
return ('', '') unless $file;
if (($idx = rindex($file, ';')) != -1) {
$name = substr($file, 0, $idx);
$code = substr($file, $idx + 1);
} else {
$name = $file;
$code = '';
}
return (&'expand($name), $code);
}
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;
}
__END__
--><HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-2022-JP">
<LINK REV="made" HREF="mailto:hasegawa@madoka.org">
<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/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;!<%8$r:o=|$9$k$?$a$NJ8;zNs$r;XDj$7$^$9!#(B
$BJ8;zNs$K$OH?1~$9$kH/8@$H$=$l$KBP$9$k%a%C%;!<%8$r(B
$B6uGr$G6h@Z$C$F;XDj$7$^$9!#(B
</DD>
<DT> auto.reply.change* $BJ8;zNs(B
</DT>
<DD> $BH?1~$9$k%a%C%;!<%8$rJQ99$9$k$?$a$NJ8;zNs$r;XDj$7$^$9!#(B
$BJ8;zNs$K$OH?1~$9$kH/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.format: #(name): #(message)
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$K4p$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>