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