Alice

 view release on metacpan or  search on metacpan

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

  },
};

command msg => {
  name => "msg",
  opts => qr{(\S+)\s*(.*)},
  eg => "/MSG [-<network>] <nick> [<msg>]",
  desc => "Sends a message to a nick.",
  connection => 1,
  network => 1,
  cb => sub  {
    my ($self, $req, $opts) = @_;

    my ($nick, $msg) = @$opts;

    my $new_window = $self->find_or_create_window($nick, $req->irc);
    $self->broadcast($new_window->join_action);

    if ($msg) {
      $self->send_message($new_window, $req->nick, $msg);
      $req->send_srv(PRIVMSG => $nick, $msg);
    }
  }
};

command nick => {
  name => "nick",
  opts => qr{(\S+)},
  connection => 1,
  network => 1,
  eg => "/NICK [-<network>] <new nick>",
  desc => "Changes your nick.",
  cb => sub {
    my ($self, $req, $opts) = @_;

    my $nick = $opts->[0];

    $req->reply("changing nick to $nick on " . $req->irc->name);
    $req->irc->send_srv(NICK => $nick);
  }
};

command qr{names|n} => {
  name => "names",
  window_type => [qw/channel/],
  connection => 1,
  eg => "/NAMES [-avatars]",
  desc => "Lists nicks in current channel.",
  cb => sub  {
    my ($self, $req) = @_;
    my @nicks = $req->irc->channel_nicks($req->window->title);
    $req->reply($req->window->nick_table(@nicks));
  },
};

command qr{join|j} => {
  name => "join",
  opts => qr{(\S+)\s*(\S+)?},
  connection => 1,
  network => 1,
  eg => "/JOIN [-<network>] <channel> [<password>]",
  desc => "Joins the specified channel.",
  cb => sub  {
    my ($self, $req, $opts) = @_;

    my $channel = $opts->[0];
    $req->reply("joining $channel on ". $req->irc->name);
    $req->send_srv(JOIN => @$opts);
  },
};

command create => {
  name => "create",
  opts => qr{(\S+)},
  connection => 1,
  network => 1,
  cb => sub  {
    my ($self, $req, $opts) = @_;

    my $name = $opts->[0];

    my $new_window = $self->find_or_create_window($name, $req->irc);
    $self->broadcast($new_window->join_action);
  }
};

command qr{close|wc|part} => {
  name => 'part',
  window_type => [qw/channel privmsg/],
  eg => "/PART",
  network => 1,
  desc => "Leaves and closes the focused window.",
  cb => sub  {
    my ($self, $req) = @_;
    my $window = $req->window;

    $self->close_window($window);
    my $irc = $self->get_irc($window->network);

    if ($window->is_channel and $irc->is_connected) {
      $irc->send_srv(PART => $window->title);
    }
  },
};

command clear =>  {
  name => 'clear',
  eg => "/CLEAR",
  desc => "Clears lines from current window.",
  cb => sub {
    my ($self, $req) = @_;
    $req->window->buffer->clear;
    $self->broadcast($req->window->clear_action);
  },
};

command qr{topic|t} => {
  name => 'topic',
  opts => qr{(.+)?},
  window_type => ['channel'],
  connection => 1,



( run in 1.965 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )