forked from monopatis/Jarvis-irc-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpspace_event_irc.pl
executable file
·92 lines (89 loc) · 2.24 KB
/
pspace_event_irc.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
#!/usr/bin/perl
use strict;
#use warnings;
use LWP::Simple;
use FindBin;
use IO::Socket;
my $srv = IO::Socket::INET->new(PeerAddr=>'irc.freenode.net',
PeerPort=>'6667',
Proto=>'tcp',
Timeout=>'30')||print "Cannot wait more... 30 secs already passed ! $!\n";
#set user
print $srv "USER events 8 * :Perl IRC\r\n";
#set nick
print $srv "NICK Jarvis_door\r\n";
#register
print $srv "PRIVMSG NickServ :IDENTIFY <password>\r\n";
#set join channel
print $srv "JOIN #p-space\r\n";
#$0 = "stealth";
#initialize variables
my $response = 'foo';
my $ready = 0;
my $event = 'foo';
my $string = 'Remote';
my $oldevent = 'foo';
my $message = 'foo';
my $time = '00:00';
my $url = 'http://pspace.dyndns.org/report/index.php?limit=1&nostyle';
#add # to the following line if you want to see the last event on start
#$oldevent = get("$url");
my @values = split(' ', $oldevent);
while($response = <$srv>){
print $response;
# if (($response =~ /PRIVMSG/) && ($response =~ /PspaceEvents who/i))
# {
# print $srv "PRIVMSG #p-space :$message, $time ago\r\n";
# }
if (($response =~ /PRIVMSG/) && ($response =~ /Jarvis_door sousami anoi3e/i))
{
print "exit from loop\n";
last;
}
if ($response =~ /^PING(.*)$/i)
{
print $srv "PONG".$1."\r\n";
}
}
while (1){
$event = get("$url");
print $event."\n";
if ($oldevent ne $event){
$oldevent = $event ;
@values = split(' ', $oldevent);
my $diftime= time()-$values[0];
my ($sec, $min, $hour, $day,$month,$year) = (gmtime($diftime))[0,1,2,3,4,5];
$hour=$hour+($day-1)*24;
# print "Unix time ".$diftime." means ".$day." day, ";
# print " ".$hour.":".$min.":".$sec."\n";
my $secs = sprintf("%02d", $sec);
my $mins = sprintf("%02d", $min);
my $hours = sprintf("%02d", $hour);
if ($hour>0){
$time = "$hour:$mins:$secs hours";
}
else{
if ($min>0) {
$time = "$min:$secs mins";
}
else {
$time = "$sec secs";
}
}
if ($string eq $values[1]){
$message = "remote button pressed";
}
else {
@values = split('<', $values[1]);
my $user = $values[0];
$message = 'Card was used by ' . $user ;
}
# 'P-space is open' '$message, $time ago'
# $response = <$srv>;
# print $response;
print $srv "PRIVMSG #p-space :$message, $time ago\r\n";
}
print $srv "PONG".$1."\r\n";
#sleep
sleep(5);
}