summaryrefslogtreecommitdiffstats
path: root/modules/command.pl
blob: 3acaeddd542192f5cdbc45c6091f412cd2287b5e (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
42
43
44
45
46
package ASM::Commander;

use warnings;
use strict;
use IO::All;
use POSIX qw(strftime);
use Data::Dumper;

sub new
{
  my $module = shift;
  my $self = {};
  bless($self);
  return $self;
}

sub command
{
  my ($self, $conn, $event) = @_;
  my $args = $event->{args}->[0];
  my $from = $event->{from};
  my $cmd = $args;
  my $d1;
  my $nick = lc $event->{nick};
  my $acct = lc $::sn{$nick}->{account};
#  return 0 unless (ASM::Util->speak($event->{to}->[0]));
  foreach my $command ( @{$::commands->{command}} )
  {
    unless (ASM::Util->speak($event->{to}->[0])) {
      next unless (defined($command->{nohush}) && ($command->{nohush} eq "nohush"));
    }
    if (defined($command->{flag})) { #If the command is restricted,
      next unless defined($::users->{person}->{$acct}); #make sure the requester has an account
      next unless defined($::users->{person}->{$acct}->{flags}); #make sure the requester has flags defined
      next unless (grep {$_ eq $command->{flag}} split('', $::users->{person}->{$acct}->{flags})); #make sure the requester has the needed flags
    }
    if ($cmd=~/$command->{cmd}/) {
      ASM::Util->dprint("$event->{from} told me: $cmd", "commander");
      eval $command->{content};
      warn $@ if $@;
      last;
    }
  }
}

1;