push xmpp messages to redis
authorDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 28 Aug 2010 20:25:24 +0000 (22:25 +0200)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Sat, 28 Aug 2010 20:25:24 +0000 (22:25 +0200)
scripts/mqr-xmpp-client.pl

index 4981d07..640fc2e 100755 (executable)
@@ -7,6 +7,7 @@ use AnyEvent::XMPP::Client;
 use AnyEvent::XMPP::Ext::Disco;
 use AnyEvent::XMPP::Ext::Version;
 use AnyEvent::XMPP::Namespaces qw/xmpp_ns/;
+use AnyEvent::Redis;
 
 my @msgs;
 
@@ -20,7 +21,7 @@ sub read_messages {
 
 binmode STDOUT, ":utf8";
 
-our ($jid, $pw, $inputfile);
+our ($jid, $pw, $inputfile, $redis_host, $redis_port);
 require 'config.pl';
 
 warn "# $jid <- $inputfile\n";
@@ -40,6 +41,8 @@ $cl->set_presence (undef, 'I\'m a talking bot.', 1);
 $cl->add_account ($jid, $pw);
 warn "connecting to $jid...\n";
 
+my $redis = AnyEvent::Redis->new( host => $redis_host, port => $redis_port );
+
 $cl->reg_cb (
    session_ready => sub {
       my ($cl, $acc) = @_;
@@ -52,6 +55,9 @@ $cl->reg_cb (
       $repl->add_body ("You said '".$msg->any_body."' but... " . $talkmsg);
       warn "Got message: '".$msg->any_body."' from ".$msg->from."\n";
       warn "Answered: $talkmsg\n";
+
+               $redis->publish( join(' ', 'channel', $msg->from), $msg->any_body );
+
       $repl->send;
    },
    contact_request_subscribe => sub {