Changeset 1101

Show
Ignore:
Timestamp:
11/04/07 18:38:35 (6 years ago)
Author:
tokuhirom
Message:

lang/perl/mobirc: now you can post message to twitter/wassr/frepa, or more target.

Location:
lang/perl/mobirc/trunk/mobirc/lib/Mobirc
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/mobirc/trunk/mobirc/lib/Mobirc/Channel.pm

    r1063 r1101  
    7171} 
    7272 
     73sub post_command { 
     74    my ($self, $command) = @_; 
     75 
     76    for my $code (@{$self->{global_context}->get_hook_codes('process_command')}) { 
     77        my $ret = $code->($self->{global_context}, $command, $self); 
     78        last if $ret; 
     79    } 
     80} 
     81 
    7382sub name { 
    7483    my ($self, $name) = @_; 
  • lang/perl/mobirc/trunk/mobirc/lib/Mobirc/HTTPD.pm

    r1082 r1101  
    6969    my $c = { 
    7070        config     => $config, 
    71         poe        => $poe, 
    7271        req        => $request, 
    7372        user_agent => $user_agent, 
    7473        mobile_agent => HTTP::MobileAgent->new($user_agent), 
    7574        irc_nick     => $poe->kernel->alias_resolve('irc_session')->get_heap->{irc}->nick_name, 
    76         irc_incode   => $poe->kernel->alias_resolve('irc_session')->get_heap->{config}->{incode}, 
    7775        global_context => Mobirc->context, 
    7876    }; 
  • lang/perl/mobirc/trunk/mobirc/lib/Mobirc/HTTPD/Controller.pm

    r1082 r1101  
    131131    DEBUG "POST MESSAGE $message"; 
    132132 
     133    $c->{global_context}->get_channel($channel)->post_command($message); 
     134 
    133135    my $irc_incode = $c->{irc_incode}; 
    134     if ($message) { 
    135         if ($message =~ m{^/}) { 
    136             DEBUG "SENDING COMMAND"; 
    137             $message =~ s!^/!!g; 
    138  
    139             my @args = 
    140               map { encode( $irc_incode, $_ ) } split /\s+/, 
    141               $message; 
    142  
    143             $c->{poe}->kernel->post('mobirc_irc', @args); 
    144         } else { 
    145             DEBUG "NORMAL PRIVMSG"; 
    146  
    147             $c->{poe}->kernel->post( 'mobirc_irc', 
    148                 privmsg => encode( $irc_incode, $channel ) => 
    149                 encode( $irc_incode, $message ) ); 
    150  
    151             DEBUG "Sending message $message"; 
    152             if ($c->{config}->{httpd}->{echo} eq true) { 
    153                 $c->{global_context}->get_channel($channel)->add_message( 
    154                     Mobirc::Message->new( 
    155                         who => decode( 
    156                             $irc_incode, 
    157                             $c->{irc_nick} 
    158                         ), 
    159                         body  => $message, 
    160                         class => 'publicfromhttpd', 
    161                     ) 
    162                 ); 
    163             } 
    164         } 
    165     } 
    166136 
    167137    my $response = HTTP::Response->new(302); 
  • lang/perl/mobirc/trunk/mobirc/lib/Mobirc/Plugin/Component/IRCClient.pm

    r1082 r1101  
    1818    DEBUG "register ircclient component"; 
    1919    $global_context->register_hook( 
    20         'run_component' => sub { _init($conf, $global_context) }, 
    21     ); 
     20        'run_component' => sub { _init($conf, shift) }, 
     21    ); 
     22    $global_context->register_hook( 
     23        'process_command' => sub { my ($global_context, $command, $channel) = @_;  _process_command($conf, $global_context, $command, $channel) }, 
     24    ); 
     25} 
     26 
     27sub _process_command { 
     28    my ($conf, $global_context, $command, $channel) = @_; 
     29 
     30    my $irc_incode = $conf->{incode}; 
     31    if ($command && $channel->name =~ /^[#*%]/) { 
     32        if ($command =~ m{^/}) { 
     33            DEBUG "SENDING COMMAND"; 
     34            $command =~ s!^/!!g; 
     35 
     36            my @args = 
     37              map { encode( $irc_incode, $_ ) } split /\s+/, 
     38              $command; 
     39 
     40            $poe_kernel->post('mobirc_irc', @args); 
     41        } else { 
     42            DEBUG "NORMAL PRIVMSG"; 
     43 
     44            $poe_kernel->post( 'mobirc_irc', 
     45                privmsg => encode( $irc_incode, $channel->name ) => 
     46                encode( $irc_incode, $command ) ); 
     47 
     48            DEBUG "Sending command $command"; 
     49            # FIXME: httpd $B4X78$J$$7o(B 
     50            if ($global_context->config->{httpd}->{echo} eq true) { 
     51                $channel->add_message( 
     52                    Mobirc::Message->new( 
     53                        who => decode( 
     54                            $irc_incode, 
     55                            $conf->{irc_nick} 
     56                        ), 
     57                        body  => $command, 
     58                        class => 'public', 
     59                    ) 
     60                ); 
     61            } 
     62        } 
     63        return true; 
     64    } 
     65    return false; 
    2266} 
    2367 
  • lang/perl/mobirc/trunk/mobirc/lib/Mobirc/Plugin/Component/Twitter.pm

    r1100 r1101  
    77use POE; 
    88use POE::Sugar::Args; 
     9use Encode; 
    910 
    1011sub register { 
     
    1516        'run_component' => sub { _init($conf, shift) }, 
    1617    ); 
     18    $global_context->register_hook( 
     19        'process_command' => sub { my ($global_context, $command, $channel) = @_;  _process_command($conf, $global_context, $command, $channel) }, 
     20    ); 
    1721 
    1822    $conf->{channel} ||= U '#twitter'; 
     
    2024    $conf->{screenname} ||= $conf->{username}; 
    2125    $conf->{friend_timeline_interval} ||= 60; 
     26} 
     27 
     28sub _process_command { 
     29    my ($conf, $global_context, $command, $channel) = @_; 
     30 
     31    if ($conf->{channel} eq $channel->name) { 
     32        $poe_kernel->post( $conf->{alias}, 'update', encode('utf-8', $command) ); 
     33        $channel->add_message( 
     34            Mobirc::Message->new( 
     35                who => $conf->{screenname}, 
     36                body  => $command, 
     37                class => 'twitter', 
     38            ) 
     39        ); 
     40        return true; 
     41    } 
     42    return false; 
    2243} 
    2344 
     
    86107      channel: #mytwitter 
    87108 
    88 =head1 LIMITATION 
    89  
    90 read only. you cannot post to twitter ;-( 
    91