#!/usr/bin/perl # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This script is made by Dennis G. # Look at http://www.gnu.org/licenses/gpl.txt my $version ='0.0.3.1'; # ------------ # Enter your fishy wishes here: my $server = "irc.freenode.net"; my $port = '6667'; my $nick = "bluesceada"; my @channels = ("#flood"); my $username = "testbot"; my $usermode = "testing"; my $realname = "perlbot"; # ------------ use IO::Socket; use strict; # put this at the beginning of every output line my $out = "\033[01;31m\<-OUT- "; # and input line: my $in = "\033[01;34m\--IN-> "; my $initiation; my $line = ' '; my @temp; print "Perl Bot for IRC by Dennis G. - Version: ".$version."\n"; print "Connecting...\n\n"; my $remote = IO::Socket::INET->new( Proto => "tcp", PeerAddr => $server, PeerPort => $port ) || die "cannot connect to $server - port $port\n"; # set autoflushing -> unbuffer it! # either set this or flush manually later $remote->autoflush(1); $remote->send ("USER $username $usermode $realname :bot\n"); print $out."USER $username $usermode $realname :bot\n"; $remote->send ("NICK $nick\n"); print $out."NICK $nick\n"; # receive all the stuff through the $remote handle # this automatically lets us process each input from the socket line-wise # (nearly) no matter how fast we get it :-) while (<$remote>) { # maybe manually flush here instead of setting autoflush above #$remote->flush(); # put the line we got to some variable $line = $_; # let us know every line we receive over the socket print $in.$line; # remove trailing bit for easier processing chomp($line); # NICK Block (Error 433 or 431) # avoid nick collisions if ($line =~ m/^(:)(.*)\s(433|431)\s(.*)$/) { # add an underline if we collide - until infinity :D $nick = $nick."_"; # and send our new flashy nickname $remote->send ("NICK $nick\n"); # of course we want to know that on the terminal print ($out."NICK $nick\n"); } # Autojoin # tell the server all the channels we want to join, if (!$initiation) { for (my $i=0; $#channels >= $i; $i++) { # join the channel $remote->send ("JOIN $channels[$i]\n"); # we also want to know that print $out."JOIN $channels[$i]\n"; $initiation = 1; } } # PING PONG Block # needed to keep connection alive in IRC @temp = split(/:/, $line, 2); if ($temp[0] eq "PING ") { #split(/:/, $line, 2); # "PONG" back the PING PING :-) print $remote ("PONG :$temp[1]\n"); # we want to know that print ($out."PONG :$temp[1]\n"); } } # if the connection fails.. if (!$remote->connected) { $remote->shutdown(); die "ERROR - connection to ".$server." lost \n"; } # never get here I guess $remote->send ("QUIT See you\n"); $remote->shutdown(); exit 1;