]> git.donarmstrong.com Git - infobot.git/blob - src/CLI/Support.pl
7ee3a0b0dc0a2ad3aa009b2cbc8f7a381ef02b95
[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 'blootbot';
30     my $prompt = "$who> ";
31     #$OUT = $term->OUT || STDOUT;
32     while ( defined ($_ = $term->readline($prompt)) ) {
33         $orig{message} = $_;
34         $message = $_;
35         chomp $message;
36         last if ($message =~ m/^quit$/);
37         $_ = &process() if $message;
38     }
39     &doExit();
40 }
41
42 sub msg {
43     my ($nick, $msg) = @_;
44     if (!defined $nick) {
45         &ERROR("msg: nick == NULL.");
46         return;
47     }
48
49     if (!defined $msg) {
50         $msg ||= 'NULL';
51         &WARN("msg: msg == $msg.");
52         return;
53     }
54
55     if ( $postprocess ) {
56         undef $postprocess;
57     } elsif ($postprocess = &getChanConf('postprocess', $talkchannel)) {
58         &DEBUG("say: $postprocess $msg");
59         &parseCmdHook($postprocess . ' ' . $msg);
60         undef $postprocess;
61         return;
62     }
63
64     &status(">$nick< $msg");
65
66     print("$nick: $msg\n");
67 }
68
69 # Usage: &action(nick || chan, txt);
70 sub action {
71     my ($target, $txt) = @_;
72     if (!defined $txt) {
73         &WARN("action: txt == NULL.");
74         return;
75     }
76
77     if (length $txt > 480) {
78         &status("action: txt too long; truncating.");
79         chop($txt) while (length $txt > 480);
80     }
81
82     &status("* $ident/$target $txt");
83 }
84
85 sub IsNickInChan {
86     my ($nick,$chan) = @_;
87     return 1;
88 }
89
90 sub performStrictReply {
91     &msg($who, @_);
92 }
93
94 sub performReply {
95     &msg($who, @_);
96 }
97
98 sub performAddressedReply {
99     return unless ($addressed);
100     &msg($who, @_);
101 }
102
103 1;