-
Notifications
You must be signed in to change notification settings - Fork 235
/
toilet.pl
76 lines (69 loc) · 1.68 KB
/
toilet.pl
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#
# 2017-09-09 bcattaneo:
# - initial release
#
# 2017-12-23 bcattaneo:
# - Added filters
#
use IPC::Open3;
use strict;
use vars qw($VERSION %IRSSI);
use Irssi qw(command_bind active_win);
#
# Usage:
# /toilet [message]
#
# Settings:
# /set toilet_filters [Filters (separated with ":")]
# /set toilet_font [Font name]
#
# Example:
# /set toilet_filters border:metal
# /set toilet_font small
# /toilet Hello!
#
our $VERSION = '1.1.0';
our %IRSSI = (
authors => 'bcattaneo',
name => 'toilet',
url => 'http://github.com/bcattaneo',
description => 'Simple toilet implementation for Irssi',
license => 'Public Domain',
changed => "2017-12-23",
# safe implementation borrowed from figlet.pl:
# Author: https://juerd.nl/site.plp/irssi
# https://github.com/irssi/scripts.irssi.org/blob/master/scripts/figlet.pl
);
Irssi::settings_add_str('toilet', 'toilet_filters' => '');
Irssi::settings_add_str('toilet', 'toilet_font' => '');
command_bind (
toilet => sub {
my ($msg) = @_;
my @toilet;
my $i = 0;
my @parm;
push(@parm,'toilet');
push(@parm,'--irc');
my $filters = Irssi::settings_get_str('toilet_filters');
my $font = Irssi::settings_get_str('toilet_font');
if ($filters ne '') {
push(@parm,'-F'.$filters);
}
if ($font ne '') {
push(@parm,'-f'.$font);
}
my $pid = open3(undef, *TOILET, *TOILET, @parm, $msg);
while (<TOILET>) {
chomp;
$toilet[$i++] .= $_;
}
close TOILET;
waitpid $pid, 0;
for (@toilet) {
(my $copy = $_) =~ s/\cC\d*(?:,\d*)?|[\cB\cO\c_]//g;
next unless $copy =~ /\S/;
active_win->command("say $_");
}
}
);