]> git.donarmstrong.com Git - infobot.git/blob - src/CLI/Support.pl
c591a5505414d801b7d5411fba91d05e6a3dca2e
[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($postprocess . ' ' . $msg);
58         undef $postprocess;
59         return;
60     }
61
62     &status(">$nick< $msg");
63
64     print("$nick: $msg\n");
65 }
66
67 # Usage: &action(nick || chan, txt);
68 sub action {
69     my ($target, $txt) = @_;
70     if (!defined $txt) {
71         &WARN("action: txt == NULL.");
72         return;
73     }
74
75     if (length $txt > 480) {
76         &status("action: txt too long; truncating.");
77         chop($txt) while (length $txt > 480);
78     }
79
80     &status("* $ident/$target $txt");
81 }
82
83 sub IsNickInChan {
84     my ($nick,$chan) = @_;
85     return 1;
86 }
87
88 sub performStrictReply {
89     &msg($who, @_);
90 }
91
92 sub performReply {
93     &msg($who, @_);
94 }
95
96 sub performAddressedReply {
97     return unless ($addressed);
98     &msg($who, @_);
99 }
100
101 1;