Skip to content

Instantly share code, notes, and snippets.

@mattn
Created June 23, 2009 04:52
Show Gist options
  • Save mattn/134368 to your computer and use it in GitHub Desktop.
Save mattn/134368 to your computer and use it in GitHub Desktop.
use strict;
use warnings;
use LWP::UserAgent;
use JSON;
use YAML;
sub irc_session {
my ($ua, $nick) = @_;
my $res = $ua->post("http://webchat.freenode.net/e/n", {nick => $nick});
my $id = @{from_json($res->decoded_content)}[1];
for (1..10) {
my $res = $ua->post("http://webchat.freenode.net/e/s", {s => $id});
my $lines = from_json($res->decoded_content);
for (@{$lines}) {
return $id if @{$_}[1] eq "376";
return 0 if @{$_}[1] eq "443";
}
sleep 3;
}
return 0;
}
sub irc_join {
my ($ua, $id, $room) = @_;
warn $room;
my $res = $ua->post("http://webchat.freenode.net/e/p", {c => "JOIN $room", s => $id});
$ua->post("http://webchat.freenode.net/e/s", {s => $id});
}
sub irc_say {
my ($ua, $id, $room, $msg) = @_;
my $res = $ua->post("http://webchat.freenode.net/e/p", {c => "PRIVMSG $room :$msg", s => $id});
}
sub irc_bye {
my ($ua, $id, $room, $msg) = @_;
my $res = $ua->post("http://webchat.freenode.net/e/p", {c => "PART $room $msg", s => $id});
}
my $ua = LWP::UserAgent->new;
my $nick = 'mattn_ha_tksk'
my $room = '#mattn-room'
my $id = irc_session $ua, $nick;
irc_join $ua, $id, $room;
sleep 1;
irc_say $ua, $id, $room, "hello, i'm mattn. i'm not TKSK!";
sleep 1;
irc_bye $ua, $id, $room, "bye.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment