Guest User

Untitled

a guest
Apr 16th, 2018
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. # AnyEvent synchronize IRC with IM
  2.  
  3. #!/usr/bin/perl
  4. use strict;
  5. use AnyEvent;
  6. use AnyEvent::IRC::Client;
  7. use AnyEvent::XMPP::Client;
  8. use Encode;
  9. use Data::Dumper;
  10.  
  11.  
  12. my $base_ac = 'bot_im_account@gmail.com';
  13. my $password = 'bot_im_password';
  14. my $send_ac = 'send_to_im_account@gmail.com';
  15. my $irc_nick = 'nickname on irc';
  16. my $channel = '#channel name';
  17.  
  18. my $cv = AnyEvent->condvar;
  19. my $cl = AnyEvent::XMPP::Client->new( debug => 1 );
  20. $cl->add_account( $base_ac, $password, 'talk.google.com', '5222' );
  21. my ($w, $rply);
  22. $cl->reg_cb(
  23. connected => sub {
  24. $w = AnyEvent->timer(
  25. interval => 60 * 5,
  26. cb => sub{
  27. }
  28. );
  29. },
  30. message => sub {
  31. my ($cl, $acc, $msg) = @_;
  32. my $reply = encode('utf8', $msg->any_body);
  33. reply($reply."\n");
  34. }
  35. );
  36.  
  37. my $pc = AnyEvent::IRC::Client->new;
  38. $pc->reg_cb(
  39. connect => sub {
  40. my ( $pc, $err ) = @_;
  41. if ( defined $err ) {
  42. print "Couldn't connect to server: $err\n";
  43. }
  44. },
  45. registered => sub {
  46. my ($self) = @_;
  47. print "registered!\n";
  48. $pc->enable_ping(60);
  49. },
  50. disconnect => sub {
  51. print "disconnected: $_[1]!\n";
  52. },
  53. read => sub {
  54. my $us =( $_[1]->{prefix} =~ /(.*?)\!/i);
  55. $us = $1;
  56. my $text = "【$us :】 $_[1]->{params}[-1] \n";
  57. $text = decode('utf8',$text);
  58. $cl->send_message( $text, $send_ac ) unless ( $_[1]->{prefix} =~ /freenode/);
  59. }
  60. );
  61.  
  62. $pc->send_srv( "JOIN", $channel );
  63. $pc->send_chan( $channel, "PRIVMSG", "stealth", "hi" );
  64. $pc->connect( "irc.freenode.net", 6667,
  65. { nick => $irc_nick, user => $irc_nick, real => $irc_nick } );
  66. sub reply{
  67. my $rep = shift;
  68. $pc->send_msg(undef, "PRIVMSG", $channel, $rep);
  69. }
  70. $cl->start;
  71. $cv->wait;
Add Comment
Please, Sign In to add comment