Alice

 view release on metacpan or  search on metacpan

lib/Alice/Config.pm  view on Meta::CPAN

        $config->{ignore} = {msg => $config->{ignore}};
      }

      if ($@) {
        warn "error loading config: $@\n";
      }
      $loaded->();
    }
  }
  else {
    say STDERR "No config found, writing a few config to ".$self->fullpath;
    $self->write($loaded);
  }
}

sub read_commandline_args {
  my $self = shift;
  my ($port, $debug, $address, $log);
  GetOptions("port=i" => \$port, "debug=s" => \$debug, "log=s" => \$log, "address=s" => \$address);
  $self->commandline->{port} = $port if $port and $port =~ /\d+/;
  $self->commandline->{address} = $address if $address;

lib/Alice/Config.pm  view on Meta::CPAN

  return $self->address;
}

sub merge {
  my ($self, $config) = @_;
  for my $key (keys %$config) {
    if (exists $config->{$key} and my $attr = $self->meta->get_attribute($key)) {
      $self->$key($config->{$key}) if $attr->has_write_method;
    }
    else {
      say STDERR "$key is not a valid config option";
    }
  }
}

sub write {
  my $self = shift;
  my $callback = pop;
  mkdir $self->path if !-d $self->path;
  aio_open $self->fullpath, POSIX::O_CREAT | POSIX::O_WRONLY | POSIX::O_TRUNC, 0644, sub {
    my $fh = shift;

lib/Alice/Role/Commands.pm  view on Meta::CPAN

    }
  }
  catch {
    $req->reply("$_");
  }
}

sub match_irc_command {
  my ($self, $line) = @_;

  $line = "/say $line" unless substr($line, 0, 1) eq "/";

  for my $name (keys %COMMANDS) {

    if ($line =~ m{^/$name\b\s*(.*)}) {
      my $args = $1;
      return ($name, $args);
    }
  }
}

lib/Alice/Role/Commands.pm  view on Meta::CPAN

sub command {
  my ($name, $opts) = @_;

  if ($opts) {
    $COMMANDS{$name} = $opts;
  }

  return $COMMANDS{$name};
}

command say => {
  name => "say",
  window_type => [qw/channel privmsg/],
  connection => 1,
  eg => "/SAY <msg>",
  opts => qr{(.+)},
  cb => sub {
    my ($self, $req, $opts) = @_;

    my $msg = $opts->[0];
    $self->send_message($req->window, $req->irc->nick, $msg);



( run in 0.757 second using v1.01-cache-2.11-cpan-483215c6ad5 )