diff --git a/etc/plugins.conf b/etc/plugins.conf index caacebf..d6857b6 100644 --- a/etc/plugins.conf +++ b/etc/plugins.conf @@ -1,34 +1,56 @@ server "*" { - channel "*" { - plugin "*" { addressed: true } - plugin "join" { access: op; addressed: true } - plugin "part" { access: op } - plugin "reload_plugins" { access: root } - plugin "restart" { access: root } - plugin "conf_dump" { access: root; } - plugin "save_config" { access: root; } - plugin "conf" { access: root; } - plugin "karma_modify" { addressed: false; } - plugin "seen" {addressed: false; } - } - channel "#perl" { - plugin "eval" {addressed: false; } - plugin "deparse" {addressed: false; } - } - channel "#perl-cats" { - plugin "eval" {addressed: false; } - plugin "deparse" {addressed: false; } - } - channel "#perlbot" { - plugin "eval" {addressed: false; } - plugin "deparse" {addressed: false; } - plugin "badfacts" {addressed: false; } - } - channel "#buubot" { - plugin "eval" {addressed: false; } - plugin "deparse" {addressed: false; } - } - channel "#regex" { - plugin "badfacts" {addressed: false; } - } + channel "*" { + plugin "*" { addressed: true } + plugin "join" { access: op; addressed: true } + plugin "part" { access: op } + plugin "reload_plugins" { access: root } + plugin "restart" { access: root } + plugin "conf_dump" { access: root; } + plugin "save_config" { access: root; } + plugin "conf" { access: root; } + plugin "karma_modify" { addressed: false; } + plugin "seen" {addressed: false; } + } + channel "#perl" { + plugin "eval" {addressed: false; } + plugin "deparse" {addressed: false; } + } + channel "#perl-cats" { + plugin "eval" {addressed: false; } + plugin "deparse" {addressed: false; } + } + channel "#perlbot" { + plugin "eval" {addressed: false; } + plugin "deparse" {addressed: false; } + plugin "badfacts" {addressed: false; } + } + channel "#buubot" { + plugin "eval" {addressed: false; } + plugin "deparse" {addressed: false; } + } + channel "#regex" { + 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; + } + } } diff --git a/plugins/.badfactstemp.pm.swp b/plugins/.badfactstemp.pm.swp new file mode 100644 index 0000000..b0da101 Binary files /dev/null and b/plugins/.badfactstemp.pm.swp differ diff --git a/plugins/badfacts.pm b/plugins/badfacts.pm deleted file mode 100644 index 843ef22..0000000 --- a/plugins/badfacts.pm +++ /dev/null @@ -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} =~ /^!(?[^@].*?)(?:\s@\s*(?\S*))?$/ || - $said->{body} =~ /^!@(?\S+)\s+(?.+)$/) { - 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. diff --git a/plugins/badfactstemp.pm b/plugins/badfactstemp.pm deleted file mode 100644 index c12671e..0000000 --- a/plugins/badfactstemp.pm +++ /dev/null @@ -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 =~ /^#(?\S+)\s+(?:(?forget|learn|relearn|literal|revert|revisions|search|protect|unprotect|substitue|macro)\s+)?(?.*?)$/) { - 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} =~ /^!(?[^@].*?)(?:\s@\s*(?\S*))?$/ || - $said->{body} =~ /^!@(?\S+)\s+(?.+)$/) { - 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. diff --git a/plugins/factoids.pm b/plugins/factoids.pm index 51d30bc..0010feb 100644 --- a/plugins/factoids.pm +++ b/plugins/factoids.pm @@ -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. $fact_string = $commandhash{$1}->($self,$subject, $said->{name}, $said); } - elsif (($subject =~ m|^\s*(.*?)\s*=~\s*s/([^/]+)/([^/]*)/([gi]*)|i) || - ($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]*)\s*$/i)) { $fact_string = $self->get_fact_substitute( $subject, $said->{name}, $said); } elsif( !$call_only and $subject =~ /\s+$COPULA_RE\s+/ ) { + return if $said->{nolearn}; my @ret = $self->store_factoid( $said ); $fact_string = "Failed to store $said->{body}" unless @ret; @@ -441,6 +442,8 @@ sub get_fact_revert { sub get_fact_learn { my( $self, $body, $name, $said, $subject, $predicate ) = @_; + return if ($said->{nolearn}); + $body =~ s/^\s*learn\s+//; ($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 ); + push @{$said->{soundex_matches}}, @$matches; + if( ($matches and @$matches) && (!$said->{backdressed}) ) { return "No factoid found. Did you mean one of these: " . join " ", map "[$_]", @$matches; } diff --git a/plugins/nfacts.pm b/plugins/nfacts.pm new file mode 100644 index 0000000..e405c55 --- /dev/null +++ b/plugins/nfacts.pm @@ -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 =~ /^(?:(?forget|learn|relearn|literal|revert|revisions|search|protect|unprotect|substitue|macro)\s+)?(?.*?)$/) { + 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 =~ /^(?#\S+)\s+(?.*)$/) { + 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(?[^@].*?)(?:\s@\s*(?\S*))?$/; + + if ($said->{body} =~ /^\Q$prefix\E(?[^@].*?)(?:\s@\s*(?\S*))?$/ || + $said->{body} =~ /^\Q$prefix\E!@(?\S+)\s+(?.+)$/) { + 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] - 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.