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 >
Text File  |  1998-10-15  |  9KB  |  319 lines

  1. <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><!-- $_ if 0; # -*- perl -*-
  2. # $Id: random.plm,v 2.14 1998/10/13 14:06:30 hasegawa Exp $
  3. # copyright (c)1997-1998 pupu_j <hasegawa@agusa.nuie.nagoya-u.ac.jp>
  4.  
  5. package auto_random;
  6.  
  7. $RATE = 100;
  8.  
  9. $_ = 'auto_random';
  10.  
  11. sub ss_privmsg {
  12.   local($serverno, $prefix, $cmd, @params) = @_;
  13.   local($userno, $mtime, $file, $idx, $name, $code, $req, $reply, $rate, $to, @list, $str);
  14.   $userno = $'userno[$serverno];
  15.   $file = &'property($userno, 'file') || '';
  16.   if (($idx = rindex($file, ';')) != -1) {
  17.     $name = substr($file, 0, $idx);
  18.     $code = substr($file, $idx + 1);
  19.   } else {
  20.     $name = $file;
  21.     $code = '';
  22.   }
  23.   $name = &'expand($name);
  24.   if ($name) {
  25.     $mtime = (stat($name))[9];
  26.     if (defined($mtime) && ($modify[$userno] || 0) != $mtime) {
  27.       $modify[$userno] = $mtime;
  28.       &read_file($userno);
  29.     }
  30.   }
  31.   ($req, $reply) = split(/\s+/, $params[1], 2);
  32.   if ($reply) {
  33.     foreach $add (&'property($userno, 'add')) {
  34.       next unless $req eq $add;
  35.       &add_file($userno, $reply);
  36.       return ($prefix, $cmd, $params[0], $params[1]);
  37.     }
  38.     foreach $remove (&'property($userno, 'remove')) {
  39.       next unless $req eq $remove;
  40.       &remove_file($userno, $reply);
  41.       return ($prefix, $cmd, @params);
  42.     }
  43.   }
  44.   $rate = &'property($userno, 'rate') || $RATE;
  45.   if (rand(100) < $rate) {
  46.     foreach $req (&'property($userno, 'request')) {
  47.       next unless $req eq $params[1];
  48.       @list = &'array($message[$userno]);
  49.       $str = @list[rand(scalar(@list))];
  50.       last unless $str;
  51.       if ($params[0] =~ /^[\#\&\+]/) {
  52.         $to = $params[0];
  53.         $str = &user_name($userno, $prefix) . ': ' . $str;
  54.       } else {
  55.         $to = &'prefix($prefix);
  56.       }
  57.       &privmsg($serverno, $to, $str);
  58.       last;
  59.     }
  60.   }
  61.   return ($prefix, $cmd, @params);
  62. }
  63.  
  64. sub privmsg {
  65.   local($serverno, $to, $msg) = @_;
  66.   &'s_print($serverno, '', 'PRIVMSG', $to, $msg);
  67.   foreach $cno (&'array($'clientlist)) {
  68.     next unless $'avail[$cno];
  69.     next unless $'server[$cno] == $serverno;
  70.     &'c_print($cno, &'user($cno), 'PRIVMSG', $to, $msg);
  71.   }
  72. }
  73.  
  74. sub add_file {
  75.   local($userno, $reply) = @_;
  76.   $message[$userno] = &'add($message[$userno], $reply);
  77.   &write_file($userno);
  78. }
  79.  
  80. sub remove_file {
  81.   local($userno, $reply) = @_;
  82.   $message[$userno] = &'remove($message[$userno], $reply);
  83.   &write_file($userno);
  84. }
  85.  
  86. sub read_file {
  87.   local($userno) = @_;
  88.   local($file, $idx, $name, $code, $line);
  89.   $file = &'property($userno, 'file') || '';
  90.   if (($idx = rindex($file, ';')) != -1) {
  91.     $name = substr($file, 0, $idx);
  92.     $code = substr($file, $idx + 1);
  93.   } else {
  94.     $name = $file;
  95.     $code = '';
  96.   }
  97.   $name = &'expand($name);
  98.   if ($name && open(FILE, $name)) {
  99.     undef($message[$userno]);
  100.     while (defined($line = <FILE>)) {
  101.       $line =~ tr/\r\n//d;
  102.       next unless $line;
  103.       $line = &code_jis($line, $code) if $code;
  104.       $line = &read_line($userno, $line);
  105.       $message[$userno] = &'add($message[$userno], $line);
  106.     }
  107.     close(FILE);
  108.   }
  109. }
  110.  
  111. sub write_file {
  112.   local($userno) = @_;
  113.   local($file, $idx, $name, $code);
  114.   $file = &'property($userno, 'file') || '';
  115.   if (($idx = rindex($file, ';')) != -1) {
  116.     $name = substr($file, 0, $idx);
  117.     $code = substr($file, $idx + 1);
  118.   } else {
  119.     $name = $file;
  120.     $code = '';
  121.   }
  122.   $name = &'expand($name);
  123.   if ($name && open(FILE, ">$name")) {
  124.     foreach $line (&'array($message[$userno])) {
  125.       $line = &jis_code($line, $code) if $code;
  126.       $line = &write_line($userno, $line);
  127.       print FILE $line, "\n";
  128.     }
  129.     close(FILE);
  130.   }
  131. }
  132.  
  133. sub user_name {
  134.   local($userno, $prefix) = @_;
  135.   local($regex, $text, $file, $idx, $name, $code, $line, $var, $arg, $type);
  136.   $file = &'property($userno, 'alias') || '';
  137.   if (($idx = rindex($file, ';')) != -1) {
  138.     $name = substr($file, 0, $idx);
  139.     $code = substr($file, $idx + 1);
  140.   } else {
  141.     $name = $file;
  142.     $code = '';
  143.   }
  144.   $name = &'expand($name);
  145.   if ($name && open(FILE, $name)) {
  146.     while (defined($line = <FILE>)) {
  147.       $line =~ s/^\s+//;
  148.       next if $line =~ /^[\#\;]/;
  149.       $line =~ tr/\r\n//d;
  150.       next unless $line;
  151.       $line =~ s/\s+$//;
  152.       $line = &code_jis($line, $code) if $code;
  153.       $line = &read_line($userno, $line);
  154.       if ((($var, $arg) = split(/\s*\:\s*/, $line, 2)) == 2) {
  155.         $type = "\L$var\E";
  156.         if ($type eq 'nick') {
  157.           $nick = &'list(split(/\,/, $arg));
  158.           $name = '';
  159.         } elsif ($type eq 'name') {
  160.           $name = &'add($name, split(/\s+/, $arg));
  161.         } elsif ($type eq 'user') {
  162.           foreach $text (split(/\s+/, $arg)) {
  163.             $regex = &'regex($text);
  164.             next unless $prefix =~ /$regex/i;
  165.             close(FILE);
  166.             return (&'array($name || $nick))[0];
  167.           }
  168.         }
  169.       }
  170.     }
  171.     close(FILE);
  172.   }
  173.   return (&'prefix($prefix))[0];
  174. }
  175.  
  176. sub code_jis {
  177.   local($line, $list) = @_;
  178.   foreach $code (split(/\,/, "\L$list\E")) {
  179.     if ($code eq 'euc') {
  180.       $line = &'euc_jis($line);
  181.     } elsif ($code eq 'jis') {
  182.       $line = &'jis_jis($line);
  183.     } elsif ($code eq 'sjis') {
  184.       $line = &'sjis_jis($line);
  185.     }
  186.   }
  187.   return $line;
  188. }
  189.  
  190. sub jis_code {
  191.   local($line, $list) = @_;
  192.   local($code);
  193.   $code = (split(/\,/, "\L$list\E"))[0];
  194.   if ($code eq 'euc') {
  195.     $line = &'jis_euc($line);
  196.   } elsif ($code eq 'jis') {
  197.     $line = &'jis_jis($line);
  198.   } elsif ($code eq 'sjis') {
  199.     $line = &'jis_sjis($line);
  200.   }
  201.   return $line;
  202. }
  203.  
  204. sub read_line {
  205.   local($userno, $line) = @_;
  206.   foreach $kanji (&'property($userno, 'kanji')) {
  207.     foreach $code (split(/\,/, "\L$kanji\E")) {
  208.       if ($code eq 'euc') {
  209.         $line = &'euc_jis($line);
  210.       } elsif ($code eq 'jis') {
  211.         $line = &'jis_jis($line);
  212.       } elsif ($code eq 'sjis') {
  213.         $line = &'sjis_jis($line);
  214.       }
  215.     }
  216.   }
  217.   return $line;
  218. }
  219.  
  220. sub write_line {
  221.   local($userno, $line) = @_;
  222.   local($kanji, $code);
  223.   $kanji = &'property($userno, 'kanji');
  224.   if ($kanji) {
  225.     $code = (split(/\,/, "\L$kanji\E"))[0];
  226.     if ($code eq 'euc') {
  227.       $line = &'jis_euc($line);
  228.     } elsif ($code eq 'jis') {
  229.       $line = &'jis_jis($line);
  230.     } elsif ($code eq 'sjis') {
  231.       $line = &'jis_sjis($line);
  232.     }
  233.   }
  234.   return $line;
  235. }
  236.  
  237. __END__
  238. --><HTML><HEAD>
  239. <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-2022-JP">
  240. <LINK REV="made" HREF="mailto:hasegawa@agusa.nuie.nagoya-u.ac.jp">
  241. <TITLE>auto/random.plm</TITLE></HEAD><BODY>
  242.  
  243. $B%*%s%i%$%s%I%-%e%a%s%H(B
  244.  
  245.  
  246. <HR><H3>$BL>A0(B</H3>
  247.  
  248. auto/random.plm - $BFCDj$NH/8@$KH?1~$7$F%i%s%@%`$JH/8@$r$9$k(B
  249.  
  250.  
  251. <HR><H3>$B@bL@(B</H3>
  252.  
  253. $BFCDj$N%a%C%;!<%8$,H/8@$5$l$k$H!";XDj$5$l$?%a%C%;!<%8$NCf$+$i(B
  254. $B$I$l$+(B1$B$D$r%i%s%@%`$KA*Br$7$FH/8@$7$^$9!#(B
  255.  
  256.  
  257. <HR><H3>$B%W%m%Q%F%#(B</H3>
  258.  
  259. <DL>
  260. <DT>  auto.random.request* $BJ8;zNs(B
  261. </DT>
  262. <DD>    $BH?1~$9$kH/8@$r;XDj$7$^$9!#(B
  263.         $B$3$3$G;XDj$7$?%a%C%;!<%8$N$I$l$+(B1$B$D$H0lCW$7$?>l9g$K(B
  264.         $B%i%s%@%`$KA*Br$5$l$?%a%C%;!<%8$rH/8@$7$^$9!#(B
  265. </DD>
  266. <DT>  auto.random.file $B%U%!%$%kL>(B[;({jis|euc|sjis})]
  267. </DT>
  268. <DD>    $B%i%s%@%`$KH/8@$9$k%a%C%;!<%8$N=q$+$l$?%U%!%$%k$r;XDj$7$^$9!#(B
  269.         $B%U%!%$%k$NCf$G$O(B1$B9T$K(B1$B$D$N%a%C%;!<%8$r=q$$$F2<$5$$!#(B
  270.         $B%U%!%$%k$O;XDj$7$?4A;z%3!<%I$GJ]B8$5$l$^$9!#(B
  271.         $B4A;z%3!<%I$rJ#?t;XDj$7$?>l9g$O!":G=i$K;XDj$7$?4A;z%3!<%I$G(B
  272.         $BJ]B8$5$l!">JN,$7$?>l9g$O!V(Bjis$B!W$r;XDj$7$?$3$H$HF1$8$G$9!#(B
  273.         $B$^$?!"!V(Beuc$B!W$H!V(Bsjis$B!W$rF1;~$K;XDj$9$k$3$H$O$G$-$^$;$s!#(B
  274. </DD>
  275. <DT>  auto.random.alias $B%U%!%$%kL>(B[;({jis|euc|sjis})]
  276. </DT>
  277. <DD>    $B%(%$%j%"%9$r;2>H$9$k%U%!%$%k$r;XDj$7$^$9!#(B
  278.         $B$3$N%U%!%$%k$,;XDj$5$l$F$$$k$H!"C/$KBP$9$kH/8@$+$r(B
  279.         $B%K%C%/%M!<%`$G$O$J$/!"BP1~$9$kL>A0$GH/8@$7$^$9!#(B
  280. </DD>
  281. <DT>  auto.random.rate $B3NN((B
  282. </DT>
  283. <DD>    $BH/8@$KH?1~$9$k3NN($r;XDj$7$^$9!#(B0$B$r;XDj$9$k$HA4$/H?1~$;$:!"(B
  284.         100$B$r;XDj$9$k$HA4$F$NH/8@$KH?1~$9$k$h$&$K$J$j$^$9!#(B
  285.         $B%G%U%)%k%H$G$O(B100$B$K$J$C$F$$$^$9!#(B
  286. </DD>
  287. <DT>  auto.random.add* $BJ8;zNs(B
  288. </DT>
  289. <DD>    $B%a%C%;!<%8$rDI2C$9$k$r;XDj$7$^$9!#(B
  290.         $B$3$3$G;XDj$7$?J8;zNs$rH/8@$9$k$H!"?7$7$$%a%C%;!<%8$rDI2C$7$^$9!#(B
  291. </DD>
  292. <DT>  auto.random.remove* $BJ8;zNs(B
  293. </DT>
  294. <DD>    $B%a%C%;!<%8$r:o=|$9$k$r;XDj$7$^$9!#(B
  295.         $B$3$3$G;XDj$7$?J8;zNs$rH/8@$9$k$H!"0lCW$9$k%a%C%;!<%8$r:o=|$7$^$9!#(B
  296. </DD>
  297. </DL>
  298.  
  299.  
  300. <HR><H3>$B@_DjNc(B</H3>
  301.  
  302. <PRE>
  303. + auto/random.plm
  304. auto.random.request: $B:#F|$N1?@*$O(B?
  305. auto.random.request: $B$&$i$J$$(B
  306. auto.random.file: random.txt;jis
  307. auto.random.rate: 100
  308. auto.random.add: $B$&$i$J$$DI2C(B
  309. auto.random.remove: $B$&$i$J$$:o=|(B
  310. </PRE>
  311.  
  312. $B!V:#F|$N1?@*$O(B?$B!W$+!V$&$i$J$$!W$N$I$A$i$+$NH/8@$,$"$C$?$H$-$K!"(B
  313. $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
  314. random.txt$B$O(Bjis$B$G=q$+$l$F$$$J$$$H$$$1$^$;$s!#(B
  315. $B$^$?!"!V$&$i$J$$DI2C(B $BBg5H$G$9!y!W$J$I$N$h$&$KH/8@$9$k$3$H$G!"(B
  316. $B?7$7$$%a%C%;!<%8$rDI2C$9$k$3$H$,$G$-$^$9!#(B
  317.  
  318. </BODY></HTML>
  319.