Bot-Cobalt
view release on metacpan or search on metacpan
lib/Bot/Cobalt/Plugin/Info3.pm view on Meta::CPAN
sub Bot_info3_relay_string {
my ($self, $core) = splice @_, 0, 2;
my $context = ${$_[0]};
my $channel = ${$_[1]};
my $nick = ${$_[2]};
my $string = ${$_[3]};
my $orig = ${$_[4]};
## format and send info3 response
## also received from RDB when handing off ~rdb responses
logger->debug("info3_relay_string received; calling _info_format");
my $resp = $self->_info_format($context, $nick, $channel, $string, $orig);
## if $resp is a +action, send ctcp action
if ( index($resp, '+') == 0 ) {
$resp = substr($resp, 1);
logger->debug("Dispatching action -> $channel");
broadcast('action', $context, $channel, $resp);
} else {
logger->debug("Dispatching msg -> $channel");
broadcast('message', $context, $channel, $resp);
}
return PLUGIN_EAT_NONE
}
sub Bot_info3_expire_maxtriggered {
my ($self, $core) = splice @_, 0, 2;
my $context = ${ $_[0] };
my $channel = ${ $_[1] };
unless ($context && $channel) {
logger->debug(
"missing context and channel pair in expire_maxtriggered"
);
}
delete $self->{LastTriggered}->{$context}->{$channel};
logger->debug("cleared maxtriggered for $channel on $context");
return PLUGIN_EAT_ALL
}
### Internal methods
sub _over_max_triggered {
my ($self, $context, $channel, $str) = @_;
if ($self->{LastTriggered}->{$context}->{$channel}) {
my $lasttrig = $self->{LastTriggered}->{$context}->{$channel};
my ($last_match, $tries) = @$lasttrig;
if ($str eq $last_match) {
++$tries;
if ($tries > $self->{MAX_TRIGGERED}) {
## we've hit this topic too many times in a row
## plugin should EAT_NONE
logger->debug("Over trigger limit for $str");
## set a timer to expire this LastTriggered
core->timer_set( 90,
{
Alias => plugin_alias($self),
Event => 'info3_expire_maxtriggered',
Args => [ $context, $channel ],
},
);
return 1
} else {
## haven't hit MAX_TRIGGERED yet.
$self->{LastTriggered}->{$context}->{$channel} = [$str, $tries];
}
} else {
## not the previously-returned topic
## reset
delete $self->{LastTriggered}->{$context}->{$channel};
}
} else {
$self->{LastTriggered}->{$context}->{$channel} = [ $str, 1 ];
}
return 0
}
sub _info_add {
my ($self, $msg, $glob, @args) = @_;
my $string = join ' ', @args;
my $context = $msg->context;
my $nick = $msg->src_nick;
my $auth_user = core->auth->username($context, $nick);
my $auth_level = core->auth->level($context, $nick);
my $pcfg = plugin_cfg( $self );
my $required = $pcfg->{RequiredLevels}->{AddTopic} // 2;
unless ($auth_level >= $required) {
return core->rpl( q{RPL_NO_ACCESS},
nick => $nick,
);
}
unless ($glob && $string) {
return core->rpl( q{INFO_BADSYNTAX_ADD} );
}
## lowercase
$glob = decode_irc(lc $glob);
if (exists $self->{Globs}->{$glob}) {
## topic already exists, use replace instead!
return core->rpl( q{INFO_ERR_EXISTS},
topic => $glob,
nick => $nick,
);
}
## set up a re
my $re = glob_to_re_str($glob);
( run in 2.244 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )