]> jfr.im git - irc/SurrealServices/srsv.git/commitdiff
refactor cs_topicappend and friends
authortabris <redacted>
Fri, 2 Sep 2011 18:27:07 +0000 (18:27 +0000)
committertabris <redacted>
Fri, 2 Sep 2011 18:27:07 +0000 (18:27 +0000)
not perfect, but a little better.

git-svn-id: http://svn.tabris.net/repos/srsv@3561 70d4eda1-72e9-0310-a436-91e5bd24443c

branches/0.4.3/modules/serviceslibs/chanserv.pm

index fba111cfe5539c24a30172fb96504fd1d6db3f72..96f34b0e8420076b475d4cfe7b1018038208db90 100644 (file)
@@ -1014,31 +1014,30 @@ sub dispatch($$$) {
                        cs_join($user, @args);
                }
        }
-       elsif($cmd =~ /^topic$/i) {
-               my $chan = shift @args;
-               if (@args == 0) {
-                       notice($user, 'Syntax: TOPIC <#channel> <message|NONE>');
-               } else {
-                       $msg =~ s/^topic #(?:\S+)? //i;
-                       cs_topic($user, { CHAN => $chan }, $msg);
-               }
-       }
-       elsif($cmd =~ /^topicappend$/i) {
-               my $chan = shift @args;
-               if (@args == 0) {
-                       notice($user, 'Syntax: TOPICAPPEND <#channel> <message>');
-               } else {
-                       $msg =~ s/^topicappend #(?:\S+)? //i;
-                       cs_topicappend($user, $chan, $msg);
-               }
-       }
-       elsif($cmd =~ /^topicprepend$/i) {
-               my $chan = shift @args;
-               if (@args == 0) {
-                       notice($user, 'Syntax: TOPICPREPEND <#channel> <message>');
-               } else {
-                       $msg =~ s/^topicprepend #(?:\S+)? //i;
-                       cs_topicprepend($user, $chan, $msg);
+       elsif($cmd =~ /^topic/i) {
+               my $cn = shift @args;
+               my $chan = { CHAN => $cn };
+               if($cmd =~ /^topicprepend$/i) {
+                       if (@args == 0) {
+                               notice($user, 'Syntax: TOPICAPPEND <#channel> <message>');
+                       } else {
+                               $msg =~ s/^topicappend $cn //i;
+                               cs_topicappend($user, $chan, 0, $msg);
+                       }
+               } elsif($cmd =~ /^topicprepend$/i) {
+                       if (@args == 0) {
+                               notice($user, 'Syntax: TOPICPREPEND <#channel> <message>');
+                       } else {
+                               $msg =~ s/^topicprepend $cn //i;
+                               cs_topicappend($user, $chan, 1, $msg);
+                       }
+               } elsif($cmd =~ /^topic$/i) {
+                       if (@args == 0) {
+                               notice($user, 'Syntax: TOPIC <#channel> <message|NONE>');
+                       } else {
+                               $msg =~ s/^topic $cn //i;
+                               cs_topic($user, $chan, $msg);
+                       }
                }
        }
        else {
@@ -4912,36 +4911,30 @@ sub process_ban($$$$) {
                $delete_ban->execute($cn, $arg, $type);
        }
 }
+
 sub cs_topicappend {
-       my ($user, $cn, $topicappend) = @_;
-       $get_topic->execute($cn);
-       my ($ntopic, $nsetter, $ntime) = $get_topic->fetchrow_array;
-       my $newtopic;
-       if ($ntopic) {
-               $newtopic = $ntopic . " | " . $topicappend;
-       }
-       else { $newtopic = $topicappend; }
-       cs_topic ($user, { CHAN => $cn }, $newtopic);
-}
-sub cs_topicprepend {
-       my ($user, $cn, $topicprepend) = @_;
+       my ($user, $chan, $front, $topicappend) = @_;
+       my $cn = $chan->{CHAN};
        $get_topic->execute($cn);
-       my ($ntopic, $nsetter, $ntime) = $get_topic->fetchrow_array;
-       my $newtopic;
-       if ($ntopic) {
-               $newtopic = $topicprepend . " | " . $ntopic;
+       my ($cur_topic, undef, undef) = $get_topic->fetchrow_array;
+       $get_topic->finish();
+       my $new_topic = $cur_topic;
+       if ($cur_topic) {
+               if($front) {
+                       $new_topic = $topicappend . ' | ' . $cur_topic;
+               } else {
+                       $new_topic .= ' | ' . $topicappend;
+               }
        }
-       else { $newtopic = $topicprepend; }
-       cs_topic ($user, { CHAN => $cn }, $newtopic);
+       cs_topic ($user, $chan, $new_topic);
 }
 sub chan_topic {
        my ($src, $cn, $setter, $time, $topic) = @_;
        my $chan = { CHAN => $cn };
        my $suser = { NICK => $setter, AGENT => agent($chan) };
 
-       
        return if cr_chk_flag($chan, CRF_CLOSE, 1);
-       
+
        if(current_message->{SYNC}) {  # We don't need to undo our own topic changes.
                $set_topic1->execute($setter, $time, $cn);
                $set_topic2->execute($cn, $topic);