-
Notifications
You must be signed in to change notification settings - Fork 0
/
word-replace.pl
76 lines (60 loc) · 1.74 KB
/
word-replace.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
# Signal stuff stolen from scrmable.pl
# Line processing from shabble's aspell.pl
# `/completion -auto` does this mostly for you
# This dictionary file is an INI style file borrowed initially from an mIRC spellcheck script, updated over time
# The script looks for a "pxdict.ini" in your irssi directory (~/.irssi)
use warnings;
use strict;
use Irssi;
use vars qw($VERSION %IRSSI);
our $VERSION = '0.1';
our %IRSSI = (
authors => 'IsaacG',
name => 'AutoReplace',
description => 'Auto replace words with correct words',
);
# INCLUDES
use Config::Tiny;
# GLOBALS
my $dict;
# CODE
# Capture the send text event
sub intercept_send
{
my ($msg, $server, $witem) = @_;
Irssi::signal_stop();
Irssi::signal_remove('send text', 'intercept_send');
Irssi::signal_emit('send text', word_replace("$msg"), $server, $witem);
Irssi::signal_add('send text', 'intercept_send');
}
# Repair the text being send
sub word_replace
{
my ($inputline) = @_;
my $output = "";
while ($inputline =~ m/\G(\S+)(\s*)/g) {
my ($word, $ws) = ($1, $2); # word, whitespace
if ($word =~ m/^([[:lower:]])/)
{
$word = $dict->{uc($1)}->{$word} if ($dict->{uc($1)}->{$word});
}
$output .= $word . $ws;
}
return $output;
}
sub replace_word_add
{
my ($data, $server, $witem) = @_;
my ($word, $replace) = split(/\s+/, lc($data), 2);
if ($word =~ m/^([[:lower:]])/)
{
$dict->{uc($1)}->{$word} = $replace;
$dict->write(Irssi::get_irssi_dir . '/pxdict.ini') or die "Failed to write dict file: " . $!;
}
}
# INIT
$dict = Config::Tiny->new;
$dict = Config::Tiny->read(Irssi::get_irssi_dir . '/pxdict.ini') or die "Failed to open dict file: " . $!;
Irssi::signal_add('send text', 'intercept_send');
Irssi::command_bind('replace_add', 'replace_word_add');
1;