#**************************************************************************
#   Copyright (C) 2008 by Michael Andreen <harvATruinDOTnu>               *
#                                                                         *
#   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, write to the                         *
#   Free Software Foundation, Inc.,                                       *
#   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
#**************************************************************************/

use strict;
use warnings;
use vars qw($VERSION %IRSSI);

use Irssi;
use Irssi::Irc;

$VERSION = "0.1";
%IRSSI = (
    authors => "harv",
    contact => "harv\@ruin.nu",
    name    => "NewDawn testbot script",
    description => "Testbot used for implementing commands for nd bots",
    license => "GPL-2 or (at your option) any later version",
    url     => "",
    changed => "",
);

$ND::refresh = 0;

$SIG{USR1} = sub{
	print "USR1";
	$ND::refresh = 1;
};


use again 'ND::DB';
use again 'ND::Include';
use again 'NDIRC::Dispatcher';
use again 'NDIRC::Context';
use again 'NDIRC::Command';
use again 'NDIRC::Misc';

my $DBH = DB();
my $TICK = $DBH->selectrow_array('SELECT tick()');

my $disp = new NDIRC::Dispatcher;

$disp->load('Basic','PA');

$disp->add_channel('#testarlite', ['pub','help']);
$disp->add_channel('#testarmer', ['pub','help']);

sub event_pubmsg {
	my ($server, $msg, $nick, $address, $channel) = @_;

	if (parseCommand($msg,$server,$nick,$address,$channel,$disp,DB())){
		#Command parsed and run successfully
	}
}

sub event_privmsg {
	my ($server, $msg, $nick, $address) = @_;

	if (parseCommand($msg,$server,$nick,$address,'pm',$disp,DB())){
		#Command parsed and run successfully
	}
}

sub refresh {
	print "SiG" if $ND::refresh;
	$ND::refresh = 0;
}

Irssi::timeout_add(60*1000, 'refresh', undef);
Irssi::timeout_add(1000, sub{refresh if $ND::refresh}, undef);
Irssi::signal_add('message public','event_pubmsg');
Irssi::signal_add('message private','event_privmsg');


