]> ruin.nu Git - NDIRC.git/blob - ndawn.pl
Converted the .gs command
[NDIRC.git] / ndawn.pl
1 #**************************************************************************
2 #   Copyright (C) 2008 by Michael Andreen <harvATruinDOTnu>               *
3 #                                                                         *
4 #   This program is free software; you can redistribute it and/or modify  *
5 #   it under the terms of the GNU General Public License as published by  *
6 #   the Free Software Foundation; either version 2 of the License, or     *
7 #   (at your option) any later version.                                   *
8 #                                                                         *
9 #   This program is distributed in the hope that it will be useful,       *
10 #   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11 #   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12 #   GNU General Public License for more details.                          *
13 #                                                                         *
14 #   You should have received a copy of the GNU General Public License     *
15 #   along with this program; if not, write to the                         *
16 #   Free Software Foundation, Inc.,                                       *
17 #   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.         *
18 #**************************************************************************/
19
20 use strict;
21 use warnings;
22 use vars qw($VERSION %IRSSI);
23
24 use Irssi;
25 use Irssi::Irc;
26
27 $VERSION = "0.1";
28 %IRSSI = (
29     authors => "harv",
30     contact => "harv\@ruin.nu",
31     name    => "NewDawn testbot script",
32     description => "Testbot used for implementing commands for nd bots",
33     license => "GPL-2 or (at your option) any later version",
34     url     => "",
35     changed => "",
36 );
37
38 $ND::refresh = 0;
39
40 $SIG{USR1} = sub{
41         print "USR1";
42         $ND::refresh = 1;
43 };
44
45
46 use again 'ND::DB';
47 use again 'ND::Include';
48 use again 'NDIRC::Dispatcher';
49 use again 'NDIRC::Context';
50 use again 'NDIRC::Command';
51 use again 'NDIRC::Misc';
52
53 my $DBH = DB();
54 my $TICK = $DBH->selectrow_array('SELECT tick()');
55
56 my $disp = new NDIRC::Dispatcher;
57
58 $disp->load('Basic','PA','Channel','Scans');
59
60 $ND::scanchan = '#testarmer';
61 $disp->add_channel('#testarlite', ['pub','help','channel']);
62 $disp->add_channel('#testarmer', ['pub','help','channel','scan']);
63 $disp->add_channel('pm', ['pub','help','pm']);
64
65 sub event_pubmsg {
66         my ($server, $msg, $nick, $address, $channel) = @_;
67
68         eval {
69                 if (parseCommand($msg,$server,$nick,$address,$channel,$disp,DB())){
70                         #Command parsed and run successfully
71                 }
72         };
73         print $@ if $@;
74 }
75
76 sub event_privmsg {
77         my ($server, $msg, $nick, $address) = @_;
78
79         eval {
80                 if (parseCommand($msg,$server,$nick,$address,'pm',$disp,DB())){
81                         #Command parsed and run successfully
82                 }
83         };
84         print $@ if $@;
85 }
86
87 sub refresh {
88         print "SiG" if $ND::refresh;
89         $ND::refresh = 0;
90 }
91
92 Irssi::timeout_add(60*1000, 'refresh', undef);
93 Irssi::timeout_add(1000, sub{refresh if $ND::refresh}, undef);
94 Irssi::signal_add('message public','event_pubmsg');
95 Irssi::signal_add('message private','event_privmsg');
96
97