-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathirssi_spy.pl
82 lines (71 loc) · 2.28 KB
/
irssi_spy.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
use strict;
use vars qw($VERSION %IRSSI);
use Irssi;
use IrssiSpy::IFTTTWebhook;
use IrssiSpy::Logger;
use IrssiSpy::Notification;
$VERSION = '0.2.0';
%IRSSI = (
authors => 'Michael Yockey',
contact => '[email protected]',
url =>
"https://mikeyockey.com",
name => 'IrssiSpy',
description =>
"A smart Irssi notification system.",
license => 'MIT',
);
Irssi::settings_add_str('misc', $IRSSI{'name'} . '_api_url', 'https://maker.ifttt.com/trigger/');
Irssi::settings_add_str('misc', $IRSSI{'name'} . '_api_key', 'key-');
Irssi::settings_add_int('misc', $IRSSI{'name'} . '_log_level', 1);
my $logger = IrssiSpy::Logger->new(
prefix => $IRSSI{'name'},
log_level => Irssi::settings_get_int($IRSSI{'name'} . '_log_level'),
);
my $ifttt_webhook = IrssiSpy::IFTTTWebhook->new(
api_url => Irssi::settings_get_str($IRSSI{'name'} . '_api_url'),
api_key => Irssi::settings_get_str($IRSSI{'name'} . '_api_key'),
logger => $logger,
);
sub handle_pub {
my ($server, $message, $user, $address, $target) = @_;
if (index($message, $server->{nick}) != -1) {
my $notification = new IrssiSpy::Notification(
network => $address,
location => $target,
name => $user,
);
$ifttt_webhook->trigger('irssi', $notification);
}
}
sub handle_priv {
my ($server, $message, $user, $address, $target) = @_;
if (index($message, $server->{nick}) != -1) {
my $notification = new IrssiSpy::Notification(
network => $address,
location => $target,
name => $user,
);
$ifttt_webhook->trigger('irssi_priv', $notification);
}
}
sub test {
my ($server, $message, $user, $address, $target) = @_;
if ($server->{nick} eq $user) {
my $notification = new IrssiSpy::Notification(
network => $address,
location => $target,
name => $user,
);
$ifttt_webhook->trigger('irssi_priv', $notification);
}
}
sub update_config {
$logger->log_level(Irssi::settings_get_int($IRSSI{'name'} . '_log_level'));
$ifttt_webhook->api_url(Irssi::settings_get_str($IRSSI{'name'} . '_api_url'));
$ifttt_webhook->api_key(Irssi::settings_get_str($IRSSI{'name'} . '_api_key'));
}
Irssi::signal_add_last("message public", "handle_pub");
Irssi::signal_add_last("message private", "handle_priv");
Irssi::signal_add_last("message own_private", "test");
Irssi::signal_add_last("setup reread", "update_config");