Package: xchat
Version: 2.8.8-6
Severity: wishlist
Tags: patch

Dear Maintainer,
Please find the attached perl plugin script, which is supposed to
guess whether ints communicated to the channels are meant as
bugs.d.o/int. Commands, as well stats are pass via query to "self".
Further suggestions, flames, improvements welcome :)

-- System Information:
Debian Release: wheezy/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'testing')
Architecture: amd64 (x86_64)

Kernel: Linux 3.2.0-3-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages xchat depends on:
ii  libatk1.0-0         2.4.0-2
ii  libc6               2.13-35
ii  libcairo2           1.12.2-2
ii  libdbus-1-3         1.6.2-2
ii  libdbus-glib-1-2    0.100-1
ii  libfontconfig1      2.9.0-7
ii  libfreetype6        2.4.9-1
ii  libgdk-pixbuf2.0-0  2.26.1-1
ii  libglib2.0-0        2.32.3-1
ii  libgtk2.0-0         2.24.10-1
ii  libpango1.0-0       1.30.0-1
ii  libperl5.14         5.14.2-12
ii  libsexy2            0.1.11-2+b1
ii  libssl1.0.0         1.0.1c-4
ii  libx11-6            2:1.5.0-1
ii  libxml2             2.8.0+dfsg1-5
ii  xchat-common        2.8.8-6

Versions of packages xchat recommends:
ii  alsa-utils     1.0.25-3
ii  libnotify-bin  0.7.5-1
ii  libnotify1     0.5.0-2
ii  libpython2.7   2.7.3-2
ii  tcl8.5         8.5.11-2
ii  xdg-utils      1.1.0~rc1+git20111210-6

xchat suggests no packages.

-- no debconf information
# Copyright (c) 2012 - George Danchev <danc...@spnet.net>

# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

use strict;
use warnings;

my $time_start = localtime();
my $self = "int2bdo";
my $vers = "0.1";
my $seve = $self . "/" . $vers;
my %cmd = (
    STAT => $self . "_stat",
    VERB => $self . "_verb",
    HELP => $self . "_help",
);
my ($opt_STAT, $opt_VERB, $opt_HELP) = (undef, 0, undef);
my $desc = "Suspicious ints 2 bugs.d.o/int (verbosity:$opt_VERB; for help type 
to self: $cmd{'HELP'})";
my $burl = "http://bugs.debian.org";;
my %freq = ( # NONE_0 => 0,
    SURE_1 => 0,
    SURE_2 => 0,
    WILD_3 => 0,
    WILD_4 => 0,
    WILD_5 => 0,
    WILD_6 => 0,
);

### init
Xchat::register($self, $vers, $desc);
Xchat::hook_print('Channel Message', \&hrefbugs);
Xchat::hook_print('Your Message', \&hrefbugs);
Xchat::hook_print('Your Message', \&dispatch);
Xchat::print("Loaded $seve - $desc");


##
sub print_line {
    Xchat::print("-" x 20);
}

###
sub percfre($) {
    my $fre = shift;
    my $hits = 0;
    map { $hits += $_ } values %freq;
    return $hits ? sprintf("%.1f" , ($fre/$hits)*100.0) : 0;
}

###
sub hrefbugs {
    W:
    while ( $_[0][1]  =~
        /(?:\#([123456789]{1}\d+))          # 1. sure guess
        |(?:bug\s*\#?([123456789]{1}\d+))   # 2. sure guess
        |(?:^([123456789]{1}\d+)\.?$)       # 3. wild guess
        |(?:\s([123456789]{1}\d+)\.?$)      # 4. wild guess
        |(?:([123456789]{1}\d+)^.\d)        # 5. wild guess - skip common 
'version 1.2' pattern
        |(?:\s([123456789]{1}\d+)\s)        # 6. wild guess - too much noise, 
but ...
        /xgi
    ) {
        my ($nam, $fre, $bug) = (undef, undef, undef);
        if    (defined($1)) {
            ($nam, $fre, $bug) = ( 'sure_1', ++$freq{'SURE_1'}, $1);
        }
        elsif (defined($2)) {
            ($nam, $fre, $bug) = ( 'sure_2', ++$freq{'SURE_2'}, $2);
        }
        elsif (defined($3)) {
            ($nam, $fre, $bug) = ( 'WILD_3', ++$freq{'WILD_3'}, $3);
        }
        elsif (defined($4)) {
            ($nam, $fre, $bug) = ( 'WILD_4', ++$freq{'WILD_4'}, $4);
        }
        elsif (defined($5)) {
            ($nam, $fre, $bug) = ( 'WILD_5', ++$freq{'WILD_5'}, $5);
        }
        elsif (defined($6)) {
            ($nam, $fre, $bug) = ( 'WILD_6', ++$freq{'WILD_6'}, $6);
        }
        else { # no-op
            ($nam, $fre, $bug) = (undef, undef, undef);
        }

        if (defined($nam) and defined($fre) and defined($bug) ) {
            my @top = sort { $b <=> $a } values %freq;
            my $rank = 0;
            for ($rank=0; $rank < scalar @top; $rank++) {
                if ( $top[$rank] eq $fre ) {
                    $rank++;
                    last;
                }
            }
            if ($opt_VERB) {
                my $perc = percfre($fre);
                Xchat::print("BUGUESS by $seve: rank:$rank name:$nam freq:$fre 
($perc%) url: $burl/$bug");
            }
            else {
                Xchat::print("BUGUESS by $seve: $burl/$bug");
            }
        }
    }

    return Xchat::EAT_NONE;
}

###
sub showstat {
    my $time_now = localtime();
    print_line;
    Xchat::print("STAT by $seve: $time_start - $time_now (ranked by 
frequency)");
    print_line;
    Xchat::print("RANK\t NAME     FREQ\n");
    my $rank = 1;
    foreach my $key (sort {$freq{$b} <=> $freq{$a} } keys %freq) {
        my $perc = percfre($freq{$key});
        Xchat::print("$rank\t $key   $freq{$key} ($perc%)");
        $rank++;
    }
    print_line;
    return Xchat::EAT_XCHAT;
}

###
sub showverb($) {
    my $in = shift;
    if ( ( !defined($in) ) or ( defined($in) and $in > 0 ) ) {
        $opt_VERB = 1; Xchat::print("$seve: setting VERBOSE mode\n");
    }
    else {
        $opt_VERB = 0; Xchat::print("$seve: setting QUIET mode\n");
    }
    return Xchat::EAT_XCHAT;
}

###
sub showhelp {
    print_line;
    Xchat::print("HELP by $seve (type to self):");
    print_line;
    foreach my $key (sort(keys %cmd)) {
        if ($key eq 'VERB') {
            Xchat::print("$cmd{$key}=[0,1]");
        }
        else {
            Xchat::print("$cmd{$key}");
        }
    }
    print_line;
    return Xchat::EAT_XCHAT;
}

###
sub dispatch {
    my $inp = $_[0][1];
    showstat     if ( $inp =~ /$cmd{'STAT'}/ );
    showverb($1) if ( $inp =~ /$cmd{'VERB'}=?([+-]*\d)?/ );
    showhelp     if ( $inp =~ /$cmd{'HELP'}/ );
    # ignore anything else
    return Xchat::EAT_NONE;
}

Reply via email to