]> git.donarmstrong.com Git - infobot.git/blob - src/CLI/Support.pl
* Merge back with trunk to r1810
[infobot.git] / src / CLI / Support.pl
1 #
2 # CLI/Support.pl: Stubs for functions that are from IRC/*
3 #         Author: Tim Riker <Tim@Rikers.org>
4 #        Version: v0.1 (20021028)
5 #        Created: 20021028
6 #
7 use strict;
8
9 my $postprocess;
10
11 use vars qw($uh $message);
12
13 sub cliloop {
14     &status('Using CLI...');
15     &status('Now type what you want.');
16
17     $nuh       = "local!local\@local";
18     $uh        = "local\@local";
19     $who       = 'local';
20     $orig{who} = 'local';
21     $ident     = $param{'ircUser'};
22     $chan      = $talkchannel = '_local';
23     $addressed = 1;
24     $msgType   = 'private';
25     $host      = 'local';
26
27     # install libterm-readline-gnu-perl to get history support
28     use Term::ReadLine;
29     my $term   = new Term::ReadLine 'infobot';
30     my $prompt = "$who> ";
31
32     #$OUT = $term->OUT || STDOUT;
33     while ( defined( $_ = $term->readline($prompt) ) ) {
34         $orig{message} = $_;
35         $message = $_;
36         chomp $message;
37         last if ( $message =~ m/^quit$/ );
38         $_ = &process() if $message;
39     }
40     &doExit();
41 }
42
43 sub msg {
44     my ( $nick, $msg ) = @_;
45     if ( !defined $nick ) {
46         &ERROR('msg: nick == NULL.');
47         return;
48     }
49
50     if ( !defined $msg ) {
51         $msg ||= 'NULL';
52         &WARN("msg: msg == $msg.");
53         return;
54     }
55
56     if ($postprocess) {
57         undef $postprocess;
58     }
59     elsif ( $postprocess = &getChanConf( 'postprocess', $talkchannel ) ) {
60         &DEBUG("say: $postprocess $msg");
61         &parseCmdHook( $postprocess . ' ' . $msg );
62         undef $postprocess;
63         return;
64     }
65
66     &status(">$nick< $msg");
67
68     print("$nick: $msg\n");
69 }
70
71 # Usage: &action(nick || chan, txt);
72 sub action {
73     my ( $target, $txt ) = @_;
74     if ( !defined $txt ) {
75         &WARN('action: txt == NULL.');
76         return;
77     }
78
79     if ( length $txt > 480 ) {
80         &status('action: txt too long; truncating.');
81         chop($txt) while ( length $txt > 480 );
82     }
83
84     &status("* $ident/$target $txt");
85 }
86
87 sub IsNickInChan {
88     my ( $nick, $chan ) = @_;
89     return 1;
90 }
91
92 sub performStrictReply {
93     &msg( $who, @_ );
94 }
95
96 sub performReply {
97     &msg( $who, @_ );
98 }
99
100 sub performAddressedReply {
101     return unless ($addressed);
102     &msg( $who, @_ );
103 }
104
105 1;
106
107 # vim:ts=4:sw=4:expandtab:tw=80