mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-03 16:42:38 +01:00
add, info, show, remove, etc, renamed to factadd, factinfo, factshow, factrem, etc; fact* commands now all take a channel parameter
This commit is contained in:
parent
4d023df17d
commit
48e1c8c455
@ -37,27 +37,28 @@ sub initialize {
|
|||||||
|
|
||||||
$self->{pbot} = $pbot;
|
$self->{pbot} = $pbot;
|
||||||
|
|
||||||
$pbot->commands->register(sub { return $self->list(@_) }, "list", 0);
|
$pbot->commands->register(sub { return $self->factadd(@_) }, "learn", 0);
|
||||||
$pbot->commands->register(sub { return $self->alias(@_) }, "alias", 0);
|
$pbot->commands->register(sub { return $self->factadd(@_) }, "factadd", 0);
|
||||||
$pbot->commands->register(sub { return $self->add_regex(@_) }, "regex", 0);
|
$pbot->commands->register(sub { return $self->factrem(@_) }, "forget", 0);
|
||||||
$pbot->commands->register(sub { return $self->add_text(@_) }, "add", 0);
|
$pbot->commands->register(sub { return $self->factrem(@_) }, "factrem", 0);
|
||||||
$pbot->commands->register(sub { return $self->add_text(@_) }, "learn", 0);
|
$pbot->commands->register(sub { return $self->factshow(@_) }, "factshow", 0);
|
||||||
$pbot->commands->register(sub { return $self->histogram(@_) }, "histogram", 0);
|
$pbot->commands->register(sub { return $self->factinfo(@_) }, "factinfo", 0);
|
||||||
$pbot->commands->register(sub { return $self->show(@_) }, "show", 0);
|
$pbot->commands->register(sub { return $self->factset(@_) }, "factset", 10);
|
||||||
$pbot->commands->register(sub { return $self->info(@_) }, "info", 0);
|
$pbot->commands->register(sub { return $self->factunset(@_) }, "factunset", 10);
|
||||||
$pbot->commands->register(sub { return $self->top20(@_) }, "top20", 0);
|
$pbot->commands->register(sub { return $self->factchange(@_) }, "factchange", 0);
|
||||||
$pbot->commands->register(sub { return $self->count(@_) }, "count", 0);
|
$pbot->commands->register(sub { return $self->factalias(@_) }, "factalias", 0);
|
||||||
$pbot->commands->register(sub { return $self->find(@_) }, "find", 0);
|
$pbot->commands->register(sub { return $self->call_factoid(@_) }, "fact", 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->list(@_) }, "list", 0);
|
||||||
$pbot->commands->register(sub { return $self->remove_text(@_) }, "forget", 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->load_module(@_) }, "load", 50);
|
||||||
$pbot->commands->register(sub { return $self->unload_module(@_) }, "unload", 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->enable_command(@_) }, "enable", 10);
|
||||||
$pbot->commands->register(sub { return $self->disable_command(@_) }, "disable", 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 {
|
sub call_factoid {
|
||||||
@ -200,28 +201,27 @@ sub list {
|
|||||||
return "/msg $nick Usage: list <modules|commands|factoids|admins>";
|
return "/msg $nick Usage: list <modules|commands|factoids|admins>";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub alias {
|
sub factalias {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
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) {
|
if(not defined $command) {
|
||||||
return "Usage: alias <keyword> <command>";
|
return "Usage: factalias <channel> <keyword> <command>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$from = '.*' if not defined $from or $from !~ /^#/;
|
my ($channel, $alias_trigger) = $self->{pbot}->factoids->find_factoid($chan, $alias, undef, 1);
|
||||||
my ($channel, $alias_trigger) = $self->{pbot}->factoids->find_factoid($from, $alias, undef, 1);
|
|
||||||
|
|
||||||
if(defined $alias_trigger) {
|
if(defined $alias_trigger) {
|
||||||
$self->{pbot}->logger->log("attempt to overwrite existing command\n");
|
$self->{pbot}->logger->log("attempt to overwrite existing command\n");
|
||||||
return "/msg $nick '$alias_trigger' already exists for channel $channel";
|
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();
|
$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 {
|
sub add_regex {
|
||||||
@ -258,18 +258,16 @@ sub add_regex {
|
|||||||
return "/msg $nick $keyword added.";
|
return "/msg $nick $keyword added.";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub add_text {
|
sub factadd {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
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) {
|
if(not defined $from_chan or not defined $text or not defined $keyword) {
|
||||||
return "/msg $nick Usage: add <keyword> is <factoid>";
|
return "/msg $nick Usage: factadd <channel> <keyword> is <factoid>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$from = '.*' if not defined $from or $from !~ /^#/;
|
my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from_chan, $keyword, undef, 1);
|
||||||
|
|
||||||
my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from, $keyword, undef, 1);
|
|
||||||
|
|
||||||
if(defined $trigger) {
|
if(defined $trigger) {
|
||||||
$self->{pbot}->logger->log("$nick!$user\@$host attempt to overwrite $keyword\n");
|
$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.";
|
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");
|
$self->{pbot}->logger->log("$nick!$user\@$host added $keyword => $text\n");
|
||||||
return "/msg $nick '$keyword' added.";
|
return "/msg $nick '$keyword' added.";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub remove_text {
|
sub factrem {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
||||||
my $factoids = $self->{pbot}->factoids->factoids->hash;
|
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) {
|
if(not defined $from_chan or not defined $from_trigger) {
|
||||||
return "/msg $nick Usage: remove <keyword>";
|
return "/msg $nick Usage: factrem <channel> <keyword>";
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
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') {
|
if($factoids->{$channel}->{$trigger}->{type} eq 'module') {
|
||||||
@ -342,7 +340,7 @@ sub histogram {
|
|||||||
return "$factoid_count factoids, top 10 submitters: $text";
|
return "$factoid_count factoids, top 10 submitters: $text";
|
||||||
}
|
}
|
||||||
|
|
||||||
sub show {
|
sub factshow {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
||||||
my $factoids = $self->{pbot}->factoids->factoids->hash;
|
my $factoids = $self->{pbot}->factoids->factoids->hash;
|
||||||
@ -350,13 +348,13 @@ sub show {
|
|||||||
my ($chan, $trig) = split / /, $arguments;
|
my ($chan, $trig) = split / /, $arguments;
|
||||||
|
|
||||||
if(not defined $chan or not defined $trig) {
|
if(not defined $chan or not defined $trig) {
|
||||||
return "Usage: show <channel> <trigger>";
|
return "Usage: factshow <channel> <trigger>";
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($chan, $trig);
|
my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($chan, $trig);
|
||||||
|
|
||||||
if(not defined $trigger) {
|
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') {
|
if($factoids->{$channel}->{$trigger}->{type} eq 'module') {
|
||||||
@ -366,7 +364,7 @@ sub show {
|
|||||||
return "$trigger: " . $factoids->{$channel}->{$trigger}->{action};
|
return "$trigger: " . $factoids->{$channel}->{$trigger}->{action};
|
||||||
}
|
}
|
||||||
|
|
||||||
sub info {
|
sub factinfo {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
||||||
my $factoids = $self->{pbot}->factoids->factoids->hash;
|
my $factoids = $self->{pbot}->factoids->factoids->hash;
|
||||||
@ -374,13 +372,13 @@ sub info {
|
|||||||
my ($chan, $trig) = split / /, $arguments;
|
my ($chan, $trig) = split / /, $arguments;
|
||||||
|
|
||||||
if(not defined $chan or not defined $trig) {
|
if(not defined $chan or not defined $trig) {
|
||||||
return "Usage: info <channel> <trigger>";
|
return "Usage: factinfo <channel> <trigger>";
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($chan, $trig);
|
my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($chan, $trig);
|
||||||
|
|
||||||
if(not defined $trigger) {
|
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});
|
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 $self = shift;
|
||||||
my ($from, $nick, $user, $host, $arguments) = @_;
|
my ($from, $nick, $user, $host, $arguments) = @_;
|
||||||
my $factoids = $self->{pbot}->factoids->factoids->hash;
|
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(defined $arguments) {
|
||||||
if($arguments =~ /^(.*?)\s+s(.)/) {
|
if($arguments =~ /^([^\s]+) ([^\s]+)\s+s(.)/) {
|
||||||
$keyword = $1;
|
$channel = $1;
|
||||||
$delim = $2;
|
$keyword = $2;
|
||||||
|
$delim = $3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($arguments =~ /$delim(.*?)$delim(.*)$delim(.*)?$/) {
|
if($arguments =~ /$delim(.*?)$delim(.*)$delim(.*)?$/) {
|
||||||
@ -589,11 +588,11 @@ sub change_text {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(not defined $changeto) {
|
if(not defined $channel or not defined $changeto) {
|
||||||
return "/msg $nick Usage: change <keyword> s/<pattern>/<replacement>/";
|
return "/msg $nick Usage: factchange <channel> <keyword> s/<pattern>/<replacement>/";
|
||||||
}
|
}
|
||||||
|
|
||||||
my ($channel, $trigger) = $self->{pbot}->factoids->find_factoid($from, $keyword);
|
($channel, $trigger) = $self->{pbot}->factoids->find_factoid($channel, $keyword);
|
||||||
|
|
||||||
if(not defined $trigger) {
|
if(not defined $trigger) {
|
||||||
return "/msg $nick $keyword not found in channel $from.";
|
return "/msg $nick $keyword not found in channel $from.";
|
||||||
|
@ -185,7 +185,7 @@ sub interpret {
|
|||||||
if(defined $trigger) {
|
if(defined $trigger) {
|
||||||
($keyword, $arguments) = ($k, "is $a");
|
($keyword, $arguments) = ($k, "is $a");
|
||||||
} else {
|
} else {
|
||||||
($keyword, $arguments) = ("add", join(' is ', $k, $a));
|
($keyword, $arguments) = ("factadd", "$from $k is $a");
|
||||||
}
|
}
|
||||||
} elsif($command =~ /^(.*?)\s+(.*)$/) {
|
} elsif($command =~ /^(.*?)\s+(.*)$/) {
|
||||||
($keyword, $arguments) = ($1, $2);
|
($keyword, $arguments) = ($1, $2);
|
||||||
|
@ -14,10 +14,10 @@ type: text
|
|||||||
action: /say This is a test in #pbot2!
|
action: /say This is a test in #pbot2!
|
||||||
created_on: 1277000257.49081
|
created_on: 1277000257.49081
|
||||||
enabled: 1
|
enabled: 1
|
||||||
last_referenced_on: 1277165616.24181
|
last_referenced_on: 1277258183.307
|
||||||
owner: pbot3
|
owner: pbot3
|
||||||
rate_limit: 10
|
rate_limit: 10
|
||||||
ref_count: 16
|
ref_count: 17
|
||||||
ref_user: pragma_
|
ref_user: pragma_
|
||||||
type: text
|
type: text
|
||||||
|
|
||||||
@ -3485,13 +3485,14 @@ ref_user: notk0
|
|||||||
type: text
|
type: text
|
||||||
|
|
||||||
<alias>
|
<alias>
|
||||||
action: am
|
action: /call factalias
|
||||||
created_on: 1194414293
|
created_on: 1277259091.375
|
||||||
enabled: 1
|
enabled: 1
|
||||||
owner: Draconx|Laptop
|
last_referenced_on: 1277259146.81587
|
||||||
|
owner: pbot3
|
||||||
rate_limit: 15
|
rate_limit: 15
|
||||||
ref_count: 0
|
ref_count: 3
|
||||||
ref_user: nobody
|
ref_user: pbot3
|
||||||
type: text
|
type: text
|
||||||
|
|
||||||
<aliases>
|
<aliases>
|
||||||
@ -6070,11 +6071,11 @@ type: text
|
|||||||
action: /say $hi_phrases, $nick
|
action: /say $hi_phrases, $nick
|
||||||
created_on: 1109044278
|
created_on: 1109044278
|
||||||
enabled: 1
|
enabled: 1
|
||||||
last_referenced_on: 1277163209.95677
|
last_referenced_on: 1277259066.50343
|
||||||
owner: pragma_
|
owner: pragma_
|
||||||
rate_limit: 15
|
rate_limit: 15
|
||||||
ref_count: 868
|
ref_count: 878
|
||||||
ref_user: angstrom
|
ref_user: pbot3
|
||||||
type: text
|
type: text
|
||||||
|
|
||||||
<hi_phrases>
|
<hi_phrases>
|
||||||
@ -6350,6 +6351,17 @@ ref_count: 1
|
|||||||
ref_user: pragma_
|
ref_user: pragma_
|
||||||
type: text
|
type: text
|
||||||
|
|
||||||
|
<info>
|
||||||
|
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
|
||||||
|
|
||||||
<inline>
|
<inline>
|
||||||
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.
|
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
|
created_on: 1273526791
|
||||||
@ -8628,13 +8640,14 @@ ref_user: nobody
|
|||||||
type: regex
|
type: regex
|
||||||
|
|
||||||
<show>
|
<show>
|
||||||
action: oort
|
action: /call factshow
|
||||||
created_on: 1264736132
|
created_on: 1277259146.86343
|
||||||
enabled: 1
|
enabled: 1
|
||||||
owner: tolkad
|
last_referenced_on: 1277259153.35938
|
||||||
|
owner: pbot3
|
||||||
rate_limit: 15
|
rate_limit: 15
|
||||||
ref_count: 0
|
ref_count: 1
|
||||||
ref_user: nobody
|
ref_user: pbot3
|
||||||
type: text
|
type: text
|
||||||
|
|
||||||
<sicp>
|
<sicp>
|
||||||
@ -9870,11 +9883,11 @@ ref_user: pragma_
|
|||||||
type: text
|
type: text
|
||||||
|
|
||||||
<version>
|
<version>
|
||||||
action: /say PBot revision 195 2010-06-21
|
action: /say PBot revision 198 2010-06-22
|
||||||
created_on: 1277176857.09794
|
created_on: 1277259006.35938
|
||||||
enabled: 1
|
enabled: 1
|
||||||
last_referenced_on: 1277163757.64518
|
last_referenced_on: 1277163757.64518
|
||||||
owner: candide
|
owner: pbot3
|
||||||
rate_limit: 15
|
rate_limit: 15
|
||||||
ref_count: 0
|
ref_count: 0
|
||||||
ref_user: nobody
|
ref_user: nobody
|
||||||
|
Loading…
Reference in New Issue
Block a user