@@ -65,6 +65,7 @@ sub is_mode {
6565}
6666
6767# current parameter for a set mode, if any.
68+ # note that this may be an object, string, or hash reference.
6869sub mode_parameter {
6970 my ($channel , $name ) = @_ ;
7071 return $channel -> {modes }{$name }{parameter };
@@ -73,6 +74,7 @@ sub mode_parameter {
7374# low-level mode set.
7475# takes an optional parameter.
7576# $channel->set_mode('moderated');
77+ # $channel->set_mode(limit => 15);
7678sub set_mode {
7779 my ($channel , $name , $parameter ) = @_ ;
7880 $channel -> {modes }{$name } = {
@@ -85,6 +87,7 @@ sub set_mode {
8587}
8688
8789# low-level mode unset.
90+ # $channel->unset_mode('moderated');
8891sub unset_mode {
8992 my ($channel , $name ) = @_ ;
9093 return unless $channel -> is_mode($name );
@@ -93,7 +96,8 @@ sub unset_mode {
9396 return 1;
9497}
9598
96- # list has something.
99+ # returns true if a list has something.
100+ # $what may be a string or object with string overload (e.g. user).
97101sub list_has {
98102 my ($channel , $name , $what ) = @_ ;
99103 return unless $channel -> {modes }{$name };
@@ -102,6 +106,7 @@ sub list_has {
102106
103107# something matches in an expression list.
104108# returns the match if there is one.
109+ # $what may be a real mask or a user object.
105110sub list_matches {
106111 my ($channel , $name , $what ) = @_ ;
107112 return unless $channel -> {modes }{$name };
@@ -121,55 +126,58 @@ sub list_elements {
121126sub add_to_list {
122127 my ($channel , $name , $parameter , %opts ) = @_ ;
123128
124- # first item. wow.
125- $channel -> {modes }{$name } = {
129+ # no duplicates plz
130+ return if $channel -> list_has($name , $parameter );
131+
132+ # first item
133+ $channel -> {modes }{$name } ||= {
126134 time => time ,
127135 list => []
128- } unless $channel -> {modes }{$name };
129-
130- # no duplicates plz.
131- return if $channel -> list_has($name , $parameter );
136+ };
132137
133- # add it.
138+ # add it
134139 L(" $$channel {name}: adding $parameter to $name list" );
135- my $array = [$parameter , \%opts ];
136- push @{ $channel -> {modes }{$name }{list } }, $array ;
140+ my $ref = [ $parameter , \%opts ];
141+ push @{ $channel -> {modes }{$name }{list } }, $ref ;
137142
138143 return 1;
139144}
140145
141146# removes something from a list.
147+ # returns true if something was removed.
142148sub remove_from_list {
143149 my ($channel , $name , $what ) = @_ ;
150+
151+ # it's not there
144152 return unless $channel -> list_has($name , $what );
145153
146- my @new = grep {
147- $_ -> [0] ne $what
148- } ref_to_list($channel -> {modes }{$name }{list });
154+ # grep it out
155+ my @old = ref_to_list($channel -> {modes }{$name }{list });
156+ my @new = grep { $_ -> [0] ne $what } @old ;
157+
158+ # nothing changed
159+ return if @old == @new ;
160+
149161 $channel -> {modes }{$name }{list } = \@new ;
150-
151162 L(" $$channel {name}: removing $what from $name list" );
152163 return 1;
153164}
154165
155- # user joins channel
166+ # low-level user join
156167sub add {
157168 my ($channel , $user ) = @_ ;
158169 return if $channel -> has_user($user );
159170
160- # add the user to the channel.
171+ # add the user to the channel
161172 push @{ $channel -> {users } }, $user ;
162-
163- # note: as of 5.91, after-join (user_joined) event is fired in
164- # mine.pm: for locals
165- # core_scommands.pm: for nonlocals.
166-
173+
174+ # notify ppl
167175 notice(channel_join => $user -> notice_info, $channel -> name)
168176 unless $user -> location-> {is_burst };
169177 return $channel -> {time };
170178}
171179
172- # remove a user.
180+ # low-level user remove .
173181# this could be due to any of part, quit, kick, server quit, etc.
174182sub remove {
175183 my ($channel , $user ) = @_ ;
@@ -524,7 +532,7 @@ sub user_is_banned {
524532 return $banned && !$channel -> list_matches(' except' , $user );
525533}
526534
527- # fetch the topic or return undef if none.
535+ # fetch the topic ref or return nothing if none is set .
528536sub topic {
529537 my $channel = shift ;
530538 return $channel -> {topic } if
@@ -541,7 +549,7 @@ sub destroy_maybe {
541549 # there are still users in here!
542550 return if $channel -> users;
543551
544- # an event said not to destroy the channel.
552+ # an event said not to destroy the channel
545553 return if $channel -> fire(' can_destroy' )-> stopper;
546554
547555 # delete the channel from the pool, purge events
@@ -579,13 +587,9 @@ sub real_local_users {
579587 return $channel -> users_satisfying(sub { shift -> is_local && !$_ -> {fake } });
580588}
581589
582- sub id { shift -> {name } }
583- sub name { shift -> {name } }
584- sub users { @{ shift -> {users } } }
585-
586- # ###########
587- # ## MINE ###
588- # ###########
590+ sub id { shift -> {name } } # channel name
591+ sub name { shift -> {name } } # channel name
592+ sub users { @{ shift -> {users } } } # list of users
589593
590594# send NAMES.
591595sub send_names {
0 commit comments