OSDN Git Service

imported http://mrmt.net/src/keitairc/keitairc r1.11
authormorimoto <morimoto@180c8125-5b33-4295-ad04-72a68a15b4cc>
Sun, 21 Mar 2004 11:03:51 +0000 (11:03 +0000)
committermorimoto <morimoto@180c8125-5b33-4295-ad04-72a68a15b4cc>
Sun, 21 Mar 2004 11:03:51 +0000 (11:03 +0000)
keitairc

index 80b9c30..93314ef 100755 (executable)
--- a/keitairc
+++ b/keitairc
@@ -1,6 +1,6 @@
 #!/usr/bin/perl
 # keitairc
-# $Id: keitairc,v 1.10 2004-03-21 11:03:38 morimoto Exp $
+# $Id: keitairc,v 1.11 2004-03-21 11:03:51 morimoto Exp $
 #
 # Copyright (c) 2003 Jun Morimoto <morimoto@xantia.citroen.org>
 # This program is covered by the GNU General Public License 2
@@ -8,7 +8,7 @@
 # Depends: libjcode-pm-perl, libpoe-component-irc-perl,
 #   liburi-perl, libwww-perl, libappconfig-perl
 
-my $rcsid = q$Id: keitairc,v 1.10 2004-03-21 11:03:38 morimoto Exp $;
+my $rcsid = q$Id: keitairc,v 1.11 2004-03-21 11:03:51 morimoto Exp $;
 my ($version) = $rcsid =~ m#,v ([0-9.]+)#;
 
 use strict;
@@ -55,6 +55,9 @@ my %mtime;
 # unread lines
 my %unread;
 
+# chk
+my ($send_chk, $update_chk);
+
 # irc component
 POE::Component::IRC->new('keitairc');
 POE::Session->new(
@@ -130,22 +133,33 @@ sub on_irc_notice{
 sub add_message{
     my($channel, $who, $msg) = @_;
 
+    my $message = sprintf('%s %s> %s', &now, $who, $msg);
+
     my @tmp = split("\n", $channel_buffer{$channel});
-    push @tmp, sprintf('%s %s> %s', &now, $who, $msg);
+    push @tmp, $message;
 
     my @tmp2 = split("\n", $channel_recent{$channel});
-    push @tmp2, sprintf('%s %s> %s', &now, $who, $msg);
+    push @tmp2, $message;
 
     if(@tmp > $config->web_lines){
-       $channel_buffer{$channel} = join("\n", splice(@tmp, -$config->web_lines));
-       $channel_recent{$channel} = join("\n", splice(@tmp2, -$config->web_lines));
+       $channel_buffer{$channel} =
+               join("\n", splice(@tmp, -$config->web_lines));
     }else{
        $channel_buffer{$channel} = join("\n", @tmp);
+    }
+
+    if(@tmp2 > $config->web_lines){
+       $channel_recent{$channel} =
+               join("\n", splice(@tmp2, -$config->web_lines));
+    }else{
        $channel_recent{$channel} = join("\n", @tmp2);
     }
 
     $mtime{$channel} = time;
-    $unread{$channel}++;
+
+    # unread lines
+    $unread{$channel} = @tmp2;
+
     if ($unread{$channel} > $config->web_lines) {
        $unread{$channel} = $config->web_lines;
     }
@@ -188,33 +202,34 @@ sub index_page{
 
        $buf .= &label($accesskey);
 
-            if($accesskey < 10){
-                $buf .= sprintf('<a accesskey="%1d" href="%s%s">%s</a>',
-                                $accesskey,
-                                $docroot,
-                                uri_escape($channel),
-                                &compact_channel_name($channel));
-            }else{
+       if($accesskey < 10){
+               $buf .= sprintf('<a accesskey="%1d" href="%s%s">%s</a>',
+                               $accesskey,
+                               $docroot,
+                               uri_escape($channel),
+                               &compact_channel_name($channel));
+       }else{
                $buf .= sprintf('<a href="%s%s">%s</a>',
-                                $docroot,
-                                uri_escape($channel),
-                                &compact_channel_name($channel));
-            }
+                               $docroot,
+                               uri_escape($channel),
+                               &compact_channel_name($channel));
+       }
 
        $accesskey++;
 
        if($unread{$channel} > 0){
-           $buf .= sprintf(' <a href="%s%s.update">(%d)</a>',
+               $buf .= sprintf(' <a href="%s%s.update">(%d)</a>',
                                $docroot,
                                uri_escape($channel),
-                               $unread{$channel});
+                               $unread{$channel});
        }
-
        $buf .= '<br>';
     }
 
     $buf .= qq(<a href="$docroot" accesskey="0"></a>);
-    $buf .= qq( - keitairc $version +++);
+#    $buf .= qq( - keitairc $version +++);
+    $buf .= '<br>';
+    $buf .= qq( - Ver.20040226a);
 
     $buf;
 }
@@ -267,7 +282,6 @@ sub render{
 
 ################################################################
 sub on_web_request{
-    local($_);
     my ($kernel, $heap, $request) = @_[KERNEL, HEAP, ARG0];
 
     # Filter::HTTPD sometimes generates HTTP::Response objects.
@@ -313,6 +327,8 @@ sub on_web_request{
            &add_message($channel, $config->irc_nick,
                         Jcode->new($message)->euc);
 
+           # set flag for "send message"
+           $send_chk = 1;
        }
     }
 
@@ -324,7 +340,7 @@ sub on_web_request{
     }else{
        $uri =~ s|^/||;
 
-       my $update_chk = ($uri =~ /.*.update/);
+       $update_chk = ($uri =~ /.*.update/);
        if ($update_chk eq 1) {
                $uri =~ s/.update//;
        }
@@ -351,7 +367,7 @@ sub on_web_request{
               length($channel_buffer{$channel})){
                $content .= qq(<a accesskey="8" href="$docroot"></a>);
                $content .= '<a accesskey="9" href="#2"></a>';
-               if ($update_chk eq 1) {
+               if (($update_chk eq 1)||($send_chk eq 1)) {
                  $content .= &render($channel_recent{$channel});
                  $content .= sprintf('<a accesskey="5" href="%s%s">
                        ..more(push 5)</a>', "../", uri_escape($channel));
@@ -366,7 +382,13 @@ sub on_web_request{
            $content .= "no such channel";
        }
 
+       # clear check flags
+       $send_chk = 0;
+
+       # clear unread counter
         $unread{$channel} = 0;
+
+       # clear recent messages buffer
        $channel_recent{$channel} = "";
     }