From f3ecbebb0e54b4726f4c25ffc9af53137d1edbae Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Fri, 11 Mar 2011 03:02:56 +0100 Subject: [PATCH] brmd IRC: Sync topic with internal state on connect --- brmd.pl | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/brmd.pl b/brmd.pl index 927e6af..f39ba1a 100755 --- a/brmd.pl +++ b/brmd.pl @@ -79,6 +79,19 @@ sub record_str { $record ? 'ON AIR' : 'OFF AIR'; } +sub topic_update { + my $newtopic = $topic; + if ($status) { + $newtopic =~ s/BRMLAB CLOSED/BRMLAB OPEN/g; + } else { + $newtopic =~ s/BRMLAB OPEN/BRMLAB CLOSED/g; + } + if ($newtopic ne $topic) { + $topic = $newtopic; + $irc->yield (topic => $channel => $topic ); + } +} + ## Brmdoor @@ -91,16 +104,7 @@ sub brmdoor_input { $status = $cur_status; my $st = status_str(); $irc->yield (privmsg => $channel => "[brmstatus] update: \002$st" ); - my $newtopic = $topic; - if ($status) { - $newtopic =~ s/BRMLAB CLOSED/BRMLAB OPEN/g; - } else { - $newtopic =~ s/BRMLAB OPEN/BRMLAB CLOSED/g; - } - if ($newtopic ne $topic) { - $topic = $newtopic; - $irc->yield (topic => $channel => $topic ); - } + topic_update(); } if ($cur_record != $record) { $record = $cur_record; @@ -253,12 +257,14 @@ sub irc_public { sub irc_332 { my ($sender, $server, $str, $data) = @_[SENDER, ARG0 .. ARG2]; $topic = $data->[1]; - print "new topic: $topic\n" + print "new topic: $topic\n"; + topic_update(); } sub irc_topic { my ($sender, $who, $where, $what) = @_[SENDER, ARG0 .. ARG2]; my $channel = $where; $topic = $what; - print "new topic: $topic\n" + print "new topic: $topic\n"; + topic_update(); }