1#!/usr/local/bin/perl
2# resets window activity status
3#  by c0ffee
4#    - http://www.penguin-breeder.org/irssi/
5
6#<scriptinfo>
7use strict;
8use vars qw($VERSION %IRSSI);
9
10use Irssi 20020120;
11$VERSION = "0.15";
12%IRSSI = (
13    authors	=> "c0ffee",
14    contact	=> "c0ffee\@penguin-breeder.org",
15    name	=> "Reset window activity status",
16    description	=> "Reset window activity status. defines command /act",
17    license	=> "Public Domain",
18    url		=> "http://www.penguin-breeder.org/irssi/",
19    changed	=> "Thu Apr 16 15:55:05 BST 2015",
20);
21#</scriptinfo>
22
23#
24# /ACT [PUBLIC|ALL]
25#
26# /ACT without parameters marks windows as non-active where no
27# public talk occured.
28#
29# /ACT PUBLIC also removes those where no nick hilight was triggered
30#
31# /ACT ALL sets all windows as non-active
32
33Irssi::command_bind 'act' => sub {
34    my ( $data, $server, $item ) = @_;
35    $data =~ s/\s+$//g;
36    if ($data) {
37      Irssi::command_runsub('act', $data, $server, $item);
38    }
39    else {
40      _act(1);
41    }
42};
43
44Irssi::command_bind('act public', sub { _act(2); });
45Irssi::command_bind('act all', sub { _act(3); });
46
47sub _act {
48  my($level) = @_;
49  for (Irssi::windows()) {
50    if ($_->{data_level} <= $level) {
51      Irssi::signal_emit("window dehilight", $_);
52    }
53  }
54}
55