mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-07 16:25:41 -04:00
Add the new factoid plugins
This commit is contained in:
parent
ef2f7491fd
commit
c756fea56d
6 changed files with 231 additions and 186 deletions
|
@ -1,34 +1,56 @@
|
||||||
server "*" {
|
server "*" {
|
||||||
channel "*" {
|
channel "*" {
|
||||||
plugin "*" { addressed: true }
|
plugin "*" { addressed: true }
|
||||||
plugin "join" { access: op; addressed: true }
|
plugin "join" { access: op; addressed: true }
|
||||||
plugin "part" { access: op }
|
plugin "part" { access: op }
|
||||||
plugin "reload_plugins" { access: root }
|
plugin "reload_plugins" { access: root }
|
||||||
plugin "restart" { access: root }
|
plugin "restart" { access: root }
|
||||||
plugin "conf_dump" { access: root; }
|
plugin "conf_dump" { access: root; }
|
||||||
plugin "save_config" { access: root; }
|
plugin "save_config" { access: root; }
|
||||||
plugin "conf" { access: root; }
|
plugin "conf" { access: root; }
|
||||||
plugin "karma_modify" { addressed: false; }
|
plugin "karma_modify" { addressed: false; }
|
||||||
plugin "seen" {addressed: false; }
|
plugin "seen" {addressed: false; }
|
||||||
}
|
}
|
||||||
channel "#perl" {
|
channel "#perl" {
|
||||||
plugin "eval" {addressed: false; }
|
plugin "eval" {addressed: false; }
|
||||||
plugin "deparse" {addressed: false; }
|
plugin "deparse" {addressed: false; }
|
||||||
}
|
}
|
||||||
channel "#perl-cats" {
|
channel "#perl-cats" {
|
||||||
plugin "eval" {addressed: false; }
|
plugin "eval" {addressed: false; }
|
||||||
plugin "deparse" {addressed: false; }
|
plugin "deparse" {addressed: false; }
|
||||||
}
|
}
|
||||||
channel "#perlbot" {
|
channel "#perlbot" {
|
||||||
plugin "eval" {addressed: false; }
|
plugin "eval" {addressed: false; }
|
||||||
plugin "deparse" {addressed: false; }
|
plugin "deparse" {addressed: false; }
|
||||||
plugin "badfacts" {addressed: false; }
|
plugin "badfacts" {addressed: false; }
|
||||||
}
|
}
|
||||||
channel "#buubot" {
|
channel "#buubot" {
|
||||||
plugin "eval" {addressed: false; }
|
plugin "eval" {addressed: false; }
|
||||||
plugin "deparse" {addressed: false; }
|
plugin "deparse" {addressed: false; }
|
||||||
}
|
}
|
||||||
channel "#regex" {
|
channel "#regex" {
|
||||||
plugin "badfacts" {addressed: false; }
|
plugin "badfacts" {addressed: false; }
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
server "*.freenode.net" {
|
||||||
|
channel "#perlbot" {
|
||||||
|
plugin "nfacts" {
|
||||||
|
addressed: false;
|
||||||
|
enabled: true;
|
||||||
|
prefix: "!";
|
||||||
|
plugins: false;
|
||||||
|
chanspace: "#perlbot";
|
||||||
|
serverspace: "freenode.net";
|
||||||
|
filtersep: false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
channel "#regex" {
|
||||||
|
plugin "nfacts" {
|
||||||
|
addressed: false;
|
||||||
|
enabled: true;
|
||||||
|
prefix: "!";
|
||||||
|
plugins: false;
|
||||||
|
filtersep: true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
BIN
plugins/.badfactstemp.pm.swp
Normal file
BIN
plugins/.badfactstemp.pm.swp
Normal file
Binary file not shown.
|
@ -1,65 +0,0 @@
|
||||||
package Bot::BB3::Plugin::Badfacts;
|
|
||||||
use strict;
|
|
||||||
no warnings 'void';
|
|
||||||
|
|
||||||
use Data::Dumper;
|
|
||||||
|
|
||||||
sub new {
|
|
||||||
my( $class ) = @_;
|
|
||||||
my $self = bless {}, $class;
|
|
||||||
$self->{name} = 'badfacts';
|
|
||||||
$self->{opts} = {
|
|
||||||
handler => 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
return $self;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub handle {
|
|
||||||
my ($self, $said, $pm) = @_;
|
|
||||||
|
|
||||||
if ($said->{body} =~ /^!(?<fact>[^@].*?)(?:\s@\s*(?<user>\S*))?$/ ||
|
|
||||||
$said->{body} =~ /^!@(?<user>\S+)\s+(?<fact>.+)$/) {
|
|
||||||
my $fact = $+{fact};
|
|
||||||
my $user = $+{user};
|
|
||||||
|
|
||||||
# TODO HACK XXX bad hack to prevent noise until better way is decided
|
|
||||||
return ('', 'handled') if $fact =~ /^regex\s/;
|
|
||||||
|
|
||||||
my ($s, $r) = runfacts($fact, $said, $pm);
|
|
||||||
if ($s) {
|
|
||||||
$r = "$user: $r" if $user;
|
|
||||||
$r = "\0".$r;
|
|
||||||
return ($r, 'handled');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub runfacts {
|
|
||||||
my( $body, $_said, $pm ) = @_;
|
|
||||||
|
|
||||||
my $said = {%$_said};
|
|
||||||
|
|
||||||
my $plugin = $pm->get_plugin( 'fact' );
|
|
||||||
|
|
||||||
$said->{body} = $body;
|
|
||||||
$said->{recommended_args} = [ split /\s+/, $body ];
|
|
||||||
$said->{command_match} = 'fact';
|
|
||||||
$said->{addressed} = 1;
|
|
||||||
|
|
||||||
local $@;
|
|
||||||
my( $status, $results ) = eval { $plugin->command( $said, $pm ) };
|
|
||||||
my $err = $@;
|
|
||||||
|
|
||||||
warn $err if $err;
|
|
||||||
|
|
||||||
if( $err ) { return( 0, "Failed to execute plugin: facts because $err" ); }
|
|
||||||
else { return( 1, $results ) }
|
|
||||||
}
|
|
||||||
|
|
||||||
"Bot::BB3::Plugin::Badfacts";
|
|
||||||
|
|
||||||
__DATA__
|
|
||||||
Supports calling factoids outside of addressed commands using special syntax. Contact simcop2387 to ask about having it enabled for your channel.
|
|
|
@ -1,87 +0,0 @@
|
||||||
package Bot::BB3::Plugin::BadfactsTemp;
|
|
||||||
use strict;
|
|
||||||
no warnings 'void';
|
|
||||||
|
|
||||||
use Data::Dumper;
|
|
||||||
|
|
||||||
sub new {
|
|
||||||
my( $class ) = @_;
|
|
||||||
my $self = bless {}, $class;
|
|
||||||
$self->{name} = 'badfactstemp';
|
|
||||||
$self->{opts} = {
|
|
||||||
handler => 1,
|
|
||||||
command => 1,
|
|
||||||
};
|
|
||||||
|
|
||||||
return $self;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub command {
|
|
||||||
my ($self, $said, $pm) = @_;
|
|
||||||
|
|
||||||
# Always require this to be addressed, regardless of plugin config
|
|
||||||
if ($said->{addressed}) {
|
|
||||||
my $body = $said->{body};
|
|
||||||
|
|
||||||
if ($body =~ /^#(?<channel>\S+)\s+(?:(?<command>forget|learn|relearn|literal|revert|revisions|search|protect|unprotect|substitue|macro)\s+)?(?<fact>.*?)$/) {
|
|
||||||
my ($command, $channel, $fact) = @+{qw/command channel fact/};
|
|
||||||
|
|
||||||
my $realfact = ($command?"$command ":"")."__${channel}_$fact";
|
|
||||||
|
|
||||||
return ('handled', $realfact);
|
|
||||||
} else {
|
|
||||||
return ('handled', "helptexthere");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub handle {
|
|
||||||
my ($self, $said, $pm) = @_;
|
|
||||||
|
|
||||||
if ($said->{body} =~ /^!(?<fact>[^@].*?)(?:\s@\s*(?<user>\S*))?$/ ||
|
|
||||||
$said->{body} =~ /^!@(?<user>\S+)\s+(?<fact>.+)$/) {
|
|
||||||
my $fact = $+{fact};
|
|
||||||
my $user = $+{user};
|
|
||||||
|
|
||||||
# TODO HACK XXX bad hack to prevent noise until better way is decided
|
|
||||||
return ('', 'handled') if $fact =~ /^regex\s/;
|
|
||||||
|
|
||||||
my ($s, $r) = runfacts($fact, $said, $pm);
|
|
||||||
if ($s) {
|
|
||||||
$r = "$user: $r" if $user;
|
|
||||||
$r = "\0".$r;
|
|
||||||
return ($r, 'handled');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
sub runfacts {
|
|
||||||
my( $body, $_said, $pm ) = @_;
|
|
||||||
|
|
||||||
my $said = {%$_said};
|
|
||||||
|
|
||||||
my $plugin = $pm->get_plugin( 'fact' );
|
|
||||||
|
|
||||||
$said->{body} = $body;
|
|
||||||
$said->{recommended_args} = [ split /\s+/, $body ];
|
|
||||||
$said->{command_match} = 'fact';
|
|
||||||
$said->{addressed} = 1;
|
|
||||||
|
|
||||||
local $@;
|
|
||||||
my( $status, $results ) = eval { $plugin->command( $said, $pm ) };
|
|
||||||
my $err = $@;
|
|
||||||
|
|
||||||
warn $err if $err;
|
|
||||||
|
|
||||||
if( $err ) { return( 0, "Failed to execute plugin: facts because $err" ); }
|
|
||||||
else { return( 1, $results ) }
|
|
||||||
}
|
|
||||||
|
|
||||||
"Bot::BB3::Plugin::BadfactsTemp";
|
|
||||||
|
|
||||||
__DATA__
|
|
||||||
Supports calling factoids outside of addressed commands using special syntax. Contact simcop2387 to ask about having it enabled for your channel.
|
|
|
@ -117,12 +117,13 @@ sub command {
|
||||||
#i lost the object oriented calling here, but i don't care too much, BECAUSE this avoids using strings for the calling, i might change that.
|
#i lost the object oriented calling here, but i don't care too much, BECAUSE this avoids using strings for the calling, i might change that.
|
||||||
$fact_string = $commandhash{$1}->($self,$subject, $said->{name}, $said);
|
$fact_string = $commandhash{$1}->($self,$subject, $said->{name}, $said);
|
||||||
}
|
}
|
||||||
elsif (($subject =~ m|^\s*(.*?)\s*=~\s*s/([^/]+)/([^/]*)/([gi]*)|i) ||
|
elsif (($subject =~ m|^\s*(.*?)\s*=~\s*s/([^/]+)/([^/]*)/([gi]*)\s*$|i) ||
|
||||||
($subject =~ m/^\s*(.*?)\s*=~\s*s\{(.+)\}\{(.*)\}([gi]*)/i))
|
($subject =~ m/^\s*(.*?)\s*=~\s*s\{(.+)\}\{(.*)\}([gi]*)\s*$/i))
|
||||||
{
|
{
|
||||||
$fact_string = $self->get_fact_substitute( $subject, $said->{name}, $said);
|
$fact_string = $self->get_fact_substitute( $subject, $said->{name}, $said);
|
||||||
}
|
}
|
||||||
elsif( !$call_only and $subject =~ /\s+$COPULA_RE\s+/ ) {
|
elsif( !$call_only and $subject =~ /\s+$COPULA_RE\s+/ ) {
|
||||||
|
return if $said->{nolearn};
|
||||||
my @ret = $self->store_factoid( $said );
|
my @ret = $self->store_factoid( $said );
|
||||||
|
|
||||||
$fact_string = "Failed to store $said->{body}" unless @ret;
|
$fact_string = "Failed to store $said->{body}" unless @ret;
|
||||||
|
@ -441,6 +442,8 @@ sub get_fact_revert {
|
||||||
sub get_fact_learn {
|
sub get_fact_learn {
|
||||||
my( $self, $body, $name, $said, $subject, $predicate ) = @_;
|
my( $self, $body, $name, $said, $subject, $predicate ) = @_;
|
||||||
|
|
||||||
|
return if ($said->{nolearn});
|
||||||
|
|
||||||
$body =~ s/^\s*learn\s+//;
|
$body =~ s/^\s*learn\s+//;
|
||||||
($subject, $predicate ) = split /\s+as\s+/, $body, 2 unless ($subject && $predicate);
|
($subject, $predicate ) = split /\s+as\s+/, $body, 2 unless ($subject && $predicate);
|
||||||
|
|
||||||
|
@ -620,6 +623,8 @@ sub basic_get_fact {
|
||||||
|
|
||||||
my $matches = $self->_soundex_matches( $soundex );
|
my $matches = $self->_soundex_matches( $soundex );
|
||||||
|
|
||||||
|
push @{$said->{soundex_matches}}, @$matches;
|
||||||
|
|
||||||
if( ($matches and @$matches) && (!$said->{backdressed}) ) {
|
if( ($matches and @$matches) && (!$said->{backdressed}) ) {
|
||||||
return "No factoid found. Did you mean one of these: " . join " ", map "[$_]", @$matches;
|
return "No factoid found. Did you mean one of these: " . join " ", map "[$_]", @$matches;
|
||||||
}
|
}
|
||||||
|
|
170
plugins/nfacts.pm
Normal file
170
plugins/nfacts.pm
Normal file
|
@ -0,0 +1,170 @@
|
||||||
|
package Bot::BB3::Plugin::NFacts;
|
||||||
|
use strict;
|
||||||
|
no warnings 'void';
|
||||||
|
|
||||||
|
use Data::Dumper;
|
||||||
|
|
||||||
|
our $pname = "nfacts";
|
||||||
|
my $fsep = "\034"; # ASCII file seperator
|
||||||
|
|
||||||
|
sub get_conf_for_channel {
|
||||||
|
my ($self, $pm, $server, $channel) = @_;
|
||||||
|
my $conf = $pm->plugin_conf($pname, $server, $channel);
|
||||||
|
return $conf;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub namespace_factoid {
|
||||||
|
my ($self, $pm, $body, $said, $forcechan, $forceserver) = @_;
|
||||||
|
|
||||||
|
my ($channel, $server) = @{$said}{qw/channel server/};
|
||||||
|
$server =~ s/^.*?([^.]+\.(?:com|net|co.uk|org|bot|info))$/$1/; # grab just the domain and tld, will expand to more domains later
|
||||||
|
|
||||||
|
$channel = $forcechan // $channel;
|
||||||
|
$server = $forceserver // $server;
|
||||||
|
|
||||||
|
warn "NAMESPACE: [ $channel , $server ]";
|
||||||
|
|
||||||
|
my $conf = $self->get_conf_for_channel($pm, $said->{server}, $channel);
|
||||||
|
|
||||||
|
warn Dumper($conf);
|
||||||
|
|
||||||
|
my $realserver = $conf->{serverspace} // $server;
|
||||||
|
my $realchannel = $conf->{chanspace} // $channel;
|
||||||
|
|
||||||
|
if ($body =~ /^(?:(?<command>forget|learn|relearn|literal|revert|revisions|search|protect|unprotect|substitue|macro)\s+)?(?<fact>.*?)$/) {
|
||||||
|
my ($command, $fact) = @+{qw/command fact/};
|
||||||
|
$body = "${command} ${fsep}${realserver}${fsep}${realchannel}${fsep}${fact}";
|
||||||
|
} else {
|
||||||
|
$body = "${fsep}${realserver}${fsep}${realchannel}${fsep}${body}";
|
||||||
|
}
|
||||||
|
|
||||||
|
return $body;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub namespace_filter {
|
||||||
|
my ($body, $enabled) = @_;
|
||||||
|
|
||||||
|
return $body =~ s|$fsep.*?$fsep.*?$fsep(\S+)(?=\s)|$1|rg if $enabled;
|
||||||
|
$body;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub new {
|
||||||
|
my( $class ) = @_;
|
||||||
|
my $self = bless {}, $class;
|
||||||
|
$self->{name} = $pname;
|
||||||
|
$self->{opts} = {
|
||||||
|
handler => 1,
|
||||||
|
command => 1,
|
||||||
|
};
|
||||||
|
|
||||||
|
return $self;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub command {
|
||||||
|
my ($self, $_said, $pm) = @_;
|
||||||
|
my $said = {%$_said}; # copy it so we can mutate it later
|
||||||
|
my $conf = $self->get_conf_for_channel($pm, $said->{server}, $said->{channel});
|
||||||
|
|
||||||
|
# Always require this to be addressed, regardless of plugin config
|
||||||
|
if ($said->{addressed}) {
|
||||||
|
my $body = $said->{body};
|
||||||
|
|
||||||
|
$body =~ s/^\s*$pname\s*//;
|
||||||
|
$body =~ s/^\s+|\s+$//g;
|
||||||
|
|
||||||
|
if ($body =~ /^(?<channel>#\S+)\s+(?<fact>.*)$/) {
|
||||||
|
my ($channel, $fact) = @+{qw/channel fact/};
|
||||||
|
|
||||||
|
$said->{channel} = $channel;
|
||||||
|
my ($status, $result) = $self->runfacts($fact, $said, $pm, $conf);
|
||||||
|
return ('handled', $result);
|
||||||
|
} else {
|
||||||
|
my ($status, $result) = $self->runfacts($body, $said, $pm, $conf);
|
||||||
|
return ('handled', $result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub handle {
|
||||||
|
my ($self, $said, $pm) = @_;
|
||||||
|
my $conf = $self->get_conf_for_channel($pm, $said->{server}, $said->{channel});
|
||||||
|
|
||||||
|
return unless $conf->{enabled};
|
||||||
|
|
||||||
|
my $prefix = $conf->{prefix} || "!";
|
||||||
|
|
||||||
|
my $regex = qr/^\Q$prefix\E(?<fact>[^@].*?)(?:\s@\s*(?<user>\S*))?$/;
|
||||||
|
|
||||||
|
if ($said->{body} =~ /^\Q$prefix\E(?<fact>[^@].*?)(?:\s@\s*(?<user>\S*))?$/ ||
|
||||||
|
$said->{body} =~ /^\Q$prefix\E!@(?<user>\S+)\s+(?<fact>.+)$/) {
|
||||||
|
my $fact = $+{fact};
|
||||||
|
my $user = $+{user};
|
||||||
|
|
||||||
|
# return (Dumper($said), "handled");
|
||||||
|
|
||||||
|
my ($s, $r) = $self->runfacts($fact, $said, $pm, $conf);
|
||||||
|
if ($s) {
|
||||||
|
$r = "$user: $r" if $user;
|
||||||
|
$r = "\0".$r;
|
||||||
|
return ($r, 'handled');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub runfacts {
|
||||||
|
my( $self, $body, $_said, $pm, $conf, $server, $channel ) = @_;
|
||||||
|
|
||||||
|
my $said = {%$_said};
|
||||||
|
my @suggests;
|
||||||
|
|
||||||
|
my $plugin = $pm->get_plugin( 'fact' );
|
||||||
|
|
||||||
|
$said->{body} = $self->namespace_factoid($pm, $body, $said, $channel, $server);
|
||||||
|
$said->{recommended_args} = [ split /\s+/, $said->{body} ];
|
||||||
|
$said->{command_match} = 'fact';
|
||||||
|
$said->{nolearn} = !($_said->{addressed}); # Only learn if we were addressed originally
|
||||||
|
$said->{addressed} = 1;
|
||||||
|
$said->{backdressed} = 1;
|
||||||
|
|
||||||
|
local $@;
|
||||||
|
my( $status, $results ) = eval { $plugin->command( $said, $pm ) };
|
||||||
|
my $err = $@;
|
||||||
|
|
||||||
|
push @suggests, @{$said->{soundex_matches} // []};
|
||||||
|
|
||||||
|
if (!$results || !$status || $err) {
|
||||||
|
$said->{body} = $body;
|
||||||
|
$said->{recommended_args} = [ split /\s+/, $said->{body} ];
|
||||||
|
$said->{nolearn} = 1; # never learn a global this way
|
||||||
|
delete $said->{soundex_matches};
|
||||||
|
|
||||||
|
( $status, $results ) = eval { $plugin->command( $said, $pm ) };
|
||||||
|
$err = $@;
|
||||||
|
|
||||||
|
push @suggests, @{$said->{soundex_matches} // []};
|
||||||
|
}
|
||||||
|
|
||||||
|
warn $err if $err;
|
||||||
|
|
||||||
|
if( $err ) {
|
||||||
|
return( 0, "Failed to execute plugin: facts because $err" );
|
||||||
|
} else {
|
||||||
|
if (!$status && !$results) {
|
||||||
|
# Do suggests from here to cross namespaces
|
||||||
|
#return( 1, "[" . join(", ", @suggests) . "]" );
|
||||||
|
return(1, "");
|
||||||
|
} else {
|
||||||
|
return( 1, namespace_filter($results, $conf->{filtersep}) );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
"Bot::BB3::Plugin::NFacts";
|
||||||
|
|
||||||
|
__DATA__
|
||||||
|
nfacts [#channel] <factoid command> - Use/set a factoid for/from a channel on this server.
|
||||||
|
Also supports calling factoids outside of addressed commands using special syntax. Contact simcop2387 to ask about having it enabled for your channel.
|
Loading…
Add table
Reference in a new issue