Changeset 100


Ignore:
Timestamp:
12/09/10 06:08:08 (13 years ago)
Author:
nanardon
Message:
  • add web page to view paste from the bot
  • add first function
Location:
server/trunk/web/lib/Sophie
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • server/trunk/web/lib/Sophie/Controller/Chat.pm

    r72 r100  
    2828 
    2929 
     30} 
     31 
     32sub viewpaste :Path :Args(1) { 
     33    my ($self, $c, $pasteid) = @_; 
     34 
     35    $c->forward('get_paste', [ $pasteid ]); 
     36    if (! $c->stash->{xmlrpc}) { 
     37        $c->go('/404/index'); 
     38    } 
    3039} 
    3140 
     
    7281} 
    7382 
     83sub paste : XMLRPCLocal { 
     84    my ($self, $c, $title, $text) = @_; 
     85 
     86    my @char = ('a' .. 'z', 'A' .. 'Z', 0 .. 9); 
     87    my $id = join('', map { $char[rand(@char)] } (0..7)); 
     88    $c->model('Base::ChatPaste')->create( 
     89        { 
     90            id => $id, 
     91            user_id => $c->model('Base::Users')->find( 
     92                { mail => $c->user->mail })->ukey, 
     93            title => $title, 
     94            reply => $text, 
     95        } 
     96    ); 
     97    $c->model('Base')->storage->dbh->commit; 
     98    $c->stash->{xmlrpc} = $id; 
     99} 
     100 
     101sub get_paste : XMLRPCLocal { 
     102    my ($self, $c, $id) = @_; 
     103 
     104    my $paste = $c->model('Base::ChatPaste')->find( 
     105            { id => $id, }, 
     106            { select => [ qw(whenpaste title reply) ], } 
     107        ); 
     108    if ($paste) { 
     109        return $c->stash->{xmlrpc} = { $paste->get_columns }; 
     110    } else { 
     111        return $c->stash->{xmlrpc} = undef; 
     112    } 
     113} 
     114 
    74115=head1 AUTHOR 
    75116 
  • server/trunk/web/lib/Sophie/Controller/Chat/Cmd.pm

    r77 r100  
    22use Moose; 
    33use namespace::autoclean; 
     4use Getopt::Long; 
    45 
    56BEGIN {extends 'Catalyst::Controller'; } 
     
    3334} 
    3435 
     36sub _getopt : Private { 
     37    my ( $self, $c, $options, @args) = @_; 
     38 
     39    local @ARGV = @args; 
     40 
     41    GetOptions(%{ $options || {} }); 
     42 
     43    return \@ARGV; 
     44} 
     45 
     46 
     47 
     48 
    3549sub help : XMLRPC { 
    3650    my ( $self, $c, $reqspec, @args ) = @_; 
    3751    return $c->{stash}->{xmlrpc} = { 
     52        private_reply => 1, 
    3853        message => [ 
    3954            'availlable command:', 
     
    4257    } 
    4358} 
    44  
    4559 
    4660sub asv : XMLRPC { 
     
    5165} 
    5266 
     67sub version : XMLRPC { 
     68    my ($self, $c, $reqspec, @args) = @_; 
     69 
     70    my @message; 
     71    $reqspec->{src} = 0; 
     72 
     73    @args = @{ $c->forward('_getopt', [ 
     74        { 
     75            'd=s' => \$reqspec->{distribution}, 
     76            'v=s' => \$reqspec->{release}, 
     77            'a=s' => \$reqspec->{arch}, 
     78            's'   => sub { $reqspec->{src} = 1 }, 
     79        }, @args ]) }; 
     80 
     81    my $rpmlist = $c->forward('/search/byname', [ $reqspec, $args[0] ]); 
     82    foreach (@{ $rpmlist->{results} }) { 
     83        my $info = $c->forward('/rpms/basicinfo', [ $_ ]); 
     84        push @message, $info->{evr}; 
     85    } 
     86    return $c->stash->{xmlrpc} = { 
     87        message => \@message, 
     88    } 
     89} 
     90 
    5391sub end : Private { 
    5492    my ($self, $c ) = @_; 
    5593    my $reqspec = $c->req->arguments->[0]; 
     94    $reqspec->{max_line} ||= 4; 
     95    my $message =  $c->stash->{xmlrpc}; 
     96 
     97    my @backup = @{ $message->{message} }; 
     98    my $needpaste = 0; 
     99 
     100    if (@{ $message->{message} } > ($reqspec->{max_line})) { 
     101        @{ $message->{message} } =  
     102            # -2 because line 0 and we remove one for paste url 
     103            @backup[0 .. $reqspec->{max_line} -2]; 
     104        $needpaste = 1; 
     105    }  
     106 
     107    if ($needpaste) { 
     108        my $id = $c->forward('/chat/paste', [ 'Bot paste', join("\n", @backup) ]); 
     109        push(@{ $message->{message} }, $c->uri_for('/chat', $id)); 
     110    } 
     111 
     112    $c->stash->{xmlrpc} = $message; 
    56113 
    57114    $c->forward('/end'); 
Note: See TracChangeset for help on using the changeset viewer.