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
/
alias.plm
next >
Wrap
Text File
|
1998-10-15
|
13KB
|
431 lines
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><!-- $_ if 0; # -*- perl -*-
# $Id: alias.plm,v 2.20 1998/07/20 09:52:49 hasegawa Exp $
# copyright (c)1998 pupu_j <hasegawa@agusa.nuie.nagoya-u.ac.jp>
package auto_alias;
$_ = 'auto_alias';
sub ss_privmsg {
local($serverno, $prefix, $cmd, @params) = @_;
local($userno, $str, $action, $type, @arg);
$userno = $'userno[$serverno];
($action, $type, @arg) = split(/\s+/, $params[1]);
if ($action) {
$type = '' unless $type;
foreach $str (&'property($userno, 'get')) {
next unless $str eq $action;
&get_alias($serverno, $prefix, $params[0], "\L$type\E", @arg);
return ($prefix, $cmd, @params);
}
foreach $str (&'property($userno, 'add')) {
next unless $str eq $action;
&add_alias($serverno, $prefix, $params[0], "\L$type\E", @arg);
return ($prefix, $cmd, @params);
}
foreach $str (&'property($userno, 'remove')) {
next unless $str eq $action;
&remove_alias($serverno, $prefix, $params[0], "\L$type\E", @arg);
return ($prefix, $cmd, @params);
}
foreach $str (&'property($userno, 'change')) {
next unless $str eq $action;
&change_alias($serverno, $prefix, $params[0], "\L$type\E", @arg);
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 get_alias {
local($serverno, $prefix, $chan, $type, $text) = @_;
local($userno, %alias, $no, $to);
$userno = $'userno[$serverno];
%alias = &read_alias($userno);
if ($text) {
$no = &fetch($type, $text, %alias);
} else {
$no = &match($prefix, %alias);
}
return unless $no;
$to = &'prefix($prefix);
foreach $line (&format($no, %alias)) {
&privmsg($serverno, $to, $line);
}
}
sub add_alias {
local($serverno, $prefix, $chan, $type, @arg) = @_;
local($userno, %alias, $no, $i);
$userno = $'userno[$serverno];
%alias = &read_alias($userno);
$no = &match($prefix, %alias);
$alias{$no, 'nick'} = &'list((&'prefix($prefix))[0]) unless $no;
if ($type) {
$alias{$no, $type} = &'add($alias{$no, $type}, @arg);
}
&write_alias($userno, %alias);
}
sub remove_alias {
local($serverno, $prefix, $chan, $type, @arg) = @_;
local($userno, %alias, $no, $i);
$userno = $'userno[$serverno];
%alias = &read_alias($userno);
return unless $type;
$no = &match($prefix, %alias);
if ($no) {
$alias{$no, $type} = &'remove($alias{$no, $type}, @arg);
}
&write_alias($userno, %alias);
}
sub change_alias {
local($serverno, $prefix, $chan, $type, @arg) = @_;
local($userno, %alias, $no, $i);
$userno = $'userno[$serverno];
%alias = &read_alias($userno);
return unless $type;
$no = &match($prefix, %alias);
if ($no) {
$alias{$no, $type} = &'change($alias{$no, $type}, @arg);
}
&write_alias($userno, %alias);
}
sub match {
local($prefix, %alias) = @_;
local($nick, $i, $regex);
$nick = &'prefix($prefix);
for ($i = 1; defined($alias{$i, 'nick'}); $i++) {
foreach $mask (&'array($alias{$i, 'user'} || '')) {
$regex = &'regex($mask);
return $i if $prefix =~ /$regex/i;
}
foreach $str (&'array($alias{$i, 'nick'})) {
return $i if "\L$nick\E" eq "\L$str\E";
}
}
return 0;
}
sub fetch {
local($type, $arg, %alias) = @_;
local($i, $regex);
return 0 unless $type;
for ($i = 1; defined($alias{$i, 'nick'}); $i++) {
if ($type eq 'nick' || $type eq '*') {
foreach $str (&'array($alias{$i, 'nick'})) {
return $i if "\L$str\E" eq "\L$arg\E";
}
}
if ($type eq 'name' || $type eq '*') {
foreach $str (&'array($alias{$i, 'name'} || '')) {
return $i if $str eq $arg;
}
}
if ($type eq 'user' || $type eq '*') {
foreach $mask (&'array($alias{$i, 'user'} || '')) {
$regex = &'regex($mask);
return $i if $arg =~ /$regex/i;
}
}
}
return 0;
}
sub format {
local($no, %alias) = @_;
local($n, $type, @list);
@list = ();
foreach $key (sort(keys(%alias))) {
($n, $type) = split(/$;/, $key, 2);
next unless $n == $no;
if ($type eq 'nick') {
unshift(@list, 'nick: ' . join(',', &'array($alias{$key})));
} elsif ($type eq 'name') {
push(@list, 'name: ' . join(' ', &'array($alias{$key})));
} else {
foreach $str (&'array($alias{$key})) {
push(@list, $type . ': ' . $str);
}
}
}
return @list;
}
sub read_alias {
local($userno) = @_;
local(%alias, $file, $idx, $name, $code, $line, $var, $arg, $type, $no);
$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)) {
%alias = ();
$no = 0;
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') {
$no++;
$alias{$no, 'nick'} = &'list(split(/\,/, $arg));
} elsif ($type eq 'name') {
$alias{$no, $type} = &'add($alias{$no, $type}, split(/\s+/, $arg));
} else {
$alias{$no, $type} = &'add($alias{$no, $type}, $arg);
}
}
}
close(FILE);
}
return %alias;
}
sub write_alias {
local($userno, %alias) = @_;
local($file, $idx, $name, $code, $line, $i);
$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")) {
for ($i = 1; defined($alias{$i, 'nick'}); $i++) {
foreach $line (&format($i, %alias)) {
$line = &jis_code($line, $code) if $code;
$line = &write_line($userno, $line);
print FILE $line, "\n";
}
print FILE "\n";
}
if (defined($alias{0, 'nick'})) {
foreach $line (&format(0, %alias)) {
$line = &jis_code($line, $code) if $code;
$line = &write_line($userno, $line);
print FILE $line, "\n";
}
print FILE "\n";
}
close(FILE);
}
}
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/alias.plm</TITLE></HEAD><BODY>
$B%*%s%i%$%s%I%-%e%a%s%H(B
<HR><H3>$BL>A0(B</H3>
auto/alias.plm - $B%f!<%6%(%$%j%"%9>pJs$N4I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