summaryrefslogtreecommitdiffstats
path: root/scripts/quitmsg.pl
blob: 102d9aa5c42d6d6245d7b86445561e79b9af7473 (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
# If quit message isn't given, quit with a random message
# read from ~/.irssi/irssi.quit

use Irssi;
use Irssi::Irc;
use strict;
use vars qw($VERSION %IRSSI);

$VERSION = "1.01";
%IRSSI = (
    authors     => 'Timo Sirainen',
    name        => 'quitmsg',
    description => 'Random quit messages',
    license     => 'Public Domain',
    changed	=> 'Mon Jul 22 20:00 EET 2020'
);

my $quitfile = Irssi::get_irssi_dir() . "/irssi.quit";

sub cmd_quit {
	my ($data, $server, $channel) = @_;
	return if ($data ne "");
	
	open (my $fh, "<", $quitfile) || return;
	my @lines = <$fh>;

	my $quitmsg = $lines[int(rand(@lines))];
	chomp($quitmsg);
	close($fh);

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

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