File: Get.pm

package info (click to toggle)
tiarra 20100212-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,732 kB
  • ctags: 1,712
  • sloc: perl: 32,032; lisp: 193; sh: 109; makefile: 10
file content (88 lines) | stat: -rw-r--r-- 2,356 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# -----------------------------------------------------------------------------
# $Id: Get.pm 11365 2008-05-10 14:58:28Z topia $
# -----------------------------------------------------------------------------
package Channel::Mode::Get;
use strict;
use warnings;
use base qw(Module);
use Multicast;

sub new {
    my $class = shift;
    my $this = $class->SUPER::new(@_);
    $this->{buffer} = []; # [IrcIO::Server,Tiarra::IRC::Message]
    $this->{timer} = undef; # Timer:必要な時だけ使われる。
    $this;
}

sub destruct {
    my $this = shift;
    if (defined $this->{timer}) {
	$this->{timer}->uninstall;
    }
}

sub message_arrived {
    my ($this,$msg,$sender) = @_;
    
    if ($sender->isa('IrcIO::Server') &&
	    $msg->command eq 'JOIN' &&
	    defined $msg->nick &&
	    $msg->nick eq RunLoop->shared->current_nick) {
	# 自分のJOINなので、MODE #channelを発行
	foreach (split /,/,$msg->param(0)) {
	    my $ch_shortname = Multicast::detatch($_);
	    my $entry = [$sender,
			 $this->construct_irc_message(
			     Command => 'MODE',
			     Param => $ch_shortname)];
	    push @{$this->{buffer}},$entry;
	    $this->setup_timer;
	}
    }
    
    $msg;
}

sub setup_timer {
    my ($this) = @_;
    # 既にタイマーが作られていたら何もせずに戻る。
    if (!defined $this->{timer}) {
	$this->{timer} = Timer->new(
	    Interval => 1,
	    Repeat => 1,
	    Code => sub {
		my $timer = shift;
		# 一度に二つずつ送り出す。
		my $msg_per_once = 2;
		my $buffer = $this->{buffer};
		for (my $i = 0;
		     $i < @$buffer && $i < $msg_per_once;
		     $i++) {
		    my $entry = $buffer->[$i];
		    $entry->[0]->send_message($entry->[1]);
		}
		splice @$buffer,0,2;
		# バッファが空になったら終了。
		if (@$buffer == 0) {
		    $timer->uninstall;
		    $this->{timer} = undef;
		}
	    })->install;
    }
}

1;

=pod
info: チャンネルにJOINした時、そのチャンネルのモードを取得します。
default: off
section: important

# Channel::Mode::Set等が正しく動くためには
# チャンネルのモードをTiarraが把握しておく必要があります。
# 自動的にモードを取得するクライアントであれば必要ありませんが、
# そうでなければこのモジュールを使うべきです。

# 設定項目は無し。
=cut