File: Shutdown.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 (67 lines) | stat: -rw-r--r-- 2,429 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
62
63
64
65
66
67
# -----------------------------------------------------------------------------
# $Id: Shutdown.pm 11365 2008-05-10 14:58:28Z topia $
# -----------------------------------------------------------------------------
package System::Shutdown;
use strict;
use warnings;
use base qw(Module);
use Mask;

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

    if ($sender->isa('IrcIO::Client')) {
	# クライアントからのコマンド
	if ($msg->command eq uc($this->config->command)) {
	    # どうせクライアントへは送られないがメッセージ表示
	    RunLoop->shared->notify_msg(
		"System::Shutdown received shutdown command from client.");
	    ::shutdown(join(' ', @{$msg->params}));;
	}
    }
    elsif ($sender->isa('IrcIO::Server')) {
	# privか?
	if (defined $msg->nick &&
	    $msg->param(0) eq RunLoop->shared->current_nick &&
	    ($msg->command eq 'PRIVMSG' || $msg->command eq 'NOTICE')) {
	    my ($command, $message) = split(/\s+/, $msg->param(1));
	    # 発言内容はmessageに完全一致しているか?
	    if (Mask::match_deep([$this->config->message('all')],
				 $command)) {
		# 発言者はmaskにマッチするか?
		if (Mask::match_deep([$this->config->mask('all')],
				     $msg->prefix)) {
		    # どうせクライアントには送られないがメッセージ表示
		    RunLoop->shared->notify_msg(
			"System::Shutdown received shutdown command from ".$msg->prefix.".");
		    ::shutdown($message);
		}
	    }
	}
    }
    $msg;
}

1;

=pod
info: Tiarraを終了させる。
default: off

# クライアントから特定のコマンドが実行された時や、
# 誰かから個人的に(privで)特定の発言が送られた時に
# Tiarra を終了させます。

# 追加するコマンド。省略された場合はコマンドでのシャットダウンは無効になります。
-command: shutdown

# Tiarraをシャットダウンさせるprivの発言。
# 省略された場合はprivでのシャットダウンは無効になります。
# パラメータとして shutdown メッセージを指定できます。
-message: shutdown

# privでのシャットダウンを許可する人。
# 省略された場合はprivでのシャットダウンは無効になります。
# 複数のマスクを指定した場合は、一つでもマッチするものがあればシャットダウンします。
-mask: example!example@*.example.jp
=cut