All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
5 use vars qw($VERSION %IRSSI);
10 contact=> 'bd@bc-bd.org',
12 description=> 'Puts people on ignore if they do a public away. See source for options.',
14 url=> 'https://bc-bd.org/svn/repos/irssi/ai',
18 # for irssi 0.8.4 by bd@bc-bd.org
26 # Ignore people saying "away"
29 # Ignore people saying "gone for good" or "back"
30 # /set ai_words gone for good,back
32 # Ignore people for 500 seconds
35 # Ignore people forever
38 # Ignore people only on channels #foo,#bar
39 # /set ai_ignore_only_in ON
40 # /set ai_channels #foo,#bar
42 # Ignore people on all channels BUT #foo,#bar
43 # /set ai_ignore_only_in OFF
44 # /set ai_channels #foo,#bar
46 # Ignore people on all channels
47 # /set ai_ignore_only_in OFF
48 # /set -clear ai_channels
50 # Perform a command on ignore (e.g send them a message)
51 # /set ai_command ^msg -$C $N no "$W" in $T please
53 # would become on #foo on chatnet bar from nick dude with "dude is away"
54 # /msg -cbar dude no "away" in #foo please
56 # look further down for details
58 # Per channel command on #irssi:
59 # /ai #irssi ^say foobar
61 # delete channel command in #irssi:
68 # /set ai_words [expr[,]+]+
69 # * expr : comma seperated list of expressions that should trigger an ignore
70 # e.g. : away,foo,bar baz bat,bam
72 # /set ai_command [command]
73 # * command : to be executed on a triggered ignore.
74 # /set -clear ai_command to disable. The following $'s are expanded
75 # ( see the default command for an example ):
76 # $C : Chatnet (e.g. IRCnet, DALNet, ...)
77 # $N : Nick (some dude)
78 # $W : Word (the word(s) that triggered the ignore
79 # $T : Target (e.g. the channel)
81 # /set ai_channels [#channel[ ]]+
82 # * #channel : space seperated list of channels, see ai_ignore_only_in
84 # /set ai_time <seconds>
85 # * seconds : number of seconds to wait before removing the ignore
87 # /set ai_ignore_only_in <ON|OFF>
88 # * ON : only trigger ignores in ai_channels
89 # * OFF : trigger ignores in all channels EXCEPT ai_channels
91 # /set ai_display <ON|OFF>
92 # * ON : log whole sentence
93 # * OFF : only log word that matched regex
102 # - added optional sentence output
105 # - added per channel command support
106 # - the command is now executed in the channel the event occured
107 # - changed the expand char from % to $
110 # - changed MSGLVL_ALL to MSGLVL_ACTIONS to avoid problems
111 # with channels with ignored Levels
120 my ($string, %format) = @_;
122 $string =~ s/\$$exp/$repl/g while (($exp, $repl) = each(%format));
126 sub combineSettings {
127 my ($setting,$string,$match) = @_;
129 $match = quotemeta($match);
132 if ($string !~ /$match\b/i) {
136 if ($string =~ /$match\b/i) {
145 my ($server,$msg,$nick,$address,$target) = @_;
149 if ($server->ignore_check($nick, $address, $target, $msg, MSGLEVEL_ACTIONS)) {
153 if (combineSettings(Irssi::settings_get_bool('ai_ignore_only_in'),
154 Irssi::settings_get_str('ai_channels'),$target)) {
158 my @words = split(',',Irssi::settings_get_str('ai_words'));
164 my $sentence = $word;
166 my $channel = $server->channel_find($target);
167 my $n = $channel->nick_find($nick);
169 my $type = Irssi::Irc::MASK_USER | Irssi::Irc::MASK_DOMAIN;
170 my $mask = Irssi::Irc::get_mask($n->{nick}, $n->{host}, $type);
172 my $time = Irssi::settings_get_int('ai_time');
176 $time = "-time ".$time;
178 Irssi::command("^ignore ".$time." $mask");
180 if (Irssi::settings_get_bool('ai_display')) {
183 Irssi::print("Ignoring $nick$target\@$server->{chatnet} because of '$sentence'");
185 my %commands = stringToHash('`',Irssi::settings_get_str('ai_commands'));
186 if (defined $commands{$target}) {
187 $command = $commands{$target};
189 $command = Irssi::settings_get_str('ai_command');
192 if ($command ne "") {
193 $command = expand($command,"C",$server->{tag},"N",$nick,"T",$target,"W",$word);
194 $server->window_item_find($target)->command($command);
195 $server->window_item_find($target)->print($command);
204 my ($delim,$str) = @_;
206 return split($delim,$str);
210 my ($delim,%hash) = @_;
212 return join($delim,%hash);
218 $com =~ s/\$(.)/%_\$$1%_/g;
224 my ($data, $server, $channel) = @_;
228 $data =~ s/^\Q$chan\E *//;
230 my %command = stringToHash('`',Irssi::settings_get_str('ai_commands'));
233 foreach my $key (keys(%command)) {
234 Irssi::print("AI: %_$key%_ = ".colorCommand($command{$key}));
237 Irssi::print("AI: placeholders: %_\$C%_)hatnet %_\$N%_)ick %_\$W%_)ord %_\$T%_)arget");
238 Irssi::print("AI: not enough parameters: ai <channel> [command]");
244 delete($command{$chan});
246 $command{$chan} = $data;
249 Irssi::settings_set_str('ai_commands',hashToString('`',%command));
251 Irssi::print("AI: command on %_$chan%_ now: '".colorCommand($data)."'");
254 Irssi::command_bind('ai', 'cmd_ai');
256 # "message irc action", SERVER_REC, char *msg, char *nick, char *address, char *target
257 Irssi::signal_add_first('message irc action', 'sig_action');
259 Irssi::settings_add_str('misc', 'ai_commands', '');
260 Irssi::settings_add_str('misc', 'ai_words', 'away,gone,ist auf');
261 Irssi::settings_add_str('misc', 'ai_command', '^msg -$C $N no "$W" in $T please');
262 Irssi::settings_add_str('misc', 'ai_channels', '');
263 Irssi::settings_add_int('misc', 'ai_time', 500);
264 Irssi::settings_add_bool('misc', 'ai_ignore_only_in', 0);
265 Irssi::settings_add_bool('misc', 'ai_display', 0);