Changeset 11757
- Timestamp:
- 05/17/08 17:56:53 (5 years ago)
- Location:
- lang/perl/XIRCD/trunk
- Files:
-
- 6 modified
-
TODO (modified) (1 diff)
-
lib/XIRCD.pm (modified) (1 diff)
-
lib/XIRCD/Component.pm (modified) (2 diffs)
-
lib/XIRCD/Component/Server.pm (modified) (2 diffs)
-
lib/XIRCD/Component/Twitter.pm (modified) (7 diffs)
-
lib/XIRCD/Component/Wassr.pm (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/XIRCD/trunk/TODO
r11679 r11757 1 - auto START & STOP2 -- auto join channel3 -- config to attribute4 -- join_channel, yeild, publish_message, etc ... write DSL5 1 - support TIG like message queue 2 - more tests -
lang/perl/XIRCD/trunk/lib/XIRCD.pm
r11751 r11757 26 26 %{$component} 27 27 ); 28 warn "load $module";29 28 } 30 29 -
lang/perl/XIRCD/trunk/lib/XIRCD/Component.pm
r11745 r11757 40 40 my ($nick, $text) = @_; 41 41 42 post ircd => ' publish_message' => $nick, $self->channel, $text;42 post ircd => '_publish_message' => $nick, $self->channel, $text; 43 43 } 44 44 … … 47 47 my ($text,) = @_; 48 48 49 post ircd => ' publish_notice' => $self->channel, $text;49 post ircd => '_publish_notice' => $self->channel, $text; 50 50 } 51 51 -
lang/perl/XIRCD/trunk/lib/XIRCD/Component/Server.pm
r11679 r11757 60 60 }; 61 61 62 event publish_message => sub {62 event _publish_message => sub { 63 63 my ($nick, $channel, $message) = get_args; 64 64 … … 78 78 }; 79 79 80 event publish_notice => sub {80 event _publish_notice => sub { 81 81 my ($channel, $message) = get_args; 82 82 -
lang/perl/XIRCD/trunk/lib/XIRCD/Component/Twitter.pm
r11679 r11757 3 3 use XIRCD::Component; 4 4 5 with qw( MooseX::POE::Aliased);5 with qw(XIRCD::Role); 6 6 7 7 use Encode; … … 13 13 14 14 15 has 'config' => ( 16 isa => 'HashRef', 17 is => 'rw', 18 ); 15 has 'apiurl' => ( isa => 'Str', is => 'rw', default => sub { 'http://twitter.com/statuses' } ); 16 has 'apihost' => ( isa => 'Str', is => 'rw', default => sub { 'twitter.com:80' } ); 17 has 'apirealm' => ( isa => 'Str', is => 'rw', default => sub { 'Twitter API' } ); 18 19 has 'screenname' => ( isa => 'Str', is => 'rw' ); 20 has 'username' => ( isa => 'Str', is => 'rw' ); 21 has 'password' => ( isa => 'Str', is => 'rw' ); 22 has 'retry' => ( isa => 'Int', is => 'rw', default => sub { 60 } ); 19 23 20 24 has 'since' => ( … … 25 29 my $call = shift; 26 30 27 my self = $call->(@_);31 my $self = $call->(@_); 28 32 29 33 POE::Component::Client::HTTP->spawn( 30 34 Agent => 'xircd_component_twitter/0.1', 31 Alias => self->http_alias,35 Alias => $self->http_alias, 32 36 ); 33 37 34 self->config->{apiurl} ||= 'http://twitter.com/statuses'; 35 self->config->{apihost} ||= 'twitter.com:80'; 36 self->config->{apirealm} ||= 'Twitter API'; 37 self->config->{alias} ||= 'twitter'; 38 39 return self; 38 return $self; 40 39 }; 41 42 sub START {43 self->alias('twitter');44 45 debug "start twitter";46 47 POE::Kernel->post( ircd => 'join_channel', self->config->{channel}, self->alias );48 self->yield('read_twitter_friend_timeline');49 }50 40 51 41 event send_message => sub { … … 53 43 54 44 my $req = HTTP::Request::Common::POST( 55 self-> config->{apiurl}. '/update.json',45 self->apiurl . '/update.json', 56 46 [ status => encode('utf-8',$status) ], 57 47 ); 58 $req->authorization_basic(self-> config->{twitter}->{username}, self->config->{twitter}->{password});48 $req->authorization_basic(self->username, self->password); 59 49 60 POE::Kernel->post(self->http_alias => request => 'http_response', $req);50 post self->http_alias => request => 'http_response', $req; 61 51 }; 62 52 63 event read_twitter_friend_timeline=> sub {53 event start => sub { 64 54 debug "read twitter"; 65 55 66 my $uri = URI->new(self-> config->{apiurl}. '/friends_timeline.json');56 my $uri = URI->new(self->apiurl . '/friends_timeline.json'); 67 57 $uri->query_form(since => HTTP::Date::time2str(self->since)) if self->since; 68 58 self->since(time); 69 59 70 60 my $req = HTTP::Request->new(GET => $uri); 71 $req->authorization_basic(self-> config->{twitter}->{username}, self->config->{twitter}->{password});61 $req->authorization_basic(self->username, self->password); 72 62 73 POE::Kernel->post(self->http_alias => request => 'http_response', $req);63 post self->http_alias => request => 'http_response', $req; 74 64 }; 75 65 … … 83 73 if ($uri =~ /update.json/) { 84 74 unless ($response->is_success) { 85 self->yield(response_error => $response);75 yield response_error => $response; 86 76 return; 87 77 } 88 self->yield(update_success => $response);78 yield update_success => $response; 89 79 } elsif ($uri =~ /friends_timeline.json/) { 90 self->yield(friend_timeline_success => $response);80 yield friend_timeline_success => $response; 91 81 } 92 82 }; … … 99 89 my $ret = JSON::Any->jsonToObj($response->content); 100 90 for my $line ( reverse @{ $ret || [] } ) { 101 POE::Kernel->post( 102 ircd => publish_message => 103 $line->{user}->{screen_name}, 104 self->config->{channel}, 105 $line->{text}, 106 ); 91 publish_message $line->{user}->{screen_name} => $line->{text}; 107 92 } 108 93 } 109 94 110 POE::Kernel->delay('read_twitter_friend_timeline', self->config->{twitter}->{retry});95 delay start => self->retry; 111 96 }; 112 97 … … 116 101 if ( $response->is_success ) { 117 102 my $ret = JSON::Any->jsonToObj($response->content); 118 POE::Kernel->post( ircd => publish_notice => self->config->{channel}, $ret->{text} );103 publish_notice $ret->{text}; 119 104 } 120 105 }; -
lang/perl/XIRCD/trunk/lib/XIRCD/Component/Wassr.pm
r11679 r11757 3 3 use XIRCD::Component; 4 4 5 with ' MooseX::POE::Aliased';5 with 'XIRCD::Role'; 6 6 7 7 use POE qw( … … 15 15 use POE::Filter::XML::NS qw/:JABBER :IQ/; 16 16 17 has 'config' => (18 isa => 'HashRef',19 is => 'rw',20 );21 22 17 has 'jabber' => ( 23 18 isa => 'POE::Component::Jabber', 24 19 is => 'rw', 25 20 ); 21 22 has 'username' => ( isa => 'Str', is => 'rw' ); 23 has 'password' => ( isa => 'Str', is => 'rw' ); 24 has 'server' => ( isa => 'Str', is => 'rw' ); 25 has 'port' => ( isa => 'Int', is => 'rw', default => sub { 5222 } ); 26 26 27 27 has 'jid' => ( … … 30 30 ); 31 31 32 sub START{32 event start => sub { 33 33 self->alias('wassr'); 34 34 35 35 debug "start wassr"; 36 37 my ($username, $hostname) = split '@', self-> config->{jabber}->{username};36 warn self->channel; 37 my ($username, $hostname) = split '@', self->username; 38 38 39 39 self->jabber( 40 40 POE::Component::Jabber->new( 41 IP => self-> config->{jabber}->{server},42 Port => self-> config->{jabber}->{port} || 5222,41 IP => self->server, 42 Port => self->port, 43 43 Hostname => $hostname, 44 44 Username => $username, 45 Password => self-> config->{jabber}->{password},45 Password => self->password, 46 46 Alias => 'jabber', 47 47 States => { … … 54 54 ); 55 55 56 POE::Kernel->post( ircd => 'join_channel', self->config->{channel}, self->alias ); 57 POE::Kernel->post( jabber => 'connect' ); 58 } 56 post jabber => 'connect'; 57 }; 59 58 60 59 event status_handler => sub { … … 65 64 self->jid(self->jabber->jid); 66 65 67 POE::Kernel->post(jabber => 'output_handler', POE::Filter::XML::Node->new('presence'));68 POE::Kernel->post(jabber => 'purge_queue');66 post jabber => 'output_handler', POE::Filter::XML::Node->new('presence'); 67 post jabber => 'purge_queue'; 69 68 } 70 69 }; 71 70 72 71 event input_handler => sub { 73 my self = shift;74 72 my ($node,) = get_args; 75 73 … … 81 79 my ($nick, $text) = $body->data =~ /^([A-Za-z0-9_.-]+): (.*)/s; 82 80 if ($nick && $text) { 83 POE::Kernel->post( ircd => 'publish_message', $nick, self->config->{channel}, $text );81 publish_message $nick => $text; 84 82 } else { 85 POE::Kernel->post( ircd => 'publish_notice', self->config->{channel}, $body->data );83 publish_notice self->config->{channel} => $body->data; 86 84 } 87 85 } … … 100 98 debug "send:", $node->to_str; 101 99 102 POE::Kernel->post( jabber => output_handler => $node );100 post jabber => output_handler => $node; 103 101 }; 104 102 … … 107 105 108 106 if ( $error == +PCJ_SOCKETFAIL or $error == +PCJ_SOCKETDISCONNECT or $error == +PCJ_CONNECTFAIL ) { 109 print "Reconnecting!\n";110 POE::Kernel->post( jabber => 'reconnect' );107 debug "Reconnecting!"; 108 post jabber => 'reconnect'; 111 109 } 112 110 elsif ( $error == +PCJ_SSLFAIL ) { 113 print "TLS/SSL negotiation failed\n";111 debug "TLS/SSL negotiation failed"; 114 112 } 115 113 elsif ( $error == +PCJ_AUTHFAIL ) { 116 print "Failed to authenticate\n";114 debug "Failed to authenticate"; 117 115 } 118 116 elsif ( $error == +PCJ_BINDFAIL ) { 119 print "Failed to bind a resource\n";117 debug "Failed to bind a resource"; 120 118 } 121 119 elsif ( $error == +PCJ_SESSIONFAIL ) { 122 print "Failed to establish a session\n";120 debug "Failed to establish a session"; 123 121 } 124 122 };
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)