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
/
nako.plm
< prev
next >
Wrap
Text File
|
1998-10-15
|
25KB
|
792 lines
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><!-- $_ if 0; # -*- perl -*-
# $Id: nako.plm,v 2.14 1998/08/23 04:22:22 hasegawa Exp $
# copyright (c)1998 pupu_j <hasegawa@agusa.nuie.nagoya-u.ac.jp>
package auto_nako;
$SYSFILE = '.nako.sys';
$MSGFILE = '.nako.msg';
$NICK = 'bot';
$AWAYNICK = 'bot_inai';
$SECRET = 'secret';
$DBCOM = 'DB';
$MEMOCOM = 'MEMO';
$LEARN = 1;
$LRNSPEAK = 1;
$DENGONF = '.nako.dengon';
$MEMOF = '.nako.memo';
$OWNPASSWD = 'masterpasswd';
$JOIN = 'join';
$AWAY = 'away';
$SHUTUPKEY = 'shutup';
$SPEAKKEY = 'talk';
$SHUTUPMSG = '+++ speak off';
$SPEAKMSG = '+++ speak on';
$SPEAKEDMSG = '+++ already speaked on';
$KICKED = 'kicked';
$KICK = 'kick';
$QUIT = 'quit';
$HAVEDN = 'i have some dengon for u.';
$THANKS = 'thanks';
$TAKEN = 'what shall i do?';
$PART = 'bye!';
$NARUTO = 'i\'ll give u chanop.';
$UNNARUTO = 'i have no naruto.';
$KEYWORD = 'keyword';
$DENGONWRITE = 'dengon';
$DENGONLISTEN = 'listen';
$NODENGON = 'i have no dengon for you.';
$SOMEDENGON = 'i have some dengon for you.';
$DENGONOK = 'ok.';
$DENGONEND = 'end..';
$WRITEERROR = 'Dengon file write error!';
$READERROR = 'Dengon file read error!';
$_ = 'auto_nako';
sub main_loop {
local($userno) = @_;
&load_sys($userno);
&load_msg($userno);
}
sub server_open {
local($serverno) = @_;
$feeling[$serverno] = 100;
$alive[$serverno] = 1;
$last[$serverno] = '';
$time[$serverno] = time();
$lrnstr[$serverno] = '';
$selfpub[$serverno] = 0;
$selfpriv[$serverno] = 0;
$cdown[$serverno] = rand(100) + 1;
}
sub ss_join {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $nick, $str, $name, $mode);
$userno = $'userno[$serverno];
$nick = &'prefix($prefix);
($name, $mode) = split(/\cG/, $params[0]);
if (!$joined{$serverno, $name}) {
$joined{$serverno, $name} = 1;
$str = &message($userno, 'JOIN') || $JOIN;
&privmsg($serverno, $name, '', $str);
}
if (&'exist($dnick[$userno], $nick)) {
$str = &message($userno, 'HAVEDN') || $HAVEDN;
&privmsg($serverno, $name, '', "$nick: $str");
}
return ($prefix, $cmd, @params);
}
sub ss_kick {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $nick, $str);
$userno = $'userno[$serverno];
$nick = &'prefix($prefix);
if ($params[1] eq $'nick[$serverno]) {
$feeling[$serverno] -= 50 if $feeling[$serverno] > 50;
$feeling[$serverno] -= 70 if $feeling[$serverno] > 100;
if ($alive[$serverno]) {
$str = &message($userno, 'KICKED', -1) || $KICKED;
&privmsg($serverno, $params[0], $nick, "\$nick: $str");
}
} else {
$feeling[$serverno] -= 10 if $feeling[$serverno] > 50;
$feeling[$serverno] -= 30 if $feeling[$serverno] > 100;
if ($alive[$serverno]) {
$str = &message($userno, 'KICK', -1) || $KICK;
&privmsg($serverno, $params[0], $nick, "\$nick: $str");
}
}
return ($prefix, $cmd, @params);
}
sub ss_mode {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $nick, $chan, $mode, @modes, $i, $char, $flag, $name, $str);
$userno = $'userno[$serverno];
$nick = &'prefix($prefix);
if ($nick ne $'nick[$serverno]) {
($chan, $mode, @modes) = @params;
for ($i = 0; $i < length($mode); $i++) {
$char = substr($mode, $i, 1);
if ($char eq '+' || $char eq '-') {
$flag = $char;
} elsif ($char eq 'o') {
$name = shift(@modes);
if ($flag eq '+' && $name eq $'nick[$serverno]) {
$feeling[$serverno] += 10 if $feeling[$serverno] < 150;
if ($alive[$serverno] && !$have{$userno, $chan}) {
$str = &message($userno, 'THANKS') || $THANKS;
&privmsg($serverno, $chan, $nick, "\$nick: $str");
}
$have{$userno, $chan} = 1;
} elsif ($flag eq '-' && $name eq $'nick[$serverno]) {
$feeling[$serverno] -= 10 if $feeling[$serverno] > 50;
if ($alive[$serverno] && $have{$userno, $chan}) {
$str = &message($userno, 'TAKEN') || $TAKEN;
&privmsg($serverno, $chan, '', $str);
}
$have{$userno, $chan} = 0;
}
} elsif ($char eq 'b' || $char eq 'v' || $char eq 'k') {
shift(@modes);
} elsif ($char eq 'l' && $flag eq '+') {
shift(@modes);
}
}
}
return ($prefix, $cmd, @params);
}
sub ss_nick {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $nick, $str);
$userno = $'userno[$serverno];
$nick = &'prefix($prefix);
if ($params[0] ne $'nick[$serverno] && &'exist($dnick[$userno], $params[0])) {
$str = &message($userno, 'HAVEDN') || $HAVEDN;
&privmsg($serverno, $params[0], '', $str);
}
return ($prefix, $cmd, $params[0]);
}
sub ss_part {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $nick, $str);
$userno = $'userno[$serverno];
$nick = &'prefix($prefix);
if ($nick ne $'nick[$serverno]) {
$feeling[$serverno] -= 1 if $feeling[$serverno] > 75;
$str = &message($userno, 'PART') || $PART;
&privmsg($serverno, $nick, '', $str);
}
return ($prefix, $cmd, @params);
}
sub ss_ping {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, @chan);
$userno = $'userno[$serverno];
$feeling[$serverno] -= 5 if $feeling[$serverno] > 75;
$cdown[$serverno] -= 1;
if ($cdown[$serverno] < 0) {
$cdown[$serverno] = rand(100) + 200;
if ($selfpub[$serverno]) {
@chan = &'array($'channellist[$serverno]);
&privmsg($serverno, $chan[rand(scalar(@chan))], '', &system($userno, 'PUBACT'));
}
}
return ($prefix, $cmd, @params);
}
sub ss_privmsg {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $nick, $str, $text, $euc, $op, $arg);
$userno = $'userno[$serverno];
$nick = &'prefix($prefix);
if ($params[0] =~ /^[\#\&\+]/) {
$euc = &'jis_euc($params[1]);
if (index($euc, &message($userno, 'KEYWORD', -1) || $KEYWORD) != -1) {
if ($have{$userno, $params[0]}) {
$text = &message($userno, 'NARUTO') || $NARUTO;
&privmsg($serverno, $params[0], $nick, "\$nick: $text");
&'s_print($serverno, '', 'MODE', $params[0], '+o', $nick);
} else {
$text = &message($userno, 'UNNARUTO') || $UNNARUTO;
&privmsg($serverno, $params[0], $nick, "\$nick: $text");
}
} elsif (index($euc, &message($userno, 'SHUTUPKEY', -1) || $SHUTUPKEY) != -1) {
$text = &message($userno, 'SHUTUPMSG', -1) || $SHUTUPMSG;
&privmsg($serverno, $params[0], '', $text) unless $silent{$serverno, $params[0]};
$silent{$serverno, $params[0]} = 1;
} elsif (index($euc, &message($userno, 'SPEAKKEY', -1) || $SPEAKKEY) != -1) {
if ($silent{$serverno, $params[0]}) {
$text = &message($userno, 'SPEAKMSG', -1) || $SPEAKMSG;
$silent{$serverno, $params[0]} = 0;
} else {
$text = &message($userno, 'SPEAKEDMSG', -1) || $SPEAKEDMSG;
}
&privmsg($serverno, $params[0], '', $text);
} elsif ($alive[$serverno]) {
if (index($euc, $last[$serverno]) != -1 && $time[$serverno] + 5 > time()) {
$last[$serverno] = $euc;
} else {
if (index($euc, $last[$serverno]) != -1 && time() < $time[$serverno] + 5) {
$feeling[$serverno] -= 1 if $feeling[$serverno] > 50;
}
$time[$serverno] = time();
$feeling[$serverno]++ if $feeling[$serverno] < 100;
if (!$silent{$serverno, $params[0]}) {
($op, $arg) = split(/\s+/, $params[1], 2);
if ($op eq (&message($userno, 'DENGONLISTEN', -1) || $DENGONLISTEN)) {
&listen($serverno, $prefix, $params[0]);
} elsif ($op eq (&message($userno, 'DENGONWRITE', -1) || $DENGONWRITE)) {
&write($serverno, $prefix, $params[0], $arg);
} elsif ($op eq (&system($userno, 'MEMOCOM') || $MEMOCOM)) {
&memo($serverno, $prefix, $arg);
} else {
&reply($serverno, $prefix, $params[0], $euc);
}
}
$last[$serverno] = $euc;
}
}
} else {
&command($serverno, $prefix, $params[1]);
}
return ($prefix, $cmd, @params);
}
sub ss_353 {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $list);
$userno = $'userno[$serverno];
$list = &'list(split(/\s+/, $params[3]));
if (&'exist($list, "\@$'nick[$serverno]")) {
$have{$userno, $params[2]} = 1;
}
return ($prefix, $cmd, @params);
}
sub command {
local($serverno, $prefix, $msg) = @_;
local($userno, $nick, $euc, $op, $arg, $ch, $str, $pass, $i);
$userno = $'userno[$serverno];
$nick = &'prefix($prefix);
($op, $arg) = (split(/\s+/, $msg, 2), '');
if ($op eq 'P' || $op eq 'p') {
($ch, $str) = split(/\s+/, $arg, 2);
&privmsg($serverno, $ch, '', $str);
} elsif ($op eq 'T' || $op eq 't') {
($ch, $str) = split(/\s+/, $arg, 2);
&'s_print($serverno, '', 'TOPIC', $ch, $str) if $str;
} elsif ($op eq 'N' || $op eq 'n') {
($pass, $str) = split(/\s+/, $arg, 2);
&'s_print($serverno, '', 'NICK', $str) if ($str && $pass eq (&system($userno, 'OWNPASSWD') || $OWNPASSWD));
} elsif ($op eq 'FEEL?') {
&privmsg($serverno, $nick, '', "value: $feeling[$serverno]");
} elsif ($op eq 'STATUS?') {
&privmsg($serverno, $nick, '', 'Version 1.56+a3r1');
&privmsg($serverno, $nick, '', "IRC server is $'servername[$serverno]");
&privmsg($serverno, $nick, '', "selfpub : $selfpub");
&privmsg($serverno, $nick, '', "selfpriv: $selfpriv");
} elsif ($op eq 'STRING?') {
&privmsg($serverno, $nick, '', 'learned string is :' . ($lrnstr[$serverno] || '(null)'));
} elsif ($op eq 'FORGET!') {
$lrnstr[$serverno] = '';
} elsif ($op eq 'CHANNEL?') {
$i = 0;
foreach $ch (&'array($'channellist[$serverno])) {
$i++;
&privmsg($serverno, $nick, '', "channel:[$i]$ch");
}
} elsif ($op eq '*HELP*') {
&privmsg($serverno, $nick, '', 'FEEL? : check status.');
$str = &message($userno, 'KEYWORD', -1) || $KEYWORD;
&privmsg($serverno, $nick, '', "$str : the bot will give you chanop.");
$str = &message($userno, 'SHUTUPKEY', -1) || $SHUTUPKEY;
&privmsg($serverno, $nick, '', "$str : shut up.");
$str = &message($userno, 'SPEAKKEY', -1) || $SPEAKKEY;
&privmsg($serverno, $nick, '', "$str : speak again.");
$str = &message($userno, 'DENGONLISTEN', -1) || $DENGONLISTEN;
&privmsg($serverno, $nick, '', "$str : check and read dengon message.");
$str = &message($userno, 'DENGONWRITE', -1) || $DENGONWRITE;
&privmsg($serverno, $nick, '', "$str : get dengon message by heart.");
&privmsg($serverno, $nick, '', '*HELP* : this help.');
} elsif ($op eq (&system($userno, 'SECRET') || $SECRET)) {
if ($have{$userno, $arg}) {
$str = &message($userno, 'NARUTO') || $NARUTO;
&privmsg($serverno, $arg, $nick, $str);
&'s_print($serverno, '', 'MODE', $arg, '+o', $nick);
} else {
$str = &message($userno, 'UNNARUTO') || $UNNARUTO;
&privmsg($serverno, $nick, $nick, $str);
}
} elsif ($op eq '*rehash*') {
&load_msg($userno) if $arg eq (&system($userno, 'OWNPASSWD') || $OWNPASSWD);
} elsif ($op eq 'EXIT') {
if ($arg eq (&system($userno, 'OWNPASSWD') || $OWNPASSWD)) {
$str = &message($userno, 'QUIT') || $QUIT;
foreach $ch (&'array($'channellist[$serverno])) {
&privmsg($serverno, $ch, '', $str);
}
&'s_print($serverno, '', 'QUIT', $str);
&'s_flush($serverno);
exit(0);
}
} elsif ($op eq 'I' || $op eq 'i') {
&'s_print($serverno, '', 'JOIN', $arg) if $arg;
} elsif ($op eq 'L' || $op eq 'l') {
&'s_print($serverno, '', 'PART', $arg) if $arg;
} elsif ($op eq 'A' || $op eq 'a') {
if ($arg eq (&system($userno, 'OWNPASSWD') || $OWNPASSWD)) {
$str = &message($userno, 'AWAY') || $AWAY;
if ($str) {
foreach $ch (&'array($'channellist[$serverno])) {
&privmsg($serverno, $ch, '', $str);
}
}
&'s_print($serverno, '', 'NICK', &system($userno, 'AWAYNICK') || $AWAYNICK);
$alive[$serverno] = 0;
}
} elsif ($op eq 'J' || $op eq 'j') {
if ($arg eq (&system($userno, 'OWNPASSWD') || $OWNPASSWD)) {
$str = &message($userno, 'JOIN') || $JOIN;
if ($str) {
foreach $ch (&'array($'channellist[$serverno])) {
&privmsg($serverno, $ch, '', $str);
}
}
&'s_print($serverno, '', 'NICK', &system($userno, 'NICK') || $NICK);
$alive[$serverno] = 1;
}
} elsif ($op eq (&system($userno, 'DBCOM') || $DBCOM)) {
&database($serverno, $prefix, $arg);
} elsif ($selfpriv[$serverno] && time() > $time[$serverno]) {
$time[$serverno] = time();
$str = &message($userno, 'PRVACT');
&prvmsg($serverno, $nick, $nick, $str);
}
}
sub database {
local($serverno, $prefix, $msg) = @_;
&access($serverno, $prefix, '.nako.db', $msg);
}
sub memo {
local($serverno, $prefix, $msg) = @_;
local($userno, $file);
$userno = $'userno[$serverno];
$file = &system($userno, 'MEMOF') || $MEMOF;
&access($serverno, $prefix, $file, $msg);
}
sub access {
local($serverno, $prefix, $file, $msg) = @_;
local($nick, $cmd, $item, $var, $arg, $num, $line, @list);
$nick = &'prefix($prefix);
($cmd, $item) = split(/\s+/, $msg, 2);
if ($cmd eq 'read') {
if (open(FILE, $file)) {
$num = 0;
while (defined($line = <FILE>)) {
$line =~ tr/\r\n//d;
($var, $arg) = split(/\:/, $line, 2);
next unless $var eq $item;
&privmsg($serverno, $nick, '', $line);
$num++;
}
close(FILE);
if ($num) {
&privmsg($serverno, $nick, '', 'thats all.');
} else {
&privmsg($serverno, $nick, '', 'nothing');
}
}
} elsif ($cmd eq 'write') {
if (index($item, ':') != -1) {
if (open(FILE, ">>$file")) {
print FILE $item, "\n";
close(FILE);
}
&privmsg($serverno, $nick, '', 'data added.');
} else {
&privmsg($serverno, $nick, '', 'wrong data format. ');
&privmsg($serverno, $nick, '', 'format is "fieldname:contents"');
}
} elsif ($cmd eq 'delete') {
@list = ();
if (open(FILE, $file)) {
while (defined($line = <FILE>)) {
$line =~ tr/\r\n//d;
($var, $arg) = split(/\:/, $line, 2);
next if $var eq $item;
push(@list, $line);
}
close(FILE);
if (open(FILE, ">$file")) {
foreach $line (@list) {
print FILE $line, "\n";
}
close(FILE);
}
}
}
}
sub listen {
local($serverno, $prefix, $chan) = @_;
local($userno, $nick, $file, $idx, $name, $code, $line, $reply, @data, @list, @rest);
$userno = $'userno[$serverno];
$nick = &'prefix($prefix);
@list = ();
@rest = ();
$file = &system($userno, 'DENGONF') || $DENGONF;
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 =~ tr/\r\n//d;
@data = split(/\s+/, $line, 2);
if ("\L$data[0]\E" eq "\L$nick\E") {
push(@list, $data[1]);
} else {
push(@rest, $line);
}
}
close(FILE);
if (@list) {
$reply = &message($userno, 'SOMEDENGON', -1) || $SOMEDENGON;
&privmsg($serverno, $chan, '', "$nick: $reply");
foreach $str (@list) {
&privmsg($serverno, $nick, '', "- $str");
}
$reply = &message($userno, 'DENGONEND', -1) || $DENGONEND;
&privmsg($serverno, $chan, '', "$nick: $reply");
} else {
$reply = &message($userno, 'NODENGON', -1) || $NODENGON;
&privmsg($serverno, $chan, '', "$nick: $reply");
}
$dnick[$userno] = &'remove($dnick[$userno], $nick);
if (open(FILE, ">$file")) {
foreach $line (@rest) {
print FILE $line, "\n";
}
close(FILE);
} else {
$reply = &message($userno, 'WRITEERROR', -1) || $WRITEERROR;
&privmsg($serverno, $chan, '', $reply);
}
} else {
$reply = &message($userno, 'READERROR', -1) || $READERROR;
&privmsg($serverno, $chan, '', $reply);
}
}
sub write {
local($serverno, $prefix, $chan, $msg) = @_;
local($userno, $nick, $file, $line, $name, $str, @time);
$userno = $'userno[$serverno];
$nick = &'prefix($prefix);
($name, $str) = split(/\s+/, $msg, 2);
if ($str) {
$file = &system($userno, 'DENGONF') || $DENGONF;
if ($file && open(FILE, ">>$file")) {
@time = localtime();
print FILE $name, &'date(' [ %a %b %d %H:%M:%S %Y ] '), $str, ' ( from ', $nick,' )', "\n";
close(FILE);
$dnick[$userno] = &'add($dnick[$userno], $name);
$str = &message($userno, 'DENGONOK', -1) || $DENGONOK;
&privmsg($serverno, $chan, '', "$nick: $str");
} else {
$str = &message($userno, 'WRITEERROR', -1) || $WRITEERROR;
&privmsg($serverno, $chan, '', $str);
}
}
}
sub reply {
local($serverno, $prefix, $chan, $msg) = @_;
local($userno, $nick, $rate, $i, $str, @list, $learn, $lrnspeak);
$userno = $'userno[$serverno];
$nick = &'prefix($prefix);
$rate = rand(100) * (100 / $feeling[$serverno]);
for ($i = 0; $i <= $count[$userno]; $i++) {
next unless $prob{$userno, $i} > $rate;
next unless &match($msg, $pattern{$userno, $i});
@list = &'array($answer{$userno, $i});
$str = $list[rand(scalar(@list))];
foreach $sub (split(/\&/, $str)) {
next unless $sub;
&privmsg($serverno, $chan, $nick, $sub);
}
last;
}
$rate = rand(100);
$learn = &system($userno, 'LEARN');
$learn = $LEARN unless defined($learn);
if ($rate <= $learn || !$lrnstr[$serverno]) {
$lrnstr[$serverno] = $msg;
$lrnchn[$userno] = $chan;
}
$lrnspeak = &system($userno, 'LRNSPEAK');
$lrnspeak = $LRNSPEAK unless defined($lrnspeak);
&privmsg($serverno, $lrnchn[$userno], '', $lrnstr[$serverno]) if $lrnspeak >= 100 -$rate;
}
sub match {
local($msg, $pattern) = @_;
foreach $sub (split(/\|/, $pattern)) {
return 0 if index($msg, $sub) == -1;
}
return 1;
}
sub system {
local($userno, $key, $num) = @_;
local($list, @array);
$list = $system{$userno, $key};
if (defined($list)) {
@array = &'array($list);
if (defined($num)) {
if ($num >= 0 && $num < scalar(@array)) {
return $array[$num];
} elsif ($num < 0 && scalar(@array) + $num >= 0) {
return $array[scalar(@array) + $num];
} else {
return undef;
}
} elsif (wantarray) {
return @array;
} else {
return $array[rand(scalar(@array))];
}
} elsif (wantarray) {
return ();
} else {
return undef;
}
}
sub message {
local($userno, $key, $num) = @_;
local($list, @array);
$list = $message{$userno, $key};
if (defined($list)) {
@array = &'array($list);
if (defined($num)) {
if ($num >= 0 && $num < scalar(@array)) {
return $array[$num];
} elsif ($num < 0 && scalar(@array) + $num >= 0) {
return $array[scalar(@array) + $num];
} else {
return undef;
}
} elsif (wantarray) {
return @array;
} else {
return $array[rand(scalar(@array))];
}
} elsif (wantarray) {
return ();
} else {
return undef;
}
}
sub load_sys {
local($userno) = @_;
local($file, $idx, $name, $code, $mtime, $line, $var, $arg);
$file = &'property($userno, 'sysfile') || $SYSFILE;
if (($idx = rindex($file, ';')) != -1) {
$name = substr($file, 0, $idx);
$code = substr($file, $idx + 1);
} else {
$name = $file;
$code = '';
}
$name = &'expand($name);
$mtime = (stat($name))[9];
if (defined($mtime) && ($sysmod[$userno] || 0) != $mtime) {
$sysmod[$userno] = $mtime;
if ($name && open(SYS, $name)) {
while (defined($line = <SYS>)) {
$line =~ s/^\s+//;
next if $line =~ /^[\#\;]/;
$line =~ tr/\r\n//d;
next unless $line;
$line = &code_euc($line, $code) if $code;
next unless (($var, $arg) = split(/\:/, $line, 2)) == 2;
next unless $var =~ /\S/;
next unless $arg =~ /\S/;
$system{$userno, $var} = &'add($system{$userno, $var}, $arg);
}
close(SYS);
if (!$system{$userno, 'MSGACT'}) {
$selfpub = 0;
$selfpriv = 0;
} elsif ($system{$userno, 'MSGACT'} == 1) {
$selfpub = 0;
$selfpriv = 1;
} elsif ($system{$userno, 'MSGACT'} == 2) {
$selfpub = 1;
$selfpriv = 0;
} elsif ($system{$userno, 'MSGACT'} == 3) {
$selfpub = 1;
$selfpriv = 1;
}
}
}
}
sub load_msg {
local($userno) = @_;
local($file, $idx, $name, $code, $mtime, $line, $var, $arg);
$file = &'property($userno, 'msgfile') || $MSGFILE;
if (($idx = rindex($file, ';')) != -1) {
$name = substr($file, 0, $idx);
$code = substr($file, $idx + 1);
} else {
$name = $file;
$code = '';
}
$name = &'expand($name);
$mtime = (stat($name))[9];
if (defined($mtime) && ($msgmod[$userno] || 0) != $mtime) {
$msgmod[$userno] = $mtime;
if ($name && open(MSG, $name)) {
foreach $key (keys(%message)) {
($no, $var) = split(/$;/, $key, 2);
next unless $no == $userno;
delete $message{$key};
}
$count[$userno] = -1;
while (defined($line = <MSG>)) {
$line =~ s/^\s+//;
next if $line =~ /^[\#\;]/;
$line =~ tr/\r\n//d;
next unless $line;
$line = &code_euc($line, $code) if $code;
$line = &read_line($userno, $line);
next if index($line, ':') == -1;
next unless (($var, $arg) = split(/\:/, $line, 2)) == 2;
next unless $var =~ /\S/;
next unless $arg =~ /\S/;
if ($var eq 'PATTERN') {
$count[$userno]++;
$pattern{$userno, $count[$userno]} = $arg;
$answer{$userno, $count[$userno]} = '';
} elsif ($var eq 'PROB') {
$prob{$userno, $count[$userno]} = $arg;
} elsif ($var eq 'ANSWER') {
$answer{$userno, $count[$userno]} = &'add($answer{$userno, $count[$userno]}, $arg);
} else {
$message{$userno, $var} = &'add($message{$userno, $var}, $arg);
}
}
close(MSG);
}
}
}
sub privmsg {
local($serverno, $to, $nick, $msg) = @_;
local($userno, $src, $dst, $replace);
$userno = $'userno[$serverno];
if ($msg) {
if ($nick) {
$replace = 0;
foreach $alias (&system($userno, 'ALIAS')) {
($src, $dst) = split(/ /, $alias, 2);
if (index($nick, $src) != -1) {
$replace = 1;
last;
}
}
if (!$replace) {
$dst = $nick . &'jis_euc('$B$5$s(B');
}
$msg =~ s/\$nick/$dst/;
}
$msg = &'euc_jis($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 code_euc {
local($line, $list) = @_;
foreach $code (split(/\,/, "\L$list\E")) {
if ($code eq 'euc') {
$line = &'euc_euc($line);
} elsif ($code eq 'jis') {
$line = &'jis_euc($line);
} elsif ($code eq 'sjis') {
$line = &'sjis_euc($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_euc($line);
} elsif ($code eq 'jis') {
$line = &'jis_euc($line);
} elsif ($code eq 'sjis') {
$line = &'sjis_euc($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/nako.plm</TITLE></HEAD><BODY>
$B%*%s%i%$%s%I%-%e%a%s%H(B
<HR><H3>$BL>A0(B</H3>
auto/nako.plm - Internet Relay Chat Robot nako$B$N%(%_%e%l!<%7%g%s$r9T$&(B
<HR><H3>$B@bL@(B</H3>
Internet Relay Chat Robot nako$B$N%(%_%e%l!<%7%g%s$r9T$$$^$9!#(B
nako$B$G;HMQ$7$F$$$k@_Dj%U%!%$%k$r$=$N$^$^MxMQ$9$k$3$H$,$G$-$^$9!#(B
$B>\$7$/$O(Bnako$B$N%I%-%e%a%s%H$r;2>H$7$F2<$5$$!#(B
<HR><H3>$B%W%m%Q%F%#(B</H3>
<DL>
<DT> auto.nako.sysfile $B%U%!%$%kL>(B[;({jis|euc|sjis})]
</DT>
<DD> $B%7%9%F%`$N@_Dj%U%!%$%k$r;XDj$7$^$9!#(B
$B%G%U%)%k%H$G$O!V(B.nako.sys$B!W$K$J$C$F$$$^$9!#(B
</DD>
<DT> auto.nako.msgfile $B%U%!%$%kL>(B[;({jis|euc|sjis})]
</DT>
<DD> $B%a%C%;!<%8%G!<%?$N@_Dj%U%!%$%k$r;XDj$7$^$9!#(B
$B%G%U%)%k%H$G$O!V(B.nako.msg$B!W$K$J$C$F$$$^$9!#(B
</DD>
</DL>
<HR><H3>$B@_DjNc(B</H3>
<PRE>
+ auto/nako.plm
auto.nako.sysfile: .nako.sys;euc,jis
auto.nako.msgfile: .nako.msg;euc,jis
</PRE>
$B%7%9%F%`@_Dj$N%U%!%$%k$H%a%C%;!<%8%G!<%?@_Dj$N%U%!%$%k$K$=$l$>$l(B
$B!V(B.nako.sys$B!W$H!V(B.nako.msg$B!W$r;HMQ$7$^$9!#(B
$B$3$l$i$N%U%!%$%k$O$$$:$l$b4A;z%3!<%I$,(Beuc$B$b$7$/$O(Bjis$B$GJ]B8$5$l$F$$$k(B
$BI,MW$,$"$j$^$9!#(B
</BODY></HTML>