From 48e1c8c4555fe6f3eedd222c20a586999bc7ff6e Mon Sep 17 00:00:00 2001 From: Pragmatic Software Date: Wed, 23 Jun 2010 02:15:13 +0000 Subject: [PATCH] add, info, show, remove, etc, renamed to factadd, factinfo, factshow, factrem, etc; fact* commands now all take a channel parameter --- PBot/FactoidCommands.pm | 105 ++++++++++++++++++++-------------------- PBot/Interpreter.pm | 2 +- data/factoids | 49 ++++++++++++------- 3 files changed, 84 insertions(+), 72 deletions(-) diff --git a/PBot/FactoidCommands.pm b/PBot/FactoidCommands.pm index e9c9bc3f..d62ddb2f 100644 --- a/PBot/FactoidCommands.pm +++ b/PBot/FactoidCommands.pm @@ -37,27 +37,28 @@ sub initialize { $self->{pbot} = $pbot; - $pbot->commands->register(sub { return $self->list(@_) }, "list", 0); - $pbot->commands->register(sub { return $self->alias(@_) }, "alias", 0); - $pbot->commands->register(sub { return $self->add_regex(@_) }, "regex", 0); - $pbot->commands->register(sub { return $self->add_text(@_) }, "add", 0); - $pbot->commands->register(sub { return $self->add_text(@_) }, "learn", 0); - $pbot->commands->register(sub { return $self->histogram(@_) }, "histogram", 0); - $pbot->commands->register(sub { return $self->show(@_) }, "show", 0); - $pbot->commands->register(sub { return $self->info(@_) }, "info", 0); - $pbot->commands->register(sub { return $self->top20(@_) }, "top20", 0); - $pbot->commands->register(sub { return $self->count(@_) }, "count", 0); - $pbot->commands->register(sub { return $self->find(@_) }, "find", 0); - $pbot->commands->register(sub { return $self->change_text(@_) }, "change", 0); - $pbot->commands->register(sub { return $self->remove_text(@_) }, "remove", 0); - $pbot->commands->register(sub { return $self->remove_text(@_) }, "forget", 0); + $pbot->commands->register(sub { return $self->factadd(@_) }, "learn", 0); + $pbot->commands->register(sub { return $self->factadd(@_) }, "factadd", 0); + $pbot->commands->register(sub { return $self->factrem(@_) }, "forget", 0); + $pbot->commands->register(sub { return $self->factrem(@_) }, "factrem", 0); + $pbot->commands->register(sub { return $self->factshow(@_) }, "factshow", 0); + $pbot->commands->register(sub { return $self->factinfo(@_) }, "factinfo", 0); + $pbot->commands->register(sub { return $self->factset(@_) }, "factset", 10); + $pbot->commands->register(sub { return $self->factunset(@_) }, "factunset", 10); + $pbot->commands->register(sub { return $self->factchange(@_) }, "factchange", 0); + $pbot->commands->register(sub { return $self->factalias(@_) }, "factalias", 0); + $pbot->commands->register(sub { return $self->call_factoid(@_) }, "fact", 0); + + $pbot->commands->register(sub { return $self->list(@_) }, "list", 0); + $pbot->commands->register(sub { return $self->add_regex(@_) }, "regex", 0); + $pbot->commands->register(sub { return $self->histogram(@_) }, "histogram", 0); + $pbot->commands->register(sub { return $self->top20(@_) }, "top20", 0); + $pbot->commands->register(sub { return $self->count(@_) }, "count", 0); + $pbot->commands->register(sub { return $self->find(@_) }, "find", 0); $pbot->commands->register(sub { return $self->load_module(@_) }, "load", 50); $pbot->commands->register(sub { return $self->unload_module(@_) }, "unload", 50); $pbot->commands->register(sub { return $self->enable_command(@_) }, "enable", 10); $pbot->commands->register(sub { return $self->disable_command(@_) }, "disable", 10); - $pbot->commands->register(sub { return $self->factset(@_) }, "factset", 10); - $pbot->commands->register(sub { return $self->factunset(@_) }, "factunset", 10); - $pbot->commands->register(sub { return $self->call_factoid(@_) }, "fact", 0); } sub call_factoid { @@ -200,28 +201,27 @@ sub list { return "/msg $nick Usage: list "; } -sub alias { +sub factalias { my $self = shift; my ($from, $nick, $user, $host, $arguments) = @_; - my ($alias, $command) = $arguments =~ /^(.*?)\s+(.*)$/ if defined $arguments; + my ($chan, $alias, $command) = split / /, $arguments, 3 if defined $arguments; if(not defined $command) { - return "Usage: alias "; + return "Usage: factalias "; } - $from = '.*' if not defined $from or $from !~ /^#/; - my ($channel, $alias_trigger) = $self->{pbot}->factoids->find_factoid($from, $alias, undef, 1); + my ($channel, $alias_trigger) = $self->{pbot}->factoids->find_factoid($chan, $alias, undef, 1); if(defined $alias_trigger) { $self->{pbot}->logger->log("attempt to overwrite existing command\n"); return "/msg $nick '$alias_trigger' already exists for channel $channel"; } - $self->{pbot}->factoids->add_factoid('text', $from, $nick, $alias, "/call $command"); + $self->{pbot}->factoids->add_factoid('text', $chan, $nick, $alias, "/call $command"); - $self->{pbot}->logger->log("$nick!$user\@$host [$from] aliased $alias => $command\n"); + $self->{pbot}->logger->log("$nick!$user\@$host [$chan] aliased $alias => $command\n"); $self->{pbot}->factoids->save_factoids(); - return "/msg $nick '$alias' aliases '$command' for channel $from"; + return "/msg $nick '$alias' aliases '$command' for channel $chan"; } sub add_regex { @@ -258,18 +258,16 @@ sub add_regex { return "/msg $nick $keyword added."; } -sub add_text { +sub factadd { my $self = shift; my ($from, $nick, $user, $host, $arguments) = @_; - my ($keyword, $text) = $arguments =~ /^(.*?)\s+is\s+(.*)$/i if defined $arguments; + my ($from_chan, $keyword, $text) = $arguments =~ /^(.*?)\s+(.*?)\s+is\s+(.*)$/i if defined $arguments; - if(not defined $text or not defined $keyword) { - return "/msg $nick Usage: add is "; + if(not defined $from_chan or not defined $text or not defined $keyword) { + return "/msg $nick Usage: factadd is "; } - $from = '.*' if not defined $from or $from !~ /^#/; - - my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from, $keyword, undef, 1); + my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from_chan, $keyword, undef, 1); if(defined $trigger) { $self->{pbot}->logger->log("$nick!$user\@$host attempt to overwrite $keyword\n"); @@ -277,27 +275,27 @@ sub add_text { return "/msg $nick $keyword already exists."; } - $self->{pbot}->factoids->add_factoid('text', $from, $nick, $keyword, $text); + $self->{pbot}->factoids->add_factoid('text', $from_chan, $nick, $keyword, $text); $self->{pbot}->logger->log("$nick!$user\@$host added $keyword => $text\n"); return "/msg $nick '$keyword' added."; } -sub remove_text { +sub factrem { my $self = shift; my ($from, $nick, $user, $host, $arguments) = @_; my $factoids = $self->{pbot}->factoids->factoids->hash; - $from = '.*' if not defined $from or $from !~ /^#/; + my ($from_chan, $from_trigger) = split / /, $arguments; - if(not defined $arguments) { - return "/msg $nick Usage: remove "; + if(not defined $from_chan or not defined $from_trigger) { + return "/msg $nick Usage: factrem "; } - my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from, $arguments); + my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from_chan, $from_trigger, undef, 1); if(not defined $trigger) { - return "/msg $nick $arguments not found in channel $from."; + return "/msg $nick $from_trigger not found in channel $from_chan."; } if($factoids->{$channel}->{$trigger}->{type} eq 'module') { @@ -342,7 +340,7 @@ sub histogram { return "$factoid_count factoids, top 10 submitters: $text"; } -sub show { +sub factshow { my $self = shift; my ($from, $nick, $user, $host, $arguments) = @_; my $factoids = $self->{pbot}->factoids->factoids->hash; @@ -350,13 +348,13 @@ sub show { my ($chan, $trig) = split / /, $arguments; if(not defined $chan or not defined $trig) { - return "Usage: show "; + return "Usage: factshow "; } my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($chan, $trig); if(not defined $trigger) { - return "/msg $nick '$trig' not found in channel '$chan' (did you mean channel '.*'?"; + return "/msg $nick '$trig' not found in channel '$chan'"; } if($factoids->{$channel}->{$trigger}->{type} eq 'module') { @@ -366,7 +364,7 @@ sub show { return "$trigger: " . $factoids->{$channel}->{$trigger}->{action}; } -sub info { +sub factinfo { my $self = shift; my ($from, $nick, $user, $host, $arguments) = @_; my $factoids = $self->{pbot}->factoids->factoids->hash; @@ -374,13 +372,13 @@ sub info { my ($chan, $trig) = split / /, $arguments; if(not defined $chan or not defined $trig) { - return "Usage: info "; + return "Usage: factinfo "; } my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($chan, $trig); if(not defined $trigger) { - return "'$trig' not found in channel '$chan' (did you mean channel '.*'?"; + return "'$trig' not found in channel '$chan'"; } my $created_ago = ago(gettimeofday - $factoids->{$channel}->{$trigger}->{created_on}); @@ -570,16 +568,17 @@ sub find { } } -sub change_text { +sub factchange { my $self = shift; my ($from, $nick, $user, $host, $arguments) = @_; my $factoids = $self->{pbot}->factoids->factoids->hash; - my ($keyword, $delim, $tochange, $changeto, $modifier); + my ($channel, $trigger, $keyword, $delim, $tochange, $changeto, $modifier); if(defined $arguments) { - if($arguments =~ /^(.*?)\s+s(.)/) { - $keyword = $1; - $delim = $2; + if($arguments =~ /^([^\s]+) ([^\s]+)\s+s(.)/) { + $channel = $1; + $keyword = $2; + $delim = $3; } if($arguments =~ /$delim(.*?)$delim(.*)$delim(.*)?$/) { @@ -589,11 +588,11 @@ sub change_text { } } - if(not defined $changeto) { - return "/msg $nick Usage: change s///"; + if(not defined $channel or not defined $changeto) { + return "/msg $nick Usage: factchange s///"; } - my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from, $keyword); + ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($channel, $keyword); if(not defined $trigger) { return "/msg $nick $keyword not found in channel $from."; diff --git a/PBot/Interpreter.pm b/PBot/Interpreter.pm index 5daf6d01..34147d78 100644 --- a/PBot/Interpreter.pm +++ b/PBot/Interpreter.pm @@ -185,7 +185,7 @@ sub interpret { if(defined $trigger) { ($keyword, $arguments) = ($k, "is $a"); } else { - ($keyword, $arguments) = ("add", join(' is ', $k, $a)); + ($keyword, $arguments) = ("factadd", "$from $k is $a"); } } elsif($command =~ /^(.*?)\s+(.*)$/) { ($keyword, $arguments) = ($1, $2); diff --git a/data/factoids b/data/factoids index ec24de82..d68784fa 100644 --- a/data/factoids +++ b/data/factoids @@ -14,10 +14,10 @@ type: text action: /say This is a test in #pbot2! created_on: 1277000257.49081 enabled: 1 -last_referenced_on: 1277165616.24181 +last_referenced_on: 1277258183.307 owner: pbot3 rate_limit: 10 -ref_count: 16 +ref_count: 17 ref_user: pragma_ type: text @@ -3485,13 +3485,14 @@ ref_user: notk0 type: text -action: am -created_on: 1194414293 +action: /call factalias +created_on: 1277259091.375 enabled: 1 -owner: Draconx|Laptop +last_referenced_on: 1277259146.81587 +owner: pbot3 rate_limit: 15 -ref_count: 0 -ref_user: nobody +ref_count: 3 +ref_user: pbot3 type: text @@ -6070,11 +6071,11 @@ type: text action: /say $hi_phrases, $nick created_on: 1109044278 enabled: 1 -last_referenced_on: 1277163209.95677 +last_referenced_on: 1277259066.50343 owner: pragma_ rate_limit: 15 -ref_count: 868 -ref_user: angstrom +ref_count: 878 +ref_user: pbot3 type: text @@ -6350,6 +6351,17 @@ ref_count: 1 ref_user: pragma_ type: text + +action: /call factinfo +created_on: 1277259101.38088 +enabled: 1 +last_referenced_on: 1277259105.95312 +owner: pbot3 +rate_limit: 15 +ref_count: 1 +ref_user: pbot3 +type: text + action: /say A function declared with an inline function specifier is an inline function. Making a function an inline function suggests that calls to the function be as fast as possible. If you use `inline', always use `static', too. created_on: 1273526791 @@ -8628,13 +8640,14 @@ ref_user: nobody type: regex -action: oort -created_on: 1264736132 +action: /call factshow +created_on: 1277259146.86343 enabled: 1 -owner: tolkad +last_referenced_on: 1277259153.35938 +owner: pbot3 rate_limit: 15 -ref_count: 0 -ref_user: nobody +ref_count: 1 +ref_user: pbot3 type: text @@ -9870,11 +9883,11 @@ ref_user: pragma_ type: text -action: /say PBot revision 195 2010-06-21 -created_on: 1277176857.09794 +action: /say PBot revision 198 2010-06-22 +created_on: 1277259006.35938 enabled: 1 last_referenced_on: 1277163757.64518 -owner: candide +owner: pbot3 rate_limit: 15 ref_count: 0 ref_user: nobody