Support Forums

Full Version: perl IRC bot
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
A basic irc bot written by me brett7 in perl, this will connect to a server and channel of your choice then idle. There is some example commands you can use to make your own!

http://brett7.pastebin.com/f7232f0be

Code:
#!/usr/bin/perl -w
# Basic IRC Bot.
# Coded by brett7.

use strict;
use IO::Socket;
use Socket;
my $server = $ARGV[0];
my $port= '6667';
my $channel = $ARGV[1];
my $nick = $ARGV[2];
my $identify = "brett";
my $name = "brett";

if (@ARGV != 3){
print q{
#########################################################
#                    brett7's irc bot                   #
#Error: correct usage "irc.pl <server> <channel> <nick>"#
#########################################################
};
exit;
}
my $socket = new IO::Socket::INET(PeerAddr => $server, PeerPort => $port, Proto => "tcp") or die "Error connecting";
print " - brett7's irc bot\n\n";
print " - Connecting  To $server on channel $channel with nickname $nick!\n\n";
print $socket "NICK $nick\r\n";
print $socket "USER $identify 8 * :$name\r\n";
print $socket "JOIN $channel\r\n";
print " - Connected  To $server successfully!\n\n";
while (my $response = <$socket>)
{
  chop $response;
  if ($response =~ /^PING(.*)$/i) { print $socket "PONG $1\r\n"; }
  if ($response =~ /^.*!ver(.*)$/i) { print $socket ("PRIVMSG $channel brett7's bot\r\n"); }
  if ($response =~ /^.*!quit(.*)$/i) { print $socket ("QUIT\r\n"); }
}
Very basic but not bad.
Good job.
The bot only connected succesfully if I didnt put the # infront of the channel name, so it actually didnt connect to anything. any idea whats wonrg
Btw: If I do put the # I get #########################################################
# brett7's irc bot #
#Error: correct usage "irc.pl <server> <channel> <nick>"
#########################################################
and im doing for example "perl irc.pl irc.malvager.com #b hublebla"
check:

my $port= '6667';
my $name = "brett";

follow brett's post
nevets you must put # before the channel name for example
irc.pl irc.server.com #channel revets04

and thanks for comments guys Smile
Looks good.

too short.
Not bad, thanks a lot.
Your bot pings out Sad no ping code line. Might want to edit ;)
When your bot joins it doesn't parse server input after NICK and USER. It's really a miracle that you got it to work.

Also, your regex is kind of messed up. /^.*!quit(.*)$/i. In the first bit '/^.*' the .* will match any character, 0 or more times making the '^' meaningless. The (.*) is also unneeded. If you want to make sure you've got input coming from a channel, use something like: /^: (.*?)!.*: $text/, $text being !quit in your case. (the nick will also be in $1)
Very basic, but it's good Smile
Pages: 1 2