Adam
view release on metacpan or search on metacpan
ex/ai-bot.pl view on Meta::CPAN
is => 'ro', lazy => 1, traits => ['NoGetopt'],
default => sub { MemoryStore->new },
);
has _mcp => ( is => 'rw', traits => ['NoGetopt'] );
has _raider => ( is => 'rw', traits => ['NoGetopt'] );
has _msg_buffer => (
is => 'rw', traits => ['NoGetopt'],
default => sub { {} }, # { channel => [messages] }
);
has _buffer_timers => (
is => 'rw', traits => ['NoGetopt'],
default => sub { {} }, # { channel => alarm_id }
);
has _processing => (
is => 'rw', traits => ['NoGetopt'],
default => 0,
);
has _pending_raid => (
is => 'rw', traits => ['NoGetopt'],
default => sub { undef },
ex/ai-bot.pl view on Meta::CPAN
required => ['reason'],
},
code => sub {
my ($tool, $args) = @_;
return $tool->text_result('__SILENT__');
},
);
$server->tool(
name => 'set_alarm',
description => 'Set an alarm that wakes you up after a delay in seconds. Like a timer or reminder â when it fires, you get woken up with the reason and can decide what to do: respond, call tools, or stay silent. You do NOT pre-write a message;...
input_schema => {
type => 'object',
properties => {
reason => { type => 'string', description => 'Why you are setting this alarm â this will be shown to you when it fires' },
delay_seconds => { type => 'number', description => 'How many seconds to wait (10-3600)' },
},
required => ['reason', 'delay_seconds'],
},
code => sub {
my ($tool, $args) = @_;
ex/ai-bot.pl view on Meta::CPAN
sub _default_channel {
my ($self) = @_;
my $channels = $self->get_channels;
return ref $channels ? $channels->[0] : $channels;
}
sub _buffer_message {
my ($self, $channel, $nick, $msg) = @_;
push @{$self->_msg_buffer->{$channel} ||= []}, { channel => $channel, nick => $nick, msg => $msg };
# Per-channel timer: cancel previous, set new
if (my $id = delete $self->_buffer_timers->{$channel}) {
POE::Kernel->alarm_remove($id);
}
my $id = POE::Kernel->alarm_set( _process_buffer => time() + $BUFFER_DELAY, $channel );
$self->_buffer_timers->{$channel} = $id;
}
event _process_buffer => sub {
my ($self, $channel) = @_[OBJECT, ARG0];
delete $self->_buffer_timers->{$channel};
return if $self->_processing;
my @messages = @{$self->_msg_buffer->{$channel} || []};
return unless @messages;
$self->_msg_buffer->{$channel} = [];
$self->_processing(1);
# Auto-recall: gather notes about active nicks
my %seen_nicks;
ex/ai-bot.pl view on Meta::CPAN
$self->info("Processing buffer for $channel:\n$input");
$self->_pending_raid({ input => $input, channel => $channel, messages => \@messages });
$self->_do_raid;
};
sub _schedule_pending_buffers {
my ($self) = @_;
for my $ch (keys %{$self->_msg_buffer}) {
next unless @{$self->_msg_buffer->{$ch} || []};
next if $self->_buffer_timers->{$ch}; # already scheduled
my $id = POE::Kernel->alarm_set( _process_buffer => time() + $BUFFER_DELAY, $ch );
$self->_buffer_timers->{$ch} = $id;
}
}
my @BRAINFREEZE = (
'*brainfreeze*',
'*buffering...*',
'*hamster needs a breather*',
'*neurons recharging*',
'*getty forgot to pay the electricity bill again*',
'*thinking intensifies... slowly*',
( run in 2.030 seconds using v1.01-cache-2.11-cpan-acebb50784d )