Created
September 8, 2009 10:59
-
-
Save yusukebe/182853 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/perl | |
| use strict; | |
| use warnings; | |
| use AnyEvent::Feed; | |
| use AnyEvent::IRC::Client; | |
| use AnyEvent; | |
| use Encode; | |
| my $channel = "#yokohama.pm"; | |
| my $cv = AnyEvent->condvar; | |
| my $pc = AnyEvent::IRC::Client->new; | |
| $pc->reg_cb( | |
| connect => sub { | |
| my ( $pc, $err ) = @_; | |
| if ( defined $err ) { | |
| print "Couldn't connect to server: $err\n"; | |
| } | |
| }, | |
| registered => sub { | |
| my ($self) = @_; | |
| print "registered!\n"; | |
| $pc->enable_ping(60); | |
| }, | |
| disconnect => sub { | |
| print "disconnected: $_[1]!\n"; | |
| } | |
| ); | |
| $pc->send_srv( "JOIN", $channel ); | |
| $pc->send_chan( $channel, "NOTICE", $channel, "hi" ); | |
| $pc->connect( "irc.freenode.net", 6667, | |
| { nick => 'atnd_bot', user => 'atnd_bot', real => 'ATND bot' } ); | |
| my $feed = AnyEvent::Feed->new( | |
| url => "http://atnd.org/events/show/1304.rss", | |
| interval => 60 * 1, | |
| on_fetch => sub { | |
| my ( $fee, $ent, $feed, $er ) = @_; | |
| if ( defined $er ) { | |
| warn "ERROR: $er\n"; | |
| $cv->send; | |
| return; | |
| } | |
| my @msg; | |
| for (@$ent) { | |
| my $str = $_->[1]->content->body; | |
| $str =~ s/\n//gm; | |
| $str =~ s/\s+/ /gm; | |
| $str = encode( 'utf8', $_->[1]->title . $str ); | |
| print "$str\n"; | |
| $pc->send_chan( $channel, "NOTICE", $channel, $str ); | |
| } | |
| } | |
| ); | |
| $cv->recv; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment