summaryrefslogtreecommitdiffstats
path: root/scripts/autostuff.pl
blob: 7b197c02a3e3646d5a480e8f49dbea8ba3bf9d3d (plain)
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
use strict;
use vars qw($VERSION %IRSSI);

$VERSION = '0.02';
%IRSSI = (
    authors     => 'Juerd',
    contact	=> '#####@juerd.nl',
    name        => 'autostuff',
    description	=> 'Save current servers, channels and windows for autoconnect and autojoin',
    license	=> 'Public Domain',
    url		=> 'http://juerd.nl/site.plp/irssi',
    changed	=> '2010-03-24 14:35',
);

use Irssi qw(command_bind servers channels windows command);

command_bind autostuff => sub {
    my ($data, $server, $window) = @_;
    for (servers) {
        my $chatnet = $_->{chatnet} || $_->{tag};
        command "/network add $chatnet";
        command "/server add -auto -network $chatnet $_->{address} $_->{port} $_->{password}";
    }
    for (channels) {
        my $chatnet = $_->{server}->{chatnet} || $_->{server}->{tag};
        command "/channel add -auto $_->{name} $chatnet $_->{key}";
    }
    command "/layout save";
    command "/save";
};

command_bind "window clean" => sub {
    for (sort { $b->{refnum} <=> $a->{refnum} } windows) {
        next if $_->{active};
        next if $_->{immortal};
        next if $_->{name};
        command "/window close $_->{refnum}";
    }
};