#!/usr/bin/perl

use strict;
use Irssi;

use vars qw($VERSION %IRSSI);

$VERSION = "0.1";
%IRSSI = (
    authors         => 'Frank "yogan" Blendinger',
    contact         => 'yogan@IRCnet or fb(at)intoxicatedmind.net',
    name            => 'shitlist',
    description     => 'script to hide, but not remove ignored messages,'
        . ' based on ignorsula.pl by apic and ignore_log.pl by jsn',
    license         => 'BSD',
    url             => 'http://yogan.meinungsverstaerker.de/irssi/',
);

Irssi::theme_register([
    "shitlist_pubmsg",        "{pubmsgnick \$[-11]0}\x0301,01\$1\x03",
    "shitlist_action_public", "{pubaction \$0}\x0301,01\$1\x03",
    "shitlist_msg_private",
        "Ignored PRIVMSG from {privmsgnick \$0}\x0301,01\$1\x03"
]);

sub handle_pub {
    my ($srv, $msg, $nick, $addr, $dst) = @_;
    if($srv->ignore_check($nick, $addr, $dst, $msg, MSGLEVEL_PUBLIC)) {
        $srv->printformat($dst,
            MSGLEVEL_PUBLIC + MSGLEVEL_NO_ACT + MSGLEVEL_NOHILIGHT,
            "shitlist_pubmsg", $nick, $msg);
    }
}

sub handle_priv {
    my ($srv, $msg, $nick, $addr) = @_;
    if($srv->ignore_check($nick, $addr, "", $msg, MSGLEVEL_MSGS)) {
        Irssi::printformat(
            MSGLEVEL_MSGS + MSGLEVEL_NO_ACT + MSGLEVEL_NOHILIGHT,
            "shitlist_msg_private", $nick, $msg);
    }
}

sub handle_act {
    my ($srv, $msg, $nick, $addr, $dst) = @_;
    if($srv->ignore_check($nick, $addr, $dst, $msg, MSGLEVEL_PUBLIC)) {
        $srv->printformat($dst,
            MSGLEVEL_ACTIONS + MSGLEVEL_NO_ACT + MSGLEVEL_NOHILIGHT,
            "shitlist_action_public", $nick, $msg);
    }
}

Irssi::signal_add_first("message public",  "handle_pub");
Irssi::signal_add_first("message private", "handle_priv");
Irssi::signal_add_first("ctcp action",     "handle_act");

# vim: set expandtab tw=78 sw=4 ts=4 sts=4 fdm=marker :
