1. Added talk mode so that I don't have to keep typing T <call> all the time.
[spider.git] / cmd / talk.pl
1 #
2 # The talk command
3 #
4 # Copyright (c) 1998 Dirk Koopman G1TLH
5 #
6 # $Id$
7 #
8
9 my ($self, $inline) = @_;
10 my $to;
11 my $via;
12 my $line;
13 my $from = $self->call;
14 my @out;
15
16 # analyse the line there are four situations...
17 # 1) talk call
18 # 2) talk call <text>
19 # 3) talk call>node 
20 # 4) talk call>node text
21 #
22
23 ($to, $via, $line) = $inline =~ /^\s*([A-Za-z0-9\-]+)\s*>([A-Za-z0-9\-]+)(.*)$/;
24 if ($via) {
25         $line =~ s/\s+// if $line;
26 } else {
27         ($to, $line) = split /\s+/, $inline, 2;  
28 }
29
30 $to = uc $to if $to;
31 $via = uc $via if $via;
32 my $call = $via ? $via : $to;
33 my $clref = DXCluster->get_exact($call);     # try an exact call
34 my $dxchan = $clref->dxchan if $clref;
35 return (1, $self->msg('e7', $call)) unless $dxchan;
36
37 # if there is a line send it, otherwise add this call to the talk list
38 # and set talk mode for command mode
39 if ($line) {
40         $dxchan->talk($self->call, $to, $via, $line) if $dxchan;
41 } else {
42         my $s = "$to>" . $dxchan->call;
43         my $ref = $self->talklist;
44         if ($ref) {
45                 unless (grep { $_ eq $s } @$ref) {
46                         $dxchan->talk($self->call, $to, $via, $self->msg('talkstart'));
47                         $self->state('talk');
48                         push @$ref, $s;
49                 }
50         } else { 
51                 $self->talklist([ $s ]);
52                 $dxchan->talk($self->call, $to, $via, $self->msg('talkstart'));
53                 push @out, $self->msg('talkinst');
54                 $self->state('talk');
55         }
56         push @out, $self->talk_prompt;
57 }
58
59 return (1, @out);
60