App-Alice

 view release on metacpan or  search on metacpan

share/commands.pl  view on Meta::CPAN

    name => 'msg',
    re => qr{^/(?:msg|query)\s+$SRVOPT(\S+)(.*)},
    eg => "/MSG [-<server name>] <nick> <message>",
    desc => "Sends a message to a nick.",
    code => sub  {
      my $self = shift;
      my $window = shift;
      my ($msg, $nick, $network);
      if (@_ == 3) {
        ($msg, $nick, $network) = @_;
      }
      elsif (@_ == 2) {
        ($msg, $nick) = @_;
      }
      $msg =~ s/^\s+//;
      my $irc = $window->irc;
      if ($network and $self->app->has_irc($network)) {
        $irc = $self->app->get_irc($network);
      }
      return unless $irc;
      my $new_window = $self->app->find_or_create_window($nick, $irc);
      my @msgs = ($new_window->join_action);
      if ($msg) {
        push @msgs, $new_window->format_message($new_window->nick, $msg);
        $irc->send_srv(PRIVMSG => $nick, $msg) if $msg;
      }
      $self->broadcast(@msgs);
    },
  },
  {
    name => 'nick',
    re => qr{^/nick\s+$SRVOPT(\S+)},
    eg => "/NICK [-<server name>] <new nick>",
    desc => "Changes your nick.",
    code => sub {
      my ($self, $window, $nick, $network) = @_;
      my $irc;
      if ($network and $self->app->has_irc($network)) {
        $irc = $self->app->get_irc($network);
      } else {
        $irc = $window->irc;
      }
      $irc->log(info => "now known as $nick");
      $irc->send_srv(NICK => $nick);
    },
  },
  {
    name => 'names',
    re => qr{^/n(?:ames)?(?:\s(-a(?:vatars)?))?},
    in_channel => 1,
    eg => "/NAMES [-avatars]",
    desc => "Lists nicks in current channel. Pass the -avatars option to display avatars with the nicks.",
    code => sub  {
      my ($self, $window, $avatars) = @_;
      $self->reply($window, $window->nick_table($avatars));
    },
  },
  {
    name => 'join',
    re => qr{^/j(?:oin)?\s+$SRVOPT(.+)},
    eg => "/JOIN [-<server name>] <channel> [<password>]",
    desc => "Joins the specified channel.",
    code => sub  {
      my ($self, $window, $channel, $network) = @_;
      my $irc;
      if ($network and $self->app->has_irc($network)) {
        $irc = $self->app->get_irc($network);
      } else {
        $irc = $window->irc;
      }
      my @params = split /\s+/, $channel;
      if ($irc and $irc->cl->is_channel_name($params[0])) {
        $irc->log(info => "joining $params[0]");
        $irc->send_srv(JOIN => @params);
      }
    },
  },
  {
    name => 'create',
    re => qr{^/create\s+(\S+)},
    code => sub  {
      my ($self, $window, $name) = @_;
      my $new_window = $self->app->find_or_create_window($name, $window->irc);
      $self->broadcast($new_window->join_action);
    },
  },
  {
    name => 'part',
    re => qr{^/(?:close|wc|part)},
    eg => "/PART",
    desc => "Leaves and closes the focused window.",
    code => sub  {
      my ($self, $window) = @_;
      $window->is_channel ? $window->irc->send_srv(PART => $window->title)
      : $self->app->close_window($window);
    },
  },
  {
    name => 'clear',
    re => qr{^/clear},
    eg => "/CLEAR",
    desc => "Clears lines from current window.",
    code => sub {
      my ($self, $window) = @_;
      $window->buffer->clear;
      $self->broadcast($window->clear_action);
    },
  },
  {
    name => 'topic',
    re => qr{^/t(?:opic)?(?:\s+(.+))?},
    in_channel => 1,
    eg => "/TOPIC [<topic>]",
    desc => "Shows and/or changes the topic of the current channel.",
    code => sub  {
      my ($self, $window, $new_topic) = @_;
      if ($new_topic) {
        $window->topic({string => $new_topic, nick => $window->nick, time => time});
        $window->irc->send_srv(TOPIC => $window->title, $new_topic);
      }
      else {



( run in 0.559 second using v1.01-cache-2.11-cpan-f56aa216473 )