/
TargetList.pm6
62 lines (50 loc) · 1.14 KB
/
TargetList.pm6
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
#! /usr/bin/env false
use v6.c;
use IRC::Client;
class IRC::Client::Plugin::Ignore::TargetList
{
has SetHash $!nicks; #= Convenience SetHash of nicks.
has SetHash $!users; #= Convenience SetHash of usernames.
has SetHash $!hosts; #= Convenience SetHash of hosts.
multi method add-nick(
Str:D $target where { !$!nicks{$target} },
--> Str
) {
$!nicks{$target}++;
"Added $target to the list";
}
multi method add-nick(
Str:D $target,
--> Str
) {
"$target is already on the list";
}
multi method remove-nick(
Str:D $target where { $!nicks{$target} },
--> Str
) {
$!nicks{$target}--;
"Removed $target from the list";
}
multi method remove-nick(
Str:D $target,
--> Str
) {
"$target is not on the list";
}
#| Check whether a given message's sender is contained in the IgnoreList.
method includes(
IRC::Client::Message:D $event
) {
$!nicks{$event.nick} or $!users{$event.username} or $!hosts{$event.host};
}
#| Refresh the IgnoreList from a configuration.
method refresh(
%lists
) {
$!nicks .= new: |%lists<nicks>;
$!users .= new: |%lists<users>;
$!hosts .= new: |%lists<hosts>;
}
}
# vim: ft=perl6 noet