#
use strict;
-use vars qw(%topiccmp %topic %channels %orig);
-use vars qw($who $chan $conn $uh $ident $topicUpdate);
-# use cache{topicUpdate}?
+use vars qw(%topiccmp %topic %channels %cache %orig);
+use vars qw($who $chan $conn $uh $ident);
###############################
##### INTERNAL FUNCTIONS
}
my $subtopic = $_;
- my $owner = "Unknown";
+ my $owner = 'Unknown';
if (/(.*)\s+\((.*?)\)$/) {
$subtopic = $1;
}
if (grep /^\Q$subtopic\E\|\|\Q$owner\E$/, @results) {
- &status("Topic: we have found a dupe in the topic, not adding.");
+ &status("Topic: we have found a dupe ($subtopic) in the topic, not adding.");
next;
}
###
# Usage: &topicCipher(@topics);
sub topicCipher {
- if (!@_) {
- &WARN("topicCipher: topic is NULL for $chan.");
- return;
- }
+ return if (!@_);
my @topic;
foreach (@_) {
my ($subtopic, $setby) = split /\|\|/;
- if ($setby =~ /(unknown|)$/i) {
- push(@topic, $subtopic);
- } else {
+ if ($param{'topicAuthor'} eq '1' and (!$setby =~ /^(unknown|)$/i)) {
push(@topic, "$subtopic ($setby)");
+ } else {
+ push(@topic, "$subtopic");
}
}
}
###
-# Usage: &topicNew($chan, $topic, $updateMsg, $topicUpdate);
+# Usage: &topicNew($chan, $topic, $updateMsg);
sub topicNew {
- my ($chan, $topic, $updateMsg, $topicUpdate) = @_;
+ my ($chan, $topic, $updateMsg) = @_;
my $maxlen = 470;
if ($channels{$chan}{t} and !$channels{$chan}{o}{$ident}) {
$topic{$chan}{'Current'} = $topic;
- # notification that the topic was altered.
- if (!$topicUpdate) { # for cached changes with '-'.
- &msg($who, "okay");
+ if ($cache{topicNotUpdate}{$chan}) {
+ &msg($who, "done. 'flush' to finalize changes.");
+ delete $cache{topicNotUpdate}{$chan};
return 1;
}
- if ($updateMsg ne "") {
+ if (defined $updateMsg && $updateMsg ne '') {
&msg($who, $updateMsg);
}
$topic{$chan}{'Who'} = $orig{who}."!".$uh;
$topic{$chan}{'Time'} = time();
- $conn->topic($chan, $topic);
- &topicAddHistory($chan,$topic);
+ if ($topic) {
+ $conn->topic($chan, $topic);
+ &topicAddHistory($chan, $topic);
+ } else {
+ $conn->topic($chan, ' ');
+ }
return 1;
}
my ($chan, $topic) = @_;
my $dupe = 0;
- return 1 if ($topic eq ""); # required fix.
+ return 1 if ($topic eq ''); # required fix.
foreach (@{ $topic{$chan}{'History'} }) {
- next if ($_ ne "" and $_ ne $topic);
+ next if ($_ ne '' and $_ ne $topic);
# checking length is required.
# slightly weird to put a return statement in a loop.
sub do_add {
my ($chan, $args) = @_;
- if ($args eq "") {
- &help("topic add");
+ if ($args eq '') {
+ &help('topic add');
return;
}
# heh, joeyh. 19990819. -xk
if ($who =~ /\|\|/) {
- &msg($who, "error: you have an invalid nick, loser!");
+ &msg($who, 'error: you have an invalid nick, loser!');
return;
}
- if (!&hasFlag("T")) {
- &msg($who, "you do not have enough flags to add topics");
- return;
- }
+ return if ($channels{$chan}{t} and !&hasFlag('T'));
my @prev = &topicDecipher($chan);
- my $new = "$args ($orig{who})";
+ my $new;
+ # If bot new to chan and topic is blank, it still got a (owner). This is fix
+ if ($param{'topicAuthor'} eq '1') {
+ $new = "$args ($orig{who})";
+ } else {
+ $new = "$args";
+ }
$topic{$chan}{'What'} = "Added '$args'.";
if (scalar @prev) {
$new = &topicCipher(@prev, $str);
}
- &topicNew($chan, $new, "", $topicUpdate);
+ &topicNew($chan, $new, '');
}
# cmd: delete.
my $topiccount = scalar @subtopics;
if ($topiccount == 0) {
- &msg($who, "No topic set.");
+ &msg($who, 'No topic set.');
return;
}
- if ($args eq "") {
- &help("topic del");
+ if ($args eq '') {
+ &help('topic del');
return;
}
}
my @delete;
- foreach (split ",", $args) {
- next if ($_ eq "");
+ foreach (split ',', $args) {
+ next if ($_ eq '');
# change to hash list instead of array?
if (/^(\d+)-(\d+)$/) {
return;
}
- $topic{$chan}{'What'} = "Deleted ".join("/",@delete);
+ $topic{$chan}{'What'} = 'Deleted '.join("/",@delete);
}
-
foreach (@delete) {
if ($_ > $topiccount || $_ < 1) {
&msg($who, "error: argument out of range. (max: $topiccount)");
my ($subtopic,$whoby) = split('\|\|', $subtopics[$_-1]);
- $whoby = "unknown" if ($whoby eq "");
+ $whoby = 'unknown' if ($whoby eq '');
&msg($who, "Deleting topic: $subtopic ($whoby)");
undef $subtopics[$_-1];
push(@newtopics, $_);
}
- &topicNew($chan, &topicCipher(@newtopics), "", $topicUpdate);
+ &topicNew($chan, &topicCipher(@newtopics), '');
}
# cmd: list
sub do_modify {
my ($chan, $args) = @_;
- if ($args eq "") {
- &help("topic mod");
+ if ($args eq '') {
+ &help('topic mod');
return;
}
my $topic = $topic{$chan}{'Current'};
### 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/)
+ 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);
+ &topicNew($chan, $topic, $_);
} else {
&msg($who, "warning: regex not found in topic.");
}
sub do_move {
my ($chan, $args) = @_;
- if ($args eq "") {
- &help("topic mv");
+ if ($args eq '') {
+ &help('topic mv');
return;
}
$subtopics[$from - 1] = $tmp;
$_ = "Swapped #\002$from\002 with #\002$to\002.";
- &topicNew($chan, &topicCipher(@subtopics), $_, $topicUpdate);
+ &topicNew($chan, &topicCipher(@subtopics), $_);
return;
}
undef @subtopics; # lets reuse this array.
foreach (@newtopics) {
- next if (!defined $_ or $_ eq "");
+ next if (!defined $_ or $_ eq '');
push(@subtopics, $_);
}
$_ = "Moved #\002$from\002 $action #\002$to\002.";
- &topicNew($chan, &topicCipher(@subtopics), $_, $topicUpdate);
+ &topicNew($chan, &topicCipher(@subtopics), $_);
}
# cmd: shuffle.
my @subtopics = &topicDecipher($chan);
my @newtopics;
- $topic{$chan}{'What'} = "shuffled";
+ $topic{$chan}{'What'} = 'shuffled';
foreach (&makeRandom(scalar @subtopics)) {
push(@newtopics, $subtopics[$_]);
}
$_ = "Shuffling the bag of lollies.";
- &topicNew($chan, &topicCipher(@newtopics), $_, $topicUpdate);
+ &topicNew($chan, &topicCipher(@newtopics), $_);
}
# cmd: history.
sub do_restore {
my ($chan, $args) = @_;
- if ($args eq "") {
- &help("topic restore");
+ if ($args eq '') {
+ &help('topic restore');
return;
}
}
$_ = "Changing topic according to request.";
- &topicNew($chan, ${ $topic{$chan}{'History'} }[$args-1], $_, $topicUpdate);
+ &topicNew($chan, ${ $topic{$chan}{'History'} }[$args-1], $_);
}
# cmd: rehash.
my ($chan) = @_;
$_ = "Rehashing topic...";
- $topic{$chan}{'What'} = "Rehash";
+ $topic{$chan}{'What'} = 'Rehash';
&topicNew($chan, $topic{$chan}{'Current'}, $_, 1);
}
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);
# Usage: &Topic($cmd, $args);
sub Topic {
my ($chan, $cmd, $args) = @_;
- my $topicUpdate = 1;
if ($cmd =~ /^-(\S+)/) {
- $topicUpdate = 0;
+ $cache{topicNotUpdate}{$chan} = 1;
$cmd = $1;
}
} elsif ($cmd =~ /^restore$/i) {
&do_restore($chan, $args);
- } elsif ($cmd =~ /^rehash$/i) {
+ } elsif ($cmd =~ /^(flush|rehash)$/i) {
&do_rehash($chan);
} elsif ($cmd =~ /^info$/i) {
&do_info($chan);
} else {
- ### CMD: HELP:
- if ($cmd ne "" and $cmd !~ /^help/i) {
+ ### HELP:
+ if ($cmd ne '' and $cmd !~ /^help/i) {
&msg($who, "Invalid command [$cmd].");
&msg($who, "Try 'help topic'.");
return;
}
- &help("topic");
+ &help('topic');
}
return;