File: avoice.pl

package info (click to toggle)
sirc 2.211-5
  • links: PTS
  • area: main
  • in suites: sarge, woody
  • size: 372 kB
  • ctags: 356
  • sloc: perl: 4,254; ansic: 1,201; sh: 571; makefile: 66
file content (179 lines) | stat: -rw-r--r-- 4,460 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# autovoice lists.. same as autoop lists, but doing a +v instead of +o
# orabidoo (roger.espel.llima@ens.fr)  7 Nov '95, after an idea from
# slackie (slackjaw@sky.net)

# also adds /bless = /mode +v, after another idea from slackie.

$add_ons.="+avoice.pl" if $add_ons !~ /voice/;

$autovoice=1;
@autovoice=();
$avfile=$ENV{"HOME"}."/.avoice-pl.sve";

sub av_hostpat {
  if ($_[0] =~ /^(\d+)\.(\d+)\.(\d+)\.(\d+)$/) {
    return "${1}.${2}.${3}.*";
  } elsif ($_[0] =~ /^([^. \t]+)\.([^. \t]+)\.(.*)$/) {
    return "*.${2}.${3}";
  } else {
    return $_[0];
  }
}

sub autovoiced {
  local($nuh)=@_;
  local($p);
  foreach $p (@autovoice) {
    return 1 if $nuh =~ /^${p}$/;
  }
  return '';
}

sub addtovoice {
  if (&autovoiced($who."!".$user."\@".$host)) {
    &tell("*\cba\cb* $who is already on your auto-voice list");
  } else {
    $host=&av_hostpat($host);
    $user =~ s/^\~//;
    local($pat)=("*!*".$user."\@".$host);
    &tell("*\cba\cb* Adding $who as $pat to your auto-voice list");
    $pat =~ s/([^\\])\./$1\\./g;
    $pat =~ s/\*/\.\*/g;
    $pat =~ s/([^\.\*\\\w])/\\$1/g;
    push(@autovoice, $pat);
    &sl("NOTICE $who :You have been added to ${nick}'s autovoice list, you should be *very* grateful");
  }
}

sub cmd_addvoice {
  &getarg;
  &tell("*\cba\cb* Must specify a nick or pattern"), return unless $newarg;
  if ($newarg =~ /\!.*\@/) {
    &tell("*\cba\cb* Adding $newarg to your auto-voice list");
    $newarg =~ s/([^\\])\./$1\\./g;
    $newarg =~ s/\*/\.\*/g;
    $newarg =~ s/([^\.\*\\\w])/\\$1/g;
    push(@autovoice, $newarg);
  } else {
    &userhost($newarg, "&addtovoice;");
  }
}
&addcmd("addvoice");

sub hook_avjoined {
  local($c)=($_[0]);
  $c =~ tr/A-Z/a-z/;
  &sl("MODE $c +v $who")
    if ($autovoice && $haveops{$c} && &autovoiced($who."!".$user."\@".$host));
}
&addhook("join", "avjoined");

sub cmd_autovoice {
  &getarg;
  if ($newarg =~ /^on$/) {
    $autovoice=1;
  } elsif ($newarg =~ /^off$/) {
    $autovoice='';
  }
  &tell("*\cba\cb* Auto-voice is ".($autovoice?"on":"off"));
}
&addcmd("autovoice");

sub cmd_listvoice {
  local($n, $p, $q)=(0);
  &tell("*\cba\cb* That's the people in your auto-voice list:");
  foreach $p (@autovoice) {
    $n++;
    $q=$p;
    $q =~ s/\\//g;
    $q =~ s/\.\*/*/g;
    &tell("*\cba\cb* $q");
  }
  &tell("*\cba\cb* which makes.. uhm... $n people, I think");
}
&addcmd("listvoice");

sub remvoice {
  local($nuh)=($who."!".$user."\@".$host);
  @autovoice=grep(($nuh !~ /^${_}$/), @autovoice);
}

sub cmd_remvoice {
  &getarg;
  if (!$newarg) {
    &tell("*\cba\cb* Must specify a nick or address");
  } elsif ($newarg =~ /\@/) {
    $newarg='*!'.$newarg if ($newarg !~ /\!/);
    &tell("*\cba\cb* Time to remove $newarg from the auto-voice list");
    @autovoice=grep(($newarg !~ /^${_}$/), @autovoice);
  } else {
    &tell("*\cba\cb* Time to remove $newarg from the auto-voice list");
    &userhost($newarg, "&remvoice;");
  }
}
&addcmd("remvoice");

sub cmd_clearvoice {
  @autovoice=();
  &tell("*\cba\cb* Auto-voice list cleared!");
}
&addcmd("clearvoice");

# saving the settings

sub cmd_svevoice {
  local($p);
  if (!open(SVE, "> ".$avfile)) {
    &tell("*\cbE\cb* can't write to save file");
    return;
  }
  print SVE ($autovoice ? "1" : "0"), "\n";
  print SVE join(" ", @autovoice), "\n";
  close SVE;
  &tell("*\cba\cb* save completed!");
}
&addcmd("svevoice");

sub cmd_bless {
  local($c, $n, $l)=($talkchannel, 0, '');
  &getarg, $c=$newarg if ($args =~ /^[\#\&]/);
  local(@ppl)=split(/ +/, $args);
  foreach (@ppl) {
    if ($n<4) {
      $l .= " ".$_;
      $n++;
    } else {
      &sl("MODE $c +vvvv $l");
      $l=$_;
      $n=1;
    }
  }
  $l && &sl("MODE $c +vvvv $l");
}
&addcmd("bless");


# some online help

&addhelp("voice", "This is \cbavoice.pl\cb for sirc, by \cborabidoo\cb
 
/autovoice [on|off]        toggles auto-voice
/addvoice <nick>|<pattrn>  adds user to your auto-voice list
/remvoice <nick>|<address> removes user from your auto-voice list
/clearvoice                clears your auto-voice list
/listvoice                 lists your auto-voice list
/svevoice                  saves your auto-voice list and toggle
/bless [<#chan>] <nick> gives a +v to someone");

# reading the saved settings

if (open(AV, "< ".$avfile)) {
  local($n, $l);
  chop($autovoice=<AV>);
  chop($l=<AV>);
  @autovoice=split(' ', $l);
  close(AV);
}

&print("*\cba\cb* \cborabidoo\cb's *\cvavoice.pl\cv* loaded, type /help voice  for help");