-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslap.pl
executable file
·64 lines (52 loc) · 1.48 KB
/
slap.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
use strict;
use warnings;
use Irssi;
use Irssi::Irc;
use YAML::Syck;
$YAML::Syck::ImplicitUnicode = 1;
my $VERSION = "1.0";
my %IRSSI = (
authors => 'InitHello',
contact => '[email protected]',
name => 'slap',
description => 'mIRC slap, multilingual. Yes, I am horrible.',
license => 'BeerWare 2.0 or equivalent',
url => 'NA',
);
my %slaps;
my $slapconf = "$ENV{HOME}/.irssi/slaps.yml";
Irssi::command_bind('slap', \&slap);
Irssi::command_bind('addslap', \&addslap);
Irssi::command_bind('listslaps', \&listslaps);
Irssi::signal_add('setup saved', 'saveslaps');
Irssi::signal_add('setup reread', 'loadslaps');
sub slap {
my ($args, $server, $window) = @_;
my ($language, $target) = split / /, $args;
return if !defined $slaps{$language};
my $slaptext = 'me ' . $slaps{$language};
$slaptext =~ s/\$1/$target/;
$window->command($slaptext);
}
sub addslap {
my $args = shift;
my ($language, @slap) = split / /, $args;
$slaps{$language} = join ' ', @slap;
Irssi::print("Added $language slap as $slaps{$language}");
}
sub saveslaps {
if (-f $slapconf) {
DumpFile($slapconf, %slaps);
}
}
sub listslaps {
foreach my $language (keys %slaps) {
Irssi::print(ucfirst $language . ": $slaps{$language}");
}
}
sub loadslaps {
if (-f $slapconf) {
%slaps = LoadFile($slapconf);
}
}
loadslaps;