Ticket #559: hyppolit-0.5-tracdb.patch

File hyppolit-0.5-tracdb.patch, 6.5 KB (added by getty, 5 years ago)

Patch for reading tracdb (needs $config->{tracdb} with fullpath to trac db) - right now fixed URL for trac of padre

  • Hyppolit/lib/Hyppolit.pm

     
    2929 
    3030 
    3131 
    32 our $VERSION = '0.04'; 
     32our $VERSION = '0.05'; 
    3333 
    3434use base 'Exporter'; 
    3535 
     
    3838use POE::Component::IRC::Plugin::AutoJoin; 
    3939use POE::Component::IRC::Plugin::Logger; 
    4040use POE::Component::IRC::Plugin::FollowTail; 
     41use DBI; 
    4142 
     43use Data::Dumper; 
    4244 
    4345use YAML::Syck qw(LoadFile DumpFile); 
    4446my $svnlook = '/usr/bin/svnlook'; 
     
    4648my @methods = qw( 
    4749    _start irc_join irc_public irc_msg 
    4850    irc_tail_input irc_tail_error irc_tail_reset 
     51    trac_check 
    4952    ); 
    5053our @EXPORT = @methods; 
    5154my $config; 
     
    7174        not @{ $config->{channels} }) { 
    7275        die "No channels defined\n"; 
    7376    } 
    74     use Data::Dumper; 
     77 
    7578    print Dumper $config; 
    7679 
    77  
    7880    POE::Session->create( 
    7981        package_states => [ 
    8082            main => \@methods 
     
    8486    $poe_kernel->run(); 
    8587} 
    8688 
     89# so that it is accessable outside of the PoCo::IRC 
     90my $irc; 
     91my $dbh; 
    8792 
    8893sub _start { 
    89     my $irc = POE::Component::IRC::State->spawn( 
     94    $irc = POE::Component::IRC::State->spawn( 
    9095        Nick   => $config->{nick}, 
    9196        Server => $config->{server}, 
    9297    ); 
     
    104109# Restricted => 0,   #did not help 
    105110            Sort_by_date => 1, 
    106111        )); 
     112        system "chmod -R 755 $config->{logdir}"; # TODO move to a better place 
    107113    } 
    108     system "chmod -R 755 $config->{logdir}"; # TODO move to a better place 
    109     if ($config->{inputfile}) { 
     114    if ($config->{inputfile}) { 
    110115        $irc->plugin_add( 'FollowTail' => POE::Component::IRC::Plugin::FollowTail->new(  
    111116            filename => $config->{inputfile}, 
    112117        )); 
    113118    } 
    114119 
    115  
    116120    $irc->yield(register => 'join'); 
    117121    #$irc->yield(register => 'all'); 
    118122    $irc->yield('connect'); 
    119     # irc_public 
     123 
     124    if ($config->{tracdb}) { 
     125        $dbh = DBI->connect("dbi:SQLite:dbname=".$config->{tracdb},"",""); 
     126        $_[ KERNEL ]->delay(trac_check => 5); 
     127    } 
     128 
    120129} 
    121130 
    122131sub irc_public { 
    123132    my $nick = (split /!/, $_[ARG0])[0]; 
    124133    my $channel = $_[ARG1]; 
    125     my $irc = $_[SENDER]->get_heap(); 
     134# now unnecessary 
     135#   my $irc = $_[SENDER]->get_heap(); 
    126136 
    127137    my $text = $_[ARG2]; 
    128138     
     
    166176        } 
    167177    } 
    168178 
     179    # regexp need adjusting, i'm bad at it ;)... 
     180    if ($text =~ /\#(\d+)/x) { 
     181        if ($1+0 > 0) { 
     182            my $text = trac_ticket_text($1); 
     183            $irc->yield(privmsg => $channel, $text ) if $text; 
     184        } 
     185    } 
    169186 
     187    # regexp need adjusting, i'm bad at it ;)... 
     188    if ($text =~ /r(\d+)/x) { 
     189        # no check at all... TODO 
     190        $irc->yield(privmsg => $channel, trac_changeset_text($1)) if $1+0 > 0; 
     191    } 
     192 
    170193    # TODO karma only users who are around ? 
    171194    # record karma 
    172195    if ($text =~ /(\S+)(\+\+|--)/) { 
     
    188211sub irc_msg { 
    189212    my $nick = (split /!/, $_[ARG0])[0]; 
    190213    #my $channel = $_[ARG1]; 
    191     my $irc = $_[SENDER]->get_heap(); 
     214# now unnecessary 
     215#   my $irc = $_[SENDER]->get_heap(); 
    192216 
    193217    my $text = $_[ARG2]; 
    194218 
     
    198222sub irc_join { 
    199223    my $nick = (split /!/, $_[ARG0])[0]; 
    200224    my $channel = $_[ARG1]; 
    201     my $irc = $_[SENDER]->get_heap(); 
     225# now unnecessary 
     226#   my $irc = $_[SENDER]->get_heap(); 
    202227 
    203228    # only send the message if we were the one joining 
    204229    if ($nick eq $irc->nick_name()) { 
     
    220245    } 
    221246    print "Giving op to '$nick' on '$channel' ($irc)\n"; 
    222247    $irc->yield(mode => $channel => "+o $nick"); 
    223     system "chmod -R 755 $config->{logdir}"; # TODO move to a better place 
     248# its already at another place, should be removed here? 
     249#   system "chmod -R 755 $config->{logdir}"; # TODO move to a better place 
    224250} 
    225251 
    226252sub _default { 
    227253    my $nick = (split /!/, $_[ARG0])[0]; 
    228254    print "Default: $nick ", scalar(@_), "\n"; 
    229255} 
     256 
    230257sub irc_all { 
    231258    my $nick = (split /!/, $_[ARG0])[0]; 
    232259    print "All: $nick ", scalar(@_), "\n"; 
     
    263290    my ($kernel, $sender, $filename, $errnum, $errstring) 
    264291        = @_[KERNEL, SENDER, ARG0 .. ARG2]; 
    265292    $kernel->post( $sender, 'privmsg', $_, "SVN ERROR: $errnum $errstring" ) for @{ $config->{channels} }; 
    266     my $irc = $sender->get_heap(); 
     293# now unnecessary 
     294#   my $irc = $sender->get_heap(); 
    267295    $irc->plugin_del( 'FollowTail' ); 
    268296    return; 
    269297} 
     
    274302    return; 
    275303} 
    276304 
     305sub trac_changeset_text { 
     306    my $changeset_id = shift; 
     307    return "Changeset #".$changeset_id." http://padre.perlide.org/trac/changeset/".$changeset_id; 
     308} 
    277309 
     310sub trac_ticket_text { 
     311    return if !$config->{tracdb}; 
     312    my $ticket_id = shift; 
     313    my $ticket = $dbh->selectrow_hashref(" 
     314        select * from ticket 
     315            where id = ? 
     316    ", {}, $ticket_id); 
     317    return if !$ticket; 
     318    my $ticket_comment = $dbh->selectrow_hashref(" 
     319        select oldvalue from ticket_change 
     320            where ticket = ? and field = 'comment' 
     321            order by time desc 
     322    ", {}, $ticket_id); 
     323    my $url = "http://padre.perlide.org/trac/ticket/".$ticket_id; 
     324    $url .= "#comment:".$ticket_comment->{oldvalue} if $ticket_comment and $ticket_comment->{oldvalue}; 
     325    return "#".$ticket_id.": ".$ticket->{summary}." (".$ticket->{status}." ".$ticket->{type}.") [ ".$url." ]"; 
     326} 
     327 
     328sub trac_check { 
     329    my $trac_check_time = time; 
     330    my $last_trac_check = $config->{last_trac_check}; 
     331 
     332    my $tickets = $dbh->selectall_hashref(" 
     333        select id from ticket 
     334            where changetime > ? and changetime <= ? 
     335            order by changetime asc 
     336    ", "id", {}, $last_trac_check, $trac_check_time); 
     337 
     338    for my $ticket_id (keys %{$tickets}) { 
     339        my $text = trac_ticket_text($ticket_id); 
     340        if ($text) { 
     341            $irc->yield( privmsg => $_, $text) for @{ $config->{channels} }; 
     342        } 
     343    } 
     344 
     345    $config->{last_trac_check} = $trac_check_time; 
     346    save_config; 
     347    $_[KERNEL]->delay(trac_check => 30); 
     348    return; 
     349} 
     350 
    2783511; 
    279352 
    280353 
  • Hyppolit/Makefile.PL

     
    1212requires       'POE::Component::IRC::State'            => '2.52'; 
    1313requires       'POE::Component::IRC::Plugin::AutoJoin' => '1.2'; 
    1414requires       'YAML::Syck'                            => '1.0'; 
     15requires       'DBD::SQLite'                           => '1.25'; 
     16requires       'DBI'                                   => '1.609'; 
    1517 
    1618no_index       'directory'                => qw{ t xt eg share inc privinc }; 
    1719#homepage       'http://padre.perlide.org/'; 
  • Hyppolit/Changes

     
    11Changes of Hyppolit the IRC bot 
    22 
     3v0.05 2009.09.23 
     4    Added tracdb config parameter for parsing of tracdb 
     5    Added reacting on "#<ticketnumber>" on channel 
     6    Added (primitive) reacting on "r<changeset>" on channel 
     7 
    38v0.04 2009.03.08 
    49    Fix karma regex 
    510    count commits as karma as well