#########################
#  GoSuBBina-Auto-Deop  #
#########################

use strict;
use Irssi;
use Irssi::Irc;

sub do_deop {
    my ($data) = @_;
    my ($server, $chan, $nick) = @$data;
    $server->command("/mode $chan -o $nick");
}

sub event_mode {
    my ($server, $data) = @_;
    my ($chan, $modes, @targets) = split ' ', $data;

    return unless $chan eq '#re-opless';

    my $nick = $server->{nick};
    my @modes = split //, $modes;
    my $add = 0;
    my $i = 0;

    foreach my $mode (@modes) {
        if ($mode eq '+') {
            $add = 1;
        } elsif ($mode eq '-') {
            $add = 0;
        } elsif ($mode eq 'o') {
            my $target = $targets[$i++];
            if ($add && $target eq $nick) {
                Irssi::timeout_add_once(30000, \&do_deop, [$server, $chan, $nick]);
            }
        } else {
            $i++;
        }
    }
}

Irssi::signal_add('event mode', 'event_mode');

#####[#RE-OPLESS]#####
