deadpickle has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/local/bin/perl -w use strict; use Gtk2 '-init'; use Glib qw/TRUE FALSE/; use threads; use threads::shared; use IO::Socket; #-------------------Shared Variables------------------- my $server:shared = "irc.freenode.net"; my $nick:shared = "simple_bot"; my $login:shared = "simple_bot"; my $channel:shared = "#GRRUVI"; my $die:shared = 0; ################################################# my $thread = threads->new( \&magic); ################################################# #-------------------Main Loop------------------- my $window = Gtk2::Window->new('toplevel'); $window->signal_connect( delete_event => sub { $die = 1; $thread->join; Gtk2->main_quit; }); $window->set_default_size( 300, 200 ); my $table = Gtk2::Table->new(2, 1, FALSE); my $scroller = Gtk2::ScrolledWindow->new; my $textview = Gtk2::TextView->new; my $entry = Gtk2::Entry->new; $scroller->add($textview); $table->attach_defaults($scroller, 0, 1, 0, 1); $table->attach_defaults($entry, 0, 1, 1, 2); $window->add($table); $window->show_all; Gtk2->main; ################################################# #-------------------IRC Thread------------------- sub magic { # Connect to the IRC server. my $sock = new IO::Socket::INET( PeerAddr => $server, PeerPort => 6667, Proto => 'tcp') or die "Can't connect\n"; # Log on to the server. print $sock "NICK $nick\r\n"; print $sock "USER $login 8 * :Perl IRC Hacks Robot\r\n"; # Read lines from the server until it tells us we have connected. while (my $input = <$sock>) { # Check the numerical responses from the server. if ($input =~ /004/) { # We are now logged in. last; } elsif ($input =~ /433/) { die "Nickname is already in use."; } } goto END if $die == 1; # Join the channel. print $sock "JOIN $channel\r\n"; # Keep reading lines from the server. while (my $input = <$sock>) { chop $input; if ($input =~ /^PING(.*)$/i) { # We must respond to PINGs to avoid being disconnected. print $sock "PONG $1\r\n"; } else { # Print the raw line received by the bot. print "$input\n"; } goto END if $die == 1; } END: undef $sock; } #################################################
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IRC Client (non-bot)
by pc88mxer (Vicar) on Feb 09, 2008 at 18:45 UTC | |
|
Re: IRC Client (non-bot)
by Anonymous Monk on Feb 10, 2008 at 11:42 UTC | |
by deadpickle (Pilgrim) on Feb 10, 2008 at 17:25 UTC | |
by deadpickle (Pilgrim) on Feb 10, 2008 at 19:53 UTC | |
by pc88mxer (Vicar) on Feb 10, 2008 at 20:34 UTC | |
by deadpickle (Pilgrim) on Feb 12, 2008 at 05:16 UTC |