forked from nchowning/multinotify
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmultinotify-irssi.pl
92 lines (78 loc) · 2.17 KB
/
multinotify-irssi.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
######
# Multinotify irssi Client
# nchowning, 2011 - [email protected]
######
######
# Parts of this script are based on my irssi-prowl-notifier script which is based
# on fnotify created by Thorsten Leemhuis
# http://www.leemhuis.info/files/fnotify/
######
use warnings;
use IO::Socket::INET;
use vars qw($VERSION %IRSSI);
use Irssi;
$VERSION = '1.0';
%IRSSI = (
authors => 'Nathan Chowning',
contact => '[email protected]',
name => 'multinotify',
description => 'A script that works with multinotify-server.pl and multinotify-client.pl to send and receive irssi notifications',
url => 'http://www.nathanchowning.com/projects/multinotify',
license => 'GPL'
);
######
# Set the IP Address & Port for your server below
######
my $IPADDRESS = 'IP ADDRESS IN HERE';
my $PORT = 'PORT IN HERE';
$| = 1; # Flush after write
my ($socket,$client_socket);
######
# Private message parsing
######
sub private_msg {
my ($server,$msg,$nick,$address,$target) = @_;
socketsend($nick,$msg);
}
######
# Sub to catch nick hilights
######
sub nick_hilight {
my ($dest, $text, $stripped) = @_;
if ($dest->{level} & MSGLEVEL_HILIGHT) {
socketsend($dest->{target}, $stripped);
}
}
######
# Send messages to notification server
######
sub socketsend {
my(@smessage) = @_;
$socket = new IO::Socket::INET (
PeerHost => '$IPADDRESS',
PeerPort => '$PORT',
Proto => 'tcp',
) or die "ERROR in Socket Creation : $!\n";
# Send "send" to the server to inform it that this is a sending client
$data = "send";
print $socket "$data\n";
# If the server approves our connection, send the username to the server
if (<$socket> eq "approved\n")
{
$data = $smessage[0];
print $socket "$data\n";
}
# If the server receives the username successfully, send the message to the server
if (<$socket> eq "un\n")
{
$data = $smessage[1];
print $socket "$data\n";
}
# Close the socket
close($socket);
}
######
# Irssi::signal_add_last / Irssi::command_bind
######
Irssi::signal_add_last("message private", "private_msg");
Irssi::signal_add_last("print text", "nick_hilight");