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
/
random.plm
< prev
next >
Wrap
Text File
|
1998-10-15
|
9KB
|
319 lines
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><!-- $_ if 0; # -*- perl -*-
# $Id: random.plm,v 2.14 1998/10/13 14:06:30 hasegawa Exp $
# copyright (c)1997-1998 pupu_j <hasegawa@agusa.nuie.nagoya-u.ac.jp>
package auto_random;
$RATE = 100;
$_ = 'auto_random';
sub ss_privmsg {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $mtime, $file, $idx, $name, $code, $req, $reply, $rate, $to, @list, $str);
$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], 2);
if ($reply) {
foreach $add (&'property($userno, 'add')) {
next unless $req eq $add;
&add_file($userno, $reply);
return ($prefix, $cmd, $params[0], $params[1]);
}
foreach $remove (&'property($userno, 'remove')) {
next unless $req eq $remove;
&remove_file($userno, $reply);
return ($prefix, $cmd, @params);
}
}
$rate = &'property($userno, 'rate') || $RATE;
if (rand(100) < $rate) {
foreach $req (&'property($userno, 'request')) {
next unless $req eq $params[1];
@list = &'array($message[$userno]);
$str = @list[rand(scalar(@list))];
last unless $str;
if ($params[0] =~ /^[\#\&\+]/) {
$to = $params[0];
$str = &user_name($userno, $prefix) . ': ' . $str;
} else {
$to = &'prefix($prefix);
}
&privmsg($serverno, $to, $str);
last;
}
}
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 add_file {
local($userno, $reply) = @_;
$message[$userno] = &'add($message[$userno], $reply);
&write_file($userno);
}
sub remove_file {
local($userno, $reply) = @_;
$message[$userno] = &'remove($message[$userno], $reply);
&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 user_name {
local($userno, $prefix) = @_;
local($regex, $text, $file, $idx, $name, $code, $line, $var, $arg, $type);
$file = &'property($userno, 'alias') || '';
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)) {
while (defined($line = <FILE>)) {
$line =~ s/^\s+//;
next if $line =~ /^[\#\;]/;
$line =~ tr/\r\n//d;
next unless $line;
$line =~ s/\s+$//;
$line = &code_jis($line, $code) if $code;
$line = &read_line($userno, $line);
if ((($var, $arg) = split(/\s*\:\s*/, $line, 2)) == 2) {
$type = "\L$var\E";
if ($type eq 'nick') {
$nick = &'list(split(/\,/, $arg));
$name = '';
} elsif ($type eq 'name') {
$name = &'add($name, split(/\s+/, $arg));
} elsif ($type eq 'user') {
foreach $text (split(/\s+/, $arg)) {
$regex = &'regex($text);
next unless $prefix =~ /$regex/i;
close(FILE);
return (&'array($name || $nick))[0];
}
}
}
}
close(FILE);
}
return (&'prefix($prefix))[0];
}
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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!"C/$KBP$9$kH/8@$+$r(B
$B%K%C%/%M!<%`$G$O$J$/!"BP1~$9$kL>A0$GH/8@$7$^$9!#(B
</DD>
<DT> auto.random.rate $B3NN((B
</DT>
<DD> $BH/8@$KH?1~$9$k3NN($r;XDj$7$^$9!#(B0$B$r;XDj$9$k$HA4$/H?1~$;$:!"(B
100$B$r;XDj$9$k$HA4$F$NH/8@$KH?1~$9$k$h$&$K$J$j$^$9!#(B
$B%G%U%)%k%H$G$O(B100$B$K$J$C$F$$$^$9!#(B
</DD>
<DT> auto.random.add* $BJ8;zNs(B
</DT>
<DD> $B%a%C%;!<%8$rDI2C$9$k$r;XDj$7$^$9!#(B
$B$3$3$G;XDj$7$?J8;zNs$rH/8@$9$k$H!"?7$7$$%a%C%;!<%8$rDI2C$7$^$9!#(B
</DD>
<DT> auto.random.remove* $BJ8;zNs(B
</DT>
<DD> $B%a%C%;!<%8$r:o=|$9$k$r;XDj$7$^$9!#(B
$B$3$3$G;XDj$7$?J8;zNs$rH/8@$9$k$H!"0lCW$9$k%a%C%;!<%8$r:o=|$7$^$9!#(B
</DD>
</DL>
<HR><H3>$B@_DjNc(B</H3>
<PRE>
+ auto/random.plm
auto.random.request: $B:#F|$N1?@*$O(B?
auto.random.request: $B$&$i$J$$(B
auto.random.file: random.txt;jis
auto.random.rate: 100
auto.random.add: $B$&$i$J$$DI2C(B
auto.random.remove: $B$&$i$J$$:o=|(B
</PRE>
$B!V:#F|$N1?@*$O(B?$B!W$+!V$&$i$J$$!W$N$I$A$i$+$NH/8@$,$"$C$?$H$-$K!"(B
$B!V(Brandom.txt$B!W$NCf$K=q$+$l$?%a%C%;!<%8$NCf$N$I$l$+(B1$B$D$rH/8@$7$^$9!#(B
random.txt$B$O(Bjis$B$G=q$+$l$F$$$J$$$H$$$1$^$;$s!#(B
$B$^$?!"!V$&$i$J$$DI2C(B $BBg5H$G$9!y!W$J$I$N$h$&$KH/8@$9$k$3$H$G!"(B
$B?7$7$$%a%C%;!<%8$rDI2C$9$k$3$H$,$G$-$^$9!#(B
</BODY></HTML>