Skip to content
Browse files

Rename ->im(...) => ->send_message( ... ) as it will also support chat

  • Loading branch information...
1 parent 911856d commit 06f61f9cb19ddecf74614e4f43be879dd78523bd @sanko committed Jun 16, 2011
Showing with 27 additions and 7 deletions.
  1. +1 −1 examples/client.pl
  2. +26 −6 lib/AnyEvent/MSN.pm
View
2 examples/client.pl
@@ -20,7 +20,7 @@
on_connect => sub { warn 'Connected as ' . shift->passport },
on_im => sub { # simple echo bot
my ($msn, $head, $body) = @_;
- $msn->im($head->{From}, $body);
+ $msn->send_messsage($head->{From}, $body);
},
on_nudge => sub {
my ($msn, $head) = @_;
View
32 lib/AnyEvent/MSN.pm
@@ -913,7 +913,7 @@ XML
);
}
- sub im {
+ sub send_message {
my ($s, $to, $msg, $format) = @_;
$to = '1:' . $to if $to !~ m[^\d+:];
$format //= 'FN=Segoe%20UI; EF=; CO=0; CS=1; PF=0';
@@ -939,11 +939,31 @@ XML
sprintf
qq[Routing: 1.0\r\nTo: %s\r\nFrom: 1:%s;epid=%s\r\n\r\nReliability: 1.0\r\n\r\nMessaging: 2.0\r\nMessage-Type: Nudge\r\nService-Channel: IM/Online\r\nContent-Type: text/plain; charset=UTF-8\r\nContent-Length: 0\r\n\r\n],
$to, $s->passport, $s->guid;
- $s->send(qq'SDG 0 %d\r\n%s', length($data), $data);
+ $s->send("SDG 0 %d\r\n%s", length($data), $data);
}
sub add_buddy {
my $s = shift;
+ my %contacts;
+ for my $contact (@_) {
+ my ($user, $domain) = split /\@/, $contact, 2;
+ push @{$contacts{$domain}}, $user;
+ }
+ my $data = sprintf '<ml%s>%s</ml>', ($s->connected ? '' : ' l="1"'),
+ join '', map {
+ sprintf '<d n="%s">%s</d>', $_, join '', map {
+ sprintf '<c n="%s" t="1">%s</c>', $_, join '',
+ map {"<s l='3' n='$_' />"}
+ qw[IM PE PF]
+ } sort @{$contacts{$_}}
+ } sort keys %contacts;
+ my $tid = $s->tid;
+ $s->send("ADL %d %d\r\n%s", $tid, length($data), $data);
+ $tid;
+ }
+
+ sub remove_buddy {
+ my $s = shift;
my $data = sprintf <<'', reverse split '@', shift, 2;
<ml>
<d n="%s">
@@ -1168,13 +1188,13 @@ C<no_autoconnect =E<gt> 1> to L<the constructor|/new>.
=item im
- $msn->im('buddy@hotmail.com', 'oh hai!');
+ $msn->send_message('buddy@hotmail.com', 'oh hai!');
This sends an instant message.
-c<im( ... )> supports a third parameter, a string to indicate how the message
-shoud be displayed. The default is C<FN=Segoe%20UI; EF=; CO=0; CS=1; PF=0>.
-Uh, let's break that down a little.
+c<send_message( ... )> supports a third parameter, a string to indicate how
+the message shoud be displayed. The default is
+C<FN=Segoe%20UI; EF=; CO=0; CS=1; PF=0>. Uh, let's break that down a little.
=for url http://msdn.microsoft.com/en-us/library/bb969558(v=office.12).aspx

0 comments on commit 06f61f9

Please sign in to comment.
Something went wrong with that request. Please try again.