| 1 | # $Id: Autoop.pm,v 1.11 2000-07-27 12:01:04-04 roderick Exp $ | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # Copyright (c) 1997-2000 Roderick Schertler. All rights reserved. | ||||||||||||||||||||||||||||
| 4 | # This program is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 5 | # it under the same terms as Perl itself. | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | # XXX | ||||||||||||||||||||||||||||
| 8 | # - track nick changes | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | package Sirc::Autoop; | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Exporter (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use Sirc::Chantrack qw(%Chan_op %Chan_user %Chan_voice); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 1 | ▶ | use Sirc::LckHash (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Sirc::Util qw(addcmd addhelp add_hook addhook ban_pattern | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | docommand doset have_ops have_ops_q ieq | ||||||||||||||||||||||||||||
| 19 | mask_to_re notice optional_channel | ||||||||||||||||||||||||||||
| 20 | settable_boolean settable_int tell_question | ||||||||||||||||||||||||||||
| 21 | 1 | timer userhost xgetarg xtell); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | ▶ | use vars qw($VERSION @ISA @EXPORT @EXPORT_OK @Autoop %Autovoice); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | $VERSION = do{my@r=q$Revision: 1.11 $=~/\d+/g;sprintf '%d.'.'%03d'x$#r,@r}; | |||||||||||||||||||||||||||
| 26 | 1 | ▶ | $VERSION .= '-l' if q$Locker: $ =~ /: \S/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 1 | @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 29 | 1 | @EXPORT = qw(); | |||||||||||||||||||||||||||
| 30 | 1 | @EXPORT_OK = qw(@Autoop %Autovoice); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | # These variables are tied to /set options. The *_delay options can be | ||||||||||||||||||||||||||||
| 33 | # either an integer or a code ref which will compute it. You have to | ||||||||||||||||||||||||||||
| 34 | # use doset rather than /set to set them to a code ref. | ||||||||||||||||||||||||||||
| 35 | 1 | my $Autoop = 1; # no autoops done if false | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | my $Autoop_delay = sub { 3 + 2 * int rand 4 }; # secs before trying to autoop | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 37 | 1 | my $Autovoice = 1; | |||||||||||||||||||||||||||
| 38 | 1 | my $Autovoice_control = 1; # ops can control autovoice delay | |||||||||||||||||||||||||||
| 39 | 0 | ▶ | my $Autovoice_delay = sub { 3 + 2 * int rand 4 }; # secs before autovoice | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 40 | 1 | my $Autovoice_timeout = 60 * 60; # secs -v is sticky | |||||||||||||||||||||||||||
| 41 | 1 | my $Debug = 0; | |||||||||||||||||||||||||||
| 42 | 1 | my $Verbose = 0; | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | settable_boolean 'autoop', \$Autoop; | |||||||||||||||||||||||||||
| 45 | 0 | ▶ | settable_int 'autoop_delay', \$Autoop_delay, sub { $_[1] >= 0 }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 1 | settable_boolean 'autovoice', \$Autovoice; | |||||||||||||||||||||||||||
| 48 | 1 | settable_boolean 'autovoice_control', \$Autovoice_control; | |||||||||||||||||||||||||||
| 49 | 0 | ▶ | settable_int 'autovoice_delay', \$Autovoice_delay, sub { $_[1] >= 0 }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | settable_int 'autovoice_timeout', \$Autovoice_timeout, sub { $_[1] >= 0 }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 1 | settable_boolean 'autoop_debug', \$Debug; | |||||||||||||||||||||||||||
| 53 | 1 | settable_boolean 'autoop_verbose', \$Verbose; | |||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # @Autoop is a list of array references. The first element of each | ||||||||||||||||||||||||||||
| 56 | # array is a pattern to match against the channel, the second is a | ||||||||||||||||||||||||||||
| 57 | # pattern to match against the nick!user@host. The optional third is | ||||||||||||||||||||||||||||
| 58 | # either 'o' or 'v' (defaulting to 'o') to tell which mode to give. | ||||||||||||||||||||||||||||
| 59 | # | ||||||||||||||||||||||||||||
| 60 | # There's no user-level interface for adding data to this (yet). | ||||||||||||||||||||||||||||
| 61 | 1 | @Autoop = (); | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | # This is a hash whose keys are are channel names. New keys should | ||||||||||||||||||||||||||||
| 64 | # get undef as value. Everybody joining one of the listed channels | ||||||||||||||||||||||||||||
| 65 | # will get a +v after $Autovoice_delay seconds. If somebody gets a -v | ||||||||||||||||||||||||||||
| 66 | # then leaves and rejoins, though, they won't get another +v unless | ||||||||||||||||||||||||||||
| 67 | # $Autovoice_timeout seconds have passed or somebody else gives them a | ||||||||||||||||||||||||||||
| 68 | # +v. | ||||||||||||||||||||||||||||
| 69 | # | ||||||||||||||||||||||||||||
| 70 | # There's no user-level interface for adding data to this (yet). | ||||||||||||||||||||||||||||
| 71 | # | ||||||||||||||||||||||||||||
| 72 | # The implementation causes each value to be a hashref pointing to | ||||||||||||||||||||||||||||
| 73 | # another hash. The keys of the second level hashes are ban_pattern | ||||||||||||||||||||||||||||
| 74 | # patterns converted to REs indicating the people who are in sticky -v | ||||||||||||||||||||||||||||
| 75 | # mode, the value for each is the time at which it got -v. The second | ||||||||||||||||||||||||||||
| 76 | # level hash will only be present if it has keys, as the last key is | ||||||||||||||||||||||||||||
| 77 | # removed the $Autovoice{$channel} entry is undeffed. | ||||||||||||||||||||||||||||
| 78 | 1 | tie %Autovoice, 'Sirc::LckHash'; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub debug { | ||||||||||||||||||||||||||
|
Subroutine
debug: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | xtell 'autoop debug ' . join '', @_ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | if $Debug; | ||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | sub verbose { | ||||||||||||||||||||||||||
|
Subroutine
verbose: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 86 | 0 | ▶ | xtell join '', @_ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Verbose or $Debug
MC/DC0%0/2
$Verbose or $Debug
$Verbose
$Debug
Truth table0%0/3
A or B
A= $VerboseB= $Debug
| |||||||||||||||||||||||||||||
| 87 | if $Verbose || $Debug; | ||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 0 | ▶ | sub autoop_match { | ||||||||||||||||||||||||||
|
Subroutine
autoop_match: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 91 | 0 | my ($channel, $nuh) = @_; | |||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 0 | debug "autoop_match @_"; | |||||||||||||||||||||||||||
| 94 | 0 | for (@Autoop) { | |||||||||||||||||||||||||||
| 95 | 0 | my ($channel_pat, $nuh_pat, $type) = @$_; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $type = 'o' if !defined $type; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | if ($type ne 'o' && $type ne 'v') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type ne "o" and $type ne "v"
MC/DC0%0/2
$type ne "o" and $type ne "v"
$type ne "o"
$type ne "v"
Truth table0%0/3
A and B
A= $type ne "o"B= $type ne "v"
| |||||||||||||||||||||||||||||
| 99 | 0 | tell_question "Invalid autoop type `$type'" | |||||||||||||||||||||||||||
| 100 | . " for /$channel_pat/ /$nuh_pat/"; | ||||||||||||||||||||||||||||
| 101 | 0 | next; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 0 | my $one = $channel =~ /$channel_pat/i; | |||||||||||||||||||||||||||
| 105 | 0 | my $two = $nuh =~ /$nuh_pat/i; | |||||||||||||||||||||||||||
| 106 | 0 | debug "channel/user $one/$two on $channel_pat/$nuh_pat"; | |||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ($one && $two) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$one and $two
MC/DC0%0/2
$one and $two
$one
$two
Truth table0%0/3
A and B
A= $oneB= $two
| |||||||||||||||||||||||||||||
| 108 | 0 | return $type; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | 0 | return 0; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | sub sticky_devoice { | ||||||||||||||||||||||||||
|
Subroutine
sticky_devoice: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 115 | 0 | my ($c, $n, $uh) = @_; | |||||||||||||||||||||||||||
| 116 | 0 | my ($h, $s, $expire); | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | $h = $Autovoice{$c}; | |||||||||||||||||||||||||||
| 119 | 0 | ▶ | return 0 unless $h; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | $expire = time - $Autovoice_timeout; | |||||||||||||||||||||||||||
| 122 | 0 | $s = "$n!$uh"; | |||||||||||||||||||||||||||
| 123 | 0 | for my $pat (keys %$h) { | |||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ($h->{$pat} < $expire) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 125 | 0 | delete $h->{$pat}; | |||||||||||||||||||||||||||
| 126 | # undef the %Autovoice value when the last member drops. | ||||||||||||||||||||||||||||
| 127 | 0 | ▶ | if (!%$h) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 128 | 0 | undef $Autovoice{$c}; | |||||||||||||||||||||||||||
| 129 | 0 | return 0; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | else { | ||||||||||||||||||||||||||||
| 133 | 0 | ▶ | return 1 if $s =~ /$pat/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | 0 | return 0; | |||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | ▶ | sub autoop_do { | ||||||||||||||||||||||||||
|
Subroutine
autoop_do: not called CC=10 SCAR=47.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 140 | 0 | my ($this_channel, $this_nick, $this_userhost, $type) = @_; | |||||||||||||||||||||||||||
| 141 | 0 | my ($mode); | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 0 | debug "autoop_do @_"; | |||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 0 | $mode = $type; | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | $mode = 'v' if $mode eq 'autovoice'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | # Don't +v or +o for ops. | ||||||||||||||||||||||||||||
| 149 | 0 | ▶ | if ($Chan_op{$this_channel}{$this_nick}) { | ||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||
| 150 | 0 | debug "autoop_do skip $this_channel/$this_nick/$type opped"; | |||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | # Don't +v people who got it already. | ||||||||||||||||||||||||||||
| 154 | ▶ | elsif ($mode eq 'v' && $Chan_voice{$this_channel}{$this_nick}) { | |||||||||||||||||||||||||||
|
Condition0%0/3
$mode eq "v" and $Sirc::Autoop::Chan_voice{$this_channel}{$this_nick}
MC/DC0%0/2
$mode eq "v" and $Sirc::Autoop::Chan_voice{$this_channel}{$this_nick}
$mode eq "v"
$Sirc::Autoop::Chan_voice{$this_channel}{$this_nick}
Truth table0%0/3
A and B
A= $mode eq "v"B= $Sirc::Autoop::Chan_voice{$this_channel}{$this_nick}
| |||||||||||||||||||||||||||||
| 155 | 0 | debug "autoop_do skip $this_channel/$this_nick/$type voiced"; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | # Don't +v if we're not moderated. | ||||||||||||||||||||||||||||
| 159 | ▶ | elsif ($mode eq 'v' && $::mode{lc $this_channel} !~ /m/) { | |||||||||||||||||||||||||||
|
Condition0%0/3
$mode eq "v" and not $main::mode{lc $this_channel} =~ /m/
MC/DC0%0/2
$mode eq "v" and not $main::mode{lc $this_channel} =~ /m/
$mode eq "v"
not $main::mode{lc $this_channel} =~ /m/
Truth table0%0/3
A and not(B)
A= $mode eq "v"B= not $main::mode{lc $this_channel} =~ /m/
| |||||||||||||||||||||||||||||
| 160 | 0 | debug "autoop_do skip $this_channel/$this_nick/$type not +m"; | |||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | # Don't autovoice people who have a sticky -v. | ||||||||||||||||||||||||||||
| 164 | ▶ | elsif ($type eq 'autovoice' | |||||||||||||||||||||||||||
|
Condition0%0/3
$type eq "autovoice" and sticky_devoice($this_channel, $this_nick, $this_userhost)
MC/DC0%0/2
$type eq "autovoice" and sticky_devoice($this_channel, $this_nick, $this_userhost)
$type eq "autovoice"
sticky_devoice($this_channel, $this_nick, $this_userhost)
Truth table0%0/3
A and B
A= $type eq "autovoice"B= sticky_devoice($this_channel, $this_nick, $this_userhost)
| |||||||||||||||||||||||||||||
| 165 | && sticky_devoice $this_channel, $this_nick, $this_userhost) { | ||||||||||||||||||||||||||||
| 166 | 0 | debug "autoop_do skip $this_channel/$this_nick/$type sticky -v"; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # Don't bother if she left already | ||||||||||||||||||||||||||||
| 170 | elsif (!$Chan_user{$this_channel}{$this_nick}) { | ||||||||||||||||||||||||||||
| 171 | 0 | debug "autoop_do skip $this_channel/$this_nick/$type gone"; | |||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | else { | ||||||||||||||||||||||||||||
| 175 | 0 | debug "autoop_do op $this_channel/$this_nick"; | |||||||||||||||||||||||||||
| 176 | 0 | docommand "mode $this_channel +$mode $this_nick\n"; | |||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | }; | ||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 0 | ▶ | sub autoop_try { | ||||||||||||||||||||||||||
|
Subroutine
autoop_try: not called CC=15 SCAR=54.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 181 | 0 | my ($this_channel, $this_nick, $this_userhost, $immediate) = @_; | |||||||||||||||||||||||||||
| 182 | 0 | my (@base_arg); | |||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | 0 | debug "autoop_try @_"; | |||||||||||||||||||||||||||
| 185 | 0 | ▶ | have_ops $this_channel or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | 0 | ▶ | return if ieq $this_nick, $::nick; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 0 | @base_arg = ($this_channel, $this_nick, $this_userhost); | |||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if ($Autoop && (my $type = autoop_match $this_channel, | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Autoop and my $type = autoop_match($this_channel, "$this_nick!$this_userhost")
MC/DC0%0/2
$Autoop and my $type = autoop_match($this_channel, "$this_nick!$this_userhost")
$Autoop
my $type = autoop_match($this_channel, "$this_nick!$this_userhost")
Truth table0%0/3
A and B
A= $AutoopB= my $type = autoop_match($this_channel, "$this_nick!$this_userhost")
| |||||||||||||||||||||||||||||
| 190 | "$this_nick!$this_userhost")) { | ||||||||||||||||||||||||||||
| 191 | 0 | ▶ | my $delay = $immediate | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 192 | ? 0 | ||||||||||||||||||||||||||||
| 193 | : ref($Autoop_delay) eq 'CODE' | ||||||||||||||||||||||||||||
| 194 | ? &$Autoop_delay(@base_arg) | ||||||||||||||||||||||||||||
| 195 | : $Autoop_delay; | ||||||||||||||||||||||||||||
| 196 | 0 | ▶ | verbose "Queueing +$type for $this_nick on $this_channel in $delay" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$delay > 0 or $Debug
MC/DC0%0/2
$delay > 0 or $Debug
$delay > 0
$Debug
Truth table0%0/3
A or B
A= $delay > 0B= $Debug
| |||||||||||||||||||||||||||||
| 197 | if $delay > 0 || $Debug; | ||||||||||||||||||||||||||||
| 198 | 0 | ▶ | timer $delay, sub { autoop_do @base_arg, $type }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | 0 | ▶ | if ($Autovoice && exists $Autovoice{$this_channel}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$Autovoice and exists $Sirc::Autoop::Autovoice{$this_channel}
MC/DC0%0/2
$Autovoice and exists $Sirc::Autoop::Autovoice{$this_channel}
$Autovoice
exists $Sirc::Autoop::Autovoice{$this_channel}
Truth table0%0/3
A and B
A= $AutovoiceB= exists $Sirc::Autoop::Autovoice{$this_channel}
| |||||||||||||||||||||||||||||
| 202 | 0 | ▶ | my $delay = $immediate | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 203 | ? 0 | ||||||||||||||||||||||||||||
| 204 | : ref($Autovoice_delay) eq 'CODE' | ||||||||||||||||||||||||||||
| 205 | ? &$Autovoice_delay(@base_arg) | ||||||||||||||||||||||||||||
| 206 | : $Autovoice_delay; | ||||||||||||||||||||||||||||
| 207 | 0 | ▶ | verbose "Queueing autovoice for $this_nick on $this_channel in $delay" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$delay > 0 or $Debug
MC/DC0%0/2
$delay > 0 or $Debug
$delay > 0
$Debug
Truth table0%0/3
A or B
A= $delay > 0B= $Debug
| |||||||||||||||||||||||||||||
| 208 | if $delay > 0 || $Debug; | ||||||||||||||||||||||||||||
| 209 | 0 | ▶ | timer $delay, sub { autoop_do @base_arg, 'autovoice' }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 0 | ▶ | sub main::hook_autoop_join { | ||||||||||||||||||||||||||
|
Subroutine
hook_autoop_join: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 214 | 0 | my $channel = shift; | |||||||||||||||||||||||||||
| 215 | 0 | my @arg = ($channel, $::who, "$::user\@$::host"); | |||||||||||||||||||||||||||
| 216 | 0 | ▶ | autoop_try @arg, 0 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | if have_ops_q $channel; | ||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | 1 | addhook 'join', 'autoop_join'; | |||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | # When a /names list comes by, note people who don't have a voice in | ||||||||||||||||||||||||||||
| 222 | # %Autovoice. Without this I'd try to +v them when I get +o myself. | ||||||||||||||||||||||||||||
| 223 | # This only has any effect when joining the channel, though it runs for | ||||||||||||||||||||||||||||
| 224 | # every /names. | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 0 | ▶ | sub main::hook_autoop_names { | ||||||||||||||||||||||||||
|
Subroutine
hook_autoop_names: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 227 | 0 | my ($rest) = @_; | |||||||||||||||||||||||||||
| 228 | 0 | my ($x1, $x2, $channel, $list) = split ' ', $rest, 4; | |||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||
| 230 | # I used to test if the channel was +m here as well, but the on-join | ||||||||||||||||||||||||||||
| 231 | # channel mode change can come after the /names. | ||||||||||||||||||||||||||||
| 232 | 0 | ▶ | return unless exists $Autovoice{$channel}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||
| 234 | 0 | my $now = time; | |||||||||||||||||||||||||||
| 235 | 0 | $list =~ s/^://; | |||||||||||||||||||||||||||
| 236 | 0 | for my $who (split ' ', $list) { | |||||||||||||||||||||||||||
| 237 | 0 | ▶ | next if $who =~ /^[+@]/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | userhost $who, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 239 | 0 | my $pat = mask_to_re ban_pattern $::who, $::user, $::host; | |||||||||||||||||||||||||||
| 240 | 0 | ▶ | $Autovoice{$channel}{$pat} ||= $now; | ||||||||||||||||||||||||||
|
Condition0%0/3
$Sirc::Autoop::Autovoice{$channel}{$pat} ||= $now
MC/DC0%0/2
$Sirc::Autoop::Autovoice{$channel}{$pat} ||= $now
$Sirc::Autoop::Autovoice{$channel}{$pat}
$now
Truth table0%0/3
A ||= B
A= $Sirc::Autoop::Autovoice{$channel}{$pat}B= $now
| |||||||||||||||||||||||||||||
| 241 | 0 | }; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | } | ||||||||||||||||||||||||||||
| 244 | 1 | addhook '353', 'autoop_names'; | |||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | # /autoop [channel] | ||||||||||||||||||||||||||||
| 247 | 0 | ▶ | sub main::cmd_autoop { | ||||||||||||||||||||||||||
|
Subroutine
cmd_autoop: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 248 | 0 | debug "cmd_autoop $::args"; | |||||||||||||||||||||||||||
| 249 | 0 | ▶ | optional_channel or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | 0 | my $c = lc xgetarg; | |||||||||||||||||||||||||||
| 251 | 0 | ▶ | have_ops $c or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 252 | 0 | ▶ | $Autoop or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 253 | 0 | ▶ | userhost [keys %{ $Chan_user{$c} }], sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 254 | 0 | autoop_try $c, $::who, "$::user\@$::host", 1; | |||||||||||||||||||||||||||
| 255 | 0 | }; | |||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||
| 257 | 1 | addcmd 'autoop'; | |||||||||||||||||||||||||||
| 258 | 1 | addhelp 'autoop', '[channel]', | |||||||||||||||||||||||||||
| 259 | q{Uses your autoop list to op and voice people on the current channel. | ||||||||||||||||||||||||||||
| 260 | Since this happens automatically you don't normally have to do this, this | ||||||||||||||||||||||||||||
| 261 | command is useful if you'd had autoopping disabled, or if there's a bug | ||||||||||||||||||||||||||||
| 262 | in the system. | ||||||||||||||||||||||||||||
| 263 | }; | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | # Try an /autoop after receiving ops. | ||||||||||||||||||||||||||||
| 266 | 0 | ▶ | add_hook '+op', sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 267 | 0 | my ($c, $n) = @_; | |||||||||||||||||||||||||||
| 268 | |||||||||||||||||||||||||||||
| 269 | 0 | ▶ | timer 10, sub { main::cmd_autoop $c } if ieq $n, $::nick; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 270 | 1 | }; | |||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 0 | ▶ | add_hook '-voice', sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 273 | 0 | my ($c, $n) = @_; | |||||||||||||||||||||||||||
| 274 | 0 | my ($now); | |||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 0 | ▶ | return unless $Autovoice; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 277 | 0 | ▶ | return unless exists $Autovoice{$c}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 278 | 0 | $now = time; | |||||||||||||||||||||||||||
| 279 | 0 | ▶ | userhost $n, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 280 | 0 | $Autovoice{$c}{mask_to_re ban_pattern $::who, $::user, $::host} | |||||||||||||||||||||||||||
| 281 | = $now; | ||||||||||||||||||||||||||||
| 282 | 0 | }; | |||||||||||||||||||||||||||
| 283 | 1 | }; | |||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | 0 | ▶ | add_hook '+voice', sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=16.1
| |||||||||||||||||||||||||||||
| 286 | 0 | my ($c, $n) = @_; | |||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 0 | ▶ | return unless $Autovoice{$c}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 289 | 0 | ▶ | userhost $n, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 290 | 0 | delete $Autovoice{$c}{mask_to_re | |||||||||||||||||||||||||||
| 291 | ban_pattern $::who, $::user, $::host}; | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | # If that was the last pattern, drop the hash ref. | ||||||||||||||||||||||||||||
| 294 | 0 | ▶ | undef $Autovoice{$c} unless %{ $Autovoice{$c} }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 295 | } | ||||||||||||||||||||||||||||
| 296 | 0 | }; | |||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | # Allow ops on autovoiced channels to control your autovoice delay with | ||||||||||||||||||||||||||||
| 299 | # a specially formatted /msg. | ||||||||||||||||||||||||||||
| 300 | # | ||||||||||||||||||||||||||||
| 301 | # autovoice report current value | ||||||||||||||||||||||||||||
| 302 | # autovoice N set it to N | ||||||||||||||||||||||||||||
| 303 | # autovoice +N add N seconds to the delay | ||||||||||||||||||||||||||||
| 304 | # autovoice -N remove N seconds from the delay | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 0 | ▶ | sub main::hook_autovoice_control_msg { | ||||||||||||||||||||||||||
|
Subroutine
hook_autovoice_control_msg: not called CC=11 SCAR=48.8
| |||||||||||||||||||||||||||||
| 307 | 0 | my ($msg) = @_; | |||||||||||||||||||||||||||
| 308 | 0 | ▶ | return unless $msg =~ s/^\s*autovoice\b//i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 309 | 0 | ▶ | return unless $Autovoice_control; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 0 | debug "autovoice_control_msg [$msg] who [$::who]"; | |||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||
| 312 | 0 | ▶ | if (!grep { $Chan_op{$_}{$::who} } keys %Autovoice) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 313 | 0 | notice $::who, "You aren't an op on a channel I'm autovoicing."; | |||||||||||||||||||||||||||
| 314 | 0 | return; | |||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | 0 | ▶ | if (ref $Autovoice_delay) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 318 | 0 | notice $::who, "My autovoice delay is a code ref, " | |||||||||||||||||||||||||||
| 319 | . "so remote control isn't available."; | ||||||||||||||||||||||||||||
| 320 | 0 | return; | |||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 0 | my $new; | |||||||||||||||||||||||||||
| 324 | 0 | ▶ | if ($msg =~ /^\s*$/) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 325 | 0 | notice $::who, "Current autovoice delay is $Autovoice_delay."; | |||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||
| 327 | elsif ($msg =~ /^\s*(\d+)\s*$/) { | ||||||||||||||||||||||||||||
| 328 | 0 | $new = $1; | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | elsif ($msg =~ /^\s*([+-]\s*\d+)\s*$/) { | ||||||||||||||||||||||||||||
| 331 | 0 | my $n = $1; | |||||||||||||||||||||||||||
| 332 | 0 | $n =~ s/\s+//g; | |||||||||||||||||||||||||||
| 333 | 0 | $new = $Autovoice_delay + $n; | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | else { | ||||||||||||||||||||||||||||
| 336 | 0 | notice $::who, "Unrecognized autovoice command, use: `autovoice', " | |||||||||||||||||||||||||||
| 337 | . "`autovoice N', `autovoice +N', `autovoice -N'."; | ||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||
| 340 | 0 | ▶ | if (defined $new) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 341 | 0 | ▶ | if ($new < 0) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 342 | 0 | notice $::who, "Ignoring invalid delay $new."; | |||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||
| 344 | elsif ($new < 1) { | ||||||||||||||||||||||||||||
| 345 | 0 | notice $::who, "Ignoring too-low delay $new, " | |||||||||||||||||||||||||||
| 346 | . "it would cause +v floods on netjoins."; | ||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | else { | ||||||||||||||||||||||||||||
| 349 | 0 | doset 'autovoice_delay', $new; | |||||||||||||||||||||||||||
| 350 | 0 | notice $::who, "Autovoice delay set to $Autovoice_delay."; | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | } | ||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||
| 354 | 1 | addhook 'msg', 'autovoice_control_msg'; | |||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||
| 356 | 1 | 1; | |||||||||||||||||||||||||||