summaryrefslogtreecommitdiffstats
path: root/modules/command.pl
blob: 87c768fe4e3ce0a2394fe64a45aca30b5c9667b4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
use warnings;
use strict;

sub do_command
{
  my ($conn, $event) = @_;
  my $args = $event->{args}->[0];
  my $from = $event->{from};
  my $cmd = $args;
  my $d1;
  my $nick = lc $event->{nick};
  foreach my $command ( @{$::commands->{command}} )
  {
    if (defined($command->{flag})) {
      next unless defined($::xusers->{$nick});
      next unless defined($::xusers->{$nick}->{flags});
      next unless defined(grep {$_ eq $command->{flag}} split('', $::xusers->{$nick}->{flags}));
      if ($::xusers->{$nick}->{host} ne 'IDENTIFY') {
        next unless leq($::xusers->{$nick}->{host}, $event->{host});
      }
      else {
        if ( $cmd =~ /$command->{cmd}/ ){
          push (@{$::idqueue{$nick}}, [$cmd, $command, $event]);
          $conn->sl("whois $nick $nick");
          next;
        }
      }
    }
    if ($cmd=~/$command->{cmd}/) {
      print "$event->{from} told me: $cmd \n";
      eval $command->{content};
      warn $@ if $@;
    }
  }
}

sub Command::killsub {
  undef &do_command;
}

return 1;