File: ClientInfo.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 (61 lines) | stat: -rw-r--r-- 1,552 bytes parent folder | download | duplicates (4)
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
# -----------------------------------------------------------------------------
# $Id: ClientInfo.pm 11365 2008-05-10 14:58:28Z topia $
# -----------------------------------------------------------------------------
# BulletinBoardのctcp-clientinfo-で始まる値を探し、それをCLIENTINFOとして応答する。
# -----------------------------------------------------------------------------
package CTCP::ClientInfo;
use strict;
use warnings;
use base qw(Module);
use CTCP;
use Multicast;
use BulletinBoard;

# CLIENTINFO設定
BulletinBoard->shared->ctcp_clientinfo_clientinfo('CLIENTINFO');

sub message_arrived {
    my ($this,$msg,$sender) = @_;

    if ($sender->isa('IrcIO::Server') &&
	$msg->command eq 'PRIVMSG' &&
	defined $msg->nick) {

	my $ctcp = CTCP::extract($msg);
	if (defined $ctcp && $ctcp eq 'CLIENTINFO') {

	    my $last = $sender->remark('last-ctcp-replied');
	    if (!defined $last || time - $last > ($this->config->interval || 3)) {
		# 前回のCTCP反応から一定時間以上経過している。

		my $clientinfo = join(
		    ' ',
		    map {
			BulletinBoard->shared->get($_);
		    } grep {
			m/^ctcp-clientinfo-/;
		    } BulletinBoard->shared->keys);

		my $reply = CTCP::make(
		    "CLIENTINFO $clientinfo",
		    scalar Multicast::detach($msg->nick)
		);
		$sender->send_message($reply);
		$sender->remark('last-ctcp-replied',time);
	    }
	}
    }

    $msg;
}

1;

=pod
info: CTCP CLIENTINFOに応答する。
default: off
section: important

# CTCP::Versionのintervalと同じ。
interval: 3
=cut