Skip to content
Extraits de code Groupes Projets
Sélectionner une révision Git
  • 015e74e7ef789fa3a9bda73aa807032d32f140f4
  • master par défaut
  • cinch
  • ruby
  • gh-pages
  • v1.0.0
6 résultats

print.pm

Blame
  • print.pm 2,73 Kio
    package PlayBot::utils::print;
    
    use strict;
    use warnings;
    
    use IRC::Utils qw(YELLOW ORANGE GREEN NORMAL LIGHT_BLUE GREY);
    
    # Used to print a content.
    # The public subroutine is print($content).
    # arg :
    #   - $content : a ref to a hash with the following keys :
    #       - author
    #       - duration (in seconds)
    #       - external_id (optional)
    #       - id
    #       - site (if external_id)
    #       - tags : a ref to a list of tags
    #       - title
    #       - url
    # returns :
    #   - a string well formated
    
    sub print
    {
        my ($content) = @_;
    
        my $msg = YELLOW.'['.$content->{'id'}.'] '.GREEN.$content->{'title'};
    
    	if (defined $content->{'author'})
        {
    		$msg .= ' | '.$content->{'author'};
    	}
    
        if (defined $content->{'duration'})
        {
            my $h = int($content->{'duration'} / 3600);
            my $m = int(($content->{'duration'} % 3600) / 60);
            my $s = int(($content->{'duration'} % 3600) % 60);
    
            $msg .= LIGHT_BLUE.' (';
            $msg .= sprintf("%02d:", $h) if ($h > 0);
            $msg .= sprintf("%02d:", $m);
            $msg .= sprintf("%02d", $s);
            $msg .= ')'.NORMAL;
        }
    
        $msg .= ' => '.$content->{'url'}.ORANGE if (defined $content->{'url'});
    
        if (defined $content->{'tags'})
        {
            $msg .= ' '.$_ foreach (@{$content->{'tags'}});
        }
    
        $msg .= GREY;
    
        return $msg;
    }
    
    sub stats
    {
        # a utils::db::stats object;
        my $stats = shift;
        my $line1; 
        my $line2;
        my $line3;
        my $line4;
    
        $line1 .= 'Posté la 1re fois par '.$stats->sender;
        $line1 .= ' le '.$stats->date;
        $line1 .= ' sur '.$stats->chan;