File: Filter.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 (40 lines) | stat: -rw-r--r-- 1,127 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
# -----------------------------------------------------------------------------
# $Id: Filter.pm 11365 2008-05-10 14:58:28Z topia $
# -----------------------------------------------------------------------------
package User::Filter;
use strict;
use warnings;
use base qw(Module);
use Mask;

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

    if ($sender->isa('IrcIO::Server') &&
	($msg->command eq 'PRIVMSG' || $msg->command eq 'NOTICE')) {
	# マッチするパターンを探す
	foreach ($this->config->pattern('all')) {
	    my ($user,$replace) = m/^(.+?)\s+(.+)$/;
	    if (Mask::match($user,$msg->prefix)) {
		# 一致した。
		$replace =~ s/#\(message\)/$msg->param(1)/eg;
		$msg->param(1,$replace);
		last;
	    }
	}
    }

    $msg;
}

1;

=pod
info: 指定された人物からのPRIVMSGやNOTICEを書き換える。
default: off

# 人物のマスクと、置換パターンを定義。
# 置換パターン中の#(message)は、発言内容に置換されます。
# 人物が複数のマスクに一致する場合は、最初に一致したものが使われます。
pattern: *!*@* #(message)
=cut