package Liens;

use POE::Component::IRC::Plugin qw( :ALL );

sub new {
    my $package = shift;
    return bless {}, $package;
}

sub PCI_register {
    my ( $self, $irc ) = splice @_, 0, 2;
    $irc->plugin_register( $self, "SERVER", qw(public) );
    return 1;
}

sub PCI_unregister {
    return 1;
}

sub S_public {
    my ( $self, $irc ) = splice @_, 0, 2;

    @cmds = ("site", "wiki", "paste");
    %templates = (
        "site" => "U-classroom sur http://u-classroom.net",
        "wiki" => "Toutes les sessions u-classroom sur http://doc.ubuntu-fr.org/projets/ecole/topic (en cours de migration)",
        "paste" => "http://paste.dunnewind.net pour les copier/coller"
    );

    my $nick = ( split /!/, ${ $_[0] } )[0];
    my $channel = ${ $_[1] }->[0];
    my $msg = ${ $_[2] };

    @tmp = (split / /, $msg);
    $cmd = (split /!/, @tmp[0])[1];
    $nick = @tmp[1] if @tmp[1];

    if (grep /^$cmd$/, @cmds) {
        $irc->yield( privmsg => $channel => "$nick: $templates{$cmd}");

        return PCI_EAT_PLUGIN;
    }
    return PCI_EAT_NONE;
}

1;
