home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.madoka.org
/
2014.12.ftp.madoka.org.tar
/
ftp.madoka.org
/
pub
/
plum
/
plum2_33_1.lzh
/
module
/
auto
/
yuurii.plm
< prev
Wrap
Text File
|
1999-03-24
|
15KB
|
548 lines
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><!-- $_ if 0; # -*- perl -*-
# $Id: yuurii.plm,v 2.31 1999/01/20 14:47:54 hasegawa Exp $
# copyright (c)1997-1999 Yoshinori Hasegawa <hasegawa@madoka.org>
package auto_yuurii;
$PLUGINRC = '.pluginrc';
$CACHE = 50;
$DOWN = 48;
$DOWNMES = 'auto down';
$TIMER = 2000;
$USETIMER = 0;
$HEADER = '%H:%M';
$DEBUG = 'logdebug';
$MODE = umask() ^ 0666;
$CLIENTINFO = 'HELP';
undef @modify;
undef %modify;
$_ = 'auto_yuurii';
sub main_loop {
local($userno) = @_;
local($sno, $nowtime, $hour, $day, $usetimer);
foreach $sno (&'array($'serverlist)) {
next unless $'avail[$sno];
next unless $'userno[$sno] == $userno;
$nowtime[$userno] = time();
$lasttime[$userno] = $nowtime[$userno] unless $lasttime[$userno];
$usetimer = &'property($userno, 'usetimer') || $USETIMER;
&do_yuurii($sno, 'do_timer', '', '', $sno, $usetimer) if $usetimer;
$lasttime[$userno] = $nowtime[$userno];
($hour, $day) = (localtime())[2, 3];
$lastday[$userno] = $hour unless defined($lastday[$userno]);
$lasthour[$userno] = $day unless defined($lasthour[$userno]);
if ($lastday[$userno] != $day && defined(&daily)) {
&do_yuurii($sno, 'daily', '', 'bot_timer');
}
if ($lasthour[$userno] != $hour && defined(&hourly)) {
&do_yuurii($sno, 'hourly', '', 'bot_timer');
}
$lastday[$userno] = $day;
$lasthour[$userno] = $hour;
}
}
sub ss_invite {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick);
$nick = &'prefix($prefix);
&do_yuurii($serverno, 'plugin', $prefix, $cmd, $params[1], $nick, '');
return ($prefix, $cmd, @params);
}
sub ss_join {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $nick, $name, $mode, $timer);
$userno = $'userno[$serverno];
$nick = &'prefix($prefix);
($name, $mode) = split(/\cG/, $params[0]);
if ($nick eq $'nick[$serverno]) {
$timer = &'property($userno, 'timer') || $TIMER;
$channeltimer{$serverno, $name} = $timer;
} else {
&do_yuurii($serverno, 'plugin', $prefix, $cmd, $name, $nick, '');
}
return ($prefix, $cmd, @params);
}
sub ss_nick {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick);
$nick = &'prefix($prefix);
&do_yuurii($serverno, 'plugin', $prefix, $cmd, 'ALL', $params[0], $nick) if $params[0] ne $'nick[$serverno];
return ($prefix, $cmd, @params);
}
sub ss_part {
local($serverno, $prefix, $cmd, @params) = @_;
local($nick);
$nick = &'prefix($prefix);
&do_yuurii($serverno, 'plugin', $prefix, $cmd, $params[0], $nick, $params[1]) if $nick ne $'nick[$serverno];
return ($prefix, $cmd, @params);
}
sub ss_privmsg {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $nick, $vchan, $tmp, $rest, $ctcp);
$nick = &'prefix($prefix);
$vchan = &'alias($params[0]);
$tmp = '';
$rest = $params[1];
while ($rest =~ /^(.*)\cA([^\cA]*)\cA(.*)$/) {
$tmp .= $1;
$ctcp = $2;
$rest = $3;
&do_ctcp($serverno, $prefix, $vchan, $ctcp);
}
$tmp .= $rest || '';
&do_yuurii($serverno, 'plugin', $prefix, $cmd, $params[0], $nick, $params[1]);
return ($prefix, $cmd, @params);
}
sub cpss_help {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $nick);
$userno = $'userno[$serverno];
$nick = &'prefix($prefix);
if (@help) {
foreach $help (@help) {
&'s_print($serverno, '', 'NOTICE', $nick, $help);
}
} else {
&'s_print($serverno, '', 'NOTICE', $nick, 'no help');
}
return ($prefix, $cmd, @params);
}
sub do_yuurii {
local($serverno, $sub, $prefix, $command, @args) = @_;
local($userno, $vchan, $my_nick, $from, $where, $chanlist, $autojoinchanlist, %nameslist, %time_count, @cache_mes, $down, $down_mes, $logmode, $use_timer, $timer_count_def, $^W);
$userno = $'userno[$serverno];
$my_nick = $'nick[$serverno];
if (index($prefix, '!') != -1) {
$from = substr($prefix, 0, index($prefix, '!'));
$where = substr($prefix, index($prefix, '!') + 1);
} else {
$from = $prefix;
$where = '';
}
$chanlist = $;;
$autojoinchanlist = $;;
foreach $chan (&'array($'channellist[$serverno])) {
$vchan = &'alias($chan);
$chanlist .= $vchan . $;;
$autojoinchanlist .= $vchan . $;;
$nameslist{$vchan} = $; . join($;, &'array($'nameslist{$serverno, $chan})) . $;;
$time_count{$vchan} = $channeltimer{$serverno, $chan};
}
@cache_mes = &'array($messagelist[$serverno]);
$down = &'property($userno, 'down') || $DOWN;
$down_mes = &'property($userno, 'downmes') || $DOWNMES;
$timer_count_def = &'property($userno, 'timer') || $TIMER;
$use_timer = &'property($userno, 'usetimer') ? 'on' : 'off';
$logmode = &'property($userno, 'mode');
if (defined($logmode)) {
$logmode = oct($logmode) | 0600;
} else {
$logmode = $MODE | 0600;
}
$^W = 0;
&$sub(@args) if defined(&$sub);
foreach $chan (&'array($'channellist[$serverno])) {
$vchan = &'alias($chan);
$channeltimer{$serverno, $chan} = $time_count{$vchan};
}
$messagelist[$serverno] = &'list(@cache_mes);
}
sub do_timer {
local($serverno, $usetimer) = @_;
local($userno, $i);
for ($i = $lasttime[$userno]; $i < $nowtime[$userno]; $i++) {
foreach $chan (&'array($'channellist[$serverno])) {
$channeltimer{$serverno, $chan} -= 1 if $channeltimer{$serverno, $chan} > 0;
$channeltimer{$serverno, $chan}++ if $channeltimer{$serverno, $chan} < 0;
}
next unless $i % $usetimer == 0;
&plugin($serverno, '', 'bot_timer', '', '', '');
}
}
sub do_ctcp {
local($serverno, $prefix, $chan, $msg) = @_;
local($userno, $cmd, $mes);
$userno = $'userno[$serverno];
($cmd, $mes) = split(/\s+/, $msg, 2);
&do_yuurii($serverno, "ctcp_\L$cmd\E", $prefix, 'privmsg', $mes);
}
sub plugin {
local(@args) = @_;
local($pluginrc, $mtime, $sub, @plugin);
$pluginrc = &'expand(&'property($userno, 'pluginrc') || $PLUGINRC);
$mtime = (stat($pluginrc))[9];
$sub = 'pluginsub_' . $userno;
if (defined($mtime) && ($modify[$userno] || 0) != $mtime) {
$modify[$userno] = $mtime;
if (open(PLUGIN, $pluginrc)) {
@plugin = <PLUGIN>;
close(PLUGIN);
undef &$sub if defined(&$sub);
eval('sub ' . $sub . ' { ' . join('', @plugin) . ' }');
}
}
&$sub(@args) if defined(&$sub);
}
sub local_chan {
local($chan) = @_;
if ($chan) {
return (&'real($chan), &'alias($chan));
} else {
return ('', '');
}
}
sub now_time {
($sec, $min, $hour, $mday, $mon, $year) = localtime(time());
$mon++;
$year += 1900;
$header = &'property($userno, 'header');
$header = $HEADER unless defined($header);
$header = &'date($header) . ' ';
}
sub redo {
local($file) = @_;
local($mtime, @names, $sub, $sublist, $plugin);
$plugin = &search_file($file);
$mtime = (stat($plugin))[9];
return unless defined($mtime);
return if (($modify{$file} || 0) == $mtime);
$modify{$file} = $mtime;
if (defined($sublist{$file})) {
foreach $name (&'array($sublist{$file})) {
undef &$name if defined(&$name);
}
}
if ($] < 5) {
@names = keys(%_auto_yuurii);
} else {
eval '@names = keys(%auto_yuurii::)';
}
foreach $name (@names) {
$sub = "auto_yuurii\'$name";
$sublist = &'add($sublist, $sub) if defined(&$sub);
}
do $plugin;
if ($] < 5) {
@names = keys(%_auto_yuurii);
} else {
eval '@names = keys(%auto_yuurii::)';
}
foreach $name (@names) {
$sub = "auto_yuurii\'$name";
next unless defined(&$sub);
next if &'exist($sublist, $sub);
$sublist{$file} = &'add($sublist{$file}, $sub);
}
}
sub search_file {
local($file) = @_;
local($path);
if (-r $file) {
return $file;
} else {
foreach $dir (&'property($userno, 'plugindir'), @INC) {
if (-r "$dir/$file") {
return "$dir/$file";
}
$path = &'expand($dir);
if (-r "$path/$file") {
return "$path/$file";
}
}
return '';
}
}
sub sendCok {
local($msg) = @_;
local($prefix, $cmd, @params);
$msg =~ tr/\r\n//d;
($prefix, $cmd, @params) = &'parse($msg);
foreach $cno (&'array($'clientlist)) {
next unless $'avail[$cno];
next unless $'server[$cno] == $serverno;
&'c_print($cno, $prefix, $cmd, @params);
}
}
sub sendCchan {
local($msg) = @_;
&sendCok($msg);
}
sub sendChan2 {
local($msg) = @_;
&sendCok($msg);
}
sub sendS {
local($msg) = @_;
if ($serverno && $'avail[$serverno]) {
$msg =~ tr/\r\n//d;
&'s_print($serverno, &'parse($msg));
}
}
sub sendSCL {
local($msg, $chan) = @_;
local($rchan, $vchan, $cache);
($rchan, $vchan) = &local_chan($chan);
$msg = &'euc_jis($msg);
&sendCok(":$'nick[$serverno] PRIVMSG $rchan :$msg\n");
&sendS("PRIVMSG $rchan :$msg\n");
push(@cache_mes, ">$vchan< $msg");
$cache = &'property($userno, 'cache') || $CACHE;
while (@cache_mes > $cache) {
shift(@cache_mes);
}
}
sub cached {
local($msg, $chan) = @_;
local($vchan);
$vchan = &'alias($chan);
return if &'exist(&'list(@cache_mes), ">$vchan< $msg");
&sendSCL($msg, $chan);
}
sub InitList {
$_[0] = $;;
}
sub AddList {
if (&ExistList($list, $item)) {
return 0;
} else {
$_[0] .= $item . $;;
return 1;
}
}
sub DelList {
local($list, $item);
$idx = index("\L$list\E", $; . "\L$item\E" . $;);
substr($_[0], $idx, length($; . $item . $;)) = $; if $idx != -1;
}
sub ExistList {
local($list, $item) = @_;
if (index("\L$list\E", "\L$;$item$;\E") != -1) {
return 1;
} else {
return 0;
}
}
sub Debug {
local($msg, $chan) = @_;
local($header, $debug);
$debug = &'expand(&'property($userno, 'debug') || $DEBUG);
$debug = &'date($debug);
$header = &'property($userno, 'header');
$header = $HEADER unless defined($header);
$header = &'date($header);
if (open(DEBUG, ">>$debug")) {
select((select(DEBUG), $| = 1)[0]);
print DEBUG $header, ' ', $msg, "\n";
close(DEBUG);
}
}
sub down {
local($msg) = @_;
print STDERR $msg;
exit(0);
}
sub kanji_jis {
local(*var) = @_;
$var = &'euc_jis($var);
}
sub kanji_euc {
local(*var) = @_;
$var = &'jis_euc($var);
}
sub jcode'convert {
local(*var, $code) = @_;
if ($code eq 'euc') {
$var = &'jis_euc($var);
} elsif ($code eq 'jis') {
$var = &'euc_jis($var);
}
}
sub jcode'euc2jis {
local(*var) = @_;
$var = &'euc_jis($var);
}
sub jcode'euc2sjis {
local(*var) = @_;
$var = &'euc_sjis($var);
}
sub jcode'jis2euc {
local(*var) = @_;
$var = &'jis_euc($var);
}
sub jcode'jis2sjis {
local(*var) = @_;
$var = &'jis_sjis($var);
}
sub jcode'sjis2euc {
local(*var) = @_;
$var = &'sjis_euc($var);
}
sub jcode'sjis2jis {
local(*var) = @_;
$var = &'sjis_jis($var);
}
__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/yuurii.plm</TITLE></HEAD><BODY>
$B%*%s%i%$%s%I%-%e%a%s%H(B
<HR><H3>$BL>A0(B</H3>
auto/yuurii.plm - pirc bot $B$f!<$j$#$N%W%i%0%$%s$rAH$_9~$`(B
<HR><H3>$B@bL@(B</H3>
pirc bot $B$f!<$j$#$N%(%_%e%l!<%7%g%s$r9T$$!"(B
$B$f!<$j$#MQ$N%W%i%0%$%s$r<B9T$G$-$k$h$&$K$7$^$9!#(B
$B$f!<$j$#MQ$N!V(B.pluginrc$B!W$d%W%i%0%$%s$,A4$F$=$N$^$^MxMQ$G$-$^$9!#(B
jcode.pl$B$KAjEv$9$k%k!<%A%s$r4^$s$G$$$k$N$G!"(Bjcode.pl$B$OI,MW$"$j$^$;$s!#(B
$B>\$7$/$O(Bpirc bot $B$f!<$j$#$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.yuurii.cache $B%-%c%C%7%e%5%$%:(B
</D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$3$G;XDj$7$?%U%!%$%k$K=PNO$7$^$9!#(B
$BJ8;zNsCf$K(B%$B$G;O$^$kJ8;zNs$,4^$^$l$F$$$k$H!"(B
$BBP1~$9$k$b$N$K$*$-$+$o$j$^$9!#(B
$B$f!<$j$#$G$N%G%U%)%k%H$O(Blog%m%d$B$G$9!#(B
</DD>
</DL>
<HR><H3>$B@_DjNc(B</H3>
<PRE>
+ auto/yuurii.plm
auto.yuurii.cache: 50
auto.yuurii.pluginrc: .pluginrc
auto.yuurii.down: 48
auto.yuurii.downmes: auto down
auto.yuurii.timer: 2000
auto.yuurii.usetimer: 0
auto.yuurii.mode: 600
auto.yuurii.header: %H:%M:%S
auto.yuurii.debug: log%m%d
</PRE>
$B$f!<$j$#$N%G%U%)%k%H$HF1$8@_Dj$G$9!#(B
$B$?$@$7:F5/F0$O$7$J$$$N$G!V(Bauto.yuurii.down$B!W$H(B
$B!V(Bauto.yuurii.downmes$B!W$N@_Dj$OL58z$G$9!#(B
<PRE>
+ auto/yuurii.plm
auto.yuurii.cache: 0
auto.yuurii.pluginrc: yuurii.conf
auto.yuurii.usetimer: 1
</PRE>
$B%-%c%C%7%e$r;H$o$J$$$h$&$K$7$F!"(B1$BIC4V$K(B1$B2s%W%i%0%$%s$r<B9T$7$^$9!#(B
$B$^$?!"!V(B.pluginrc$B!W$NBe$o$j$K!V(Byuurii.conf$B!W$r;H$$$^$9!#(B
</BODY></HTML>