Rename $stuff to $context throughout

This commit is contained in:
Pragmatic Software 2020-05-01 20:59:51 -07:00
parent 195dd39330
commit cfba96e8ae
29 changed files with 597 additions and 594 deletions

View File

@ -83,8 +83,8 @@ sub ban_exempted {
}
sub ban_exempt {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my $arglist = $stuff->{arglist};
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $arglist = $context->{arglist};
$self->{pbot}->{interpreter}->lc_args($arglist);
my $command = $self->{pbot}->{interpreter}->shift_arg($arglist);
@ -163,7 +163,7 @@ sub update_join_watch {
}
sub check_flood {
my ($self, $channel, $nick, $user, $host, $text, $max_messages, $max_time, $mode, $stuff) = @_;
my ($self, $channel, $nick, $user, $host, $text, $max_messages, $max_time, $mode, $context) = @_;
$channel = lc $channel;
my $mask = "$nick!$user\@$host";
@ -218,7 +218,7 @@ sub check_flood {
}
# don't do flood processing for unidentified or banned users in +z channels
if (defined $stuff and $stuff->{'chan-z'} and ($stuff->{'unidentified'} or $stuff->{'banned'})) { return; }
if (defined $context and $context->{'chan-z'} and ($context->{'unidentified'} or $context->{'banned'})) { return; }
my $ancestor = $self->{pbot}->{messagehistory}->{database}->get_ancestor_id($account);
$self->{pbot}->{logger}->log("Processing anti-flood account $account " . ($ancestor != $account ? "[ancestor $ancestor] " : '') . "for mask $mask\n")

View File

@ -55,9 +55,9 @@ sub is_spam {
}
sub antispam_cmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $arglist = $stuff->{arglist};
my $arglist = $context->{arglist};
my $command = $self->{pbot}->{interpreter}->shift_arg($arglist);

View File

@ -128,8 +128,8 @@ sub banlist_cmd {
}
sub checkban_cmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($target, $channel) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($target, $channel) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
return "Usage: checkban <mask> [channel]" if not defined $target;
$channel = $from if not defined $channel;
@ -139,8 +139,8 @@ sub checkban_cmd {
}
sub checkmute_cmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($target, $channel) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($target, $channel) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
return "Usage: checkmute <mask> [channel]" if not defined $target;
$channel = $from if not defined $channel;

View File

@ -144,9 +144,9 @@ sub check_blacklist {
}
sub blacklist {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $arglist = $stuff->{arglist};
my $arglist = $context->{arglist};
$self->{pbot}->{interpreter}->lc_args($arglist);
my $command = $self->{pbot}->{interpreter}->shift_arg($arglist);

View File

@ -148,18 +148,18 @@ sub list {
}
sub capcmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $command = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
my $command = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
my $result;
given ($command) {
when ('list') {
my $cap = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
my $cap = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
return $self->list($cap);
}
when ('whohas') {
my $cap = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
my $cap = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
return "Usage: cap whohas <capability>; Lists all users who have <capability>" if not defined $cap;
return "No such capability $cap." if not $self->exists($cap);
my $result = "Users with capability $cap: ";
@ -180,7 +180,7 @@ sub capcmd {
}
when ('userhas') {
my ($name, $cap) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($name, $cap) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
return "Usage: cap userhas <username> [capability]; Lists capabilities belonging to <user>" if not defined $name;
$cap = lc $cap if defined $cap;
@ -213,7 +213,7 @@ sub capcmd {
}
when ('group') {
my ($cap, $subcaps) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($cap, $subcaps) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
return "Usage: cap group <existing or new capability> <existing capabilities...>" if not defined $cap or not defined $subcaps;
my $u = $self->{pbot}->{users}->loggedin($from, "$nick!$user\@$host");
@ -231,7 +231,7 @@ sub capcmd {
}
when ('ungroup') {
my ($cap, $subcaps) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($cap, $subcaps) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
return "Usage: cap ungroup <existing capability group> <grouped capabilities...>" if not defined $cap or not defined $subcaps;
return "No such capability $cap." if not $self->exists($cap);

View File

@ -132,14 +132,14 @@ sub on_nosuchnick {
}
sub invite {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($channel, $target);
if ($from !~ m/^#/) {
# from /msg
my $usage = "Usage from /msg: invite <channel> [nick]; if you omit [nick] then you will be invited";
return $usage if not length $arguments;
($channel, $target) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
($channel, $target) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
return "$channel is not a channel; $usage" if $channel !~ m/^#/;
$target = $nick if not defined $target;
} else {
@ -147,8 +147,8 @@ sub invite {
return "Usage: invite [channel] <nick>" if not length $arguments;
# add current channel as default channel
$self->{pbot}->{interpreter}->unshift_arg($stuff->{arglist}, $from) if $stuff->{arglist}[0] !~ m/^#/;
($channel, $target) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
$self->{pbot}->{interpreter}->unshift_arg($context->{arglist}, $from) if $context->{arglist}[0] !~ m/^#/;
($channel, $target) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
}
$self->{invites}->{lc $channel}->{lc $target} = $nick;
@ -158,14 +158,14 @@ sub invite {
}
sub generic_mode_user {
my ($self, $mode_flag, $mode_name, $channel, $nick, $stuff) = @_;
my ($self, $mode_flag, $mode_name, $channel, $nick, $context) = @_;
my $result = '';
my ($flag, $mode_char) = $mode_flag =~ m/(.)(.)/;
if ($channel !~ m/^#/) {
# from message
$channel = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
$channel = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
if (not defined $channel) { return "Usage from message: $mode_name <channel> [nick]"; }
elsif ($channel !~ m/^#/) { return "$channel is not a channel. Usage from message: $mode_name <channel> [nick]"; }
}
@ -174,14 +174,14 @@ sub generic_mode_user {
if (not $self->{pbot}->{chanops}->can_gain_ops($channel)) { return "I am not configured as an OP for $channel. See `chanset` command for more information."; }
# add $nick to $args if no argument
if (not $self->{pbot}->{interpreter}->arglist_size($stuff->{arglist})) { $self->{pbot}->{interpreter}->unshift_arg($stuff->{arglist}, $nick); }
if (not $self->{pbot}->{interpreter}->arglist_size($context->{arglist})) { $self->{pbot}->{interpreter}->unshift_arg($context->{arglist}, $nick); }
my $max_modes = $self->{pbot}->{ircd}->{MODES} // 1;
my $mode = $flag;
my $list = '';
my $i = 0;
foreach my $targets ($self->{pbot}->{interpreter}->unquoted_args($stuff->{arglist})) {
foreach my $targets ($self->{pbot}->{interpreter}->unquoted_args($context->{arglist})) {
foreach my $target (split /,/, $targets) {
$mode .= $mode_char;
$list .= "$target ";
@ -189,8 +189,8 @@ sub generic_mode_user {
if ($i >= $max_modes) {
my $args = "$channel $mode $list";
$stuff->{arglist} = $self->{pbot}->{interpreter}->make_args($args);
$result = $self->mode($channel, $nick, $stuff->{user}, $stuff->{host}, $args, $stuff);
$context->{arglist} = $self->{pbot}->{interpreter}->make_args($args);
$result = $self->mode($channel, $nick, $context->{user}, $context->{host}, $args, $context);
$mode = $flag;
$list = '';
$i = 0;
@ -201,45 +201,45 @@ sub generic_mode_user {
if ($i) {
my $args = "$channel $mode $list";
$stuff->{arglist} = $self->{pbot}->{interpreter}->make_args($args);
$result = $self->mode($channel, $nick, $stuff->{user}, $stuff->{host}, $args, $stuff);
$context->{arglist} = $self->{pbot}->{interpreter}->make_args($args);
$result = $self->mode($channel, $nick, $context->{user}, $context->{host}, $args, $context);
}
return $result;
}
sub op_user {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
return $self->generic_mode_user('+o', 'op', $from, $nick, $stuff);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
return $self->generic_mode_user('+o', 'op', $from, $nick, $context);
}
sub deop_user {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
return $self->generic_mode_user('-o', 'deop', $from, $nick, $stuff);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
return $self->generic_mode_user('-o', 'deop', $from, $nick, $context);
}
sub voice_user {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
return $self->generic_mode_user('+v', 'voice', $from, $nick, $stuff);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
return $self->generic_mode_user('+v', 'voice', $from, $nick, $context);
}
sub devoice_user {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
return $self->generic_mode_user('-v', 'devoice', $from, $nick, $stuff);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
return $self->generic_mode_user('-v', 'devoice', $from, $nick, $context);
}
sub mode {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
if (not length $arguments) { return "Usage: mode [channel] <arguments>"; }
# add current channel as default channel
if ($stuff->{arglist}[0] !~ m/^#/) {
if ($from =~ m/^#/) { $self->{pbot}->{interpreter}->unshift_arg($stuff->{arglist}, $from); }
if ($context->{arglist}[0] !~ m/^#/) {
if ($from =~ m/^#/) { $self->{pbot}->{interpreter}->unshift_arg($context->{arglist}, $from); }
else { return "Usage from private message: mode <channel> <arguments>"; }
}
my ($channel, $modes, $args) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
my ($channel, $modes, $args) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3);
my @targets = split /\s+/, $args if defined $args;
my $modifier;
my $i = 0;
@ -336,8 +336,8 @@ sub mode {
}
sub ban_user {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($target, $channel, $length) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($target, $channel, $length) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3);
$channel = '' if not defined $channel;
$length = '' if not defined $length;
@ -350,18 +350,18 @@ sub ban_user {
if ($channel !~ m/^#/) {
$length = "$channel $length";
$length = undef if $length eq ' ';
$channel = exists $stuff->{admin_channel_override} ? $stuff->{admin_channel_override} : $from;
$channel = exists $context->{admin_channel_override} ? $context->{admin_channel_override} : $from;
}
$channel = exists $stuff->{admin_channel_override} ? $stuff->{admin_channel_override} : $from if not defined $channel or not length $channel;
$channel = exists $context->{admin_channel_override} ? $context->{admin_channel_override} : $from if not defined $channel or not length $channel;
if (not defined $target) { return "Usage: ban <mask> [channel [timeout (default: 24 hours)]]"; }
my $no_length = 0;
if (not defined $length) {
# TODO: user account length override
$length = $self->{pbot}->{registry}->get_value($channel, 'default_ban_timeout', 0, $stuff)
// $self->{pbot}->{registry}->get_value('general', 'default_ban_timeout', 0, $stuff) // 60 * 60 * 24; # 24 hours
$length = $self->{pbot}->{registry}->get_value($channel, 'default_ban_timeout', 0, $context)
// $self->{pbot}->{registry}->get_value('general', 'default_ban_timeout', 0, $context) // 60 * 60 * 24; # 24 hours
$no_length = 1;
} else {
my $error;
@ -414,14 +414,14 @@ sub ban_user {
sub unban_user {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($from, $nick, $user, $host, $arguments, $context) = @_;
if (not defined $from) {
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
return "";
}
my ($target, $channel, $immediately) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
my ($target, $channel, $immediately) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3);
if (defined $target and defined $channel and $channel !~ /^#/) {
my $temp = $target;
@ -431,7 +431,7 @@ sub unban_user {
if (not defined $target) { return "Usage: unban <nick/mask> [channel [false value to use unban queue]]"; }
$channel = exists $stuff->{admin_channel_override} ? $stuff->{admin_channel_override} : $from if not defined $channel;
$channel = exists $context->{admin_channel_override} ? $context->{admin_channel_override} : $from if not defined $channel;
$immediately = 1 if not defined $immediately;
return "Usage for /msg: unban <nick/mask> <channel> [false value to use unban queue]" if $channel !~ /^#/;
@ -463,8 +463,8 @@ sub unban_user {
}
sub mute_user {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($target, $channel, $length) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($target, $channel, $length) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3);
$channel = '' if not defined $channel;
@ -478,10 +478,10 @@ sub mute_user {
if ($channel !~ m/^#/) {
$length = $channel . ' ' . (defined $length ? $length : '');
$length = undef if $length eq ' ';
$channel = exists $stuff->{admin_channel_override} ? $stuff->{admin_channel_override} : $from;
$channel = exists $context->{admin_channel_override} ? $context->{admin_channel_override} : $from;
}
$channel = exists $stuff->{admin_channel_override} ? $stuff->{admin_channel_override} : $from if not defined $channel;
$channel = exists $context->{admin_channel_override} ? $context->{admin_channel_override} : $from if not defined $channel;
if ($channel !~ m/^#/) { return "Please specify a channel."; }
@ -489,8 +489,8 @@ sub mute_user {
my $no_length = 0;
if (not defined $length) {
$length = $self->{pbot}->{registry}->get_value($channel, 'default_mute_timeout', 0, $stuff)
// $self->{pbot}->{registry}->get_value('general', 'default_mute_timeout', 0, $stuff) // 60 * 60 * 24; # 24 hours
$length = $self->{pbot}->{registry}->get_value($channel, 'default_mute_timeout', 0, $context)
// $self->{pbot}->{registry}->get_value('general', 'default_mute_timeout', 0, $context) // 60 * 60 * 24; # 24 hours
$no_length = 1;
} else {
my $error;
@ -543,14 +543,14 @@ sub mute_user {
sub unmute_user {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($from, $nick, $user, $host, $arguments, $context) = @_;
if (not defined $from) {
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
return "";
}
my ($target, $channel, $immediately) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
my ($target, $channel, $immediately) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3);
if (defined $target and defined $channel and $channel !~ /^#/) {
my $temp = $target;
@ -560,7 +560,7 @@ sub unmute_user {
if (not defined $target) { return "Usage: unmute <nick/mask> [channel [false value to use unban queue]]"; }
$channel = exists $stuff->{admin_channel_override} ? $stuff->{admin_channel_override} : $from if not defined $channel;
$channel = exists $context->{admin_channel_override} ? $context->{admin_channel_override} : $from if not defined $channel;
$immediately = 1 if not defined $immediately;
return "Usage for /msg: unmute <nick/mask> <channel> [false value to use unban queue]" if $channel !~ /^#/;
@ -593,7 +593,7 @@ sub unmute_user {
sub kick_user {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($from, $nick, $user, $host, $arguments, $context) = @_;
if (not defined $from) {
$self->{pbot}->{logger}->log("Command missing ~from parameter!\n");
@ -609,7 +609,7 @@ sub kick_user {
} else {
# used in channel
if ($arguments =~ s/^(#\S+)\s+(\S+)\s*//) { ($channel, $victim) = ($1, $2); }
elsif ($arguments =~ s/^(\S+)\s*//) { ($victim, $channel) = ($1, exists $stuff->{admin_channel_override} ? $stuff->{admin_channel_override} : $from); }
elsif ($arguments =~ s/^(\S+)\s*//) { ($victim, $channel) = ($1, exists $context->{admin_channel_override} ? $context->{admin_channel_override} : $from); }
else { return "Usage: kick [channel] <nick> [reason]"; }
}

View File

@ -51,15 +51,15 @@ sub part_cmd {
}
sub set {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($channel, $key, $value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($channel, $key, $value) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3);
return "Usage: chanset <channel> [key [value]]" if not defined $channel;
return $self->{channels}->set($channel, $key, $value);
}
sub unset {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($channel, $key) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($channel, $key) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
return "Usage: chanunset <channel> <key>" if not defined $channel or not defined $key;
return $self->{channels}->unset($channel, $key);
}

View File

@ -66,27 +66,27 @@ sub exists {
}
sub interpreter {
my ($self, $stuff) = @_;
my ($self, $context) = @_;
my $result;
if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) {
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$self->{pbot}->{logger}->log("Commands::interpreter\n");
$self->{pbot}->{logger}->log(Dumper $stuff);
$self->{pbot}->{logger}->log(Dumper $context);
}
my $keyword = lc $stuff->{keyword};
my $from = $stuff->{from};
my $keyword = lc $context->{keyword};
my $from = $context->{from};
my ($cmd_channel) = $stuff->{arguments} =~ m/\B(#[^ ]+)/; # assume command is invoked in regards to first channel-like argument
my ($cmd_channel) = $context->{arguments} =~ m/\B(#[^ ]+)/; # assume command is invoked in regards to first channel-like argument
$cmd_channel = $from if not defined $cmd_channel; # otherwise command is invoked in regards to the channel the user is in
my $user = $self->{pbot}->{users}->find_user($cmd_channel, "$stuff->{nick}!$stuff->{user}\@$stuff->{host}");
my $user = $self->{pbot}->{users}->find_user($cmd_channel, "$context->{nick}!$context->{user}\@$context->{host}");
my $cap_override;
if (exists $stuff->{'cap-override'}) {
$self->{pbot}->{logger}->log("Override cap to $stuff->{'cap-override'}\n");
$cap_override = $stuff->{'cap-override'};
if (exists $context->{'cap-override'}) {
$self->{pbot}->{logger}->log("Override cap to $context->{'cap-override'}\n");
$cap_override = $context->{'cap-override'};
}
foreach my $ref (@{$self->{handlers}}) {
@ -95,40 +95,40 @@ sub interpreter {
if ($requires_cap) {
if (defined $cap_override) {
if (not $self->{pbot}->{capabilities}->has($cap_override, "can-$keyword")) {
return "/msg $stuff->{nick} The $keyword command requires the can-$keyword capability, which cap-override $cap_override does not have.";
return "/msg $context->{nick} The $keyword command requires the can-$keyword capability, which cap-override $cap_override does not have.";
}
} else {
if (not defined $user) {
my ($found_chan, $found_mask) = $self->{pbot}->{users}->find_user_account($cmd_channel, "$stuff->{nick}!$stuff->{user}\@$stuff->{host}", 1);
if (not defined $found_chan) { return "/msg $stuff->{nick} You must have a user account to use $keyword."; }
else { return "/msg $stuff->{nick} You must have a user account in $cmd_channel to use $keyword. (You have an account in $found_chan.)"; }
my ($found_chan, $found_mask) = $self->{pbot}->{users}->find_user_account($cmd_channel, "$context->{nick}!$context->{user}\@$context->{host}", 1);
if (not defined $found_chan) { return "/msg $context->{nick} You must have a user account to use $keyword."; }
else { return "/msg $context->{nick} You must have a user account in $cmd_channel to use $keyword. (You have an account in $found_chan.)"; }
} elsif (not $user->{loggedin}) {
return "/msg $stuff->{nick} You must be logged into your user account to use $keyword.";
return "/msg $context->{nick} You must be logged into your user account to use $keyword.";
}
if (not $self->{pbot}->{capabilities}->userhas($user, "can-$keyword")) {
return "/msg $stuff->{nick} The $keyword command requires the can-$keyword capability, which your user account does not have.";
return "/msg $context->{nick} The $keyword command requires the can-$keyword capability, which your user account does not have.";
}
}
}
$stuff->{action} = $stuff->{arguments};
$stuff->{arguments} = $self->{pbot}->{factoids}->expand_factoid_vars($stuff);
$stuff->{arguments} = $self->{pbot}->{factoids}->expand_special_vars($stuff->{from}, $stuff->{nick}, $stuff->{keyword}, $stuff->{arguments});
delete $stuff->{action};
$context->{action} = $context->{arguments};
$context->{arguments} = $self->{pbot}->{factoids}->expand_factoid_vars($context);
$context->{arguments} = $self->{pbot}->{factoids}->expand_special_vars($context->{from}, $context->{nick}, $context->{keyword}, $context->{arguments});
delete $context->{action};
$stuff->{no_nickoverride} = 1;
$context->{no_nickoverride} = 1;
if ($self->get_meta($keyword, 'background-process')) {
my $timeout = $self->get_meta($keyword, 'process-timeout') // $self->{pbot}->{registry}->get_value('processmanager', 'default_timeout');
$self->{pbot}->{process_manager}->execute_process(
$stuff,
sub { $stuff->{result} = $ref->{subref}->($stuff->{from}, $stuff->{nick}, $stuff->{user}, $stuff->{host}, $stuff->{arguments}, $stuff) },
$context,
sub { $context->{result} = $ref->{subref}->($context->{from}, $context->{nick}, $context->{user}, $context->{host}, $context->{arguments}, $context) },
$timeout
);
return "";
} else {
my $result = $ref->{subref}->($stuff->{from}, $stuff->{nick}, $stuff->{user}, $stuff->{host}, $stuff->{arguments}, $stuff);
return undef if $stuff->{referenced} and $result =~ m/(?:usage:|no results)/i;
my $result = $ref->{subref}->($context->{from}, $context->{nick}, $context->{user}, $context->{host}, $context->{arguments}, $context);
return undef if $context->{referenced} and $result =~ m/(?:usage:|no results)/i;
return $result;
}
}
@ -149,27 +149,27 @@ sub get_meta {
}
sub cmdset {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($command, $key, $value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($command, $key, $value) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3);
return "Usage: cmdset <command> [key [value]]" if not defined $command;
return $self->{metadata}->set($command, $key, $value);
}
sub cmdunset {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($command, $key) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($command, $key) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
return "Usage: cmdunset <command> <key>" if not defined $command or not defined $key;
return $self->{metadata}->unset($command, $key);
}
sub help {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
if (not length $arguments) {
return "For general help, see <https://github.com/pragma-/pbot/tree/master/doc>. For help about a specific command or factoid, use `help <keyword> [channel]`.";
}
my $keyword = lc $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
my $keyword = lc $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
# check built-in commands first
if ($self->exists($keyword)) {
@ -188,7 +188,7 @@ sub help {
}
# then factoids
my $channel_arg = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
my $channel_arg = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
$channel_arg = $from if not defined $channel_arg or not length $channel_arg;
$channel_arg = '.*' if $channel_arg !~ m/^#/;
@ -234,24 +234,24 @@ sub help {
}
sub uptime {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
return localtime($self->{pbot}->{startup_timestamp}) . " [" . duration(time - $self->{pbot}->{startup_timestamp}) . "]";
}
sub in_channel {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $usage = "Usage: in <channel> <command>";
return $usage if not $arguments;
my ($channel, $command) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2, 0, 1);
my ($channel, $command) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2, 0, 1);
return $usage if not defined $channel or not defined $command;
if (not $self->{pbot}->{nicklist}->is_present($channel, $nick)) { return "You must be present in $channel to do this."; }
$stuff->{from} = $channel;
$stuff->{command} = $command;
return $self->{pbot}->{interpreter}->interpret($stuff);
$context->{from} = $channel;
$context->{command} = $command;
return $self->{pbot}->{interpreter}->interpret($context);
}
1;

View File

@ -263,9 +263,9 @@ sub get_keys {
if (not $nocache) { return keys %{$self->{cache}}; }
@keys = eval {
my $stuff = $self->{dbh}->selectall_arrayref('SELECT DISTINCT index1 FROM Stuff');
if (@$stuff) {
return map { $_->[0] } @$stuff;
my $context = $self->{dbh}->selectall_arrayref('SELECT DISTINCT index1 FROM Stuff');
if (@$context) {
return map { $_->[0] } @$context;
} else {
return ();
}
@ -287,9 +287,9 @@ sub get_keys {
@keys = eval {
my $sth = $self->{dbh}->prepare('SELECT index2 FROM Stuff WHERE index1 = ?');
$sth->execute($index1);
my $stuff = $sth->fetchall_arrayref;
if (@$stuff) {
return map { $_->[0] } @$stuff;
my $context = $sth->fetchall_arrayref;
if (@$context) {
return map { $_->[0] } @$context;
} else {
return ();
}
@ -313,15 +313,15 @@ sub get_keys {
@keys = eval {
my $sth = $self->{dbh}->prepare('SELECT * FROM Stuff WHERE index1 = ? AND index2 = ?');
$sth->execute($index1, $index2);
my $stuff = $sth->fetchall_arrayref({});
my $context = $sth->fetchall_arrayref({});
my @k = ();
return @k if not @{$stuff};
return @k if not @{$context};
my ($lc_index1, $lc_index2) = (lc $index1, lc $index2);
foreach my $key (keys %{$stuff->[0]}) {
foreach my $key (keys %{$context->[0]}) {
next if $key eq 'index1' or $key eq 'index2';
push @k, $key if defined $stuff->[0]->{$key};
$self->{cache}->{$lc_index1}->{$lc_index2}->{$key} = $stuff->[0]->{$key};
push @k, $key if defined $context->[0]->{$key};
$self->{cache}->{$lc_index1}->{$lc_index2}->{$key} = $context->[0]->{$key};
}
my $timeout = $self->{pbot}->{registry}->get_value('dualindexsqliteobject', 'cache_timeout') // 60 * 30;
@ -519,14 +519,14 @@ sub get_data {
my $data = eval {
my $sth = $self->{dbh}->prepare('SELECT * FROM Stuff WHERE index1 = ? AND index2 = ?');
$sth->execute($index1, $index2);
my $stuff = $sth->fetchall_arrayref({});
my $context = $sth->fetchall_arrayref({});
my $d = {};
foreach my $key (keys %{$stuff->[0]}) {
foreach my $key (keys %{$context->[0]}) {
next if $key eq 'index1' or $key eq 'index2';
if (defined $stuff->[0]->{$key}) {
$self->{cache}->{$lc_index1}->{$lc_index2}->{$key} = $stuff->[0]->{$key};
$d->{$key} = $stuff->[0]->{$key};
if (defined $context->[0]->{$key}) {
$self->{cache}->{$lc_index1}->{$lc_index2}->{$key} = $context->[0]->{$key};
$d->{$key} = $context->[0]->{$key};
}
}
@ -560,17 +560,17 @@ sub get_data {
my $value = eval {
my $sth = $self->{dbh}->prepare('SELECT * FROM Stuff WHERE index1 = ? AND index2 = ?');
$sth->execute($index1, $index2);
my $stuff = $sth->fetchall_arrayref({});
my $context = $sth->fetchall_arrayref({});
foreach my $key (keys %{$stuff->[0]}) {
foreach my $key (keys %{$context->[0]}) {
next if $key eq 'index1' or $key eq 'index2';
$self->{cache}->{$lc_index1}->{$lc_index2}->{$key} = $stuff->[0]->{$key};
$self->{cache}->{$lc_index1}->{$lc_index2}->{$key} = $context->[0]->{$key};
}
my $timeout = $self->{pbot}->{registry}->get_value('dualindexsqliteobject', 'cache_timeout') // 60 * 30;
$self->{cache_timeouts}->{$lc_index1}->{$lc_index2} = time + $timeout;
return $stuff->[0]->{$data_index};
return $context->[0]->{$data_index};
};
if ($@) {

View File

@ -73,8 +73,8 @@ sub initialize {
sub call_factoid {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($chan, $keyword, $args) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3, 0, 1);
my ($from, $nick, $user, $host, $arguments, $context) = @_;
my ($chan, $keyword, $args) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3, 0, 1);
if (not defined $chan or not defined $keyword) { return "Usage: fact <channel> <keyword> [arguments]"; }
@ -82,13 +82,13 @@ sub call_factoid {
if (not defined $trigger) { return "No such factoid $keyword exists for $chan"; }
$stuff->{keyword} = $trigger;
$stuff->{trigger} = $trigger;
$stuff->{ref_from} = $channel;
$stuff->{arguments} = $args;
$stuff->{root_keyword} = $trigger;
$context->{keyword} = $trigger;
$context->{trigger} = $trigger;
$context->{ref_from} = $channel;
$context->{arguments} = $args;
$context->{root_keyword} = $trigger;
return $self->{pbot}->{factoids}->interpreter($stuff);
return $self->{pbot}->{factoids}->interpreter($context);
}
sub log_factoid {
@ -297,7 +297,7 @@ sub list_undo_history {
}
sub factundo {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $usage = "Usage: factundo [-l [N]] [-r N] [channel] <keyword> (-l list undo history, optionally starting from N; -r jump to revision N)";
my $getopt_error;
@ -605,8 +605,8 @@ sub factunset {
sub factmove {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($src_channel, $source, $target_channel, $target) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 5);
my ($from, $nick, $user, $host, $arguments, $context) = @_;
my ($src_channel, $source, $target_channel, $target) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 5);
my $usage = "Usage: factmove <source channel> <source factoid> <target channel/factoid> [target factoid]";
return $usage if not defined $target_channel;
@ -690,8 +690,8 @@ sub factmove {
sub factalias {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($chan, $alias, $command) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3, 0, 1);
my ($from, $nick, $user, $host, $arguments, $context) = @_;
my ($chan, $alias, $command) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3, 0, 1);
if (defined $chan and not($chan eq '.*' or $chan =~ m/^#/)) {
# $chan doesn't look like a channel, so shift everything to the right
@ -733,8 +733,8 @@ sub factalias {
}
sub add_regex {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($keyword, $text) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($keyword, $text) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
$from = '.*' if not defined $from or $from !~ /^#/;
@ -764,10 +764,10 @@ sub add_regex {
sub factadd {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($from, $nick, $user, $host, $arguments, $context) = @_;
my ($from_chan, $keyword, $text, $force);
my @arglist = @{$stuff->{arglist}};
my @arglist = @{$context->{arglist}};
if (@arglist) {
# check for -f since we allow it to be before optional channel argument
@ -869,10 +869,10 @@ sub factadd {
sub factrem {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($from, $nick, $user, $host, $arguments, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{factoids};
my ($from_chan, $from_trig) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($from_chan, $from_trig) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
if (not defined $from_trig) {
$from_trig = $from_chan;
@ -937,9 +937,9 @@ sub histogram {
sub factshow {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($from, $nick, $user, $host, $arguments, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{factoids};
$stuff->{preserve_whitespace} = 1;
$context->{preserve_whitespace} = 1;
my $usage = "Usage: factshow [-p] [channel] <keyword>; -p to paste";
return $usage if not $arguments;
@ -1063,9 +1063,9 @@ sub factlog {
sub factinfo {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($from, $nick, $user, $host, $arguments, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{factoids};
my ($chan, $trig) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($chan, $trig) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
if (not defined $trig) {
$trig = $chan;
@ -1154,13 +1154,13 @@ sub factinfo {
}
sub top20 {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{factoids};
my %hash = ();
my $text = "";
my $i = 0;
my ($channel, $args) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($channel, $args) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
if (not defined $channel) { return "Usage: top20 <channel> [nick or 'recent']"; }
@ -1357,16 +1357,16 @@ sub factfind {
sub factchange {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($from, $nick, $user, $host, $arguments, $context) = @_;
my $factoids_data = $self->{pbot}->{factoids}->{factoids};
my ($channel, $trigger, $keyword, $delim, $tochange, $changeto, $modifier, $url);
$stuff->{preserve_whitespace} = 1;
$context->{preserve_whitespace} = 1;
my $needs_disambig;
if (length $arguments) {
my $args = $stuff->{arglist};
my $args = $context->{arglist};
my $sub;
my $arg_count = $self->{pbot}->{interpreter}->arglist_size($args);

View File

@ -451,12 +451,12 @@ sub expand_special_vars {
}
sub expand_factoid_vars {
my ($self, $stuff, @exclude) = @_;
my ($self, $context, @exclude) = @_;
my $from = length $stuff->{ref_from} ? $stuff->{ref_from} : $stuff->{from};
my $nick = $stuff->{nick};
my $root_keyword = $stuff->{keyword_override} ? $stuff->{keyword_override} : $stuff->{root_keyword};
my $action = $stuff->{action};
my $from = length $context->{ref_from} ? $context->{ref_from} : $context->{from};
my $nick = $context->{nick};
my $root_keyword = $context->{keyword_override} ? $context->{keyword_override} : $context->{root_keyword};
my $action = $context->{action};
my $debug = 0;
my $depth = 0;
@ -464,7 +464,7 @@ sub expand_factoid_vars {
if ($debug) {
$self->{pbot}->{logger}->log("enter expand_factoid_vars\n");
use Data::Dumper;
$self->{pbot}->{logger}->log(Dumper $stuff);
$self->{pbot}->{logger}->log(Dumper $context);
}
if ($action =~ m/^\/call --keyword-override=([^ ]+)/i) { $root_keyword = $1; }
@ -702,44 +702,44 @@ sub expand_action_arguments {
}
sub execute_code_factoid_using_vm {
my ($self, $stuff) = @_;
my ($self, $context) = @_;
unless ($self->{factoids}->exists($stuff->{channel}, $stuff->{keyword}, 'interpolate')
and $self->{factoids}->get_data($stuff->{channel}, $stuff->{keyword}, 'interpolate') eq '0')
unless ($self->{factoids}->exists($context->{channel}, $context->{keyword}, 'interpolate')
and $self->{factoids}->get_data($context->{channel}, $context->{keyword}, 'interpolate') eq '0')
{
if ($stuff->{code} =~ m/(?:\$\{?nick\b|\$\{?args\b|\$\{?arg\[)/ and length $stuff->{arguments}) { $stuff->{no_nickoverride} = 1; }
else { $stuff->{no_nickoverride} = 0; }
if ($context->{code} =~ m/(?:\$\{?nick\b|\$\{?args\b|\$\{?arg\[)/ and length $context->{arguments}) { $context->{no_nickoverride} = 1; }
else { $context->{no_nickoverride} = 0; }
$stuff->{action} = $stuff->{code};
$stuff->{code} = $self->expand_factoid_vars($stuff);
$context->{action} = $context->{code};
$context->{code} = $self->expand_factoid_vars($context);
if ($self->{factoids}->get_data($stuff->{channel}, $stuff->{keyword}, 'allow_empty_args')) {
$stuff->{code} = $self->expand_action_arguments($stuff->{code}, $stuff->{arguments}, '');
if ($self->{factoids}->get_data($context->{channel}, $context->{keyword}, 'allow_empty_args')) {
$context->{code} = $self->expand_action_arguments($context->{code}, $context->{arguments}, '');
} else {
$stuff->{code} = $self->expand_action_arguments($stuff->{code}, $stuff->{arguments}, $stuff->{nick});
$context->{code} = $self->expand_action_arguments($context->{code}, $context->{arguments}, $context->{nick});
}
} else {
$stuff->{no_nickoverride} = 0;
$context->{no_nickoverride} = 0;
}
my %h = (
nick => $stuff->{nick}, channel => $stuff->{from}, lang => $stuff->{lang}, code => $stuff->{code}, arguments => $stuff->{arguments},
factoid => "$stuff->{channel}:$stuff->{keyword}"
nick => $context->{nick}, channel => $context->{from}, lang => $context->{lang}, code => $context->{code}, arguments => $context->{arguments},
factoid => "$context->{channel}:$context->{keyword}"
);
if ($self->{factoids}->exists($stuff->{channel}, $stuff->{keyword}, 'persist-key')) {
$h{'persist-key'} = $self->{factoids}->get_data($stuff->{channel}, $stuff->{keyword}, 'persist-key');
if ($self->{factoids}->exists($context->{channel}, $context->{keyword}, 'persist-key')) {
$h{'persist-key'} = $self->{factoids}->get_data($context->{channel}, $context->{keyword}, 'persist-key');
}
my $json = encode_json \%h;
$stuff->{special} = 'code-factoid';
$stuff->{root_channel} = $stuff->{channel};
$stuff->{keyword} = 'compiler';
$stuff->{arguments} = $json;
$stuff->{args_utf8} = 1;
$context->{special} = 'code-factoid';
$context->{root_channel} = $context->{channel};
$context->{keyword} = 'compiler';
$context->{arguments} = $json;
$context->{args_utf8} = 1;
$self->{pbot}->{modules}->execute_module($stuff);
$self->{pbot}->{modules}->execute_module($context);
return "";
}
@ -749,38 +749,38 @@ sub execute_code_factoid {
}
sub interpreter {
my ($self, $stuff) = @_;
my ($self, $context) = @_;
my $pbot = $self->{pbot};
if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) {
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$self->{pbot}->{logger}->log("Factoids::interpreter\n");
$self->{pbot}->{logger}->log(Dumper $stuff);
$self->{pbot}->{logger}->log(Dumper $context);
}
return undef if not length $stuff->{keyword} or $stuff->{interpret_depth} > $self->{pbot}->{registry}->get_value('interpreter', 'max_recursion');
return undef if not length $context->{keyword} or $context->{interpret_depth} > $self->{pbot}->{registry}->get_value('interpreter', 'max_recursion');
$stuff->{from} = lc $stuff->{from};
$context->{from} = lc $context->{from};
my $strictnamespace = $self->{pbot}->{registry}->get_value($stuff->{from}, 'strictnamespace');
my $strictnamespace = $self->{pbot}->{registry}->get_value($context->{from}, 'strictnamespace');
if (not defined $strictnamespace) { $strictnamespace = $self->{pbot}->{registry}->get_value('general', 'strictnamespace'); }
# search for factoid against global channel and current channel (from unless ref_from is defined)
my $original_keyword = $stuff->{keyword};
my $original_keyword = $context->{keyword};
my ($channel, $keyword) =
$self->find_factoid($stuff->{ref_from} ? $stuff->{ref_from} : $stuff->{from}, $stuff->{keyword}, arguments => $stuff->{arguments}, exact_channel => 1);
$self->find_factoid($context->{ref_from} ? $context->{ref_from} : $context->{from}, $context->{keyword}, arguments => $context->{arguments}, exact_channel => 1);
if (not $stuff->{ref_from} or $stuff->{ref_from} eq '.*' or $stuff->{ref_from} eq $stuff->{from}) { $stuff->{ref_from} = ""; }
if (not $context->{ref_from} or $context->{ref_from} eq '.*' or $context->{ref_from} eq $context->{from}) { $context->{ref_from} = ""; }
if (defined $channel and not $channel eq '.*' and not $channel eq lc $stuff->{from}) { $stuff->{ref_from} = $channel; }
if (defined $channel and not $channel eq '.*' and not $channel eq lc $context->{from}) { $context->{ref_from} = $channel; }
$stuff->{arguments} = "" if not defined $stuff->{arguments};
$context->{arguments} = "" if not defined $context->{arguments};
# if no match found, attempt to call factoid from another channel if it exists there
if (not defined $keyword) {
my $string = "$original_keyword $stuff->{arguments}";
my $string = "$original_keyword $context->{arguments}";
my @chanlist = ();
my ($fwd_chan, $fwd_trig);
@ -793,36 +793,36 @@ sub interpreter {
$fwd_trig = $original_keyword;
}
my $ref_from = $stuff->{ref_from} ? "[$stuff->{ref_from}] " : "";
my $ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : "";
# if multiple channels have this keyword, then ask user to disambiguate
if (@chanlist> 1) {
return undef if $stuff->{referenced};
return undef if $context->{referenced};
return $ref_from . "Ambiguous keyword '$original_keyword' exists in multiple channels (use 'fact <channel> $original_keyword' to choose one): " . join(', ', @chanlist);
}
# if there's just one other channel that has this keyword, trigger that instance
elsif (@chanlist == 1) {
$pbot->{logger}->log("Found '$original_keyword' as '$fwd_trig' in [$fwd_chan]\n");
$stuff->{keyword} = $fwd_trig;
$stuff->{interpret_depth}++;
$stuff->{ref_from} = $fwd_chan;
return $pbot->{factoids}->interpreter($stuff);
$context->{keyword} = $fwd_trig;
$context->{interpret_depth}++;
$context->{ref_from} = $fwd_chan;
return $pbot->{factoids}->interpreter($context);
}
# otherwise keyword hasn't been found, display similiar matches for all channels
else {
my $namespace = $strictnamespace ? $stuff->{from} : '.*';
my $namespace = $strictnamespace ? $context->{from} : '.*';
$namespace = '.*' if $namespace !~ /^#/;
my $namespace_regex = $namespace;
if ($strictnamespace) { $namespace_regex = "(?:" . (quotemeta $namespace) . '|\\.\\*)'; }
my $matches = $self->{commands}->factfind($stuff->{from}, $stuff->{nick}, $stuff->{user}, $stuff->{host}, quotemeta($original_keyword) . " -channel $namespace_regex");
my $matches = $self->{commands}->factfind($context->{from}, $context->{nick}, $context->{user}, $context->{host}, quotemeta($original_keyword) . " -channel $namespace_regex");
# found factfind matches
if ($matches !~ m/^No factoids/) {
return undef if $stuff->{referenced};
return undef if $context->{referenced};
return "No such factoid '$original_keyword'; $matches";
}
@ -830,18 +830,18 @@ sub interpreter {
$matches = $self->{factoids}->levenshtein_matches($namespace, lc $original_keyword, 0.50, $strictnamespace);
# if a non-nick argument was supplied, e.g., a sentence using the bot's nick, /msg the error to the caller
if (length $stuff->{arguments} and not $self->{pbot}->{nicklist}->is_present($stuff->{from}, $stuff->{arguments})) {
$stuff->{send_msg_to_caller} = 1;
if (length $context->{arguments} and not $self->{pbot}->{nicklist}->is_present($context->{from}, $context->{arguments})) {
$context->{send_msg_to_caller} = 1;
}
# /msg the caller if nothing similiar was found
$stuff->{send_msg_to_caller} = 1 if $matches eq 'none';
$stuff->{send_msg_to_caller} = 1 if $stuff->{referenced};
$context->{send_msg_to_caller} = 1 if $matches eq 'none';
$context->{send_msg_to_caller} = 1 if $context->{referenced};
my $msg_caller = '';
$msg_caller = "/msg $stuff->{nick} " if $stuff->{send_msg_to_caller};
$msg_caller = "/msg $context->{nick} " if $context->{send_msg_to_caller};
my $ref_from = $stuff->{ref_from} ? "[$stuff->{ref_from}] " : "";
my $ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : "";
if ($matches eq 'none') {
return $msg_caller . $ref_from . "No such factoid '$original_keyword'; no similar matches.";
} else {
@ -855,32 +855,32 @@ sub interpreter {
$channel_name = 'global' if $channel_name eq '.*';
$trigger_name = "\"$trigger_name\"" if $trigger_name =~ / /;
$stuff->{keyword} = $keyword;
$stuff->{trigger} = $keyword;
$stuff->{channel} = $channel;
$stuff->{original_keyword} = $original_keyword;
$stuff->{channel_name} = $channel_name;
$stuff->{trigger_name} = $trigger_name;
$context->{keyword} = $keyword;
$context->{trigger} = $keyword;
$context->{channel} = $channel;
$context->{original_keyword} = $original_keyword;
$context->{channel_name} = $channel_name;
$context->{trigger_name} = $trigger_name;
return undef if $stuff->{referenced} and $self->{factoids}->get_data($channel, $keyword, 'noembed');
return undef if $context->{referenced} and $self->{factoids}->get_data($channel, $keyword, 'noembed');
if ($self->{factoids}->get_data($channel, $keyword, 'locked_to_channel')) {
if ($stuff->{ref_from} ne "") { # called from another channel
return "$trigger_name may be invoked only in $stuff->{ref_from}.";
if ($context->{ref_from} ne "") { # called from another channel
return "$trigger_name may be invoked only in $context->{ref_from}.";
}
}
if ($self->{factoids}->exists($channel, $keyword, 'last_referenced_on')) {
if ($self->{factoids}->exists($channel, $keyword, 'last_referenced_in')) {
if ($self->{factoids}->get_data($channel, $keyword, 'last_referenced_in') eq $stuff->{from}) {
my $ratelimit = $self->{pbot}->{registry}->get_value($stuff->{from}, 'ratelimit_override');
if ($self->{factoids}->get_data($channel, $keyword, 'last_referenced_in') eq $context->{from}) {
my $ratelimit = $self->{pbot}->{registry}->get_value($context->{from}, 'ratelimit_override');
$ratelimit = $self->{factoids}->get_data($channel, $keyword, 'rate_limit') if not defined $ratelimit;
if (gettimeofday - $self->{factoids}->get_data($channel, $keyword, 'last_referenced_on') < $ratelimit) {
my $ref_from = $stuff->{ref_from} ? "[$stuff->{ref_from}] " : "";
my $ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : "";
return
"/msg $stuff->{nick} $ref_from'$trigger_name' is rate-limited; try again in "
"/msg $context->{nick} $ref_from'$trigger_name' is rate-limited; try again in "
. duration($ratelimit - int(gettimeofday - $self->{factoids}->get_data($channel, $keyword, 'last_referenced_on'))) . "."
unless $self->{pbot}->{users}->loggedin_admin($channel, "$stuff->{nick}!$stuff->{user}\@$stuff->{host}");
unless $self->{pbot}->{users}->loggedin_admin($channel, "$context->{nick}!$context->{user}\@$context->{host}");
}
}
}
@ -889,22 +889,22 @@ sub interpreter {
my $ref_count = $self->{factoids}->get_data($channel, $keyword, 'ref_count');
my $update_data = {
ref_count => ++$ref_count,
ref_user => "$stuff->{nick}!$stuff->{user}\@$stuff->{host}",
ref_user => "$context->{nick}!$context->{user}\@$context->{host}",
last_referenced_on => scalar gettimeofday,
last_referenced_in => $stuff->{from} || 'stdin',
last_referenced_in => $context->{from} || 'stdin',
};
$self->{factoids}->add($channel, $keyword, $update_data, 1, 1);
my $action;
if ($self->{factoids}->exists($channel, $keyword, 'usage') and not length $stuff->{arguments} and $self->{factoids}->get_data($channel, $keyword, 'requires_arguments')) {
$stuff->{alldone} = 1;
if ($self->{factoids}->exists($channel, $keyword, 'usage') and not length $context->{arguments} and $self->{factoids}->get_data($channel, $keyword, 'requires_arguments')) {
$context->{alldone} = 1;
my $usage = $self->{factoids}->get_data($channel, $keyword, 'usage');
$usage =~ s/\$0|\$\{0\}/$trigger_name/g;
return $usage;
}
if (length $stuff->{arguments} and $self->{factoids}->exists($channel, $keyword, 'action_with_args')) {
if (length $context->{arguments} and $self->{factoids}->exists($channel, $keyword, 'action_with_args')) {
$action = $self->{factoids}->get_data($channel, $keyword, 'action_with_args');
} else {
$action = $self->{factoids}->get_data($channel, $keyword, 'action');
@ -913,81 +913,81 @@ sub interpreter {
if ($action =~ m{^/code\s+([^\s]+)\s+(.+)$}msi) {
my ($lang, $code) = ($1, $2);
if ($self->{factoids}->exists($channel, $keyword, 'usage') and not length $stuff->{arguments}) {
$stuff->{alldone} = 1;
if ($self->{factoids}->exists($channel, $keyword, 'usage') and not length $context->{arguments}) {
$context->{alldone} = 1;
my $usage = $self->{factoids}->get_data($channel, $keyword, 'usage');
$usage =~ s/\$0|\$\{0\}/$trigger_name/g;
return $usage;
}
$stuff->{lang} = $lang;
$stuff->{code} = $code;
$self->execute_code_factoid($stuff);
$context->{lang} = $lang;
$context->{code} = $code;
$self->execute_code_factoid($context);
return "";
}
if ($self->{factoids}->get_data($channel, $keyword, 'background-process')) {
my $timeout = $self->{factoids}->get_data($channel, $keyword, 'process-timeout') // $self->{pbot}->{registry}->get_value('processmanager', 'default_timeout');
$self->{pbot}->{process_manager}->execute_process(
$stuff,
sub { $stuff->{result} = $self->handle_action($stuff, $action); },
$context,
sub { $context->{result} = $self->handle_action($context, $action); },
$timeout
);
return "";
} else {
return $self->handle_action($stuff, $action);
return $self->handle_action($context, $action);
}
}
sub handle_action {
my ($self, $stuff, $action) = @_;
my ($self, $context, $action) = @_;
if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) {
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$self->{pbot}->{logger}->log("Factoids::handle_action [$action]\n");
$self->{pbot}->{logger}->log(Dumper $stuff);
$self->{pbot}->{logger}->log(Dumper $context);
}
return "" if not length $action;
my ($channel, $keyword) = ($stuff->{channel}, $stuff->{trigger});
my ($channel_name, $trigger_name) = ($stuff->{channel_name}, $stuff->{trigger_name});
my $ref_from = $stuff->{ref_from} ? "[$stuff->{ref_from}] " : "";
my ($channel, $keyword) = ($context->{channel}, $context->{trigger});
my ($channel_name, $trigger_name) = ($context->{channel_name}, $context->{trigger_name});
my $ref_from = $context->{ref_from} ? "[$context->{ref_from}] " : "";
unless ($self->{factoids}->exists($channel, $keyword, 'interpolate') and $self->{factoids}->get_data($channel, $keyword, 'interpolate') eq '0') {
my ($root_channel, $root_keyword) =
$self->find_factoid($stuff->{ref_from} ? $stuff->{ref_from} : $stuff->{from}, $stuff->{root_keyword}, arguments => $stuff->{arguments}, exact_channel => 1);
$self->find_factoid($context->{ref_from} ? $context->{ref_from} : $context->{from}, $context->{root_keyword}, arguments => $context->{arguments}, exact_channel => 1);
if (not defined $root_channel or not defined $root_keyword) {
$root_channel = $channel;
$root_keyword = $keyword;
}
if (not length $stuff->{keyword_override} and length $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override')) {
$stuff->{keyword_override} = $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override');
if (not length $context->{keyword_override} and length $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override')) {
$context->{keyword_override} = $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override');
}
$stuff->{action} = $action;
$action = $self->expand_factoid_vars($stuff);
$context->{action} = $action;
$action = $self->expand_factoid_vars($context);
}
if (length $stuff->{arguments}) {
if (length $context->{arguments}) {
if ($action =~ m/\$\{?args/ or $action =~ m/\$\{?arg\[/) {
unless (defined $self->{factoids}->get_data($channel, $keyword, 'interpolate') and $self->{factoids}->get_data($channel, $keyword, 'interpolate') eq '0') {
$action = $self->expand_action_arguments($action, $stuff->{arguments}, $stuff->{nick});
$stuff->{no_nickoverride} = 1;
$action = $self->expand_action_arguments($action, $context->{arguments}, $context->{nick});
$context->{no_nickoverride} = 1;
} else {
$stuff->{no_nickoverride} = 0;
$context->{no_nickoverride} = 0;
}
$stuff->{arguments} = "";
$stuff->{original_arguments} = "";
$context->{arguments} = "";
$context->{original_arguments} = "";
} else {
if ($self->{factoids}->get_data($channel, $keyword, 'type') eq 'text') {
my $target = $self->{pbot}->{nicklist}->is_present_similar($stuff->{from}, $stuff->{arguments});
my $target = $self->{pbot}->{nicklist}->is_present_similar($context->{from}, $context->{arguments});
if ($target and $action !~ /\$\{?(?:nick|args)\b/) {
$stuff->{nickoverride} = $target unless $stuff->{force_nickoverride};
$stuff->{no_nickoverride} = 0;
$context->{nickoverride} = $target unless $context->{force_nickoverride};
$context->{no_nickoverride} = 0;
} else {
$stuff->{no_nickoverride} = 1;
$context->{no_nickoverride} = 1;
}
}
}
@ -996,12 +996,12 @@ sub handle_action {
if ($self->{factoids}->exists($channel, $keyword, 'usage')) {
$action = "/say " . $self->{factoids}->get_data($channel, $keyword, 'usage');
$action =~ s/\$0|\$\{0\}/$trigger_name/g;
$stuff->{alldone} = 1;
$context->{alldone} = 1;
} else {
if ($self->{factoids}->get_data($channel, $keyword, 'allow_empty_args')) { $action = $self->expand_action_arguments($action, undef, ''); }
else { $action = $self->expand_action_arguments($action, undef, $stuff->{nick}); }
else { $action = $self->expand_action_arguments($action, undef, $context->{nick}); }
}
$stuff->{no_nickoverride} = 0;
$context->{no_nickoverride} = 0;
}
# Check if it's an alias
@ -1009,75 +1009,75 @@ sub handle_action {
my $command = $1;
$command =~ s/\n$//;
unless ($self->{factoids}->get_data($channel, $keyword, 'require_explicit_args')) {
my $args = $stuff->{arguments};
$command .= " $args" if length $args and not $stuff->{special} eq 'code-factoid';
$stuff->{arguments} = '';
my $args = $context->{arguments};
$command .= " $args" if length $args and not $context->{special} eq 'code-factoid';
$context->{arguments} = '';
}
unless ($self->{factoids}->get_data($channel, $keyword, 'no_keyword_override')) {
if ($command =~ s/\s*--keyword-override=([^ ]+)\s*//) { $stuff->{keyword_override} = $1; }
if ($command =~ s/\s*--keyword-override=([^ ]+)\s*//) { $context->{keyword_override} = $1; }
}
$stuff->{command} = $command;
$stuff->{aliased} = 1;
$context->{command} = $command;
$context->{aliased} = 1;
$self->{pbot}->{logger}
->log("[" . (defined $stuff->{from} ? $stuff->{from} : "stdin") . "] ($stuff->{nick}!$stuff->{user}\@$stuff->{host}) $trigger_name aliased to: $command\n");
->log("[" . (defined $context->{from} ? $context->{from} : "stdin") . "] ($context->{nick}!$context->{user}\@$context->{host}) $trigger_name aliased to: $command\n");
if (defined $self->{factoids}->get_data($channel, $keyword, 'cap-override')) {
if ($self->{factoids}->get_data($channel, $keyword, 'locked')) {
$self->{pbot}->{logger}->log("Capability override set to " . $self->{factoids}->get_data($channel, $keyword, 'cap-override') . "\n");
$stuff->{'cap-override'} = $self->{factoids}->get_data($channel, $keyword, 'cap-override');
$context->{'cap-override'} = $self->{factoids}->get_data($channel, $keyword, 'cap-override');
} else {
$self->{pbot}->{logger}->log("Ignoring cap-override of " . $self->{factoids}->get_data($channel, $keyword, 'cap-override') . " on unlocked factoid\n");
}
}
return $self->{pbot}->{interpreter}->interpret($stuff);
return $self->{pbot}->{interpreter}->interpret($context);
}
$self->{pbot}->{logger}
->log("(" . (defined $stuff->{from} ? $stuff->{from} : "(undef)") . "): $stuff->{nick}!$stuff->{user}\@$stuff->{host}: $trigger_name: action: \"$action\"\n");
->log("(" . (defined $context->{from} ? $context->{from} : "(undef)") . "): $context->{nick}!$context->{user}\@$context->{host}: $trigger_name: action: \"$action\"\n");
if ($self->{factoids}->get_data($channel, $keyword, 'enabled') == 0) {
$self->{pbot}->{logger}->log("$trigger_name disabled.\n");
return "/msg $stuff->{nick} ${ref_from}$trigger_name is currently disabled.";
return "/msg $context->{nick} ${ref_from}$trigger_name is currently disabled.";
}
unless ($self->{factoids}->exists($channel, $keyword, 'interpolate') and $self->{factoids}->get_data($channel, $keyword, 'interpolate') eq '0') {
my ($root_channel, $root_keyword) =
$self->find_factoid($stuff->{ref_from} ? $stuff->{ref_from} : $stuff->{from}, $stuff->{root_keyword}, arguments => $stuff->{arguments}, exact_channel => 1);
$self->find_factoid($context->{ref_from} ? $context->{ref_from} : $context->{from}, $context->{root_keyword}, arguments => $context->{arguments}, exact_channel => 1);
if (not defined $root_channel or not defined $root_keyword) {
$root_channel = $channel;
$root_keyword = $keyword;
}
if (not length $stuff->{keyword_override} and length $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override')) {
$stuff->{keyword_override} = $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override');
if (not length $context->{keyword_override} and length $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override')) {
$context->{keyword_override} = $self->{factoids}->get_data($root_channel, $root_keyword, 'keyword_override');
}
$stuff->{action} = $action;
$action = $self->expand_factoid_vars($stuff);
$context->{action} = $action;
$action = $self->expand_factoid_vars($context);
if ($self->{factoids}->get_data($channel, $keyword, 'allow_empty_args')) { $action = $self->expand_action_arguments($action, $stuff->{arguments}, ''); }
else { $action = $self->expand_action_arguments($action, $stuff->{arguments}, $stuff->{nick}); }
if ($self->{factoids}->get_data($channel, $keyword, 'allow_empty_args')) { $action = $self->expand_action_arguments($action, $context->{arguments}, ''); }
else { $action = $self->expand_action_arguments($action, $context->{arguments}, $context->{nick}); }
}
return $action if $stuff->{special} eq 'code-factoid';
return $action if $context->{special} eq 'code-factoid';
if ($self->{factoids}->get_data($channel, $keyword, 'type') eq 'module') {
my $preserve_whitespace = $self->{factoids}->get_data($channel, $keyword, 'preserve_whitespace');
$preserve_whitespace = 0 if not defined $preserve_whitespace;
$stuff->{preserve_whitespace} = $preserve_whitespace;
$stuff->{root_keyword} = $keyword unless defined $stuff->{root_keyword};
$stuff->{root_channel} = $channel;
$context->{preserve_whitespace} = $preserve_whitespace;
$context->{root_keyword} = $keyword unless defined $context->{root_keyword};
$context->{root_channel} = $channel;
my $result = $self->{pbot}->{modules}->execute_module($stuff);
my $result = $self->{pbot}->{modules}->execute_module($context);
if (length $result) { return $ref_from . $result; }
else { return ""; }
} elsif ($self->{factoids}->get_data($channel, $keyword, 'type') eq 'text') {
# Don't allow user-custom /msg factoids, unless factoid triggered by admin
if ($action =~ m/^\/msg/i) {
my $admin = $self->{pbot}->{users}->loggedin_admin($stuff->{from}, "$stuff->{nick}!$stuff->{user}\@$stuff->{host}");
my $admin = $self->{pbot}->{users}->loggedin_admin($context->{from}, "$context->{nick}!$context->{user}\@$context->{host}");
if (not $admin) {
$self->{pbot}->{logger}->log("[ABUSE] Bad factoid (contains /msg): $action\n");
return "You must be an admin to use /msg in a factoid.";
@ -1093,7 +1093,7 @@ sub handle_action {
}
} elsif ($self->{factoids}->get_data($channel, $keyword, 'type') eq 'regex') {
my $result = eval {
my $string = "$stuff->{original_keyword}" . (defined $stuff->{arguments} ? " $stuff->{arguments}" : "");
my $string = "$context->{original_keyword}" . (defined $context->{arguments} ? " $context->{arguments}" : "");
my $cmd;
if ($string =~ m/$keyword/i) {
$self->{pbot}->{logger}->log("[$string] matches [$keyword] - calling [" . $action . "$']\n");
@ -1116,8 +1116,8 @@ sub handle_action {
$cmd = $action;
}
$stuff->{command} = $cmd;
return $self->{pbot}->{interpreter}->interpret($stuff);
$context->{command} = $cmd;
return $self->{pbot}->{interpreter}->interpret($context);
};
if ($@) {
@ -1128,7 +1128,7 @@ sub handle_action {
if (length $result) { return $ref_from . $result; }
else { return ""; }
} else {
$self->{pbot}->{logger}->log("($stuff->{from}): $stuff->{nick}!$stuff->{user}\@$stuff->{host}): Unknown command type for '$trigger_name'\n");
$self->{pbot}->{logger}->log("($context->{from}): $context->{nick}!$context->{user}\@$context->{host}): Unknown command type for '$trigger_name'\n");
return "/me blinks." . " $ref_from";
}
}

View File

@ -59,13 +59,13 @@ sub unregister {
}
sub do_func {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my $func = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $func = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
return "Usage: func <keyword> [arguments]; see also: func help" if not defined $func;
return "[No such func '$func']" if not exists $self->{funcs}->{$func};
my @params;
while (defined(my $param = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist}))) { push @params, $param; }
while (defined(my $param = $self->{pbot}->{interpreter}->shift_arg($context->{arglist}))) { push @params, $param; }
my $result = $self->{funcs}->{$func}->{subref}->(@params);
$result =~ s/\x1/1/g;

View File

@ -127,9 +127,9 @@ sub is_ignored {
}
sub ignore_cmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($target, $channel, $length) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
my ($target, $channel, $length) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3);
return "Usage: ignore <hostmask> [channel [timeout]] | ignore list" if not defined $target;
@ -173,8 +173,8 @@ sub ignore_cmd {
}
sub unignore_cmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($target, $channel) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($target, $channel) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
if (not defined $target) { return "Usage: unignore <hostmask> [channel]"; }

View File

@ -34,12 +34,12 @@ sub process_line {
my ($from, $nick, $user, $host, $text) = @_;
$from = lc $from if defined $from;
my $stuff = {from => $from, nick => $nick, user => $user, host => $host, text => $text};
my $context = {from => $from, nick => $nick, user => $user, host => $host, text => $text};
my $pbot = $self->{pbot};
my $message_account = $pbot->{messagehistory}->get_message_account($nick, $user, $host);
$pbot->{messagehistory}->add_message($message_account, "$nick!$user\@$host", $from, $text, $pbot->{messagehistory}->{MSG_CHAT});
$stuff->{message_account} = $message_account;
$context->{message_account} = $message_account;
my $flood_threshold = $pbot->{registry}->get_value($from, 'chat_flood_threshold');
my $flood_time_threshold = $pbot->{registry}->get_value($from, 'chat_flood_time_threshold');
@ -50,23 +50,23 @@ sub process_line {
if (defined $from and $from =~ m/^#/) {
my $chanmodes = $self->{pbot}->{channels}->get_meta($from, 'MODE');
if (defined $chanmodes and $chanmodes =~ m/z/) {
$stuff->{'chan-z'} = 1;
$context->{'chan-z'} = 1;
if ($self->{pbot}->{banlist}->{quietlist}->exists($from, '$~a')) {
my $nickserv = $self->{pbot}->{messagehistory}->{database}->get_current_nickserv_account($message_account);
if (not defined $nickserv or not length $nickserv) { $stuff->{unidentified} = 1; }
if (not defined $nickserv or not length $nickserv) { $context->{unidentified} = 1; }
}
$stuff->{banned} = 1 if $self->{pbot}->{banlist}->is_banned($nick, $user, $host, $from);
$context->{banned} = 1 if $self->{pbot}->{banlist}->is_banned($nick, $user, $host, $from);
}
}
$pbot->{antiflood}->check_flood(
$from, $nick, $user, $host, $text,
$flood_threshold, $flood_time_threshold,
$pbot->{messagehistory}->{MSG_CHAT}, $stuff
$pbot->{messagehistory}->{MSG_CHAT}, $context
) if defined $from;
if ($stuff->{banned} or $stuff->{unidentified}) {
if ($context->{banned} or $context->{unidentified}) {
$self->{pbot}->{logger}->log("Disregarding banned/unidentified user message (channel $from is +z).\n");
return 1;
}
@ -145,73 +145,73 @@ sub process_line {
return 1;
}
$stuff->{text} = $text;
$stuff->{command} = $command;
$context->{text} = $text;
$context->{command} = $command;
if ($nick_override) {
$stuff->{nickoverride} = $nick_override;
$stuff->{force_nickoverride} = 1;
$context->{nickoverride} = $nick_override;
$context->{force_nickoverride} = 1;
}
$stuff->{referenced} = $embedded;
$stuff->{interpret_depth} = 1;
$stuff->{preserve_whitespace} = $preserve_whitespace;
$context->{referenced} = $embedded;
$context->{interpret_depth} = 1;
$context->{preserve_whitespace} = $preserve_whitespace;
$stuff->{result} = $self->interpret($stuff);
$self->handle_result($stuff);
$context->{result} = $self->interpret($context);
$self->handle_result($context);
$processed++;
}
return $processed;
}
sub interpret {
my ($self, $stuff) = @_;
my ($self, $context) = @_;
my ($keyword, $arguments) = ('', '');
my $text;
my $pbot = $self->{pbot};
$pbot->{logger}->log("=== [$stuff->{interpret_depth}] Got command: ("
. (defined $stuff->{from} ? $stuff->{from} : "undef")
. ") $stuff->{nick}!$stuff->{user}\@$stuff->{host}: $stuff->{command}\n");
$pbot->{logger}->log("=== [$context->{interpret_depth}] Got command: ("
. (defined $context->{from} ? $context->{from} : "undef")
. ") $context->{nick}!$context->{user}\@$context->{host}: $context->{command}\n");
$stuff->{special} = "" unless exists $self->{special};
$context->{special} = "" unless exists $self->{special};
if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) {
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$self->{pbot}->{logger}->log("Interpreter::interpret\n");
$self->{pbot}->{logger}->log(Dumper $stuff);
$self->{pbot}->{logger}->log(Dumper $context);
}
return "Too many levels of recursion, aborted." if (++$stuff->{interpret_depth} > $self->{pbot}->{registry}->get_value('interpreter', 'max_recursion'));
return "Too many levels of recursion, aborted." if (++$context->{interpret_depth} > $self->{pbot}->{registry}->get_value('interpreter', 'max_recursion'));
if (not defined $stuff->{nick} || not defined $stuff->{user} || not defined $stuff->{host} || not defined $stuff->{command}) {
if (not defined $context->{nick} || not defined $context->{user} || not defined $context->{host} || not defined $context->{command}) {
$pbot->{logger}->log("Error 1, bad parameters to interpret_command\n");
return undef;
}
# check for splitted commands
if ($stuff->{command} =~ m/^(.*?)\s*(?<!\\);;;\s*(.*)/ms) {
$stuff->{command} = $1;
$stuff->{command_split} = $2;
if ($context->{command} =~ m/^(.*?)\s*(?<!\\);;;\s*(.*)/ms) {
$context->{command} = $1;
$context->{command_split} = $2;
}
my $cmdlist = $self->make_args($stuff->{command});
$stuff->{commands} = [] unless exists $stuff->{commands};
push @{$stuff->{commands}}, $stuff->{command};
my $cmdlist = $self->make_args($context->{command});
$context->{commands} = [] unless exists $context->{commands};
push @{$context->{commands}}, $context->{command};
if ($self->arglist_size($cmdlist) >= 4 and lc $cmdlist->[0] eq 'tell' and (lc $cmdlist->[2] eq 'about' or lc $cmdlist->[2] eq 'the')) {
# tell nick about/the cmd [args]
$stuff->{nickoverride} = $cmdlist->[1];
$context->{nickoverride} = $cmdlist->[1];
($keyword, $arguments) = $self->split_args($cmdlist, 2, 3, 1);
$arguments = '' if not defined $arguments;
my $similar = $self->{pbot}->{nicklist}->is_present_similar($stuff->{from}, $stuff->{nickoverride});
my $similar = $self->{pbot}->{nicklist}->is_present_similar($context->{from}, $context->{nickoverride});
if ($similar) {
$stuff->{nickoverride} = $similar;
$stuff->{force_nickoverride} = 1;
$context->{nickoverride} = $similar;
$context->{force_nickoverride} = 1;
} else {
delete $stuff->{nickoverride};
delete $stuff->{force_nickoverride};
delete $context->{nickoverride};
delete $context->{force_nickoverride};
}
} else {
# normal command
@ -231,13 +231,13 @@ sub interpret {
if (length $command) {
$arguments =~ s/&\s*\{\Q$command\E\}/&{subcmd}/;
push @{$stuff->{subcmd}}, "$keyword $arguments";
push @{$context->{subcmd}}, "$keyword $arguments";
$command =~ s/^\s+|\s+$//g;
$stuff->{command} = $command;
$stuff->{commands} = [];
push @{$stuff->{commands}}, $command;
$stuff->{result} = $self->interpret($stuff);
return $stuff->{result};
$context->{command} = $command;
$context->{commands} = [];
push @{$context->{commands}}, $command;
$context->{result} = $self->interpret($context);
return $context->{result};
}
}
@ -248,33 +248,33 @@ sub interpret {
$arguments =~ s/\s*(?<!\\)\|\s*{(\Q$pipe\E)}.*$//s;
$pipe =~ s/^\s+|\s+$//g;
if (exists $stuff->{pipe}) { $stuff->{pipe_rest} = "$rest | { $stuff->{pipe} }$stuff->{pipe_rest}"; }
else { $stuff->{pipe_rest} = $rest; }
$stuff->{pipe} = $pipe;
if (exists $context->{pipe}) { $context->{pipe_rest} = "$rest | { $context->{pipe} }$context->{pipe_rest}"; }
else { $context->{pipe_rest} = $rest; }
$context->{pipe} = $pipe;
}
if ( not $self->{pbot}->{commands}->get_meta($keyword, 'dont-replace-pronouns')
and not $self->{pbot}->{factoids}->get_meta($stuff->{from}, $keyword, 'dont-replace-pronouns'))
and not $self->{pbot}->{factoids}->get_meta($context->{from}, $keyword, 'dont-replace-pronouns'))
{
$stuff->{nickoverride} = $stuff->{nick} if defined $stuff->{nickoverride} and lc $stuff->{nickoverride} eq 'me';
$context->{nickoverride} = $context->{nick} if defined $context->{nickoverride} and lc $context->{nickoverride} eq 'me';
$keyword =~ s/(\w+)([?!.]+)$/$1/;
$arguments =~ s/(?<![\w\/\-\\])i am\b/$stuff->{nick} is/gi if defined $arguments && $stuff->{interpret_depth} <= 2;
$arguments =~ s/(?<![\w\/\-\\])me\b/$stuff->{nick}/gi if defined $arguments && $stuff->{interpret_depth} <= 2;
$arguments =~ s/(?<![\w\/\-\\])my\b/$stuff->{nick}'s/gi if defined $arguments && $stuff->{interpret_depth} <= 2;
$arguments =~ s/\\my\b/my/gi if defined $arguments && $stuff->{interpret_depth} <= 2;
$arguments =~ s/\\me\b/me/gi if defined $arguments && $stuff->{interpret_depth} <= 2;
$arguments =~ s/\\i am\b/i am/gi if defined $arguments && $stuff->{interpret_depth} <= 2;
$arguments =~ s/(?<![\w\/\-\\])i am\b/$context->{nick} is/gi if defined $arguments && $context->{interpret_depth} <= 2;
$arguments =~ s/(?<![\w\/\-\\])me\b/$context->{nick}/gi if defined $arguments && $context->{interpret_depth} <= 2;
$arguments =~ s/(?<![\w\/\-\\])my\b/$context->{nick}'s/gi if defined $arguments && $context->{interpret_depth} <= 2;
$arguments =~ s/\\my\b/my/gi if defined $arguments && $context->{interpret_depth} <= 2;
$arguments =~ s/\\me\b/me/gi if defined $arguments && $context->{interpret_depth} <= 2;
$arguments =~ s/\\i am\b/i am/gi if defined $arguments && $context->{interpret_depth} <= 2;
}
if (not $self->{pbot}->{commands}->get_meta($keyword, 'dont-protect-self') and not $self->{pbot}->{factoids}->get_meta($stuff->{from}, $keyword, 'dont-protect-self')) {
if (not $self->{pbot}->{commands}->get_meta($keyword, 'dont-protect-self') and not $self->{pbot}->{factoids}->get_meta($context->{from}, $keyword, 'dont-protect-self')) {
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
if (defined $arguments && ($arguments =~ m/^(your|him|her|its|it|them|their)(self|selves)$/i || $arguments =~ m/^$botnick$/i)) {
my $delay = rand(10) + 5;
my $message = {
nick => $stuff->{nick}, user => $stuff->{user}, host => $stuff->{host}, command => $stuff->{command}, checkflood => 1,
message => "$stuff->{nick}: Why would I want to do that to myself?"
nick => $context->{nick}, user => $context->{user}, host => $context->{host}, command => $context->{command}, checkflood => 1,
message => "$context->{nick}: Why would I want to do that to myself?"
};
$self->add_message_to_output_queue($stuff->{from}, $message, $delay);
$self->add_message_to_output_queue($context->{from}, $message, $delay);
$delay = duration($delay);
$self->{pbot}->{logger}->log("($delay delay) $message->{message}\n");
return undef;
@ -286,10 +286,10 @@ sub interpret {
return undef;
}
if (not exists $stuff->{root_keyword}) { $stuff->{root_keyword} = $keyword; }
if (not exists $context->{root_keyword}) { $context->{root_keyword} = $keyword; }
$stuff->{keyword} = $keyword;
$stuff->{original_arguments} = $arguments;
$context->{keyword} = $keyword;
$context->{original_arguments} = $arguments;
# unescape any escaped command splits
$arguments =~ s/\\;;;/;;;/g if defined $arguments;
@ -303,21 +303,21 @@ sub interpret {
$arguments = validate_string($arguments);
# set arguments as a plain string
$stuff->{arguments} = $arguments;
delete $stuff->{args_utf8};
$context->{arguments} = $arguments;
delete $context->{args_utf8};
# set arguments as an array
$stuff->{arglist} = $self->make_args($arguments);
$context->{arglist} = $self->make_args($arguments);
# execute all registered interpreters
my $result;
foreach my $func (@{$self->{handlers}}) {
$result = &{$func->{subref}}($stuff);
$result = &{$func->{subref}}($context);
last if defined $result;
# reset any manipulated arguments
$stuff->{arguments} = $stuff->{original_arguments};
delete $stuff->{args_utf8};
$context->{arguments} = $context->{original_arguments};
delete $context->{args_utf8};
}
return $result;
}
@ -731,86 +731,86 @@ sub truncate_result {
}
sub handle_result {
my ($self, $stuff, $result) = @_;
$result = $stuff->{result} if not defined $result;
$stuff->{preserve_whitespace} = 0 if not defined $stuff->{preserve_whitespace};
my ($self, $context, $result) = @_;
$result = $context->{result} if not defined $result;
$context->{preserve_whitespace} = 0 if not defined $context->{preserve_whitespace};
if ($self->{pbot}->{registry}->get_value('general', 'debugcontext') and length $stuff->{result}) {
if ($self->{pbot}->{registry}->get_value('general', 'debugcontext') and length $context->{result}) {
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$self->{pbot}->{logger}->log("Interpreter::handle_result [$result]\n");
$self->{pbot}->{logger}->log(Dumper $stuff);
$self->{pbot}->{logger}->log(Dumper $context);
}
return 0 if not defined $result or length $result == 0;
if ($result =~ s#^(/say|/me) ##) { $stuff->{prepend} = $1; }
elsif ($result =~ s#^(/msg \S+) ##) { $stuff->{prepend} = $1; }
if ($result =~ s#^(/say|/me) ##) { $context->{prepend} = $1; }
elsif ($result =~ s#^(/msg \S+) ##) { $context->{prepend} = $1; }
if ($stuff->{pipe}) {
my ($pipe, $pipe_rest) = (delete $stuff->{pipe}, delete $stuff->{pipe_rest});
if (not $stuff->{alldone}) {
$stuff->{command} = "$pipe $result $pipe_rest";
$result = $self->interpret($stuff);
$stuff->{result} = $result;
if ($context->{pipe}) {
my ($pipe, $pipe_rest) = (delete $context->{pipe}, delete $context->{pipe_rest});
if (not $context->{alldone}) {
$context->{command} = "$pipe $result $pipe_rest";
$result = $self->interpret($context);
$context->{result} = $result;
}
$self->handle_result($stuff, $result);
$self->handle_result($context, $result);
return 0;
}
if (exists $stuff->{subcmd}) {
my $command = pop @{$stuff->{subcmd}};
if (exists $context->{subcmd}) {
my $command = pop @{$context->{subcmd}};
if (@{$stuff->{subcmd}} == 0 or $stuff->{alldone}) { delete $stuff->{subcmd}; }
if (@{$context->{subcmd}} == 0 or $context->{alldone}) { delete $context->{subcmd}; }
$command =~ s/&\{subcmd\}/$result/;
if (not $stuff->{alldone}) {
$stuff->{command} = $command;
$result = $self->interpret($stuff);
$stuff->{result} = $result;
if (not $context->{alldone}) {
$context->{command} = $command;
$result = $self->interpret($context);
$context->{result} = $result;
}
$self->handle_result($stuff);
$self->handle_result($context);
return 0;
}
if ($stuff->{prepend}) { $result = "$stuff->{prepend} $result"; }
if ($context->{prepend}) { $result = "$context->{prepend} $result"; }
if ($stuff->{command_split}) {
if ($context->{command_split}) {
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
$stuff->{command} = delete $stuff->{command_split};
$context->{command} = delete $context->{command_split};
$result =~ s#^/say #\n#i;
$result =~ s#^/me #\n* $botnick #i;
if (not length $stuff->{split_result}) {
if (not length $context->{split_result}) {
$result =~ s/^\n//;
$stuff->{split_result} = $result;
$context->{split_result} = $result;
} else {
$stuff->{split_result} .= $result;
$context->{split_result} .= $result;
}
$result = $self->interpret($stuff);
$self->handle_result($stuff, $result);
$result = $self->interpret($context);
$self->handle_result($context, $result);
return 0;
}
if ($stuff->{split_result}) {
if ($context->{split_result}) {
my $botnick = $self->{pbot}->{registry}->get_value('irc', 'botnick');
$result =~ s#^/say #\n#i;
$result =~ s#^/me #\n* $botnick #i;
$result = $stuff->{split_result} . $result;
$result = $context->{split_result} . $result;
}
my $original_result = $result;
my $use_output_queue = 0;
if (defined $stuff->{command}) {
my $cmdlist = $self->make_args($stuff->{command});
if (defined $context->{command}) {
my $cmdlist = $self->make_args($context->{command});
my ($cmd, $args) = $self->split_args($cmdlist, 2, 0, 1);
if (not $self->{pbot}->{commands}->exists($cmd)) {
my ($chan, $trigger) = $self->{pbot}->{factoids}->find_factoid($stuff->{from}, $cmd, arguments => $args, exact_channel => 1, exact_trigger => 0, find_alias => 1);
my ($chan, $trigger) = $self->{pbot}->{factoids}->find_factoid($context->{from}, $cmd, arguments => $args, exact_channel => 1, exact_trigger => 0, find_alias => 1);
if (defined $trigger) {
if ($stuff->{preserve_whitespace} == 0) {
$stuff->{preserve_whitespace} = $self->{pbot}->{factoids}->{factoids}->get_data($chan, $trigger, 'preserve_whitespace') // 0;
if ($context->{preserve_whitespace} == 0) {
$context->{preserve_whitespace} = $self->{pbot}->{factoids}->{factoids}->get_data($chan, $trigger, 'preserve_whitespace') // 0;
}
$use_output_queue = $self->{pbot}->{factoids}->{factoids}->get_data($chan, $trigger, 'use_output_queue');
@ -819,12 +819,12 @@ sub handle_result {
}
}
my $preserve_newlines = $self->{pbot}->{registry}->get_value($stuff->{from}, 'preserve_newlines');
my $preserve_newlines = $self->{pbot}->{registry}->get_value($context->{from}, 'preserve_newlines');
$result =~ s/[\n\r]/ /g unless $preserve_newlines;
$result =~ s/[ \t]+/ /g unless $stuff->{preserve_whitespace};
$result =~ s/[ \t]+/ /g unless $context->{preserve_whitespace};
my $max_lines = $self->{pbot}->{registry}->get_value($stuff->{from}, 'max_newlines');
my $max_lines = $self->{pbot}->{registry}->get_value($context->{from}, 'max_newlines');
$max_lines = 4 if not defined $max_lines;
my $lines = 0;
@ -836,35 +836,35 @@ sub handle_result {
next if not length $stripped_line;
if (++$lines >= $max_lines) {
my $link = $self->{pbot}->{webpaste}->paste("[" . (defined $stuff->{from} ? $stuff->{from} : "stdin") . "] <$stuff->{nick}> $stuff->{text}\n\n$original_result");
my $link = $self->{pbot}->{webpaste}->paste("[" . (defined $context->{from} ? $context->{from} : "stdin") . "] <$context->{nick}> $context->{text}\n\n$original_result");
if ($use_output_queue) {
my $message = {
nick => $stuff->{nick}, user => $stuff->{user}, host => $stuff->{host}, command => $stuff->{command},
nick => $context->{nick}, user => $context->{user}, host => $context->{host}, command => $context->{command},
message => "And that's all I have to say about that. See $link for full text.",
checkflood => 1
};
$self->add_message_to_output_queue($stuff->{from}, $message, 0);
$self->add_message_to_output_queue($context->{from}, $message, 0);
} else {
$self->{pbot}->{conn}->privmsg($stuff->{from}, "And that's all I have to say about that. See $link for full text.") unless $stuff->{from} eq 'stdin@pbot';
$self->{pbot}->{conn}->privmsg($context->{from}, "And that's all I have to say about that. See $link for full text.") unless $context->{from} eq 'stdin@pbot';
}
last;
}
if ($preserve_newlines) { $line = $self->truncate_result($stuff->{from}, $stuff->{nick}, $stuff->{text}, $line, $line, 1); }
else { $line = $self->truncate_result($stuff->{from}, $stuff->{nick}, $stuff->{text}, $original_result, $line, 1); }
if ($preserve_newlines) { $line = $self->truncate_result($context->{from}, $context->{nick}, $context->{text}, $line, $line, 1); }
else { $line = $self->truncate_result($context->{from}, $context->{nick}, $context->{text}, $original_result, $line, 1); }
if ($use_output_queue) {
my $delay = rand(10) + 5;
my $message = {
nick => $stuff->{nick}, user => $stuff->{user}, host => $stuff->{host}, command => $stuff->{command},
nick => $context->{nick}, user => $context->{user}, host => $context->{host}, command => $context->{command},
message => $line, checkflood => 1
};
$self->add_message_to_output_queue($stuff->{from}, $message, $delay);
$self->add_message_to_output_queue($context->{from}, $message, $delay);
$delay = duration($delay);
$self->{pbot}->{logger}->log("($delay delay) $line\n");
} else {
$stuff->{line} = $line;
$self->output_result($stuff);
$context->{line} = $line;
$self->output_result($context);
$self->{pbot}->{logger}->log("$line\n");
}
}
@ -895,49 +895,49 @@ sub dehighlight_nicks {
}
sub output_result {
my ($self, $stuff) = @_;
my ($self, $context) = @_;
my ($pbot, $botnick) = ($self->{pbot}, $self->{pbot}->{registry}->get_value('irc', 'botnick'));
if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) {
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$self->{pbot}->{logger}->log("Interpreter::output_result\n");
$self->{pbot}->{logger}->log(Dumper $stuff);
$self->{pbot}->{logger}->log(Dumper $context);
}
my $line = $stuff->{line};
my $line = $context->{line};
return if not defined $line or not length $line;
return 0 if $stuff->{from} eq 'stdin@pbot';
return 0 if $context->{from} eq 'stdin@pbot';
$line = $self->dehighlight_nicks($line, $stuff->{from}) if $stuff->{from} =~ /^#/ and $line !~ /^\/msg\s+/i;
$line = $self->dehighlight_nicks($line, $context->{from}) if $context->{from} =~ /^#/ and $line !~ /^\/msg\s+/i;
if ($line =~ s/^\/say\s+//i) {
if (defined $stuff->{nickoverride} and ($stuff->{no_nickoverride} == 0 or $stuff->{force_nickoverride} == 1)) { $line = "$stuff->{nickoverride}: $line"; }
$pbot->{conn}->privmsg($stuff->{from}, $line) if defined $stuff->{from} && $stuff->{from} ne $botnick;
$pbot->{antiflood}->check_flood($stuff->{from}, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'pbot', $line, 0, 0, 0) if $stuff->{checkflood};
if (defined $context->{nickoverride} and ($context->{no_nickoverride} == 0 or $context->{force_nickoverride} == 1)) { $line = "$context->{nickoverride}: $line"; }
$pbot->{conn}->privmsg($context->{from}, $line) if defined $context->{from} && $context->{from} ne $botnick;
$pbot->{antiflood}->check_flood($context->{from}, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'pbot', $line, 0, 0, 0) if $context->{checkflood};
} elsif ($line =~ s/^\/me\s+//i) {
$pbot->{conn}->me($stuff->{from}, $line) if defined $stuff->{from} && $stuff->{from} ne $botnick;
$pbot->{antiflood}->check_flood($stuff->{from}, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'pbot', '/me ' . $line, 0, 0, 0) if $stuff->{checkflood};
$pbot->{conn}->me($context->{from}, $line) if defined $context->{from} && $context->{from} ne $botnick;
$pbot->{antiflood}->check_flood($context->{from}, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'pbot', '/me ' . $line, 0, 0, 0) if $context->{checkflood};
} elsif ($line =~ s/^\/msg\s+([^\s]+)\s+//i) {
my $to = $1;
if ($to =~ /,/) {
$pbot->{logger}->log("[HACK] Possible HACK ATTEMPT /msg multiple users: [$stuff->{nick}!$stuff->{user}\@$stuff->{host}] [$stuff->{command}] [$line]\n");
$pbot->{logger}->log("[HACK] Possible HACK ATTEMPT /msg multiple users: [$context->{nick}!$context->{user}\@$context->{host}] [$context->{command}] [$line]\n");
} elsif ($to =~ /.*serv(?:@.*)?$/i) {
$pbot->{logger}->log("[HACK] Possible HACK ATTEMPT /msg *serv: [$stuff->{nick}!$stuff->{user}\@$stuff->{host}] [$stuff->{command}] [$line]\n");
$pbot->{logger}->log("[HACK] Possible HACK ATTEMPT /msg *serv: [$context->{nick}!$context->{user}\@$context->{host}] [$context->{command}] [$line]\n");
} elsif ($line =~ s/^\/me\s+//i) {
$pbot->{conn}->me($to, $line) if $to ne $botnick;
$pbot->{antiflood}->check_flood($to, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'pbot', '/me ' . $line, 0, 0, 0) if $stuff->{checkflood};
$pbot->{antiflood}->check_flood($to, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'pbot', '/me ' . $line, 0, 0, 0) if $context->{checkflood};
} else {
$line =~ s/^\/say\s+//i;
if (defined $stuff->{nickoverride} and ($stuff->{no_nickoverride} == 0 or $stuff->{force_nickoverride} == 1)) { $line = "$stuff->{nickoverride}: $line"; }
if (defined $context->{nickoverride} and ($context->{no_nickoverride} == 0 or $context->{force_nickoverride} == 1)) { $line = "$context->{nickoverride}: $line"; }
$pbot->{conn}->privmsg($to, $line) if $to ne $botnick;
$pbot->{antiflood}->check_flood($to, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'pbot', $line, 0, 0, 0) if $stuff->{checkflood};
$pbot->{antiflood}->check_flood($to, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'pbot', $line, 0, 0, 0) if $context->{checkflood};
}
} else {
if (defined $stuff->{nickoverride} and ($stuff->{no_nickoverride} == 0 or $stuff->{force_nickoverride} == 1)) { $line = "$stuff->{nickoverride}: $line"; }
$pbot->{conn}->privmsg($stuff->{from}, $line) if defined $stuff->{from} && $stuff->{from} ne $botnick;
$pbot->{antiflood}->check_flood($stuff->{from}, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'pbot', $line, 0, 0, 0) if $stuff->{checkflood};
if (defined $context->{nickoverride} and ($context->{no_nickoverride} == 0 or $context->{force_nickoverride} == 1)) { $line = "$context->{nickoverride}: $line"; }
$pbot->{conn}->privmsg($context->{from}, $line) if defined $context->{from} && $context->{from} ne $botnick;
$pbot->{antiflood}->check_flood($context->{from}, $botnick, $pbot->{registry}->get_value('irc', 'username'), 'pbot', $line, 0, 0, 0) if $context->{checkflood};
}
}
@ -946,7 +946,7 @@ sub add_message_to_output_queue {
$self->{pbot}->{timer}->enqueue_event(
sub {
my $stuff = {
my $context = {
from => $channel,
nick => $message->{nick},
user => $message->{user},
@ -956,7 +956,7 @@ sub add_message_to_output_queue {
checkflood => $message->{checkflood}
};
$self->output_result($stuff);
$self->output_result($context);
},
$delay, "output $channel $message->{message}"
);
@ -967,7 +967,7 @@ sub add_to_command_queue {
$self->{pbot}->{timer}->enqueue_event(
sub {
my $stuff = {
my $context = {
from => $channel,
nick => $command->{nick},
user => $command->{user},
@ -980,12 +980,12 @@ sub add_to_command_queue {
if (exists $command->{'cap-override'}) {
$self->{pbot}->{logger}->log("[command queue] Override command capability with $command->{'cap-override'}\n");
$stuff->{'cap-override'} = $command->{'cap-override'};
$context->{'cap-override'} = $command->{'cap-override'};
}
my $result = $self->interpret($stuff);
$stuff->{result} = $result;
$self->handle_result($stuff, $result);
my $result = $self->interpret($context);
$context->{result} = $result;
$self->handle_result($context, $result);
},
$delay, "command $channel $command->{command}", $repeating
);

View File

@ -22,9 +22,9 @@ sub initialize {
}
sub load_cmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $factoids = $self->{pbot}->{factoids}->{factoids};
my ($keyword, $module) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($keyword, $module) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
return "Usage: load <keyword> <module>" if not defined $module;
if ($factoids->exists('.*', $keyword)) { return 'There is already a keyword named ' . $factoids->get_data('.*', $keyword, '_name') . '.'; }
@ -37,8 +37,8 @@ sub load_cmd {
}
sub unload_cmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my $module = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $module = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
return "Usage: unload <keyword>" if not defined $module;
my $factoids = $self->{pbot}->{factoids}->{factoids};
return "/say $module not found." if not $factoids->exists('.*', $module);
@ -52,39 +52,39 @@ sub unload_cmd {
}
sub execute_module {
my ($self, $stuff) = @_;
my ($self, $context) = @_;
my $text;
if ($self->{pbot}->{registry}->get_value('general', 'debugcontext')) {
use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$self->{pbot}->{logger}->log("execute_module\n");
$self->{pbot}->{logger}->log(Dumper $stuff);
$self->{pbot}->{logger}->log(Dumper $context);
}
$self->{pbot}->{process_manager}->execute_process($stuff, sub { $self->launch_module(@_) });
$self->{pbot}->{process_manager}->execute_process($context, sub { $self->launch_module(@_) });
}
sub launch_module {
my ($self, $stuff) = @_;
$stuff->{arguments} = "" if not defined $stuff->{arguments};
my @factoids = $self->{pbot}->{factoids}->find_factoid($stuff->{from}, $stuff->{keyword}, exact_channel => 2, exact_trigger => 2);
my ($self, $context) = @_;
$context->{arguments} = "" if not defined $context->{arguments};
my @factoids = $self->{pbot}->{factoids}->find_factoid($context->{from}, $context->{keyword}, exact_channel => 2, exact_trigger => 2);
if (not @factoids or not $factoids[0]) {
$stuff->{checkflood} = 1;
$self->{pbot}->{interpreter}->handle_result($stuff, "/msg $stuff->{nick} Failed to find module for '$stuff->{keyword}' in channel $stuff->{from}\n");
$context->{checkflood} = 1;
$self->{pbot}->{interpreter}->handle_result($context, "/msg $context->{nick} Failed to find module for '$context->{keyword}' in channel $context->{from}\n");
return;
}
my ($channel, $trigger) = ($factoids[0]->[0], $factoids[0]->[1]);
$stuff->{channel} = $channel;
$stuff->{keyword} = $trigger;
$stuff->{trigger} = $trigger;
$context->{channel} = $channel;
$context->{keyword} = $trigger;
$context->{trigger} = $trigger;
my $module = $self->{pbot}->{factoids}->{factoids}->get_data($channel, $trigger, 'action');
$self->{pbot}->{logger}->log("("
. (defined $stuff->{from} ? $stuff->{from} : "(undef)")
. "): $stuff->{nick}!$stuff->{user}\@$stuff->{host}: Executing module [$stuff->{command}] $module $stuff->{arguments}\n");
$stuff->{arguments} = $self->{pbot}->{factoids}->expand_special_vars($stuff->{from}, $stuff->{nick}, $stuff->{root_keyword}, $stuff->{arguments});
. (defined $context->{from} ? $context->{from} : "(undef)")
. "): $context->{nick}!$context->{user}\@$context->{host}: Executing module [$context->{command}] $module $context->{arguments}\n");
$context->{arguments} = $self->{pbot}->{factoids}->expand_special_vars($context->{from}, $context->{nick}, $context->{root_keyword}, $context->{arguments});
my $module_dir = $self->{pbot}->{registry}->get_value('general', 'module_dir');
if (not chdir $module_dir) {
@ -98,8 +98,8 @@ sub launch_module {
# FIXME -- add check to ensure $module exists
my ($exitval, $stdout, $stderr) = eval {
my $args = $stuff->{arguments};
if (not $stuff->{args_utf8}) { $args = encode('UTF-8', $args); }
my $args = $context->{arguments};
if (not $context->{args_utf8}) { $args = encode('UTF-8', $args); }
my @cmdline = ("./$module", $self->{pbot}->{interpreter}->split_line($args));
my $timeout = $self->{pbot}->{registry}->get_value('general', 'module_timeout') // 30;
my ($stdin, $stdout, $stderr);
@ -112,7 +112,7 @@ sub launch_module {
if ($@) {
my $error = $@;
if ($error =~ m/timeout on timer/) { ($exitval, $stdout, $stderr) = (-1, "$stuff->{trigger}: timed-out", ''); }
if ($error =~ m/timeout on timer/) { ($exitval, $stdout, $stderr) = (-1, "$context->{trigger}: timed-out", ''); }
else { ($exitval, $stdout, $stderr) = (-1, '', $error); }
}
@ -125,8 +125,8 @@ sub launch_module {
}
}
$stuff->{result} = $stdout;
chomp $stuff->{result};
$context->{result} = $stdout;
chomp $context->{result};
}
1;

View File

@ -34,7 +34,7 @@ sub initialize {
}
sub ps_cmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $usage = 'Usage: ps [-atu]; -a show all information; -t show running time; -u show user/channel';
my $getopt_error;
@ -83,7 +83,7 @@ sub ps_cmd {
}
sub kill_cmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $usage = 'Usage: kill [-a] [-t <seconds>] [-s <signal>] [pids...]; -a kill all processes; -t <seconds> kill processes running longer than <seconds>; -s send <signal> to processes';
my $getopt_error;
@ -133,10 +133,10 @@ sub kill_cmd {
}
sub add_process {
my ($self, $pid, $stuff) = @_;
$stuff->{process_start} = gettimeofday;
$self->{processes}->{$pid} = $stuff;
$self->{pbot}->{logger}->log("Starting process $pid: $stuff->{commands}->[0]\n");
my ($self, $pid, $context) = @_;
$context->{process_start} = gettimeofday;
$self->{processes}->{$pid} = $context;
$self->{pbot}->{logger}->log("Starting process $pid: $context->{commands}->[0]\n");
}
sub remove_process {
@ -153,30 +153,30 @@ sub remove_process {
}
sub execute_process {
my ($self, $stuff, $subref, $timeout) = @_;
my ($self, $context, $subref, $timeout) = @_;
$timeout //= 30;
if (not exists $stuff->{commands}) { $stuff->{commands} = [$stuff->{command}]; }
if (not exists $context->{commands}) { $context->{commands} = [$context->{command}]; }
# don't fork again if we're already a forked process
if (exists $stuff->{pid}) {
$subref->($stuff);
return $stuff->{result};
if (exists $context->{pid}) {
$subref->($context);
return $context->{result};
}
pipe(my $reader, my $writer);
$stuff->{pid} = fork;
$context->{pid} = fork;
if (not defined $stuff->{pid}) {
if (not defined $context->{pid}) {
$self->{pbot}->{logger}->log("Could not fork process: $!\n");
close $reader;
close $writer;
$stuff->{checkflood} = 1;
$self->{pbot}->{interpreter}->handle_result($stuff, "/me groans loudly.\n");
$context->{checkflood} = 1;
$self->{pbot}->{interpreter}->handle_result($context, "/me groans loudly.\n");
return;
}
if ($stuff->{pid} == 0) {
if ($context->{pid} == 0) {
# child
close $reader;
@ -188,25 +188,25 @@ sub execute_process {
# remove atexit handlers
$self->{pbot}->{atexit}->unregister_all;
# execute the provided subroutine, results are stored in $stuff
# execute the provided subroutine, results are stored in $context
eval {
local $SIG{ALRM} = sub { die "Process `$stuff->{commands}->[0]` timed-out" };
local $SIG{ALRM} = sub { die "Process `$context->{commands}->[0]` timed-out" };
alarm $timeout;
$subref->($stuff);
$subref->($context);
die if $@;
};
alarm 0;
# check for errors
if ($@) {
$stuff->{result} = $@;
$stuff->{'timed-out'} = 1 if $stuff->{result} =~ /^Process .* timed-out at PBot\/ProcessManager/;
$self->{pbot}->{logger}->log("Error executing process: $stuff->{result}\n");
$stuff->{result} =~ s/ at PBot.*$//ms;
$context->{result} = $@;
$context->{'timed-out'} = 1 if $context->{result} =~ /^Process .* timed-out at PBot\/ProcessManager/;
$self->{pbot}->{logger}->log("Error executing process: $context->{result}\n");
$context->{result} =~ s/ at PBot.*$//ms;
}
# print $stuff to pipe
my $json = encode_json $stuff;
# print $context to pipe
my $json = encode_json $context;
print $writer "$json\n";
# end child
@ -214,8 +214,8 @@ sub execute_process {
} else {
# parent
close $writer;
$self->add_process($stuff->{pid}, $stuff);
$self->{pbot}->{select_handler}->add_reader($reader, sub { $self->process_pipe_reader($stuff->{pid}, @_) });
$self->add_process($context->{pid}, $context);
$self->{pbot}->{select_handler}->add_reader($reader, sub { $self->process_pipe_reader($context->{pid}, @_) });
# return empty string since reader will handle the output when child is finished
return "";
}
@ -223,66 +223,66 @@ sub execute_process {
sub process_pipe_reader {
my ($self, $pid, $buf) = @_;
my $stuff = decode_json $buf or do {
my $context = decode_json $buf or do {
$self->{pbot}->{logger}->log("Failed to decode bad json: [$buf]\n");
return;
};
delete $stuff->{pid};
delete $context->{pid};
if (not defined $stuff->{result} or not length $stuff->{result}) {
if (not defined $context->{result} or not length $context->{result}) {
$self->{pbot}->{logger}->log("No result from process.\n");
return;
}
if ($stuff->{referenced}) { return if $stuff->{result} =~ m/(?:no results)/i; }
if ($context->{referenced}) { return if $context->{result} =~ m/(?:no results)/i; }
if (exists $stuff->{special} and $stuff->{special} eq 'code-factoid') {
$stuff->{result} =~ s/\s+$//g;
$self->{pbot}->{logger}->log("No text result from code-factoid.\n") and return if not length $stuff->{result};
$stuff->{original_keyword} = $stuff->{root_keyword};
$stuff->{result} = $self->{pbot}->{factoids}->handle_action($stuff, $stuff->{result});
if (exists $context->{special} and $context->{special} eq 'code-factoid') {
$context->{result} =~ s/\s+$//g;
$self->{pbot}->{logger}->log("No text result from code-factoid.\n") and return if not length $context->{result};
$context->{original_keyword} = $context->{root_keyword};
$context->{result} = $self->{pbot}->{factoids}->handle_action($context, $context->{result});
}
$stuff->{checkflood} = 0;
$context->{checkflood} = 0;
if (defined $stuff->{nickoverride}) { $self->{pbot}->{interpreter}->handle_result($stuff, $stuff->{result}); }
if (defined $context->{nickoverride}) { $self->{pbot}->{interpreter}->handle_result($context, $context->{result}); }
else {
# don't override nick if already set
if ( exists $stuff->{special}
and $stuff->{special} ne 'code-factoid'
and $self->{pbot}->{factoids}->{factoids}->exists($stuff->{channel}, $stuff->{trigger}, 'add_nick')
and $self->{pbot}->{factoids}->{factoids}->get_data($stuff->{channel}, $stuff->{trigger}, 'add_nick') != 0)
if ( exists $context->{special}
and $context->{special} ne 'code-factoid'
and $self->{pbot}->{factoids}->{factoids}->exists($context->{channel}, $context->{trigger}, 'add_nick')
and $self->{pbot}->{factoids}->{factoids}->get_data($context->{channel}, $context->{trigger}, 'add_nick') != 0)
{
$stuff->{nickoverride} = $stuff->{nick};
$stuff->{no_nickoverride} = 0;
$stuff->{force_nickoverride} = 1;
$context->{nickoverride} = $context->{nick};
$context->{no_nickoverride} = 0;
$context->{force_nickoverride} = 1;
} else {
# extract nick-like thing from module result
if ($stuff->{result} =~ s/^(\S+): //) {
if ($context->{result} =~ s/^(\S+): //) {
my $nick = $1;
if (lc $nick eq "usage") {
# put it back on result if it's a usage message
$stuff->{result} = "$nick: $stuff->{result}";
$context->{result} = "$nick: $context->{result}";
} else {
my $present = $self->{pbot}->{nicklist}->is_present($stuff->{channel}, $nick);
my $present = $self->{pbot}->{nicklist}->is_present($context->{channel}, $nick);
if ($present) {
# nick is present in channel
$stuff->{nickoverride} = $present;
$context->{nickoverride} = $present;
} else {
# nick not present, put it back on result
$stuff->{result} = "$nick: $stuff->{result}";
$context->{result} = "$nick: $context->{result}";
}
}
}
}
$self->{pbot}->{interpreter}->handle_result($stuff, $stuff->{result});
$self->{pbot}->{interpreter}->handle_result($context, $context->{result});
}
my $text = $self->{pbot}->{interpreter}
->truncate_result($stuff->{channel}, $self->{pbot}->{registry}->get_value('irc', 'botnick'), 'undef', $stuff->{result}, $stuff->{result}, 0);
->truncate_result($context->{channel}, $self->{pbot}->{registry}->get_value('irc', 'botnick'), 'undef', $context->{result}, $context->{result}, 0);
$self->{pbot}->{antiflood}
->check_flood($stuff->{from}, $self->{pbot}->{registry}->get_value('irc', 'botnick'), $self->{pbot}->{registry}->get_value('irc', 'username'), 'pbot', $text, 0, 0, 0);
->check_flood($context->{from}, $self->{pbot}->{registry}->get_value('irc', 'botnick'), $self->{pbot}->{registry}->get_value('irc', 'username'), 'pbot', $text, 0, 0, 0);
}
1;

View File

@ -101,15 +101,15 @@ sub unset {
}
sub get_value {
my ($self, $section, $item, $as_text, $stuff) = @_;
my ($self, $section, $item, $as_text, $context) = @_;
$section = lc $section;
$item = lc $item;
my $key = $item;
# TODO: use user-metadata for this
if (defined $stuff and exists $stuff->{nick}) {
my $stuff_nick = lc $stuff->{nick};
if ($self->{registry}->exists($section, "$item.nick.$stuff_nick")) { $key = "$item.nick.$stuff_nick"; }
if (defined $context and exists $context->{nick}) {
my $context_nick = lc $context->{nick};
if ($self->{registry}->exists($section, "$item.nick.$context_nick")) { $key = "$item.nick.$context_nick"; }
}
if ($self->{registry}->exists($section, $key)) {
@ -120,15 +120,15 @@ sub get_value {
}
sub get_array_value {
my ($self, $section, $item, $index, $stuff) = @_;
my ($self, $section, $item, $index, $context) = @_;
$section = lc $section;
$item = lc $item;
my $key = $item;
# TODO: use user-metadata for this
if (defined $stuff and exists $stuff->{nick}) {
my $stuff_nick = lc $stuff->{nick};
if ($self->{registry}->exists($section, "$item.nick.$stuff_nick")) { $key = "$item.nick.$stuff_nick"; }
if (defined $context and exists $context->{nick}) {
my $context_nick = lc $context->{nick};
if ($self->{registry}->exists($section, "$item.nick.$context_nick")) { $key = "$item.nick.$context_nick"; }
}
if ($self->{registry}->exists($section, $key)) {

View File

@ -26,17 +26,17 @@ sub initialize {
sub regset {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($from, $nick, $user, $host, $arguments, $context) = @_;
my $usage = "Usage: regset <section>.<item> [value]";
# support "<section>.<key>" syntax in addition to "<section> <key>"
my $section = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist}) // return $usage;
my $section = $self->{pbot}->{interpreter}->shift_arg($context->{arglist}) // return $usage;
my ($item, $value);
if ($section =~ m/^(.+?)\.(.+)$/) {
($section, $item) = ($1, $2);
($value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 1);
($value) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 1);
} else {
($item, $value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
($item, $value) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
}
if (not defined $section or not defined $item) { return $usage; }
@ -50,14 +50,14 @@ sub regset {
sub regunset {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($from, $nick, $user, $host, $arguments, $context) = @_;
my $usage = "Usage: regunset <section>.<item>";
# support "<section>.<key>" syntax in addition to "<section> <key>"
my $section = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist}) // return $usage;
my $section = $self->{pbot}->{interpreter}->shift_arg($context->{arglist}) // return $usage;
my $item;
if ($section =~ m/^(.+?)\.(.+)$/) { ($section, $item) = ($1, $2); }
else { ($item) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 1); }
else { ($item) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 1); }
if (not defined $section or not defined $item) { return $usage; }
@ -72,17 +72,17 @@ sub regunset {
sub regsetmeta {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($from, $nick, $user, $host, $arguments, $context) = @_;
my $usage = "Usage: regsetmeta <section>.<item> [key [value]]";
# support "<section>.<key>" syntax in addition to "<section> <key>"
my $section = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist}) // return $usage;
my $section = $self->{pbot}->{interpreter}->shift_arg($context->{arglist}) // return $usage;
my ($item, $key, $value);
if ($section =~ m/^(.+?)\.(.+)$/) {
($section, $item) = ($1, $2);
($key, $value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
($key, $value) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
} else {
($item, $key, $value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
($item, $key, $value) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3);
}
if (not defined $section or not defined $item) { return $usage; }
@ -94,17 +94,17 @@ sub regsetmeta {
sub regunsetmeta {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($from, $nick, $user, $host, $arguments, $context) = @_;
my $usage = "Usage: regunsetmeta <section>.<item> <key>";
# support "<section>.<key>" syntax in addition to "<section> <key>"
my $section = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist}) // return $usage;
my $section = $self->{pbot}->{interpreter}->shift_arg($context->{arglist}) // return $usage;
my ($item, $key);
if ($section =~ m/^(.+?)\.(.+)$/) {
($section, $item) = ($1, $2);
($key) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 1);
($key) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 1);
} else {
($item, $key) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
($item, $key) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
}
if (not defined $section or not defined $item or not defined $key) { return $usage; }
@ -113,15 +113,15 @@ sub regunsetmeta {
sub regshow {
my $self = shift;
my ($from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($from, $nick, $user, $host, $arguments, $context) = @_;
my $registry = $self->{pbot}->{registry}->{registry};
my $usage = "Usage: regshow <section>.<item>";
# support "<section>.<key>" syntax in addition to "<section> <key>"
my $section = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist}) // return $usage;
my $section = $self->{pbot}->{interpreter}->shift_arg($context->{arglist}) // return $usage;
my $item;
if ($section =~ m/^(.+?)\.(.+)$/) { ($section, $item) = ($1, $2); }
else { ($item) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 1); }
else { ($item) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 1); }
if (not defined $section or not defined $item) { return $usage; }

View File

@ -50,11 +50,11 @@ sub initialize {
}
sub event_queue_cmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $usage = "Usage: eventqueue list [filter regex] | add <relative time> <command> [-repeat] | remove <event>";
my $command = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
my $command = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
if (not defined $command) {
return $usage;
@ -65,7 +65,7 @@ sub event_queue_cmd {
my $result = eval {
my $text = "Queued events:\n";
my ($regex) = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
my ($regex) = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
my $i = 0;
my $events = 0;
@ -99,7 +99,7 @@ sub event_queue_cmd {
}
if ($command eq 'add') {
my ($duration, $command) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($duration, $command) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
return "Usage: eventqueue add <relative time> <command> [-repeat]" if not defined $duration or not defined $command;
my ($delay, $error) = $self->{pbot}->{parsedate}->parsedate($duration);
@ -120,7 +120,7 @@ sub event_queue_cmd {
}
if ($command eq 'remove') {
my ($regex) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 1);
my ($regex) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 1);
return "Usage: eventqueue remove <event>" if not defined $regex;
$regex =~ s/\*/.*?/g;
return $self->dequeue_event($regex);

View File

@ -359,8 +359,8 @@ sub logoutcmd {
}
sub users {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my $channel = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $channel = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
my $include_global = '';
if (not defined $channel) {
@ -405,8 +405,8 @@ sub users {
}
sub useradd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($name, $hostmasks, $channels, $capabilities, $password) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 5);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($name, $hostmasks, $channels, $capabilities, $password) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 5);
$capabilities //= 'none';
if (not defined $name or not defined $hostmasks) { return "Usage: useradd <username> <hostmasks> [channels [capabilities [password]]]"; }
@ -443,7 +443,7 @@ sub useradd {
}
sub userdel {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
if (not length $arguments) { return "Usage: userdel <username>"; }
@ -462,9 +462,9 @@ sub userdel {
}
sub userset {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($name, $key, $value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 3);
my ($name, $key, $value) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 3);
if (not defined $name) { return "Usage: userset <username> [key [value]]"; }
@ -506,9 +506,9 @@ sub userset {
}
sub userunset {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($name, $key) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($name, $key) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
if (not defined $name or not defined $key) { return "Usage: userunset <username> <key>"; }
@ -549,8 +549,8 @@ sub userunset {
}
sub mycmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($key, $value) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 2);
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my ($key, $value) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 2);
if (defined $value) {
$value =~ s/^is\s+//;
@ -616,7 +616,7 @@ sub mycmd {
}
sub idcmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $target = length $arguments ? $arguments : $nick;

View File

@ -32,7 +32,7 @@ sub initialize {
sub version { return BUILD_NAME . " version " . BUILD_REVISION . " " . BUILD_DATE; }
sub version_cmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $ratelimit = $self->{pbot}->{registry}->get_value('version', 'check_limit') // 300;

View File

@ -322,14 +322,14 @@ sub check_trigger {
}
sub actiontrigger {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
return "Internal error." if not $self->{dbh};
my $command = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
my $command = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
my $result;
given ($command) {
when ('list') {
my $channel = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
my $channel = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
if (not defined $channel) {
if ($from !~ /^#/) { $channel = 'global'; }
else { $channel = $from; }
@ -359,7 +359,7 @@ sub actiontrigger {
my $channel;
if ($from =~ m/^#/) { $channel = $from; }
else {
$channel = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
$channel = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
if (not defined $channel) {
return
@ -369,7 +369,7 @@ sub actiontrigger {
}
}
my ($cap_override, $repeatdelay, $trigger, $action) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 4, 0, 1);
my ($cap_override, $repeatdelay, $trigger, $action) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 4, 0, 1);
if (not defined $trigger or not defined $action) {
if ($from !~ m/^#/) {
@ -401,13 +401,13 @@ sub actiontrigger {
my $channel;
if ($from =~ m/^#/) { $channel = $from; }
else {
$channel = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
$channel = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
if ($channel !~ m/^#/ and $channel ne 'global') {
return "To use this command from private message the <channel> argument is required. Usage: actiontrigger delete <#channel or global> <regex trigger>";
}
}
my ($trigger) = $self->{pbot}->{interpreter}->split_args($stuff->{arglist}, 1);
my ($trigger) = $self->{pbot}->{interpreter}->split_args($context->{arglist}, 1);
if (not defined $trigger) {
if ($from !~ m/^#/) {

View File

@ -27,7 +27,7 @@ sub unload {
}
sub datecmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $usage = "date [-u <user account>] [timezone]";
my $getopt_error;
local $SIG{__WARN__} = sub {
@ -66,13 +66,13 @@ sub datecmd {
if (defined $user_override and not length $tz_override) { return "No timezone set or user account does not exist."; }
my $newstuff = {
my $newcontext = {
from => $from, nick => $nick, user => $user, host => $host,
command => "date_module $timezone", root_channel => $from, root_keyword => "date_module",
keyword => "date_module", arguments => "$timezone"
};
$self->{pbot}->{modules}->execute_module($newstuff);
$self->{pbot}->{modules}->execute_module($newcontext);
}
1;

View File

@ -40,6 +40,9 @@ sub func_sed {
if ($text =~ /^s(.)(.*?)(?<!\\)\1(.*?)(?<!\\)\1(\S*)\s+(.*)/p) {
my ($a, $r, $g, $m, $t) = ($5, "'\"$3\"'", index($4, "g") != -1, $4, $2);
print "a: $a, r: $r, g: $g, m: $m, t: $t\n";
print "text: [$text]\n";
if ($m =~ /P/) {
$r =~ s/^'"(.*)"'$/$1/;
$m =~ s/P//g;

View File

@ -31,7 +31,7 @@ sub unload {
}
sub googlesearch {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
return "Usage: google [number of results] query\n" if not length $arguments;
my $matches = 1;

View File

@ -47,8 +47,8 @@ sub unload {
}
sub help {
my ($self, $stuff) = @_;
my $command = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist}) // 'help';
my ($self, $context) = @_;
my $command = $self->{pbot}->{interpreter}->shift_arg($context->{arglist}) // 'help';
if (exists $self->{commands}->{$command}) {
return $self->{commands}->{$command}->{help};
@ -58,16 +58,16 @@ sub help {
}
sub list {
my ($self, $stuff) = @_;
my ($self, $context) = @_;
return "Available mod commands: " . join ', ', sort keys %{$self->{commands}};
}
sub generic_command {
my ($self, $stuff, $command) = @_;
my ($self, $context, $command) = @_;
my $channel = $stuff->{from};
my $channel = $context->{from};
if ($channel !~ m/^#/) {
$channel = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
$channel = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
if (not defined $channel or $channel !~ /^#/) { return "Must specify channel from private message. Usage: mod $command <channel> <nick>"; }
}
@ -76,15 +76,15 @@ sub generic_command {
return "Voiced moderation is not enabled for this channel. Use `regset $channel.restrictedmod 1` to enable."
if not $self->{pbot}->{registry}->get_value($channel, 'restrictedmod');
my $hostmask = "$stuff->{nick}!$stuff->{user}\@$stuff->{host}";
my $hostmask = "$context->{nick}!$context->{user}\@$context->{host}";
my $user = $self->{pbot}->{users}->loggedin($channel, $hostmask) // {admin => 0, chanmod => 0};
my $voiced = $self->{pbot}->{nicklist}->get_meta($channel, $stuff->{nick}, '+v');
my $voiced = $self->{pbot}->{nicklist}->get_meta($channel, $context->{nick}, '+v');
if (not $voiced and not $self->{pbot}->{capabilities}->userhas($user, 'admin') and not $self->{pbot}->{capabilities}->userhas($user, 'chanmod')) {
return "You must be voiced (usermode +v) or have the admin or chanmod capability to use this command.";
}
my $target = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist});
my $target = $self->{pbot}->{interpreter}->shift_arg($context->{arglist});
return "Missing target. Usage: mod $command <nick>" if not defined $target;
if ($command eq 'unban') {
@ -106,7 +106,7 @@ sub generic_command {
}
my $target_nicklist;
if (not $self->{pbot}->{nicklist}->is_present($channel, $target)) { return "$stuff->{nick}: I do not see anybody named $target in this channel."; }
if (not $self->{pbot}->{nicklist}->is_present($channel, $target)) { return "$context->{nick}: I do not see anybody named $target in this channel."; }
else { $target_nicklist = $self->{pbot}->{nicklist}->{nicklist}->{lc $channel}->{lc $target}; }
my $target_user = $self->{pbot}->{users}->loggedin($channel, $target_nicklist->{hostmask});
@ -128,7 +128,7 @@ sub generic_command {
'b',
$target,
3600 * 24,
"$stuff->{nick}!$stuff->{user}\@$stuff->{host}",
"$context->{nick}!$context->{user}\@$context->{host}",
"doing something naughty (moderator ban)",
1
);
@ -138,7 +138,7 @@ sub generic_command {
'q',
$target,
3600 * 24,
"$stuff->{nick}!$stuff->{user}\@$stuff->{host}",
"$context->{nick}!$context->{user}\@$context->{host}",
"doing something naughty (moderator mute)",
1
);
@ -147,45 +147,45 @@ sub generic_command {
}
sub kick {
my ($self, $stuff) = @_;
return $self->generic_command($stuff, 'kick');
my ($self, $context) = @_;
return $self->generic_command($context, 'kick');
}
sub ban {
my ($self, $stuff) = @_;
return $self->generic_command($stuff, 'ban');
my ($self, $context) = @_;
return $self->generic_command($context, 'ban');
}
sub mute {
my ($self, $stuff) = @_;
return $self->generic_command($stuff, 'mute');
my ($self, $context) = @_;
return $self->generic_command($context, 'mute');
}
sub unban {
my ($self, $stuff) = @_;
return $self->generic_command($stuff, 'unban');
my ($self, $context) = @_;
return $self->generic_command($context, 'unban');
}
sub unmute {
my ($self, $stuff) = @_;
return $self->generic_command($stuff, 'unmute');
my ($self, $context) = @_;
return $self->generic_command($context, 'unmute');
}
sub kb {
my ($self, $stuff) = @_;
my $result = $self->ban(dclone $stuff); # note: using copy of $stuff to preserve $stuff->{arglist} for $self->kick($stuff)
my ($self, $context) = @_;
my $result = $self->ban(dclone $context); # note: using copy of $context to preserve $context->{arglist} for $self->kick($context)
return $result if length $result;
return $self->kick($stuff);
return $self->kick($context);
}
sub modcmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $command = $self->{pbot}->{interpreter}->shift_arg($stuff->{arglist}) // '';
my $command = $self->{pbot}->{interpreter}->shift_arg($context->{arglist}) // '';
$command = lc $command;
if (grep { $_ eq $command } keys %{$self->{commands}}) {
return $self->{commands}->{$command}->{subref}->($stuff);
return $self->{commands}->{$command}->{subref}->($context);
} else {
my $commands = join ', ', sort keys %{$self->{commands}};
if ($from !~ m/^#/) { return "Usage: mod <channel> <command> [arguments]; commands are: $commands; see `mod help <command>` for more information."; }

View File

@ -64,13 +64,13 @@ sub show_url_titles {
next;
}
my $stuff = {
my $context = {
from => $channel, nick => $nick, user => $user, host => $host,
command => "title $nick $url", root_channel => $channel, root_keyword => "title",
keyword => "title", arguments => "$nick $url"
};
$self->{pbot}->{modules}->execute_module($stuff);
$self->{pbot}->{modules}->execute_module($context);
}
}
return 0;

View File

@ -29,7 +29,7 @@ sub unload {
}
sub weathercmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my $usage = "Usage: weather [-u <user account>] [location]";
my $getopt_error;
local $SIG{__WARN__} = sub {

View File

@ -35,7 +35,7 @@ sub unload {
}
sub wttrcmd {
my ($self, $from, $nick, $user, $host, $arguments, $stuff) = @_;
my ($self, $from, $nick, $user, $host, $arguments, $context) = @_;
my @wttr_options = (
"conditions",