Add -editby to factfind, move some responses from /msg to public

This commit is contained in:
Pragmatic Software 2014-06-01 21:31:54 +00:00
parent 2cb5d60b51
commit 33765c6d3a
1 changed files with 48 additions and 36 deletions

View File

@ -194,7 +194,7 @@ sub list {
my $text; my $text;
if(not defined $arguments) { if(not defined $arguments) {
return "/msg $nick Usage: list <modules|factoids|commands|admins>"; return "Usage: list <modules|factoids|commands|admins>";
} }
# TODO - update this to use new MessageHistory API # TODO - update this to use new MessageHistory API
@ -309,7 +309,7 @@ sub list {
} }
return $text; return $text;
} }
return "/msg $nick Usage: list <modules|commands|factoids|admins>"; return "Usage: list <modules|commands|factoids|admins>";
} }
sub factmove { sub factmove {
@ -349,7 +349,7 @@ sub factmove {
if((lc $nick ne lc $owner) and (not $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host"))) { if((lc $nick ne lc $owner) and (not $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host"))) {
$self->{pbot}->{logger}->log("$nick!$user\@$host attempted to move [$found_src_channel] $found_source (not owner)\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host attempted to move [$found_src_channel] $found_source (not owner)\n");
my $chan = ($found_src_channel eq '.*' ? 'the global channel' : $found_src_channel); my $chan = ($found_src_channel eq '.*' ? 'the global channel' : $found_src_channel);
return "/msg $nick You are not the owner of $found_source for $chan"; return "You are not the owner of $found_source for $chan";
} }
if($factoids->{$found_src_channel}->{$found_source}->{'locked'}) { if($factoids->{$found_src_channel}->{$found_source}->{'locked'}) {
@ -391,14 +391,14 @@ sub factalias {
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 "'$alias_trigger' already exists for channel $channel";
} }
$self->{pbot}->{factoids}->add_factoid('text', $chan, "$nick!$user\@$host", $alias, "/call $command"); $self->{pbot}->{factoids}->add_factoid('text', $chan, "$nick!$user\@$host", $alias, "/call $command");
$self->{pbot}->{logger}->log("$nick!$user\@$host [$chan] 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 " . ($chan eq '.*' ? 'the global channel' : $chan); return "'$alias' aliases '$command' for " . ($chan eq '.*' ? 'the global channel' : $chan);
} }
sub add_regex { sub add_regex {
@ -427,12 +427,12 @@ sub add_regex {
if(defined $trigger) { if(defined $trigger) {
$self->{pbot}->{logger}->log("$nick!$user\@$host attempt to overwrite $trigger\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host attempt to overwrite $trigger\n");
return "/msg $nick $trigger already exists for channel $channel."; return "$trigger already exists for channel $channel.";
} }
$self->{pbot}->{factoids}->add_factoid('regex', $from, "$nick!$user\@$host", $keyword, $text); $self->{pbot}->{factoids}->add_factoid('regex', $from, "$nick!$user\@$host", $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 "$keyword added.";
} }
sub factadd { sub factadd {
@ -441,7 +441,7 @@ sub factadd {
my ($from_chan, $keyword, $text) = $arguments =~ /^(\S+)\s+(\S+)\s+is\s+(.*)$/i if defined $arguments; my ($from_chan, $keyword, $text) = $arguments =~ /^(\S+)\s+(\S+)\s+is\s+(.*)$/i if defined $arguments;
if(not defined $from_chan or not defined $text or not defined $keyword) { if(not defined $from_chan or not defined $text or not defined $keyword) {
return "/msg $nick Usage: factadd <channel> <keyword> is <factoid>"; return "Usage: factadd <channel> <keyword> is <factoid>";
} }
$from_chan = '.*' if not $from_chan =~ m/^#/; $from_chan = '.*' if not $from_chan =~ m/^#/;
@ -450,13 +450,13 @@ sub factadd {
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");
return "/msg $nick $keyword already exists for " . ($from_chan eq '.*' ? 'global channel' : $from_chan) . "."; return "$keyword already exists for " . ($from_chan eq '.*' ? 'global channel' : $from_chan) . ".";
} }
$self->{pbot}->{factoids}->add_factoid('text', $from_chan, "$nick!$user\@$host", $keyword, $text); $self->{pbot}->{factoids}->add_factoid('text', $from_chan, "$nick!$user\@$host", $keyword, $text);
$self->{pbot}->{logger}->log("$nick!$user\@$host added [$from_chan] $keyword => $text\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host added [$from_chan] $keyword => $text\n");
return "/msg $nick '$keyword' added to " . ($from_chan eq '.*' ? 'global channel' : $from_chan) . "."; return "$keyword added to " . ($from_chan eq '.*' ? 'global channel' : $from_chan) . ".";
} }
sub factrem { sub factrem {
@ -467,18 +467,18 @@ sub factrem {
my ($from_chan, $from_trigger) = split / /, $arguments; my ($from_chan, $from_trigger) = split / /, $arguments;
if(not defined $from_chan or not defined $from_trigger) { if(not defined $from_chan or not defined $from_trigger) {
return "/msg $nick Usage: factrem <channel> <keyword>"; return "Usage: factrem <channel> <keyword>";
} }
my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from_chan, $from_trigger, undef, 1, 1); my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($from_chan, $from_trigger, undef, 1, 1);
if(not defined $trigger) { if(not defined $trigger) {
return "/msg $nick $from_trigger not found in channel $from_chan."; return "$from_trigger not found in channel $from_chan.";
} }
if($factoids->{$channel}->{$trigger}->{type} eq 'module') { if($factoids->{$channel}->{$trigger}->{type} eq 'module') {
$self->{pbot}->{logger}->log("$nick!$user\@$host attempted to remove $trigger [not factoid]\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host attempted to remove $trigger [not factoid]\n");
return "/msg $nick $trigger is not a factoid."; return "$trigger is not a factoid.";
} }
my ($owner) = $factoids->{$channel}->{$trigger}->{'owner'} =~ m/([^!]+)/; my ($owner) = $factoids->{$channel}->{$trigger}->{'owner'} =~ m/([^!]+)/;
@ -486,7 +486,7 @@ sub factrem {
if((lc $nick ne lc $owner) and (not $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host"))) { if((lc $nick ne lc $owner) and (not $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host"))) {
$self->{pbot}->{logger}->log("$nick!$user\@$host attempted to remove $trigger [not owner]\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host attempted to remove $trigger [not owner]\n");
my $chan = ($channel eq '.*' ? 'the global channel' : $channel); my $chan = ($channel eq '.*' ? 'the global channel' : $channel);
return "/msg $nick You are not the owner of $trigger for $chan"; return "You are not the owner of $trigger for $chan";
} }
if($factoids->{$channel}->{$trigger}->{'locked'}) { if($factoids->{$channel}->{$trigger}->{'locked'}) {
@ -495,7 +495,7 @@ sub factrem {
$self->{pbot}->{logger}->log("$nick!$user\@$host removed [$channel][$trigger][" . $factoids->{$channel}->{$trigger}->{action} . "]\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host removed [$channel][$trigger][" . $factoids->{$channel}->{$trigger}->{action} . "]\n");
$self->{pbot}->{factoids}->remove_factoid($channel, $trigger); $self->{pbot}->{factoids}->remove_factoid($channel, $trigger);
return "/msg $nick $trigger removed from " . ($channel eq '.*' ? 'the global channel' : $channel) . "."; return "$trigger removed from " . ($channel eq '.*' ? 'the global channel' : $channel) . ".";
} }
sub histogram { sub histogram {
@ -540,7 +540,7 @@ sub factshow {
my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $trig, undef, 0, 1); my ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($chan, $trig, undef, 0, 1);
if(not defined $trigger) { if(not defined $trigger) {
return "/msg $nick $trig not found in channel $chan"; return "$trig not found in channel $chan";
} }
my $result = "$trigger: " . $factoids->{$channel}->{$trigger}->{action}; my $result = "$trigger: " . $factoids->{$channel}->{$trigger}->{action};
@ -589,7 +589,7 @@ sub factinfo {
return "$trigger: Regex created by " . $factoids->{$channel}->{$trigger}->{owner} . " for $chan on " . localtime($factoids->{$channel}->{$trigger}->{created_on}) . " [$created_ago], " . (defined $factoids->{$channel}->{$trigger}->{edited_by} ? "last edited by $factoids->{$channel}->{$trigger}->{edited_by} on " . localtime($factoids->{$channel}->{$trigger}->{edited_on}) . " [" . ago(gettimeofday - $factoids->{$channel}->{$trigger}->{edited_on}) . "], " : "") . " used " . $factoids->{$channel}->{$trigger}->{ref_count} . " times (last by " . $factoids->{$channel}->{$trigger}->{ref_user} . (exists $factoids->{$channel}->{$trigger}->{last_referenced_on} ? " on " . localtime($factoids->{$channel}->{$trigger}->{last_referenced_on}) . " [$ref_ago]" : "") . ")"; return "$trigger: Regex created by " . $factoids->{$channel}->{$trigger}->{owner} . " for $chan on " . localtime($factoids->{$channel}->{$trigger}->{created_on}) . " [$created_ago], " . (defined $factoids->{$channel}->{$trigger}->{edited_by} ? "last edited by $factoids->{$channel}->{$trigger}->{edited_by} on " . localtime($factoids->{$channel}->{$trigger}->{edited_on}) . " [" . ago(gettimeofday - $factoids->{$channel}->{$trigger}->{edited_on}) . "], " : "") . " used " . $factoids->{$channel}->{$trigger}->{ref_count} . " times (last by " . $factoids->{$channel}->{$trigger}->{ref_user} . (exists $factoids->{$channel}->{$trigger}->{last_referenced_on} ? " on " . localtime($factoids->{$channel}->{$trigger}->{last_referenced_on}) . " [$ref_ago]" : "") . ")";
} }
return "/msg $nick $trigger is not a factoid or a module"; return "$trigger is not a factoid or a module";
} }
sub top20 { sub top20 {
@ -666,7 +666,7 @@ sub count {
my $total = 0; my $total = 0;
if(not defined $arguments) { if(not defined $arguments) {
return "/msg $nick Usage: count <nick|factoids>"; return "Usage: count <nick|factoids>";
} }
$arguments = ".*" if($arguments =~ /^factoids$/); $arguments = ".*" if($arguments =~ /^factoids$/);
@ -701,17 +701,19 @@ sub factfind {
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash; my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
if(not defined $arguments) { if(not defined $arguments) {
return "/msg $nick Usage: factfind [-channel channel] [-owner nick] [-by nick] [text]"; return "Usage: factfind [-channel channel] [-owner regex] [-editby regex] [-refby regex] [text]";
} }
my ($channel, $owner, $by); my ($channel, $owner, $refby, $editby);
$channel = $1 if $arguments =~ s/-channel\s+([^\b\s]+)//i; $channel = $1 if $arguments =~ s/-channel\s+([^\b\s]+)//i;
$owner = $1 if $arguments =~ s/-owner\s+([^\b\s]+)//i; $owner = $1 if $arguments =~ s/-owner\s+([^\b\s]+)//i;
$by = $1 if $arguments =~ s/-by\s+([^\b\s]+)//i; $refby = $1 if $arguments =~ s/-refby\s+([^\b\s]+)//i;
$editby = $1 if $arguments =~ s/-editby\s+([^\b\s]+)//i;
$owner = '.*' if not defined $owner; $owner = '.*' if not defined $owner;
$by = '.*' if not defined $by; $refby = '.*' if not defined $refby;
$editby = '.*' if not defined $editby;
$arguments =~ s/^\s+//; $arguments =~ s/^\s+//;
$arguments =~ s/\s+$//; $arguments =~ s/\s+$//;
@ -723,11 +725,19 @@ sub factfind {
$argtype = "owned by $owner"; $argtype = "owned by $owner";
} }
if($by ne '.*') { if($refby ne '.*') {
if(not defined $argtype) { if(not defined $argtype) {
$argtype = "last referenced by $by"; $argtype = "last referenced by $refby";
} else { } else {
$argtype .= " and last referenced by $by"; $argtype .= " and last referenced by $refby";
}
}
if($editby ne '.*') {
if(not defined $argtype) {
$argtype = "last edited by $editby";
} else {
$argtype .= " and last edited by $editby";
} }
} }
@ -743,7 +753,7 @@ sub factfind {
} }
if(not defined $argtype) { if(not defined $argtype) {
return "/msg $nick Usage: factfind [-channel] [-owner nick] [-by nick] [text]"; return "Usage: factfind [-channel] [-owner regex] [-refby regex] [-editby regex] [text]";
} }
my ($text, $last_trigger, $last_chan, $i); my ($text, $last_trigger, $last_chan, $i);
@ -754,7 +764,9 @@ sub factfind {
next if defined $channel and $chan !~ /$channel/i; next if defined $channel and $chan !~ /$channel/i;
foreach my $trigger (sort keys %{ $factoids->{$chan} }) { foreach my $trigger (sort keys %{ $factoids->{$chan} }) {
if($factoids->{$chan}->{$trigger}->{type} eq 'text' or $factoids->{$chan}->{$trigger}->{type} eq 'regex') { if($factoids->{$chan}->{$trigger}->{type} eq 'text' or $factoids->{$chan}->{$trigger}->{type} eq 'regex') {
if($factoids->{$chan}->{$trigger}->{owner} =~ /$owner/i && $factoids->{$chan}->{$trigger}->{ref_user} =~ /$by/i) { if($factoids->{$chan}->{$trigger}->{owner} =~ /$owner/i
&& $factoids->{$chan}->{$trigger}->{ref_user} =~ /$refby/i
&& $factoids->{$chan}->{$trigger}->{edited_by} =~ /$editby/i) {
next if($arguments ne "" && $factoids->{$chan}->{$trigger}->{action} !~ /$arguments/i && $trigger !~ /$arguments/i); next if($arguments ne "" && $factoids->{$chan}->{$trigger}->{action} !~ /$arguments/i && $trigger !~ /$arguments/i);
$i++; $i++;
@ -811,7 +823,7 @@ sub factchange {
($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $keyword, undef, 0, 1); ($channel, $trigger) = $self->{pbot}->{factoids}->find_factoid($channel, $keyword, undef, 0, 1);
if(not defined $trigger) { if(not defined $trigger) {
return "/msg $nick $keyword not found in channel $from."; return "$keyword not found in channel $from.";
} }
if(not $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host") and $factoids->{$channel}->{$trigger}->{'locked'}) { if(not $self->{pbot}->{admins}->loggedin($from, "$nick!$user\@$host") and $factoids->{$channel}->{$trigger}->{'locked'}) {
@ -822,7 +834,7 @@ sub factchange {
use re::engine::RE2 -strict => 1; use re::engine::RE2 -strict => 1;
if(not $factoids->{$channel}->{$trigger}->{action} =~ s|$tochange|$changeto|) { if(not $factoids->{$channel}->{$trigger}->{action} =~ s|$tochange|$changeto|) {
$self->{pbot}->{logger}->log("($from) $nick!$user\@$host: failed to change '$trigger' 's$delim$tochange$delim$changeto$delim\n"); $self->{pbot}->{logger}->log("($from) $nick!$user\@$host: failed to change '$trigger' 's$delim$tochange$delim$changeto$delim\n");
return "/msg $nick Change $trigger failed."; return "Change $trigger failed.";
} else { } else {
$self->{pbot}->{logger}->log("($from) $nick!$user\@$host: changed '$trigger' 's/$tochange/$changeto/\n"); $self->{pbot}->{logger}->log("($from) $nick!$user\@$host: changed '$trigger' 's/$tochange/$changeto/\n");
$factoids->{$channel}->{$trigger}->{edited_by} = "$nick!$user\@$host"; $factoids->{$channel}->{$trigger}->{edited_by} = "$nick!$user\@$host";
@ -842,7 +854,7 @@ sub load_module {
my ($keyword, $module) = $arguments =~ /^(.*?)\s+(.*)$/ if defined $arguments; my ($keyword, $module) = $arguments =~ /^(.*?)\s+(.*)$/ if defined $arguments;
if(not defined $module) { if(not defined $module) {
return "/msg $nick Usage: load <keyword> <module>"; return "Usage: load <keyword> <module>";
} }
if(not exists($factoids->{'.*'}->{$keyword})) { if(not exists($factoids->{'.*'}->{$keyword})) {
@ -850,9 +862,9 @@ sub load_module {
$factoids->{'.*'}->{$keyword}->{add_nick} = 1; $factoids->{'.*'}->{$keyword}->{add_nick} = 1;
$self->{pbot}->{logger}->log("$nick!$user\@$host loaded module $keyword => $module\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host loaded module $keyword => $module\n");
$self->{pbot}->{factoids}->save_factoids(); $self->{pbot}->{factoids}->save_factoids();
return "/msg $nick Loaded module $keyword => $module"; return "Loaded module $keyword => $module";
} else { } else {
return "/msg $nick There is already a keyword named $keyword."; return "There is already a keyword named $keyword.";
} }
} }
@ -862,16 +874,16 @@ sub unload_module {
my $factoids = $self->{pbot}->{factoids}->{factoids}->hash; my $factoids = $self->{pbot}->{factoids}->{factoids}->hash;
if(not defined $arguments) { if(not defined $arguments) {
return "/msg $nick Usage: unload <keyword>"; return "Usage: unload <keyword>";
} elsif(not exists $factoids->{'.*'}->{$arguments}) { } elsif(not exists $factoids->{'.*'}->{$arguments}) {
return "/msg $nick $arguments not found."; return "$arguments not found.";
} elsif($factoids->{'.*'}->{$arguments}{type} ne 'module') { } elsif($factoids->{'.*'}->{$arguments}{type} ne 'module') {
return "/msg $nick $arguments is not a module."; return "$arguments is not a module.";
} else { } else {
delete $factoids->{'.*'}->{$arguments}; delete $factoids->{'.*'}->{$arguments};
$self->{pbot}->{factoids}->save_factoids(); $self->{pbot}->{factoids}->save_factoids();
$self->{pbot}->{logger}->log("$nick!$user\@$host unloaded module $arguments\n"); $self->{pbot}->{logger}->log("$nick!$user\@$host unloaded module $arguments\n");
return "/msg $nick $arguments unloaded."; return "$arguments unloaded.";
} }
} }