Changeset 100
- Timestamp:
- 12/09/10 06:08:08 (13 years ago)
- 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 28 28 29 29 30 } 31 32 sub 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 } 30 39 } 31 40 … … 72 81 } 73 82 83 sub 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 101 sub 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 74 115 =head1 AUTHOR 75 116 -
server/trunk/web/lib/Sophie/Controller/Chat/Cmd.pm
r77 r100 2 2 use Moose; 3 3 use namespace::autoclean; 4 use Getopt::Long; 4 5 5 6 BEGIN {extends 'Catalyst::Controller'; } … … 33 34 } 34 35 36 sub _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 35 49 sub help : XMLRPC { 36 50 my ( $self, $c, $reqspec, @args ) = @_; 37 51 return $c->{stash}->{xmlrpc} = { 52 private_reply => 1, 38 53 message => [ 39 54 'availlable command:', … … 42 57 } 43 58 } 44 45 59 46 60 sub asv : XMLRPC { … … 51 65 } 52 66 67 sub 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 53 91 sub end : Private { 54 92 my ($self, $c ) = @_; 55 93 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; 56 113 57 114 $c->forward('/end');
Note: See TracChangeset
for help on using the changeset viewer.