Changeset 451


Ignore:
Timestamp:
07/09/12 15:40:49 (12 years ago)
Author:
nanardon
Message:

Add tryme command

Many users complain about the new asv behavior. It has been decided to
reintroduced it.
At the French Perl Workshow Cognominal suggested "try me" as command, so here it
is.

Location:
server/trunk/web/lib/Sophie/Controller
Files:
2 edited

Legend:

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

    r379 r451  
    102102        return $c->go('/chat/cmd/' . $cmd, [ $reqspec, @args ]); 
    103103    } else { 
    104         $c->stash->{xmlrpc} = { 
    105             error => 'No such command', 
    106         }; 
     104        return $c->forward('err_no_cmd', []); 
    107105    } 
     106} 
     107 
     108=head2 err_no_cmd 
     109 
     110Return the 'no such command error'. 
     111 
     112=cut 
     113 
     114sub err_no_cmd : Private { 
     115    my ($self, $c ) = @_; 
     116    return $c->stash->{xmlrpc} = { 
     117        error => 'No such command', 
     118    }; 
    108119} 
    109120 
  • server/trunk/web/lib/Sophie/Controller/Chat/Cmd.pm

    r447 r451  
    1818=cut 
    1919 
     20my %hidden_functions; 
     21 
     22# The given function will not be listed by help anymore 
     23 
     24sub _hidden_functions { 
     25    my ($func) = @_; 
     26 
     27    $hidden_functions{$func} = 1; 
     28} 
     29 
     30my @to_list_functions; 
     31 
     32# The given functions will be listed by help 
     33 
     34sub _to_list_functions { 
     35    my ($func) = @_; 
     36 
     37    push(@to_list_functions, $func); 
     38} 
    2039 
    2140=head2 index 
     
    6988sub _commands { 
    7089    my ( $self, $c ) = @_; 
    71     [ grep { m/^[^_]/ } map { $_->name } $self->get_action_methods() ]; 
     90    [ 
     91        sort { $a cmp $b } 
     92        grep { ! $hidden_functions{$_} } # Command to not list 
     93                                    # TODO: not hardcode list here 
     94        grep { m/^[^_]/ } 
     95        (map { $_->name } 
     96        $self->get_action_methods()), @to_list_functions ]; 
    7297} 
    7398 
     
    13141339} 
    13151340 
     1341_to_list_functions('try me'); 
     1342 
     1343=head2 try me 
     1344 
     1345Just try me 
     1346 
     1347=head1 HIDDEN BOT FUNCTION 
     1348 
     1349=cut 
     1350 
     1351_hidden_functions('try'); 
     1352 
     1353sub try : XMLRPC { 
     1354    my ($self, $c, $reqspec, @args) = @_; 
     1355 
     1356    if (($args[0] || '') eq 'me') { 
     1357        my %tryme = %{ $c->forward('/user/fetchdata', [ 'tryme' ]) || {} }; 
     1358        my @msgs = @{ $tryme{msgs} || []}; 
     1359 
     1360        if (@msgs) { 
     1361            return $c->stash->{xmlrpc} = { 
     1362                message => [ $msgs[rand(scalar(@msgs))] ], 
     1363            }; 
     1364        } else { 
     1365            return $c->stash->{xmlrpc} = { 
     1366                message => [ 'I don\'t know what you mean' ], 
     1367            }; 
     1368        } 
     1369    } else { 
     1370        return $c->stash->{xmlrpc} = $c->go('/chat/err_no_cmd', []); 
     1371    } 
     1372} 
     1373 
    13161374=head1 AUTHOR 
    13171375 
Note: See TracChangeset for help on using the changeset viewer.