File: bot-basicbot-pluggable-cgi

package info (click to toggle)
libbot-basicbot-pluggable-perl 1.30%2Bds1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 516 kB
  • sloc: perl: 3,153; makefile: 17
file content (149 lines) | stat: -rwxr-xr-x 2,957 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/local/bin/perl -w
use lib qw(lib);

=head1 NAME

bot-basicbot-pluggable.pl - A standard Bot::BasicBot::Pluggable script

=head1 VERSION

version 1.30

=head1 DESCRIPTION

A standard Bot::BasicBot::Pluggable interface. You can /query the bot to
load in more modules. Change the admin password ASAP - 
See perldoc L<Bot::BasicBot::Pluggable::Auth> for details of this.

=head1 USAGE

  bot-basicbot-pluggable.pl --nick MyBot --server irc.perl.org

=head2 SEE ALSO

Bot::BasicBot::Pluggable

=cut

use warnings;
use strict;
use CGI;
use Template;

my $q        = CGI->new; print $q->header;
my $tt       = Template->new || die $Template::ERROR."\n";
my $template = join "", <DATA>;


my $nick = "dipsy";

my $bot = Bot::BasicBot::Pluggable::CLI->new(
  channels => [ ],
  server => "",
  nick => $nick,
  charset => "utf8",
  store   => { type => 'Storable' },
);


# Loader lets you tell the bot to load other modules.
$bot->load("Loader");

my @dunno = split /\|/, $bot->store->get('Infobot',"user_unknown_responses");

my $in = $q->param("q");
my $ret;
goto VARS unless defined $in;

# strip off whitespace before and after the message
$in =~ s!(^\s*|\s*$)!!g;

my $mess = { 
				address => 1, 
                channel => "#$nick",
				body => $in, 
				who => $ENV{USER},
		  };

if ($mess->{body} =~ /^help/i) {
	$ret = $bot->help($mess);
} else {
	$bot->said($mess);
	$ret = $bot->{_tmp_reply}->{body} if ($bot->{_tmp_reply});
	$bot->{_tmp_reply} = undef;
}

VARS:
$ret = $dunno[rand $#dunno] unless defined $ret and $ret ne "";

my $vars = {
				nick     => $nick,
			    question => $in,
                response => $ret,
		   };


$tt->process(\$template, $vars) || die $tt->error(), "\n";




package Bot::BasicBot::Pluggable::CLI;
$Bot::BasicBot::Pluggable::CLI::VERSION = '1.30';
use base qw(Bot::BasicBot::Pluggable);

sub reply {
    my $self = shift;
    my ($mess, $body) = @_;
	$mess->{body} = $body;
	$self->{_tmp_reply} = $mess;

}

package main;
$main::VERSION = '1.30';
__DATA__
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Web Dipsy [% IF question %] - [% question | html %] [% END %]</title>
<style type="text/css">
body {
  background: #fff;
  color: #000
}
p, td {
  font-family: Geneva, MS Sans Serif, Helvetica, Arial, sans-serif; 
}
.botname {
	
}
.botanswer {

}
.username {

}
.userquestion {
}
</style>
</head>
<body>

<p>
[% IF question %]
<span class="username">you:</span>&nbsp;<span class="userquestion">[% question | html %]</span><br />
<span class="botname">[% nick | html %]:</span>&nbsp;<span class="botanswer">[% response | html %]</span><br />
[% ELSE %]
<span class="botname">[% nick %]:</span><span class="botanswer">Hello!</span><br />
[% END %]
</p>
<p>
<form action="" method="GET">
You: <input type="text" name="q" />&nbsp;<input type="submit" name="submit" value="?" />
</form>


</body>
</html>