X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2FModules%2FTopic.pl;h=c0d9d95c879abd62284936ae3aa6781389dd857a;hb=c68ac9b2d4b88535c1a2cfa695f6c4f683f0373c;hp=97e68c0edc2a5d1c782f229348b952d29f89c568;hpb=3780524a411a9fb1618a26e49c40d36923b7afcc;p=infobot.git diff --git a/src/Modules/Topic.pl b/src/Modules/Topic.pl index 97e68c0..c0d9d95 100644 --- a/src/Modules/Topic.pl +++ b/src/Modules/Topic.pl @@ -20,12 +20,9 @@ sub topicDecipher { my @results; if (!exists $topic{$chan}{'Current'}) { - &DEBUG("Topic: does not exist for $chan."); return; } - &DEBUG("Topic: hrm => '$topic{$chan}{'Current'}'."); - foreach (split /\|\|/, $topic{$chan}{'Current'}) { s/^\s+//; s/\s+$//; @@ -43,6 +40,11 @@ sub topicDecipher { $owner = $2; } + if (grep /^\Q$subtopic\E\|\|\Q$owner\E$/, @results) { + &status("Topic: we have found a dupe in the topic, not adding."); + next; + } + push(@results, "$subtopic||$owner"); } @@ -53,7 +55,7 @@ sub topicDecipher { # Usage: &topicCipher(@topics); sub topicCipher { if (!@_) { - &DEBUG("topicCipher: topic is NULL."); + &WARN("topicCipher: topic is NULL for $chan."); return; } @@ -97,7 +99,7 @@ sub topicNew { # notification that the topic was altered. if (!$topicUpdate) { # for cached changes with '-'. - &performReply("okay"); + &msg($who, "okay"); return 1; } @@ -174,17 +176,18 @@ sub Topic { ### CMD: ADD: if ($args eq "") { &help("topic add"); - return 'NOREPLY'; + return; } # heh, joeyh. 19990819. -xk if ($who =~ /\|\|/) { &msg($who, "error: you have an invalid nick, loser!"); - return 'NOREPLY'; + return; } my @prev = &topicDecipher($chan); my $new = "$args ($orig{who})"; + $topic{$chan}{'What'} = "Added '$args'."; if (scalar @prev) { $new = &topicCipher(@prev, sprintf("%s||%s", $args, $who)); } @@ -197,12 +200,12 @@ sub Topic { if ($topiccount == 0) { &msg($who, "No topic set."); - return 'NOREPLY'; + return; } if ($args eq "") { &help("topic del"); - return 'NOREPLY'; + return; } $args = ",".$args.","; @@ -214,7 +217,7 @@ sub Topic { if ($args !~ /[\,\-\d]/) { &msg($who, "error: Invalid argument ($args)."); - return 'NOREPLY'; + return; } foreach (split ",", $args) { @@ -231,13 +234,15 @@ sub Topic { push(@delete, $1); } else { &msg($who, "error: Invalid sub-argument ($_)."); - return 'NOREPLY'; + return; } + $topic{$chan}{'What'} = "Deleted ".join("/",@delete); + foreach (@delete) { if ($_ > $topiccount || $_ < 1) { &msg($who, "error: argument out of range. (max: $topiccount)"); - return 'NOREPLY'; + return; } # skip if already deleted. # only checked if x-y range is given. @@ -263,7 +268,7 @@ sub Topic { my @topics = &topicDecipher($chan); if (!scalar @topics) { &msg($who, "No topics for \002$chan\002."); - return 'NOREPLY'; + return; } &msg($who, "Topics for \002$chan\002:"); @@ -284,7 +289,7 @@ sub Topic { if ($args eq "") { &help("topic mod"); - return 'NOREPLY'; + return; } # a warning message instead of halting. we kind of trust the user now. @@ -292,26 +297,29 @@ sub Topic { &msg($who, "warning: adding double pipes manually == evil. be warned."); } + $topic{$chan}{'What'} = "SAR $args"; + # SAR patch. mu++ if ($args =~ m|^\s*s([/,#])(.+?)\1(.*?)\1([a-z]*);?\s*$|) { - my ($delim, $op, $np, $flags) = ($1,quotemeta $2,$3,$4); + my ($delim, $op, $np, $flags) = ($1,$2,$3,$4); if ($flags !~ /^(g)?$/) { &msg($who, "error: Invalid flags to regex."); - return 'NOREPLY'; + return; } my $topic = $topic{$chan}{'Current'}; - if (($flags eq "g" and $topic =~ s/$op/$np/g) || - ($flags eq "" and $topic =~ s/$op/$np/)) { + ### TODO: use m### to make code safe! + if (($flags eq "g" and $topic =~ s/\Q$op\E/$np/g) || + ($flags eq "" and $topic =~ s/\Q$op\E/$np/)) { $_ = "Modifying topic with sar s/$op/$np/."; &topicNew($chan, $topic, $_, $topicUpdate); } else { &msg($who, "warning: regex not found in topic."); } - return 'NOREPLY'; + return; } &msg($who, "error: Invalid regex. Try s/1/2/, s#3#4#..."); @@ -321,7 +329,7 @@ sub Topic { if ($args eq "") { &help("topic mv"); - return 'NOREPLY'; + return; } if ($args =~ /^(first|last|\d+)\s+(before|after|swap)\s+(first|last|\d+)$/i) { @@ -332,7 +340,7 @@ sub Topic { if ($topiccount == 1) { &msg($who, "error: impossible to move the only subtopic, dumbass."); - return 'NOREPLY'; + return; } # Is there an easier way to do this? @@ -343,14 +351,16 @@ sub Topic { if ($from > $topiccount || $to > $topiccount || $from < 1 || $to < 1) { &msg($who, "error: or is out of range."); - return 'NOREPLY'; + return; } if ($from == $to) { &msg($who, "error: and are the same."); - return 'NOREPLY'; + return; } + $topic{$chan}{'What'} = "Move $from to $to"; + if ($action =~ /^(swap)$/i) { my $tmp = $subtopics[$to - 1]; $subtopics[$to - 1] = $subtopics[$from - 1]; @@ -358,7 +368,7 @@ sub Topic { $_ = "Swapped #\002$from\002 with #\002$to\002."; &topicNew($chan, &topicCipher(@subtopics), $_, $topicUpdate); - return 'NOREPLY'; + return; } # action != swap: @@ -380,14 +390,14 @@ sub Topic { undef @subtopics; # lets reuse this array. foreach (@newtopics) { - next if ($_ eq ""); + next if (!defined $_ or $_ eq ""); push(@subtopics, $_); } $_ = "Moved #\002$from\002 $action #\002$to\002."; &topicNew($chan, &topicCipher(@subtopics), $_, $topicUpdate); - return 'NOREPLY'; + return; } &msg($who, "Invalid arguments."); @@ -397,6 +407,8 @@ sub Topic { my @subtopics = &topicDecipher($chan); my @newtopics; + $topic{$chan}{'What'} = "shuffled"; + foreach (&makeRandom(scalar @subtopics)) { push(@newtopics, $subtopics[$_]); } @@ -406,14 +418,14 @@ sub Topic { } elsif ($cmd =~ /^(history)$/i) { ### CMD: HISTORY: - if (!scalar @{$topic{$chan}{'History'}}) { + if (!scalar @{ $topic{$chan}{'History'} }) { &msg($who, "Sorry, no topics in history list."); - return 'NOREPLY'; + return; } &msg($who, "History of topics on \002$chan\002:"); - for (1 .. scalar @{$topic{$chan}{'History'}}) { - my $topic = ${$topic{$chan}{'History'}}[$_-1]; + for (1 .. scalar @{ $topic{$chan}{'History'} }) { + my $topic = ${ $topic{$chan}{'History'} }[$_-1]; &msg($who, " #\002$_\002: $topic"); # To prevent excess floods. @@ -425,28 +437,30 @@ sub Topic { ### CMD: RESTORE: if ($args eq "") { &help("topic restore"); - return 'NOREPLY'; + return; } + $topic{$chan}{'What'} = "Restore topic $args"; + # following needs to be verified. if ($args =~ /^last$/i) { - if (${$topic{$chan}{'History'}}[0] eq $topic{$chan}{'Current'}) { + if (${ $topic{$chan}{'History'} }[0] eq $topic{$chan}{'Current'}) { &msg($who,"error: cannot restore last topic because it's mine."); - return 'NOREPLY'; + return; } $args = 1; } if ($args =~ /\d+/) { - if ($args > $#{$topic{$chan}{'History'}} || $args < 1) { + if ($args > $#{ $topic{$chan}{'History'} } || $args < 1) { &msg($who, "error: argument is out of range."); - return 'NOREPLY'; + return; } $_ = "Changing topic according to request."; - &topicNew($chan, ${$topic{$chan}{'History'}}[$args-1], $_, $topicUpdate); + &topicNew($chan, ${ $topic{$chan}{'History'} }[$args-1], $_, $topicUpdate); - return 'NOREPLY'; + return; } &msg($who, "error: argument is not positive integer."); @@ -454,6 +468,7 @@ sub Topic { } elsif ($cmd =~ /^rehash$/i) { ### CMD: REHASH. $_ = "Rehashing topic..."; + $topic{$chan}{'What'} = "Rehash"; &topicNew($chan, $topic{$chan}{'Current'}, $_, 1); } elsif ($cmd =~ /^info$/i) { @@ -462,7 +477,10 @@ sub Topic { if (exists $topic{$chan}{'Who'} and exists $topic{$chan}{'Time'}) { $reply = "topic on \002$chan\002 was last set by ". $topic{$chan}{'Who'}. ". This was done ". - &Time2String(time() - $topic{$chan}{'Time'}) ." ago."; + &Time2String(time() - $topic{$chan}{'Time'}) ." ago". + ". Length: ".length($topic{$chan}{'Current'}); + my $change = $topic{$chan}{'What'}; + $reply .= ". Change => $change" if (defined $change); } &performStrictReply($reply); @@ -471,13 +489,13 @@ sub Topic { if ($cmd ne "" and $cmd !~ /^help/i) { &msg($who, "Invalid command [$cmd]."); &msg($who, "Try 'help topic'."); - return 'NOREPLY'; + return; } &help("topic"); } - return 'NOREPLY'; + return; } 1;