Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # AnyEvent synchronize IRC with IM
- #!/usr/bin/perl
- use strict;
- use AnyEvent;
- use AnyEvent::IRC::Client;
- use AnyEvent::XMPP::Client;
- use Encode;
- use Data::Dumper;
- my $base_ac = 'bot_im_account@gmail.com';
- my $password = 'bot_im_password';
- my $send_ac = 'send_to_im_account@gmail.com';
- my $irc_nick = 'nickname on irc';
- my $channel = '#channel name';
- my $cv = AnyEvent->condvar;
- my $cl = AnyEvent::XMPP::Client->new( debug => 1 );
- $cl->add_account( $base_ac, $password, 'talk.google.com', '5222' );
- my ($w, $rply);
- $cl->reg_cb(
- connected => sub {
- $w = AnyEvent->timer(
- interval => 60 * 5,
- cb => sub{
- }
- );
- },
- message => sub {
- my ($cl, $acc, $msg) = @_;
- my $reply = encode('utf8', $msg->any_body);
- reply($reply."\n");
- }
- );
- my $pc = AnyEvent::IRC::Client->new;
- $pc->reg_cb(
- connect => sub {
- my ( $pc, $err ) = @_;
- if ( defined $err ) {
- print "Couldn't connect to server: $err\n";
- }
- },
- registered => sub {
- my ($self) = @_;
- print "registered!\n";
- $pc->enable_ping(60);
- },
- disconnect => sub {
- print "disconnected: $_[1]!\n";
- },
- read => sub {
- my $us =( $_[1]->{prefix} =~ /(.*?)\!/i);
- $us = $1;
- my $text = "ã$us :ã $_[1]->{params}[-1] \n";
- $text = decode('utf8',$text);
- $cl->send_message( $text, $send_ac ) unless ( $_[1]->{prefix} =~ /freenode/);
- }
- );
- $pc->send_srv( "JOIN", $channel );
- $pc->send_chan( $channel, "PRIVMSG", "stealth", "hi" );
- $pc->connect( "irc.freenode.net", 6667,
- { nick => $irc_nick, user => $irc_nick, real => $irc_nick } );
- sub reply{
- my $rep = shift;
- $pc->send_msg(undef, "PRIVMSG", $channel, $rep);
- }
- $cl->start;
- $cv->wait;
Add Comment
Please, Sign In to add comment