aboutsummaryrefslogtreecommitdiffstats
path: root/.irssi/scripts/notify_irssi.pl
blob: 90a5f31d7680178e8e8ce00e3956dbbd11c5c9a1 (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
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
#!/usr/bin/perl

## Put me in ~/.irssi/scripts, and then execute the following in irssi:
##
##       /load perl
##       /script load notify_irssi.pl
##

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

$VERSION = "0.01";
%IRSSI = (
    authors     => 'konni',
    contact     => 'konstantin.koslowski@gmail.com',
    name        => 'notify_irssi.pl',
    description => 'TODO',
    license     => 'GNU General Public License',
    url         => 'none',
);

my $divider = ":::";

# server, nick, msg, active
sub notify {
  my $sock = new IO::Socket::INET (
    PeerAddr => '127.0.0.1',
    PeerPort => '7090',
    Proto => 'tcp',
  );

  if ($sock) {
    my($server, $nick, $msg, $active) = @_;
    print $sock $server,$divider,"$nick",$divider,"$msg",$divider,$active;
  }
}

sub notify_message {
  my($dest, $msg, $nick, $address, $target) = @_;
  my $server = $dest->{server};

  my $active_win = Irssi::active_win();
  my $active = 0;
  if ($active_win->get_active_name() eq $nick) {
    $active = 1;
  }
  # return if ($active);

  notify($server, $nick, $msg, $active);
}

sub notify_print {
  my ($dest, $text, $msg) = @_;
  my $server = $dest->{server};
  my $nick = $dest->{target};

  return if (!$server || !($dest->{level} & MSGLEVEL_HILIGHT));

  $msg =~ s/[^a-zA-Z0-9 .,!?\@:\>]//g;

  notify($server, $nick, $msg, 0);
}

Irssi::signal_add("message private", "notify_message");
Irssi::signal_add("message invite", "notify_message");
Irssi::signal_add("print text", "notify_print");
#Irssi::signal_add("dcc request", "notify");