Guest User

Untitled

a guest
Apr 15th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. use Perl6::Say;
  7. use AnyEvent::XMPP::Client;
  8. use AnyEvent::XMPP::Connection;
  9. use Config::Pit;
  10.  
  11. my $config = pit_get("gtalk", require => {
  12. username => "username",
  13. password => "password"
  14. });
  15.  
  16. my $j = AnyEvent->condvar;
  17.  
  18. my $client = AnyEvent::XMPP::Client->new( debug => 0 );
  19. $client->add_account($config->{username}, $config->{password}, 'talk.google.com', 5222);
  20. $client->start;
  21.  
  22. $client->reg_cb(
  23. connected => sub {
  24. # $client->send_message( 'test', 'cho45@lowreal.net' );
  25. say "Connected";
  26. },
  27.  
  28. message => sub {
  29. my ($client, $account, $msg) = @_;
  30. # google サーバに決め打ちしたければそうすればよい? 親アカウントが gmail アカウントなのでなんもしなくても届くっぽい
  31. # my $connection = AnyEvent::XMPP::Connection->new(username => 'cho45', domain => 'lowreal.net', host => 'xmpp-server.l.google.com', port => 5269);
  32. # $msg->send($connection);
  33.  
  34. use Data::Dumper;
  35. warn Dumper $msg->from;
  36. if ($msg->from =~ /api\@im\.kayac\.com/) {
  37. $client->send_message("Notice: " . $msg->body, 'cho45@lowreal.net');
  38. }
  39. }
  40. );
  41.  
  42. $j->wait;
Add Comment
Please, Sign In to add comment