Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Skype効率化

akiym
September 29, 2012

 Skype効率化

YAPC::Asia 2012

akiym

September 29, 2012
Tweet

More Decks by akiym

Other Decks in Programming

Transcript

  1. use strict; use warnings; use Skype::Any; my $skype = Skype::Any->new();

    $skype->message_received(sub { my ($msg) = @_; my $body = $msg->body; if ($body eq 'ping') { $msg->chat->send_message('pong'); } }); $skype->run;
  2. use strict; use warnings; use Skype::Any; my $skype = Skype::Any->new();

    $skype->message_received(sub { my ($msg) = @_; my $body = $msg->body; if ($body eq 'ping') { $msg->chat->send_message('pong'); } }); $skype->run; ஫ҙ4LZQFΫϥΠΞϯτΛ্ཱ͓ͪ͛ͯ͘͜ͱ
  3. use strict; use warnings; use Skype::Any; my $skype = Skype::Any->new();

    $skype->message_received(sub { my ($msg) = @_; my $body = $msg->body; if ($body eq 'ping') { $msg->chat->send_message('pong'); } }); $skype->run;
  4. use strict; use warnings; use Skype::Any; my $skype = Skype::Any->new();

    $skype->message_received(sub { my ($msg) = @_; my $body = $msg->body; if ($body eq 'ping') { $msg->chat->send_message('pong'); } }); $skype->run; ϝοηʔδΛड৴͢Δͱݺ͹ΕΔ 4LZQF"OZ0CKFDU$IBU.FTTBHF
  5. use strict; use warnings; use Skype::Any; my $skype = Skype::Any->new();

    $skype->message_received(sub { my ($msg) = @_; my $body = $msg->body; if ($body eq 'ping') { $msg->chat->send_message('pong'); } }); $skype->run; ૹΒΕ͖ͯͨϝοηʔδͷຊจ
  6. use strict; use warnings; use Skype::Any; my $skype = Skype::Any->new();

    $skype->message_received(sub { my ($msg) = @_; my $body = $msg->body; if ($body eq 'ping') { $msg->chat->send_message('pong'); } }); $skype->run; νϟοτʹbQPOH`ͱϝοηʔδΛૹ৴ ϝοηʔδ͕ૹΒΕ͖ͯͨνϟοτ
  7. use strict; use warnings; use Skype::Any; my $skype = Skype::Any->new();

    $skype->message_received(sub { my ($msg) = @_; my $body = $msg->body; if ($body eq 'ping') { $msg->chat->send_message('pong'); } }); $skype->run; Πϕϯτϧʔϓͷ։࢝
  8. say $skype->user('t.akiym')->chat->name; #=> #t.akiym/$akiym_bot;f8efe7736e507088 say $skype->user('t.akiym')->chat->name; #=> #t.akiym/$akiym_bot;f8efe7736e507088 say $skype->user('t.akiym,

    echo123')->chat->name; #=> #akiym_bot/$84192e06d8b4cce9 say $skype->user('t.akiym, echo123')->chat->name; #=> #akiym_bot/$d2257830ee67a5bb άϧʔϓνϟοτͷ৔߹͸ νϟοτΛ࡞੒͢Δͨͼʹ৽͍͠΋ͷ͕࡞੒͞ΕΔ
  9. use strict; use warnings; use LWP::UserAgent; use Skype::Any; my $ua

    = LWP::UserAgent->new; my $skype = Skype::Any->new; $skype->message_received(sub { my ($msg) = @_; my $body = $msg->body; while ($body =~ m!(?=(https?://\S+))!g) { my $url = $1; my $res = $ua->get($url); return unless $res->is_success; my ($title) = $res->decoded_content =~ m! <title>(.*?)</title>!i; $msg->chat->send_message($title) if $title; } }); $skype->run;
  10. use strict; use warnings; use utf8; use Email::Sender::Simple qw(sendmail); use

    Email::Simple; use Email::Simple::Creator; use Data::Recursive::Encode; use Encode; use Email::Sender::Transport::SMTP::TLS; use Skype::Any; my $sender = Email::Sender::Transport::SMTP::TLS->new( host => 'smtp.gmail.com', port => 587, username => '[email protected]', password => 'pa33w0rd', helo => 'example.com', );
  11. my $skype = Skype::Any->new; $skype->message_received(sub { my ($msg) = @_;

    my $body = $msg->body; if ($body =~ /^!email/) { my $email = Email::Simple->create( header => Data::Recursive::Encode->encode( 'MIME-Header-ISO_2022_JP' => [ To => '"̨̩̠̠" <[email protected]>', From => '"·ͬͭΜ" <[email protected]>', Subject => "༦൧", ] ), body => encode( 'iso-2022-jp', "͏ͪͰͨ΂Δͷʁ" ), attributes => { content_type => 'text/plain', charset => 'ISO-2022-JP', encoding => '7bit', }, ); my $ret = sendmail($email, {transport => $sender}); } }); $skype->run;
  12. use strict; use warnings; use Skype::Any; use Acme::Zenra; use Try::Tiny;

    my $zenra = Acme::Zenra->new( yahoo_appid => $ENV{YAHOO_APPID}, ); my $skype = Skype::Any->new; my $chatname = ''; # your chatname
  13. use strict; use warnings; use Skype::Any; use Acme::Zenra; use Try::Tiny;

    my $zenra = Acme::Zenra->new( yahoo_appid => $ENV{YAHOO_APPID}, ); my $skype = Skype::Any->new; my $chatname = ''; # your chatname ZVTVLFCF"DNF;FOSB
  14. $skype->message_received(sub { my ($msg) = @_; if ($msg->chatname eq $chatname)

    { my $body = $msg->body; try { my $result = $zenra->zenrize($body); unless ($body eq $result) { # Edit message $msg->body($result); } }; } }); $skype->run;
  15. $skype->message_received(sub { my ($msg) = @_; if ($msg->chatname eq $chatname)

    { my $body = $msg->body; try { my $result = $zenra->zenrize($body); unless ($body eq $result) { # Edit message $msg->body($result); } }; } }); $skype->run; ฤू͢Δ͜ͱ͕Ͱ͖ͳ͍ϝοηʔδ΋͋ΔͨΊ
  16. $skype->message_received(sub { my ($msg) = @_; if ($msg->chatname eq $chatname)

    { my $body = $msg->body; try { my $result = $zenra->zenrize($body); unless ($body eq $result) { # Edit message $msg->body($result); } }; } }); $skype->run; 5JQT$msg->body(‘’);Ͱϝοηʔδͷ࡟আ
  17. use strict; use warnings; use utf8; use Encode; use Lingua::JA::Regular::Unicode

    qw/alnum_z2h/; use LWP::UserAgent; use Skype::Any; use XML::Simple (); use URI; use URI::QueryParam; our %DICT_TYPE = (e2j => 'EJdict', j2e => 'EdictJE'); my $ua = LWP::UserAgent->new; my $api_url = 'http://public.dejizo.jp/NetDicV09.asmx'; my $skype = Skype::Any->new; $skype->message_received(sub { my $msg = shift; if (my ($word) = $msg->body =~ /^dict:\s*(.+)/) { my $type = $word =~ /^[a-zA-Z0-9_]+$/ ? 'e2j' : 'j2e'; my $user = $msg->object(user => $msg->from_handle); if (my $item_id = get_item_id($word, $type)) { my $body = get_body($item_id, $type); $body = alnum_z2h($body); $user->chat->send_message($body); } else { $user->chat->send_message('Sorry, did not match... ;('); } } }); $skype->run;
  18. use strict; use warnings; use utf8; use Encode; use Lingua::JA::Regular::Unicode

    qw/alnum_z2h/; use LWP::UserAgent; use Skype::Any; use XML::Simple (); use URI; use URI::QueryParam; our %DICT_TYPE = (e2j => 'EJdict', j2e => 'EdictJE'); my $ua = LWP::UserAgent->new; my $api_url = 'http://public.dejizo.jp/NetDicV09.asmx'; my $skype = Skype::Any->new; $skype->message_received(sub { my $msg = shift; if (my ($word) = $msg->body =~ /^dict:\s*(.+)/) { my $type = $word =~ /^[a-zA-Z0-9_]+$/ ? 'e2j' : 'j2e'; my $user = $msg->object(user => $msg->from_handle); if (my $item_id = get_item_id($word, $type)) { my $body = get_body($item_id, $type); $body = alnum_z2h($body); $user->chat->send_message($body); } else { $user->chat->send_message('Sorry, did not match... ;('); } } }); $skype->run; dict: Ͱ࢝·Δϝοηʔδ
  19. use strict; use warnings; use utf8; use Encode; use Lingua::JA::Regular::Unicode

    qw/alnum_z2h/; use LWP::UserAgent; use Skype::Any; use XML::Simple (); use URI; use URI::QueryParam; our %DICT_TYPE = (e2j => 'EJdict', j2e => 'EdictJE'); my $ua = LWP::UserAgent->new; my $api_url = 'http://public.dejizo.jp/NetDicV09.asmx'; my $skype = Skype::Any->new; $skype->message_received(sub { my $msg = shift; if (my ($word) = $msg->body =~ /^dict:\s*(.+)/) { my $type = $word =~ /^[a-zA-Z0-9_]+$/ ? 'e2j' : 'j2e'; my $user = $msg->object(user => $msg->from_handle); if (my $item_id = get_item_id($word, $type)) { my $body = get_body($item_id, $type); $body = alnum_z2h($body); $user->chat->send_message($body); } else { $user->chat->send_message('Sorry, did not match... ;('); } } }); $skype->run; $skype->user($msg->from_handle);
  20. sub get_item_id { my ($word, $type) = @_; my $uri

    = URI->new("$api_url/SearchDicItemLite"); $uri->query_form_hash({ Dic => $DICT_TYPE{$type}, Word => $word, Scope => 'HEADWORD', Match => 'STARTWITH', Merge => 'AND', Prof => 'XHTML', PageSize => 1, PageIndex => 0, }); my $res = $ua->get($uri); return unless $res->is_success; my $xml = XML::Simple::XMLin($res->content); return if $xml->{ItemCount} == 0; $xml->{TitleList}{DicItemTitle}{ItemID}; }
  21. sub get_body { my ($item_id, $type) = @_; my $uri

    = URI->new("$api_url/GetDicItemLite"); $uri->query_form_hash({ Dic => $DICT_TYPE{$type}, Item => $item_id, Loc => '', Prof => 'XHTML', }); my $res = $ua->get($uri); return unless $res->is_success; my $xml = XML::Simple::XMLin( $res->content, SuppressEmpty => 1, # returns empty element. ); if ($type eq 'e2j') { my $caption = $xml->{Head}->{div}{span}{content}; if ($caption =~ s/\.$//) { my @results = split /\s+/, $xml->{Body}->{div}{div}; sprintf '%d results: %s', scalar @results, join ', ', @results; } else { sprintf '[%s] %s', $caption, join "\n", split /\s+/, $xml->{Body}->{div}{div}; } } else { (my $caption = $xml->{Head}->{div}{span}{content}) =~ s/\n* \s+.*$//ms; my $stuff = $xml->{Body}->{div}{div}{div}; if (ref $stuff eq 'ARRAY') {
  22. Item => $item_id, Loc => '', Prof => 'XHTML', });

    my $res = $ua->get($uri); return unless $res->is_success; my $xml = XML::Simple::XMLin( $res->content, SuppressEmpty => 1, # returns empty element. ); if ($type eq 'e2j') { my $caption = $xml->{Head}->{div}{span}{content}; if ($caption =~ s/\.$//) { my @results = split /\s+/, $xml->{Body}->{div}{div}; sprintf '%d results: %s', scalar @results, join ', ', @results; } else { sprintf '[%s] %s', $caption, join "\n", split /\s+/, $xml->{Body}->{div}{div}; } } else { (my $caption = $xml->{Head}->{div}{span}{content}) =~ s/\n* \s+.*$//ms; my $stuff = $xml->{Body}->{div}{div}{div}; if (ref $stuff eq 'ARRAY') { sprintf '[%s] %s', $caption, join ', ', @{$xml->{Body}- >{div}{div}{div}}; } else { sprintf '[%s] %s', $caption, $stuff; } } }
  23. use strict; use warnings; use Skype::Any; use LWP::UserAgent; my $IM_KAYAC

    = 'http://im.kayac.com/api/post'; my $username = ''; # im.kayac my $password = ''; my $ua = LWP::UserAgent->new();
  24. my $skype = Skype::Any->new(); $skype->message_received(sub { my ($msg) = @_;

    my $from = $msg->from_handle; my $body = $msg->body; my $res = $ua->post("$IM_KAYAC/$username", { message => "$from: $body", handler => 'skype://', password => $password, }); die $res->status_line unless $res->is_success; }); $skype->run;
  25. my $skype = Skype::Any->new(); $skype->message_received(sub { my ($msg) = @_;

    my $from = $msg->from_handle; my $body = $msg->body; my $res = $ua->post("$IM_KAYAC/$username", { message => "$from: $body", handler => 'skype://', password => $password, }); die $res->status_line unless $res->is_success; }); $skype->run; ϝοηʔδΛૹ৴ͨ͠ϢʔβʔJE
  26. my $skype = Skype::Any->new(); $skype->message_received(sub { my ($msg) = @_;

    my $from = $msg->from_handle; my $body = $msg->body; my $res = $ua->post("$IM_KAYAC/$username", { message => "$from: $body", handler => 'skype://', password => $password, }); die $res->status_line unless $res->is_success; }); $skype->run; ϝοηʔδΛૹ৴ͨ͠ϢʔβʔJE 5JQT$msg->from_dispname;
  27. my $skype = Skype::Any->new(); $skype->message_received(sub { my ($msg) = @_;

    my $from = $msg->from_handle; my $body = $msg->body; my $res = $ua->post("$IM_KAYAC/$username", { message => "$from: $body", handler => 'skype://', password => $password, }); die $res->status_line unless $res->is_success; }); $skype->run;
  28. use strict; use warnings; use AnySan; use AnySan::Provider::Skype; use LWP::UserAgent;

    my $ua = LWP::UserAgent->new; my $skype = skype; AnySan->register_listener( url => { event => 'chatmessage', cb => sub { my $receive = shift; my $message = $receive->message; while ($message =~ m!(?=(https?://\S+))!g) { my $url = $1; my $res = $ua->get($url); $res->is_success or return; my ($title) = $res->decoded_content =~ m! <title>(.*?)</title>!i; $title // return; $receive->send_reply($title); } }, }, ); AnySan->run;
  29. use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; use

    Config::Pit; use Redmine::Chan; use utf8; my $minechan = Redmine::Chan->new(%{pit_get('redmine', require => { redmine_url => '', redmine_api_key => '', })}, skype_chats => { '#t.akiym/$akiym_bot;e36505b33ee2e9c8' => {project_id => 1} }, status_commands => { 1 => [qw/new/], 2 => [qw/ongoing doing/], 3 => [qw/ϨϏϡʔ͓ئ͍͠·͢ ϨϏϡʔ͓Ͷ͕͍͠·͢/], 4 => [qw/ϨϏϡʔ͠·͢/], 7 => [qw/ϨϏϡʔ͠·ͨ͠/], 6 => [qw/done/], }, custom_field_prefix => { 2 => [qw(origin/)], # branch }, issue_fields => [qw/subject assigned_to status 1/], nick => 'minechan', ); $minechan->cook;
  30. use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; use

    Config::Pit; use Redmine::Chan; use utf8; my $minechan = Redmine::Chan->new(%{pit_get('redmine', require => { redmine_url => '', redmine_api_key => '', })}, skype_chats => { '#t.akiym/$akiym_bot;e36505b33ee2e9c8' => {project_id => 1} }, status_commands => { 1 => [qw/new/], 2 => [qw/ongoing doing/], 3 => [qw/ϨϏϡʔ͓ئ͍͠·͢ ϨϏϡʔ͓Ͷ͕͍͠·͢/], 4 => [qw/ϨϏϡʔ͠·͢/], 7 => [qw/ϨϏϡʔ͠·ͨ͠/], 6 => [qw/done/], }, custom_field_prefix => { 2 => [qw(origin/)], # branch }, issue_fields => [qw/subject assigned_to status 1/], nick => 'minechan', ); $minechan->cook; ͜͜ʹDIBUJE NJOFDIBOࢿྉ࡞Δ