#
use strict;
-use vars qw(%topiccmp);
-no strict "refs"; ### FIXME!!!
+use vars qw(%topiccmp %topic %channels %orig);
+use vars qw($who $chan $conn $uh $ident);
###############################
##### INTERNAL FUNCTIONS
my @results;
if (!exists $topic{$chan}{'Current'}) {
- &DEBUG("Topic: does not exist for $chan.");
return;
}
}
if (grep /^\Q$subtopic\E\|\|\Q$owner\E$/, @results) {
- &DEBUG("topic: we have found a dupe in the topic, not adding.");
+ &status("Topic: we have found a dupe in the topic, not adding.");
next;
}
# Usage: &topicCipher(@topics);
sub topicCipher {
if (!@_) {
- &DEBUG("topicCipher: topic is NULL.");
+ &WARN("topicCipher: topic is NULL for $chan.");
return;
}
my ($chan, $topic, $updateMsg, $topicUpdate) = @_;
my $maxlen = 470;
- &DEBUG("topic: chan{$chan} is +t.") if ($channels{$chan}{t});
- &DEBUG("topic: chan{$chan} is -t.") unless ($channels{$chan}{t});
- &DEBUG("topic: I have +o.") if ($channels{$chan}{o}{$ident});
- &DEBUG("topic: I don't have +o.") unless ($channels{$chan}{o}{$ident});
-
if ($channels{$chan}{t} and !$channels{$chan}{o}{$ident}) {
&msg($who, "error: cannot change topic without ops. (channel is +t) :(");
return 0;
# notification that the topic was altered.
if (!$topicUpdate) { # for cached changes with '-'.
- &performReply("okay");
+ &msg($who, "okay");
return 1;
}
$topic{$chan}{'Last'} = $topic;
$topic{$chan}{'Who'} = $orig{who}."!".$uh;
$topic{$chan}{'Time'} = time();
- rawout("TOPIC $chan :$topic");
+ $conn->topic($chan, $topic);
&topicAddHistory($chan,$topic);
return 1;
}
### 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);
if ($topiccount == 0) {
&msg($who, "No topic set.");
- return $noreply;
+ return;
}
if ($args eq "") {
&help("topic del");
- return $noreply;
+ return;
}
$args = ",".$args.",";
if ($args !~ /[\,\-\d]/) {
&msg($who, "error: Invalid argument ($args).");
- return $noreply;
+ return;
}
foreach (split ",", $args) {
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.
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:");
if ($args eq "") {
&help("topic mod");
- return $noreply;
+ return;
}
# a warning message instead of halting. we kind of trust the user now.
# 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#...");
if ($args eq "") {
&help("topic mv");
- return $noreply;
+ return;
}
if ($args =~ /^(first|last|\d+)\s+(before|after|swap)\s+(first|last|\d+)$/i) {
if ($topiccount == 1) {
&msg($who, "error: impossible to move the only subtopic, dumbass.");
- return $noreply;
+ return;
}
# Is there an easier way to do this?
if ($from > $topiccount || $to > $topiccount || $from < 1 || $to < 1) {
&msg($who, "error: <from> or <to> is out of range.");
- return $noreply;
+ return;
}
if ($from == $to) {
&msg($who, "error: <from> and <to> are the same.");
- return $noreply;
+ return;
}
$topic{$chan}{'What'} = "Move $from to $to";
$_ = "Swapped #\002$from\002 with #\002$to\002.";
&topicNew($chan, &topicCipher(@subtopics), $_, $topicUpdate);
- return $noreply;
+ return;
}
# action != swap:
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.");
} 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.
### 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.");
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);
+ $reply .= ". Change => $change" if (defined $change);
}
&performStrictReply($reply);
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;