8 use Digest
::SHA
qw(sha256_hex);
12 use AnyEvent
::IRC
::Client
;
14 use Log
::Log4perl qw
/:easy/;
15 Log
::Log4perl
->easy_init($INFO);
20 channel
=> '#raumzeitlabor',
21 nick
=> 'RaumZeitInfo',
24 server
=> 'irc.hackint.eu',
25 rejoin
=> 3600, # in seconds
26 refresh
=> 300, # in seconds
30 'http://raumzeitlabor.de/feed',
31 'http://raumzeitlabor.de/w/index.php5?title=Spezial:Letzte_%C3%84nderungen&feed=atom',
32 'https://twitter.com/statuses/user_timeline/114430885.rss',
35 GetOptions
(\
%opt, 'channel=s', 'nick=s', 'port=i', 'server=s', 'rejoin=i', 'ssl=i');
40 my $irc = new AnyEvent
::IRC
::Client
;
41 $irc->enable_ssl() if $opt{ssl
};
42 $irc->connect($opt{server
}, $opt{port
}, { nick
=> $opt{nick
} });
44 $irc->reg_cb(registered
=> sub { INFO
"connected to ".$opt{server
}; });
46 $irc->reg_cb(join => sub {
47 my ($nick, $channel, $is_myself) = @_;
48 INFO
"joined channel ".$opt{channel
} if $is_myself;
51 # if we get kicked, we either rejoin after some time or leave the network
52 $irc->reg_cb(kick
=> sub {
53 my ($kicked_nick, $channel, $is_myself, $msg, $kicker_nick) = @_;
54 return unless $is_myself;
58 INFO
"rejoining channel in ".$opt{rejoin
}."s";
59 my $timer; $timer = AnyEvent
->timer(
60 after
=> $opt{rejoin
},
63 $irc->send_srv(JOIN
=> ($opt{channel
}));
71 $irc->reg_cb(disconnect
=> sub {
77 $irc->send_srv(join => ($opt{channel
}));
81 foreach my $f (@feeds) {
83 my $reader = AnyEvent
::Feed
->new (
85 interval
=> $opt{refresh
},
87 my ($feed_reader, $new_entries, $feed, $error) = @_;
94 # only post updates noticed after first refresh to prevent spam
95 if ($init) { $init--; return; };
98 my ($hash, $entry) = @
$_;
100 if (sha256_hex
($entry->content) ~~ @old_entries) {
101 WARN
"tried to send old item...";
103 while (scalar(@old_entries) > 100) {
107 push(@old_entries, sha256_hex
($entry->content));
108 my $msg = "Update: \"".$entry->title."\" von ".$entry->author." um ".
109 $entry->issued->set_time_zone('local')->strftime("%H:%I")
110 ." Uhr (".$entry->id.")";
112 $irc->send_chan($opt{channel
}, PRIVMSG
=> ($opt{channel
}, $msg));
118 push @feed_reader, $reader;
121 # if SIGINT is received, leave the network
122 my $w = AnyEvent
->signal (signal
=> 'INT', cb
=> sub {
123 WARN
"SIGINT received, disconnecting...";
124 $irc->disconnect("shutting down...");