1package DJabberd::BotContext; 2use strict; 3use fields ( 4 # expire times, 5 # start time, 6 # history of chat... 7 # etc, etc 8 'vhost', 9 'method', 10 'fromjid', 11 'myjid', 12 'lasttext', 13 ); 14use warnings; 15 16sub new { 17 my ($class, $vhost, $method, $fromjid, $myjid) = @_; 18 my $self = fields::new($class); 19 $self->{vhost} = $vhost; 20 $self->{method} = $method; 21 $self->{fromjid} = $fromjid; 22 $self->{myjid} = $myjid; 23 return $self; 24} 25 26sub add_text { 27 my ($self, $text, $html) = @_; 28 $self->{lasttext} = [$text, $html]; 29} 30 31sub last_text { 32 my $self = shift; 33 return $self->{lasttext} ? $self->{lasttext}[0] : undef; 34} 35 36sub last_html { 37 my $self = shift; 38 return $self->{lasttext} ? $self->{lasttext}[1] : undef; 39} 40 41sub reply { 42 my ($self, $text, $html) = @_; 43 return unless $text || $html; 44 45 my $body = ""; 46 if ($text) { 47 $body .= "<body>". DJabberd::Util::exml($text) . "</body>"; 48 } 49 if ($html) { 50 $body .= qq{<html xmlns='http://jabber.org/protocol/xhtml-im'><body xmlns='http://www.w3.org/1999/xhtml'>$html</body></html>}; 51 } 52 53 my $reply = DJabberd::Message->new('jabber:client', 'message', { 54 '{}type' => 'chat', 55 '{}to' => $self->{fromjid}->as_string, 56 '{}from' => $self->{myjid}->as_string, 57 }, []); 58 $reply->set_raw($body); 59 $reply->deliver($self->{vhost}); 60} 61 621; 63