Changeset 11679 for lang/perl/XIRCD
- Timestamp:
- 05/16/08 10:46:51 (5 years ago)
- Location:
- lang/perl/XIRCD/trunk
- Files:
-
- 6 modified
-
TODO (modified) (1 diff)
-
lib/XIRCD/Component.pm (modified) (2 diffs)
-
lib/XIRCD/Component/Server.pm (modified) (2 diffs)
-
lib/XIRCD/Component/Time.pm (modified) (1 diff)
-
lib/XIRCD/Component/Twitter.pm (modified) (4 diffs)
-
lib/XIRCD/Component/Wassr.pm (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/XIRCD/trunk/TODO
r11669 r11679 1 - use self2 - get_args use Devel::Caller3 1 - auto START & STOP 4 2 -- auto join channel -
lang/perl/XIRCD/trunk/lib/XIRCD/Component.pm
r11670 r11679 2 2 use Moose; 3 3 4 use self; 5 use Devel::Caller qw(caller_args); 6 4 7 use Sub::Exporter -setup => { 5 exports => [qw( debug get_args http_alias)],8 exports => [qw(self debug get_args http_alias)], 6 9 groups => { 7 10 default => [ -all ], … … 13 16 } 14 17 15 sub get_args (@){16 return @_[9..19];18 sub get_args { 19 return (caller_args(1))[10..20]; 17 20 } 18 21 19 22 sub http_alias { 20 my $self = shift; 21 return 'twitter_' . $self->get_session_id; 23 return 'twitter_' . self->get_session_id; 22 24 } 23 25 -
lang/perl/XIRCD/trunk/lib/XIRCD/Component/Server.pm
r11669 r11679 33 33 34 34 sub START { 35 my $self = shift; 36 37 $self->alias('ircd'); 35 self->alias('ircd'); 38 36 39 37 debug "start irc"; 40 38 41 $self->config->{servername} ||= 'xircd.ircd';42 $self->config->{client_encoding} ||= 'utf-8';39 self->config->{servername} ||= 'xircd.ircd'; 40 self->config->{client_encoding} ||= 'utf-8'; 43 41 44 $self->ircd(POE::Component::Server::IRC->spawn( config => clone($self->config) ));45 $self->ircd->yield('register');46 $self->ircd->add_auth( mask => '*@*' );47 $self->ircd->add_listener( port => $self->config->{port} || 6667 );42 self->ircd(POE::Component::Server::IRC->spawn( config => clone(self->config) )); 43 self->ircd->yield('register'); 44 self->ircd->add_auth( mask => '*@*' ); 45 self->ircd->add_listener( port => self->config->{port} || 6667 ); 48 46 49 $self->ircd->yield( add_spoofed_nick => { nick => $self->config->{server_nick} } );47 self->ircd->yield( add_spoofed_nick => { nick => self->config->{server_nick} } ); 50 48 } 51 49 52 50 event ircd_daemon_public => sub { 53 my $self = shift; 54 my($nick, $channel, $text) = get_args(@_); 55 my $encoding = $self->config->{client_encoding}; 51 my($nick, $channel, $text) = get_args; 52 my $encoding = self->config->{client_encoding}; 56 53 57 54 debug "public [$channel] $nick : $text"; 58 55 59 my $component = $self->components->{$channel};56 my $component = self->components->{$channel}; 60 57 return unless $component; 61 58 … … 64 61 65 62 event publish_message => sub { 66 my $self = shift; 67 my ($nick, $channel, $message) = get_args(@_); 63 my ($nick, $channel, $message) = get_args; 68 64 69 65 debug "publish to irc: [$channel] $nick : $message"; 70 66 71 $self->nicknames->{$channel} ||= {};72 if ($nick && ! $self->nicknames->{$channel}->{$nick}) {73 $self->nicknames->{$channel}->{$nick}++;74 $self->ircd->yield( add_spoofed_nick => { nick => $nick } );75 $self->ircd->yield( daemon_cmd_join => $nick, $channel );67 self->nicknames->{$channel} ||= {}; 68 if ($nick && !self->nicknames->{$channel}->{$nick}) { 69 self->nicknames->{$channel}->{$nick}++; 70 self->ircd->yield( add_spoofed_nick => { nick => $nick } ); 71 self->ircd->yield( daemon_cmd_join => $nick, $channel ); 76 72 } 77 73 78 #$message = encode( $self->config->{client_encoding}, $message );74 #$message = encode( self->config->{client_encoding}, $message ); 79 75 80 $self->ircd->yield( daemon_cmd_privmsg => $nick => $channel, $_ )76 self->ircd->yield( daemon_cmd_privmsg => $nick => $channel, $_ ) 81 77 for split /\r?\n/, $message; 82 78 }; 83 79 84 80 event publish_notice => sub { 85 my $self = shift; 86 my ($channel, $message) = get_args(@_); 81 my ($channel, $message) = get_args; 87 82 88 83 debug "notice to irc: [$channel] $message"; 89 84 90 #$message = encode( $self->config->{client_encoding}, $message );85 #$message = encode( self->config->{client_encoding}, $message ); 91 86 92 $self->ircd->yield( daemon_cmd_notice => $self->config->{server_nick} => $channel, $_ )87 self->ircd->yield( daemon_cmd_notice => self->config->{server_nick} => $channel, $_ ) 93 88 for split /\r?\n/, $message; 94 89 }; 95 90 96 91 event join_channel => sub { 97 my $self = shift; 98 my ($channel, $component) = get_args(@_); 92 my ($channel, $component) = get_args; 99 93 100 94 debug "join channel: $channel"; 101 95 debug "register: $channel => $component"; 102 96 103 $self->components->{$channel} = $component;104 $self->ircd->yield( daemon_cmd_join => $self->config->{server_nick}, $channel );97 self->components->{$channel} = $component; 98 self->ircd->yield( daemon_cmd_join => self->config->{server_nick}, $channel ); 105 99 }; 106 100 -
lang/perl/XIRCD/trunk/lib/XIRCD/Component/Time.pm
r11669 r11679 19 19 20 20 sub START { 21 my $self = shift; 22 23 $self->alias('time'); 21 self->alias('time'); 24 22 25 23 debug 'start time'; 26 24 27 POE::Kernel->post( ircd => 'join_channel', $self->config->{channel} );28 $self->yield('timecall');25 POE::Kernel->post( ircd => 'join_channel', self->config->{channel} ); 26 self->yield('timecall'); 29 27 } 30 28 31 29 event timecall => sub { 32 my $self = shift;33 34 30 debug "timecall"; 35 31 36 POE::Kernel->post( ircd => 'publish_message' => 'time', $self->config->{channel}, $self->date->strftime("%Y/%m/%d %H:%M:%S") ); 37 POE::Kernel->delay('timecall', 10); 32 POE::Kernel->post( 33 ircd => 'publish_message' => 'time', 34 self->config->{channel}, self->date->strftime("%Y/%m/%d %H:%M:%S") 35 ); 36 POE::Kernel->delay( 'timecall', 10 ); 38 37 }; 39 38 -
lang/perl/XIRCD/trunk/lib/XIRCD/Component/Twitter.pm
r11669 r11679 25 25 my $call = shift; 26 26 27 my $self = $call->(@_);27 my self = $call->(@_); 28 28 29 29 POE::Component::Client::HTTP->spawn( 30 30 Agent => 'xircd_component_twitter/0.1', 31 Alias => $self->http_alias,31 Alias => self->http_alias, 32 32 ); 33 33 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';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 38 39 return $self;39 return self; 40 40 }; 41 41 42 42 sub START { 43 my $self = shift; 44 45 $self->alias('twitter'); 43 self->alias('twitter'); 46 44 47 45 debug "start twitter"; 48 46 49 POE::Kernel->post( ircd => 'join_channel', $self->config->{channel}, $self->alias );50 $self->yield('read_twitter_friend_timeline');47 POE::Kernel->post( ircd => 'join_channel', self->config->{channel}, self->alias ); 48 self->yield('read_twitter_friend_timeline'); 51 49 } 52 50 53 51 event send_message => sub { 54 my $self = shift; 55 my ($status,) = get_args(@_); 52 my ($status,) = get_args; 56 53 57 54 my $req = HTTP::Request::Common::POST( 58 $self->config->{apiurl} . '/update.json',55 self->config->{apiurl} . '/update.json', 59 56 [ status => encode('utf-8',$status) ], 60 57 ); 61 $req->authorization_basic( $self->config->{twitter}->{username}, $self->config->{twitter}->{password});58 $req->authorization_basic(self->config->{twitter}->{username}, self->config->{twitter}->{password}); 62 59 63 POE::Kernel->post( $self->http_alias => request => 'http_response', $req);60 POE::Kernel->post(self->http_alias => request => 'http_response', $req); 64 61 }; 65 62 66 63 event read_twitter_friend_timeline => sub { 67 my $self = shift;68 69 64 debug "read twitter"; 70 65 71 my $uri = URI->new( $self->config->{apiurl} . '/friends_timeline.json');72 $uri->query_form(since => HTTP::Date::time2str( $self->since)) if $self->since;73 $self->since(time);66 my $uri = URI->new(self->config->{apiurl} . '/friends_timeline.json'); 67 $uri->query_form(since => HTTP::Date::time2str(self->since)) if self->since; 68 self->since(time); 74 69 75 70 my $req = HTTP::Request->new(GET => $uri); 76 $req->authorization_basic( $self->config->{twitter}->{username}, $self->config->{twitter}->{password});71 $req->authorization_basic(self->config->{twitter}->{username}, self->config->{twitter}->{password}); 77 72 78 POE::Kernel->post( $self->http_alias => request => 'http_response', $req);73 POE::Kernel->post(self->http_alias => request => 'http_response', $req); 79 74 }; 80 75 81 76 event http_response => sub { 82 my $self = shift; 83 my ($request_packet, $response_packet) = get_args(@_); 77 my ($request_packet, $response_packet) = get_args; 84 78 85 79 my $request = $request_packet->[0]; … … 89 83 if ($uri =~ /update.json/) { 90 84 unless ($response->is_success) { 91 $self->yield(response_error => $response);85 self->yield(response_error => $response); 92 86 return; 93 87 } 94 $self->yield(update_success => $response);88 self->yield(update_success => $response); 95 89 } elsif ($uri =~ /friends_timeline.json/) { 96 $self->yield(friend_timeline_success => $response);90 self->yield(friend_timeline_success => $response); 97 91 } 98 92 }; 99 93 100 94 event friend_timeline_success => sub { 101 my $self = shift;102 103 95 debug "get friend timeline"; 104 my ( $response, ) = get_args (@_);96 my ( $response, ) = get_args; 105 97 106 98 if ( $response->is_success ) { … … 110 102 ircd => publish_message => 111 103 $line->{user}->{screen_name}, 112 $self->config->{channel},104 self->config->{channel}, 113 105 $line->{text}, 114 106 ); … … 116 108 } 117 109 118 POE::Kernel->delay('read_twitter_friend_timeline', $self->config->{twitter}->{retry});110 POE::Kernel->delay('read_twitter_friend_timeline', self->config->{twitter}->{retry}); 119 111 }; 120 112 121 113 event update_success => sub { 122 my $self = shift; 123 124 my ( $response, ) = get_args(@_); 114 my ( $response, ) = get_args; 125 115 126 116 if ( $response->is_success ) { 127 117 my $ret = JSON::Any->jsonToObj($response->content); 128 POE::Kernel->post( ircd => publish_notice => $self->config->{channel}, $ret->{text} );118 POE::Kernel->post( ircd => publish_notice => self->config->{channel}, $ret->{text} ); 129 119 } 130 120 }; -
lang/perl/XIRCD/trunk/lib/XIRCD/Component/Wassr.pm
r11669 r11679 31 31 32 32 sub START { 33 my $self = shift; 34 35 $self->alias('wassr'); 33 self->alias('wassr'); 36 34 37 35 debug "start wassr"; 38 36 39 my ($username, $hostname) = split '@', $self->config->{jabber}->{username};37 my ($username, $hostname) = split '@', self->config->{jabber}->{username}; 40 38 41 $self->jabber(39 self->jabber( 42 40 POE::Component::Jabber->new( 43 IP => $self->config->{jabber}->{server},44 Port => $self->config->{jabber}->{port} || 5222,41 IP => self->config->{jabber}->{server}, 42 Port => self->config->{jabber}->{port} || 5222, 45 43 Hostname => $hostname, 46 44 Username => $username, 47 Password => $self->config->{jabber}->{password},45 Password => self->config->{jabber}->{password}, 48 46 Alias => 'jabber', 49 47 States => { … … 56 54 ); 57 55 58 POE::Kernel->post( ircd => 'join_channel', $self->config->{channel}, $self->alias );56 POE::Kernel->post( ircd => 'join_channel', self->config->{channel}, self->alias ); 59 57 POE::Kernel->post( jabber => 'connect' ); 60 58 } 61 59 62 60 event status_handler => sub { 63 my $self = shift; 64 my ($state,) = get_args(@_); 61 my ($state,) = get_args; 65 62 66 63 if ($state == +PCJ_INIT_FINISHED) { 67 64 debug "init finished"; 68 $self->jid($self->jabber->jid);65 self->jid(self->jabber->jid); 69 66 70 67 POE::Kernel->post(jabber => 'output_handler', POE::Filter::XML::Node->new('presence')); … … 74 71 75 72 event input_handler => sub { 76 my $self = shift;77 my ($node,) = get_args (@_);73 my self = shift; 74 my ($node,) = get_args; 78 75 79 76 debug "recv:", $node->to_str; … … 84 81 my ($nick, $text) = $body->data =~ /^([A-Za-z0-9_.-]+): (.*)/s; 85 82 if ($nick && $text) { 86 POE::Kernel->post( ircd => 'publish_message', $nick, $self->config->{channel}, $text );83 POE::Kernel->post( ircd => 'publish_message', $nick, self->config->{channel}, $text ); 87 84 } else { 88 POE::Kernel->post( ircd => 'publish_notice', $self->config->{channel}, $body->data );85 POE::Kernel->post( ircd => 'publish_notice', self->config->{channel}, $body->data ); 89 86 } 90 87 } … … 92 89 93 90 event send_message => sub { 94 my $self = shift; 95 my ($message,) = get_args(@_); 91 my ($message,) = get_args; 96 92 97 93 my $node = POE::Filter::XML::Node->new('message'); 98 94 99 95 $node->attr('to', 'wassr-bot@wassr.jp'); 100 $node->attr('from', $self->{jid} );96 $node->attr('from', self->{jid} ); 101 97 $node->attr('type', 'chat'); 102 98 $node->insert_tag('body')->data( $message ); … … 108 104 109 105 event error_handler => sub { 110 my $self = shift; 111 my ($error,) = get_args(@_); 106 my ($error,) = get_args; 112 107 113 108 if ( $error == +PCJ_SOCKETFAIL or $error == +PCJ_SOCKETDISCONNECT or $error == +PCJ_CONNECTFAIL ) {
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)