summaryrefslogtreecommitdiff
path: root/scripts/quitmsg.pl
blob: 46e45ffdcccb675dd98493a3373cb13e2b2cee2b (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
# Quit with a random quit message read from ~/.irssi/irssi.quit

use Irssi;
use Irssi::Irc;

$quitfile = "$ENV{HOME}/.irssi/irssi.quit";

sub cmd_quit {
	my ($data, $server, $channel) = @_;

	open (f, $quitfile) || return;
	$lines = 0; while(<f>) { $lines++; };

	$line = int(rand($lines))+1;

	seek(f, 0, 0); $. = 0;
	while(<f>) {
		next if ($. != $line);

		chomp;
		$quitmsg = $_;
		last;
	}
	close(f);

	@servers = Irssi::servers;
	foreach $server (@servers) {
		$server->command("/disconnect ".$server->{tag}." $quitmsg");
	}
}

Irssi::command_bind('quit', '', 'cmd_quit');