mirror of
https://github.com/perlbot/perlbuut
synced 2025-06-07 16:45:40 -04:00
More tidy
This commit is contained in:
parent
0ed7f4a51c
commit
38525a9b4c
3 changed files with 245 additions and 337 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -13,3 +13,5 @@ jail.ext4
|
||||||
var/asn.db
|
var/asn.db
|
||||||
langs/
|
langs/
|
||||||
*.swp
|
*.swp
|
||||||
|
*.LOG
|
||||||
|
*.bak
|
||||||
|
|
1
perltidy.cmd
Normal file
1
perltidy.cmd
Normal file
|
@ -0,0 +1 @@
|
||||||
|
perltidy -g -ce -i=4 -b -l=180 -conv -pt=2 -sbt=2 -bt=1 -bbt=2 -tso -nsfs plugins/factoids.pm
|
|
@ -35,11 +35,7 @@ chomp $dbpass;
|
||||||
#
|
#
|
||||||
#############################
|
#############################
|
||||||
|
|
||||||
my $fsep = "\034"; # ASCII file seperator
|
my $COPULA = join '|', qw/is are was isn't were being am/, "to be", "will be", "has been", "have been", "shall be", "can has", "wus liek", "iz liek", "used to be";
|
||||||
|
|
||||||
my $COPULA = join '|', qw/is are was isn't were being am/, "to be", "will be",
|
|
||||||
"has been", "have been", "shall be", "can has", "wus liek", "iz liek",
|
|
||||||
"used to be";
|
|
||||||
my $COPULA_RE = qr/\b(?:$COPULA)\b/i;
|
my $COPULA_RE = qr/\b(?:$COPULA)\b/i;
|
||||||
|
|
||||||
#this is a hash that gives all the commands their names and functions, added to avoid some symbol table funkery that happened originally.
|
#this is a hash that gives all the commands their names and functions, added to avoid some symbol table funkery that happened originally.
|
||||||
|
@ -79,8 +75,7 @@ sub dbh($self) {
|
||||||
}
|
}
|
||||||
|
|
||||||
my $dbh = $self->{dbh} =
|
my $dbh = $self->{dbh} =
|
||||||
DBI->connect( "dbi:Pg:dbname=$dbname", $dbuser, $dbpass,
|
DBI->connect("dbi:Pg:dbname=$dbname", $dbuser, $dbpass, { RaiseError => 1, PrintError => 0 });
|
||||||
{ RaiseError => 1, PrintError => 0 } );
|
|
||||||
|
|
||||||
# DBD::SQLite::BundledExtensions->load_spellfix($dbh);
|
# DBD::SQLite::BundledExtensions->load_spellfix($dbh);
|
||||||
|
|
||||||
|
@ -104,8 +99,7 @@ sub __get_namespaced_factoid {
|
||||||
my $command;
|
my $command;
|
||||||
|
|
||||||
my ($channel, $server) = @{$said}{qw/channel server/};
|
my ($channel, $server) = @{$said}{qw/channel server/};
|
||||||
$server =~ s/^.*?([^.]+\.(?:com|net|co.uk|org|bot|info))$/$1/
|
$server =~ s/^.*?([^.]+\.(?:com|net|co.uk|org|bot|info))$/$1/; # grab just the domain and tld, will expand to more domains later
|
||||||
; # grab just the domain and tld, will expand to more domains later
|
|
||||||
|
|
||||||
$channel = $forcechan // $channel;
|
$channel = $forcechan // $channel;
|
||||||
$server = $forceserver // $server;
|
$server = $forceserver // $server;
|
||||||
|
@ -209,35 +203,29 @@ sub command ( $self, $_said, $pm ) {
|
||||||
$body = $+{fact};
|
$body = $+{fact};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $said->{channel} ne '##NULL' )
|
if ($said->{channel} ne '##NULL') { # fuck ##NULL, they don't get factoids
|
||||||
{ # fuck ##NULL, they don't get factoids
|
($realserver, $realchannel) = $self->get_namespaced_factoid($pm, $fact, $said);
|
||||||
( $realserver, $realchannel ) =
|
|
||||||
$self->get_namespaced_factoid( $pm, $fact, $said );
|
|
||||||
print $fh "New body is $body\n";
|
print $fh "New body is $body\n";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$body = $command . " " . $body;
|
$body = $command . " " . $body;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
# handle a channel prefix on everything
|
# handle a channel prefix on everything
|
||||||
if ($body =~ /^\s*(?<channel>#\S+)\s+(?<fact>.*)$/) {
|
if ($body =~ /^\s*(?<channel>#\S+)\s+(?<fact>.*)$/) {
|
||||||
$said->{channel} = $+{channel};
|
$said->{channel} = $+{channel};
|
||||||
$body = $+{fact};
|
$body = $+{fact};
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( $said->{channel} ne '##NULL' )
|
if ($said->{channel} ne '##NULL') { # fuck ##NULL, they don't get factoids
|
||||||
{ # fuck ##NULL, they don't get factoids
|
($realserver, $realchannel) = $self->get_namespaced_factoid($pm, $body, $said);
|
||||||
( $realserver, $realchannel ) =
|
|
||||||
$self->get_namespaced_factoid( $pm, $body, $said );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
print $fh Dumper($said);
|
print $fh Dumper($said);
|
||||||
|
|
||||||
my ( $handled, $fact_out ) =
|
my ($handled, $fact_out) = $self->sub_command($said, $pm, $realchannel, $realserver);
|
||||||
$self->sub_command( $said, $pm, $realchannel, $realserver );
|
|
||||||
|
|
||||||
$fact_out = $self->namespace_filter($fact_out, $conf->{filtersep});
|
$fact_out = $self->namespace_filter($fact_out, $conf->{filtersep});
|
||||||
|
|
||||||
|
@ -261,18 +249,14 @@ sub sub_command ( $self, $said, $pm, $realchannel, $realserver ) {
|
||||||
#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 =
|
$fact_string =
|
||||||
$commandhash{$1}->($self, $subject, $said->{name}, $said);
|
$commandhash{$1}->($self, $subject, $said->{name}, $said);
|
||||||
}
|
} elsif (($subject =~ m{\w\s*=~\s*s /.+ / .* /[gi]*\s*$}ix)
|
||||||
elsif (( $subject =~ m{\w\s*=~\s*s /.+ / .* /[gi]*\s*$}ix )
|
|
||||||
|| ($subject =~ m{\w\s*=~\s*s\|.+\| .*\|[gi]*\s*$}ix)
|
|| ($subject =~ m{\w\s*=~\s*s\|.+\| .*\|[gi]*\s*$}ix)
|
||||||
|| ($subject =~ m{\w\s*=~\s*s\{.+\}\{.*\}[gi]*\s*$}ix)
|
|| ($subject =~ m{\w\s*=~\s*s\{.+\}\{.*\}[gi]*\s*$}ix)
|
||||||
|| ($subject =~ m{\w\s*=~\s*s <.+ > <.* >[gi]*\s*$}ix)
|
|| ($subject =~ m{\w\s*=~\s*s <.+ > <.* >[gi]*\s*$}ix)
|
||||||
|| ($subject =~ m{\w\s*=~\s*s\(.+\)\(.*\)[gi]*\s*$}ix))
|
|| ($subject =~ m{\w\s*=~\s*s\(.+\)\(.*\)[gi]*\s*$}ix))
|
||||||
{
|
{
|
||||||
$fact_string =
|
$fact_string = $self->get_fact_substitute($subject, $said->{name}, $said, $realchannel, $realserver);
|
||||||
$self->get_fact_substitute( $subject, $said->{name}, $said,
|
} elsif (!$call_only and $subject =~ /\s+$COPULA_RE\s+/) {
|
||||||
$realchannel, $realserver );
|
|
||||||
}
|
|
||||||
elsif ( !$call_only and $subject =~ /\s+$COPULA_RE\s+/ ) {
|
|
||||||
return if $said->{nolearn};
|
return if $said->{nolearn};
|
||||||
my @ret = $self->store_factoid($said, $realchannel, $realserver);
|
my @ret = $self->store_factoid($said, $realchannel, $realserver);
|
||||||
|
|
||||||
|
@ -280,28 +264,22 @@ sub sub_command ( $self, $said, $pm, $realchannel, $realserver ) {
|
||||||
|
|
||||||
$fact_string = "@ret" if ($ret[0] =~ /^insuff/i);
|
$fact_string = "@ret" if ($ret[0] =~ /^insuff/i);
|
||||||
$fact_string = "Stored @ret";
|
$fact_string = "Stored @ret";
|
||||||
}
|
} else {
|
||||||
else {
|
$fact_string = $self->get_fact($pm, $said, $subject, $said->{name}, $call_only, $realchannel, $realserver);
|
||||||
$fact_string =
|
|
||||||
$self->get_fact( $pm, $said, $subject, $said->{name}, $call_only,
|
|
||||||
$realchannel, $realserver );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (defined $fact_string) {
|
if (defined $fact_string) {
|
||||||
return ('handled', $fact_string);
|
return ('handled', $fact_string);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
# Handler code stolen from the old nfacts plugin
|
# Handler code stolen from the old nfacts plugin
|
||||||
sub handle ($self, $said, $pm) {
|
sub handle ($self, $said, $pm) {
|
||||||
my $conf =
|
my $conf = $self->get_conf_for_channel($pm, $said->{server}, $said->{channel});
|
||||||
$self->get_conf_for_channel( $pm, $said->{server}, $said->{channel} );
|
|
||||||
|
|
||||||
$said->{body} =~
|
$said->{body} =~ s/^\s*(what|who|where|how|when|why)\s+($COPULA_RE)\s+(?<fact>.*?)\??\s*$/$+{fact}/i;
|
||||||
s/^\s*(what|who|where|how|when|why)\s+($COPULA_RE)\s+(?<fact>.*?)\??\s*$/$+{fact}/i;
|
|
||||||
|
|
||||||
my $prefix = $conf->{prefix_command};
|
my $prefix = $conf->{prefix_command};
|
||||||
return unless $prefix;
|
return unless $prefix;
|
||||||
|
@ -309,8 +287,7 @@ s/^\s*(what|who|where|how|when|why)\s+($COPULA_RE)\s+(?<fact>.*?)\??\s*$/$+{fact
|
||||||
# TODO make this channel configurable and make it work properly to learn shit with colors later.
|
# TODO make this channel configurable and make it work properly to learn shit with colors later.
|
||||||
$said->{body} = strip_formatting strip_color $said->{body};
|
$said->{body} = strip_formatting strip_color $said->{body};
|
||||||
|
|
||||||
if ( $said->{body} =~
|
if ( $said->{body} =~ /^\Q$prefix\E(?<fact>[^@]*?)(?:\s@\s*(?<user>\S*)\s*)?$/
|
||||||
/^\Q$prefix\E(?<fact>[^@]*?)(?:\s@\s*(?<user>\S*)\s*)?$/
|
|
||||||
|| $said->{body} =~ /^\Q$prefix\E!@(?<user>\S+)\s+(?<fact>.+)$/)
|
|| $said->{body} =~ /^\Q$prefix\E!@(?<user>\S+)\s+(?<fact>.+)$/)
|
||||||
{
|
{
|
||||||
my $fact = $+{fact};
|
my $fact = $+{fact};
|
||||||
|
@ -359,8 +336,7 @@ sub _clean_subject_func ( $subject, $variant ) { # for parametrized macros
|
||||||
|
|
||||||
($key, $arg) = ($1, $2);
|
($key, $arg) = ($1, $2);
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$subject =~ /\A\s*(\S+)(?:\s+(.*))?\z/s or return;
|
$subject =~ /\A\s*(\S+)(?:\s+(.*))?\z/s or return;
|
||||||
|
|
||||||
($key, $arg) = ($1, $2);
|
($key, $arg) = ($1, $2);
|
||||||
|
@ -389,32 +365,18 @@ sub store_factoid ( $self, $said ) {
|
||||||
if ($subject =~ s/^\s*\@?macro\b\s*//) {$compose_macro = 1;}
|
if ($subject =~ s/^\s*\@?macro\b\s*//) {$compose_macro = 1;}
|
||||||
elsif ($subject =~ s/^\s*\@?func\b\s*//) {$compose_macro = 2;}
|
elsif ($subject =~ s/^\s*\@?func\b\s*//) {$compose_macro = 2;}
|
||||||
elsif ($predicate =~ s/^\s*also\s+//) {
|
elsif ($predicate =~ s/^\s*also\s+//) {
|
||||||
my $fact = $self->_db_get_fact( _clean_subject($subject),
|
my $fact = $self->_db_get_fact(_clean_subject($subject), $author, $server, $namespace);
|
||||||
$author, $server, $namespace );
|
|
||||||
|
|
||||||
$predicate = $fact->{predicate} . " | " . $predicate;
|
$predicate = $fact->{predicate} . " | " . $predicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
return
|
return
|
||||||
unless $self->_insert_factoid(
|
unless $self->_insert_factoid($author, $subject, $copula, $predicate, $compose_macro, $self->_db_get_protect($subject, $server, $namespace), $aliasserver, $aliasnamespace);
|
||||||
$author,
|
|
||||||
$subject,
|
|
||||||
$copula,
|
|
||||||
$predicate,
|
|
||||||
$compose_macro,
|
|
||||||
$self->_db_get_protect( $subject, $server, $namespace ),
|
|
||||||
$aliasserver,
|
|
||||||
$aliasnamespace
|
|
||||||
);
|
|
||||||
|
|
||||||
return ($subject, $copula, $predicate);
|
return ($subject, $copula, $predicate);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub _insert_factoid (
|
sub _insert_factoid ($self, $author, $subject, $copula, $predicate, $compose_macro, $protected, $server, $namespace) {
|
||||||
$self, $author, $subject, $copula, $predicate,
|
|
||||||
$compose_macro, $protected, $server, $namespace
|
|
||||||
)
|
|
||||||
{
|
|
||||||
my = @_;
|
my = @_;
|
||||||
my $dbh = $self->dbh;
|
my $dbh = $self->dbh;
|
||||||
|
|
||||||
|
@ -423,13 +385,11 @@ sub _insert_factoid (
|
||||||
my $key;
|
my $key;
|
||||||
if ($compose_macro == 2) {
|
if ($compose_macro == 2) {
|
||||||
($key, my $arg) = _clean_subject_func($subject, 1);
|
($key, my $arg) = _clean_subject_func($subject, 1);
|
||||||
warn
|
warn "*********************** GENERATED [$key] FROM [$subject] and [$arg]\n";
|
||||||
"*********************** GENERATED [$key] FROM [$subject] and [$arg]\n";
|
|
||||||
|
|
||||||
$arg =~ /\S/
|
$arg =~ /\S/
|
||||||
and return;
|
and return;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
$key = _clean_subject($subject);
|
$key = _clean_subject($subject);
|
||||||
}
|
}
|
||||||
return unless $key =~ /\S/;
|
return unless $key =~ /\S/;
|
||||||
|
@ -465,17 +425,13 @@ sub get_fact_protect ( $self, $subject, $name, $said ) {
|
||||||
return "Insufficient permissions for protecting factoid [$subject]"
|
return "Insufficient permissions for protecting factoid [$subject]"
|
||||||
if (!$self->_db_check_perm($subject, $said));
|
if (!$self->_db_check_perm($subject, $said));
|
||||||
|
|
||||||
my $fact = $self->_db_get_fact( _clean_subject($subject),
|
my $fact = $self->_db_get_fact(_clean_subject($subject), $name, $server, $namespace);
|
||||||
$name, $server, $namespace );
|
|
||||||
|
|
||||||
if (defined($fact->{predicate})) {
|
if (defined($fact->{predicate})) {
|
||||||
$self->_insert_factoid( $name, $subject, $fact->{copula},
|
$self->_insert_factoid($name, $subject, $fact->{copula}, $fact->{predicate}, $fact->{compose_macro}, 1, $aliasserver, $aliasnamespace);
|
||||||
$fact->{predicate}, $fact->{compose_macro},
|
|
||||||
1, $aliasserver, $aliasnamespace );
|
|
||||||
|
|
||||||
return "Protected [$subject]";
|
return "Protected [$subject]";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return "Unable to protect nonexisting factoid [$subject]";
|
return "Unable to protect nonexisting factoid [$subject]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -490,17 +446,13 @@ sub get_fact_unprotect ( $self, $subject, $name, $said ) {
|
||||||
return "Insufficient permissions for unprotecting factoid [$subject]"
|
return "Insufficient permissions for unprotecting factoid [$subject]"
|
||||||
if (!$self->_db_check_perm($subject, $said));
|
if (!$self->_db_check_perm($subject, $said));
|
||||||
|
|
||||||
my $fact = $self->_db_get_fact( _clean_subject($subject),
|
my $fact = $self->_db_get_fact(_clean_subject($subject), $name, $server, $namespace);
|
||||||
$name, $server, $namespace );
|
|
||||||
|
|
||||||
if (defined($fact->{predicate})) {
|
if (defined($fact->{predicate})) {
|
||||||
$self->_insert_factoid( $name, $subject, $fact->{copula},
|
$self->_insert_factoid($name, $subject, $fact->{copula}, $fact->{predicate}, $fact->{compose_macro}, 0, $aliasserver, $aliasnamespace);
|
||||||
$fact->{predicate}, $fact->{compose_macro},
|
|
||||||
0, $aliasserver, $aliasnamespace );
|
|
||||||
|
|
||||||
return "Unprotected [$subject]";
|
return "Unprotected [$subject]";
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return "Unable to unprotect nonexisting factoid [$subject]";
|
return "Unable to unprotect nonexisting factoid [$subject]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -512,13 +464,10 @@ sub get_fact_forget ( $self, $subject, $name, $said ) {
|
||||||
warn "===TRYING TO FORGET [$subject] [$name]\n";
|
warn "===TRYING TO FORGET [$subject] [$name]\n";
|
||||||
|
|
||||||
#XXX check permissions here
|
#XXX check permissions here
|
||||||
return
|
return "Insufficient permissions for forgetting protected factoid [$subject]"
|
||||||
"Insufficient permissions for forgetting protected factoid [$subject]"
|
|
||||||
if (!$self->_db_check_perm($subject, $said));
|
if (!$self->_db_check_perm($subject, $said));
|
||||||
|
|
||||||
$self->_insert_factoid( $name, $subject, "is", " ", 0,
|
$self->_insert_factoid($name, $subject, "is", " ", 0, $self->_db_get_protect($subject, $server, $namespace), $aliasserver, $aliasnamespace);
|
||||||
$self->_db_get_protect( $subject, $server, $namespace ),
|
|
||||||
$aliasserver, $aliasnamespace );
|
|
||||||
|
|
||||||
return "Forgot $subject";
|
return "Forgot $subject";
|
||||||
}
|
}
|
||||||
|
@ -527,9 +476,7 @@ sub _fact_literal_format($r) {
|
||||||
|
|
||||||
# TODO make this express the parent namespace if present
|
# TODO make this express the parent namespace if present
|
||||||
# <server:namespace>
|
# <server:namespace>
|
||||||
( $r->{protected} ? "P:" : "" )
|
($r->{protected} ? "P:" : "") . ("", "macro ", "func ")[$r->{compose_macro}] . "$r->{subject} $r->{copula} $r->{predicate}";
|
||||||
. ( "", "macro ", "func " )[ $r->{compose_macro} ]
|
|
||||||
. "$r->{subject} $r->{copula} $r->{predicate}";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_fact_revisions ($self, $subject, $name) {
|
sub get_fact_revisions ($self, $subject, $name) {
|
||||||
|
@ -548,9 +495,7 @@ sub get_fact_revisions ( $self, $subject, $name ) {
|
||||||
_clean_subject($subject),
|
_clean_subject($subject),
|
||||||
);
|
);
|
||||||
|
|
||||||
my $ret_string = join " ", map {
|
my $ret_string = join " ", map {"[$_->{factoid_id} by $_->{author}: " . _fact_literal_format($_) . "]";} @$revisions;
|
||||||
"[$_->{factoid_id} by $_->{author}: " . _fact_literal_format($_) . "]";
|
|
||||||
} @$revisions;
|
|
||||||
|
|
||||||
return $ret_string;
|
return $ret_string;
|
||||||
}
|
}
|
||||||
|
@ -558,8 +503,7 @@ sub get_fact_revisions ( $self, $subject, $name ) {
|
||||||
sub get_fact_literal ($self, $subject, $name) {
|
sub get_fact_literal ($self, $subject, $name) {
|
||||||
|
|
||||||
my ($server, $namespace) = $self->get_namespace($said);
|
my ($server, $namespace) = $self->get_namespace($said);
|
||||||
my $fact = $self->_db_get_fact( _clean_subject($subject),
|
my $fact = $self->_db_get_fact(_clean_subject($subject), $name, $server, $namespace);
|
||||||
$name, $server, $namespace );
|
|
||||||
|
|
||||||
return _fact_literal_format($fact);
|
return _fact_literal_format($fact);
|
||||||
}
|
}
|
||||||
|
@ -578,14 +522,11 @@ sub _fact_substitute ( $self, $pred, $match, $subst, $flags ) {
|
||||||
$realsubst =~ s/\\(?=\$)//g;
|
$realsubst =~ s/\\(?=\$)//g;
|
||||||
|
|
||||||
substr $pred, $matchstart, $matchend - $matchstart, $realsubst;
|
substr $pred, $matchstart, $matchend - $matchstart, $realsubst;
|
||||||
pos $pred = $matchstart +
|
pos $pred = $matchstart + length($realsubst); #set the new position, might have an off by one?
|
||||||
length($realsubst)
|
|
||||||
; #set the new position, might have an off by one?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $pred;
|
return $pred;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
my $regex = $flags =~ /i/ ? qr/(?i:$match)/i : qr/$match/;
|
my $regex = $flags =~ /i/ ? qr/(?i:$match)/i : qr/$match/;
|
||||||
|
|
||||||
if ($pred =~ /$regex/) {
|
if ($pred =~ /$regex/) {
|
||||||
|
@ -607,41 +548,24 @@ sub get_fact_substitute ( $self, $subject, $name, $said ) {
|
||||||
my ($aliasserver, $aliasnamespace) = $self->get_alias_namespace($said);
|
my ($aliasserver, $aliasnamespace) = $self->get_alias_namespace($said);
|
||||||
my ($server, $namespace) = $self->get_namespace($said);
|
my ($server, $namespace) = $self->get_namespace($said);
|
||||||
|
|
||||||
if (
|
if ( ($said->{body} =~ m{^(?:\s*substitute)?\s*(.*?)\s*=~\s*s /([^/]+ ) /([^/]* )/([gi]*)\s*$}ix)
|
||||||
(
|
|| ($said->{body} =~ m{^(?:\s*substitute)?\s*(.*?)\s*=~\s*s\|([^|]+ ) \|([^|]* )\|([gi]*)\s*$}ix)
|
||||||
$said->{body} =~
|
|| ($said->{body} =~ m{^(?:\s*substitute)?\s*(.*?)\s*=~\s*s\{([^\}]+)\}\{([^\}]*?)\}([gi]*)\s*$}ix)
|
||||||
m{^(?:\s*substitute)?\s*(.*?)\s*=~\s*s /([^/]+ ) /([^/]* )/([gi]*)\s*$}ix
|
|| ($said->{body} =~ m{^(?:\s*substitute)?\s*(.*?)\s*=~\s*s\(([^)]+ )\)\(([^)]*? )\)([gi]*)\s*$}ix)
|
||||||
)
|
|| ($said->{body} =~ m{^(?:\s*substitute)?\s*(.*?)\s*=~\s*s <([^>]+ ) > <([^>]*? ) >([gi]*)\s*$}ix))
|
||||||
|| ( $said->{body} =~
|
|
||||||
m{^(?:\s*substitute)?\s*(.*?)\s*=~\s*s\|([^|]+ ) \|([^|]* )\|([gi]*)\s*$}ix
|
|
||||||
)
|
|
||||||
|| ( $said->{body} =~
|
|
||||||
m{^(?:\s*substitute)?\s*(.*?)\s*=~\s*s\{([^\}]+)\}\{([^\}]*?)\}([gi]*)\s*$}ix
|
|
||||||
)
|
|
||||||
|| ( $said->{body} =~
|
|
||||||
m{^(?:\s*substitute)?\s*(.*?)\s*=~\s*s\(([^)]+ )\)\(([^)]*? )\)([gi]*)\s*$}ix
|
|
||||||
)
|
|
||||||
|| ( $said->{body} =~
|
|
||||||
m{^(?:\s*substitute)?\s*(.*?)\s*=~\s*s <([^>]+ ) > <([^>]*? ) >([gi]*)\s*$}ix
|
|
||||||
)
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
my ($subject, $match, $subst, $flags) = ($1, $2, $3, $4);
|
my ($subject, $match, $subst, $flags) = ($1, $2, $3, $4);
|
||||||
|
|
||||||
# TODO does this need to be done via the ->get_fact() instead now?
|
# TODO does this need to be done via the ->get_fact() instead now?
|
||||||
my $fact = $self->_db_get_fact( _clean_subject($subject),
|
my $fact = $self->_db_get_fact(_clean_subject($subject), $name, $server, $namespace);
|
||||||
$name, $server, $namespace );
|
|
||||||
|
|
||||||
if ( $fact && $fact->{predicate} =~ /\S/ )
|
if ($fact && $fact->{predicate} =~ /\S/) { #we've got a fact to operate on
|
||||||
{ #we've got a fact to operate on
|
if ($match !~ /(?:\(\?\??\{)/) { #ok, match has checked out to be "safe", this will likely be extended later
|
||||||
if ( $match !~ /(?:\(\?\??\{)/ )
|
|
||||||
{ #ok, match has checked out to be "safe", this will likely be extended later
|
|
||||||
my $pred = $fact->{predicate};
|
my $pred = $fact->{predicate};
|
||||||
my $result;
|
my $result;
|
||||||
|
|
||||||
#moving this to its own function for cleanliness
|
#moving this to its own function for cleanliness
|
||||||
$result =
|
$result = $self->_fact_substitute($pred, $match, $subst, $flags);
|
||||||
$self->_fact_substitute( $pred, $match, $subst, $flags );
|
|
||||||
|
|
||||||
# my( $self, $body, $name, $said ) = @_;
|
# my( $self, $body, $name, $said ) = @_;
|
||||||
|
|
||||||
|
@ -650,17 +574,13 @@ m{^(?:\s*substitute)?\s*(.*?)\s*=~\s*s <([^>]+ ) > <([^>]*? ) >([gi]*)\s*$}ix
|
||||||
|
|
||||||
# TODO why is this calling there?
|
# TODO why is this calling there?
|
||||||
# let this fail for now
|
# let this fail for now
|
||||||
my $ret = $self->get_fact_learn( "learn $subject as $result",
|
my $ret = $self->get_fact_learn("learn $subject as $result", $name, $said, $subject, $result);
|
||||||
$name, $said, $subject, $result );
|
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
|
} else {
|
||||||
|
return "Can't use dangerous things in a regex, you naughty user";
|
||||||
}
|
}
|
||||||
else {
|
} else {
|
||||||
return
|
|
||||||
"Can't use dangerous things in a regex, you naughty user";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return "Can't substitute on unknown factoid [$subject]";
|
return "Can't substitute on unknown factoid [$subject]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -673,8 +593,7 @@ sub get_fact_revert ( $self, $subject, $name, $said ) {
|
||||||
my ($server, $namespace) = $self->get_namespace($said);
|
my ($server, $namespace) = $self->get_namespace($said);
|
||||||
|
|
||||||
#XXX check permissions here
|
#XXX check permissions here
|
||||||
return
|
return "Insufficient permissions for reverting protected factoid [$subject]"
|
||||||
"Insufficient permissions for reverting protected factoid [$subject]"
|
|
||||||
if (!$self->_db_check_perm($subject, $said));
|
if (!$self->_db_check_perm($subject, $said));
|
||||||
|
|
||||||
$subject =~ s/^\s*(\d+)\s*$//
|
$subject =~ s/^\s*(\d+)\s*$//
|
||||||
|
@ -689,16 +608,13 @@ sub get_fact_revert ( $self, $subject, $name, $said ) {
|
||||||
$rev_id
|
$rev_id
|
||||||
);
|
);
|
||||||
|
|
||||||
my $protect =
|
my $protect = $self->_db_get_protect($fact_rev->{subject}, $server, $namespace);
|
||||||
$self->_db_get_protect( $fact_rev->{subject}, $server, $namespace );
|
|
||||||
|
|
||||||
return "Bad revision id"
|
return "Bad revision id"
|
||||||
unless $fact_rev and $fact_rev->{subject}; # Make sure it's valid..
|
unless $fact_rev and $fact_rev->{subject}; # Make sure it's valid..
|
||||||
|
|
||||||
# subject, copula, predicate
|
# subject, copula, predicate
|
||||||
$self->_insert_factoid( $name,
|
$self->_insert_factoid($name, @$fact_rev{qw"subject copula predicate compose_macro"}, $protect, $aliasserver, $aliasnamespace);
|
||||||
@$fact_rev{qw"subject copula predicate compose_macro"},
|
|
||||||
$protect, $aliasserver, $aliasnamespace );
|
|
||||||
|
|
||||||
return "Reverted $fact_rev->{subject} to revision $rev_id";
|
return "Reverted $fact_rev->{subject} to revision $rev_id";
|
||||||
}
|
}
|
||||||
|
@ -719,9 +635,7 @@ sub get_fact_learn ( $self, $body, $name, $said, $subject, $predicate ) {
|
||||||
if (!$self->_db_check_perm($subject, $said));
|
if (!$self->_db_check_perm($subject, $said));
|
||||||
|
|
||||||
#my @ret = $self->store_factoid( $name, $said->{body} );
|
#my @ret = $self->store_factoid( $name, $said->{body} );
|
||||||
$self->_insert_factoid( $name, $subject, 'is', $predicate, 0,
|
$self->_insert_factoid($name, $subject, 'is', $predicate, 0, $self->_db_get_protect($subject), $aliasserver, $aliasnamespace);
|
||||||
$self->_db_get_protect($subject),
|
|
||||||
$aliasserver, $aliasnamespace );
|
|
||||||
|
|
||||||
return "Stored $subject as $predicate";
|
return "Stored $subject as $predicate";
|
||||||
}
|
}
|
||||||
|
@ -751,8 +665,8 @@ sub get_fact_search ( $self, $body, $name ) {
|
||||||
{ Slice => {} },
|
{ Slice => {} },
|
||||||
$search, $search,
|
$search, $search,
|
||||||
);
|
);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
#XXX: need to also search contents of factoids TODO
|
#XXX: need to also search contents of factoids TODO
|
||||||
$results = $self->dbh->selectall_arrayref(
|
$results = $self->dbh->selectall_arrayref(
|
||||||
"SELECT subject,copula,predicate
|
"SELECT subject,copula,predicate
|
||||||
|
@ -774,8 +688,7 @@ sub get_fact_search ( $self, $body, $name ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return $ret_string;
|
return $ret_string;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return "No matches.";
|
return "No matches.";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -847,8 +760,7 @@ sub _db_get_fact ( $self, $subj, $func, $namespace, $server ) {
|
||||||
|
|
||||||
if ($func && (!$fact->{compose_macro})) {
|
if ($func && (!$fact->{compose_macro})) {
|
||||||
return undef;
|
return undef;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return $fact;
|
return $fact;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -882,16 +794,14 @@ sub basic_get_fact {
|
||||||
|
|
||||||
local $said->{macro_arg} = $arg;
|
local $said->{macro_arg} = $arg;
|
||||||
local $said->{body} = $fact->{predicate};
|
local $said->{body} = $fact->{predicate};
|
||||||
local $said->{addressed} = 1
|
local $said->{addressed} = 1; # Force addressed to circumvent restrictions? May not be needed!
|
||||||
; # Force addressed to circumvent restrictions? May not be needed!
|
|
||||||
|
|
||||||
open(my $fh, ">/tmp/wutwut");
|
open(my $fh, ">/tmp/wutwut");
|
||||||
print $fh Dumper($said, $plugin, $pm);
|
print $fh Dumper($said, $plugin, $pm);
|
||||||
|
|
||||||
my $ret = $plugin->command($said, $pm);
|
my $ret = $plugin->command($said, $pm);
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
print $fh Dumper(
|
print $fh Dumper({ key => $key, arg => $arg, fact => $fact, ret => $ret });
|
||||||
{ key => $key, arg => $arg, fact => $fact, ret => $ret } );
|
|
||||||
|
|
||||||
# $ret = "die 'fuck me silly';";
|
# $ret = "die 'fuck me silly';";
|
||||||
|
|
||||||
|
@ -899,19 +809,16 @@ sub basic_get_fact {
|
||||||
$ret = "\x00$ret" if ($key eq "tell");
|
$ret = "\x00$ret" if ($key eq "tell");
|
||||||
|
|
||||||
return $ret;
|
return $ret;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
return "$fact->{predicate}";
|
return "$fact->{predicate}";
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
if ($subject =~ /[\?\.\!]$/
|
if ($subject =~ /[\?\.\!]$/
|
||||||
) #check if some asshole decided to add a ? at the end of the factoid, if so remove it and recurse, this should only be able to recurse N times so it should be fine
|
) #check if some asshole decided to add a ? at the end of the factoid, if so remove it and recurse, this should only be able to recurse N times so it should be fine
|
||||||
{
|
{
|
||||||
my $newsubject = $subject;
|
my $newsubject = $subject;
|
||||||
$newsubject =~ s/[\?\.\!]$//;
|
$newsubject =~ s/[\?\.\!]$//;
|
||||||
return $self->basic_get_fact( $pm, $said, $newsubject, $name,
|
return $self->basic_get_fact($pm, $said, $newsubject, $name, $call_only);
|
||||||
$call_only );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
my $metaphone = Metaphone(_clean_subject($subject, 1));
|
my $metaphone = Metaphone(_clean_subject($subject, 1));
|
||||||
|
@ -921,10 +828,8 @@ sub basic_get_fact {
|
||||||
push @{ $said->{metaphone_matches} }, @$matches;
|
push @{ $said->{metaphone_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 " ",
|
return "No factoid found. Did you mean one of these: " . join " ", map "[$_]", @$matches;
|
||||||
map "[$_]", @$matches;
|
} else {
|
||||||
}
|
|
||||||
else {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue