- From the Editor
- The Login
- The Mentality
- Perl Culture
- Intro to Perl Bots v3
- Anomalies of Code
- Last Months Challenge
- This Months Challenge
- Rexor
- Cascading Style Sheets
- INTRO
- SYNTAX
- APPLYING CSS TO YOUR PAGE
- Header Tag
- Header Tag
- Text
- Background
- Classes
- Lists
- Virtual Private Networks
- Cryptool Review
- Post of the Month
- Leadership Part B
- China Attacks!
- Former Staff Bio: Mar A1B4
- Fun Stuff
- Ping-pong fun
- Gaussian Gun
- My Music
- Viral Videos
- interesting videos
- Contact Us!
Intro to Perl Bots v3
By: Gothicfreak
Ok for this you need a basic understanding of perl and IRC.
There are plenty of books out there for perl to help you learn regex
and to learn basic perl functions/abilities.
For the IRC aspect you basically need to know the syntax of the cmds
and responses. To learn this read rfc1459.
So now you have your bot basically coded, it connects it fork()s and
thats about it. So what you need to do is inside of the
-
while ($irc) {};
is add something to catch the information coming in parse it and figure
out what it is and see if its something you want to respond/react to.
So lets jump right in. I’m going to start out with a blurb of code
and explain what its doing after that.
-
$line = $_;
-
if ($lines[1] eq ‘PRIVMSG’) {
-
if ($lines[2] eq "$botnick") {
-
#privmsg cmds
-
}
-
else {
-
#channel cmds
-
}
-
}
Ok what that does is it reads the socket, removes the linebreaks,
then splits the info into an array for easier parsing. It then reads
the 2nd word in the array to find out what the cmd is
(ie privmsg, mode, kick, etc). If it is a PRIVMSG from someone it then
looks to see if the 3rd line is the bots nickname. If it is, it’s a
message to the bot not to a channel if its not the bots nick, it’s a message
to a channel. That way you can have different commands for private messages
and channel messages.
Next, I’ll show you some of the more basic commands that are built into some
services (I’m going to skip access levels/lists though).
Inside the: else {} statements if you put something like:
-
if ($lines[3] eq ‘!op’) {
-
if ($lines[4]) {
-
}
-
else {
-
}
-
}
Basically that removes the : before the message checks to see if its the
command or phrase we are looking for and handles accordingly. Now
I have another if-then-else statement in there to see if they are trying
to just op themselves or someone else hence the if ($lines[4])
If they are trying to op themselves you need to get just the nickname they
are using. So you have to remove everything after the ! in their nick/user.
I do it a simple way that i’m sure could be improved with the proper regex.
I just do a split. The reason i do this is because later on you can use it
and break it into an address/username if you wanted to do bans or verify
an internal access list by address/username.
Now everyone has seen the quotes database and such that some bots have had.
They are actually quite simple to setup. Basically have a database (flatfile)
of quotes or phrases whatever you want and put one quote per line.
Then just add this information into your bot:
-
$fortune_db = ‘/path/to/data/base’;
-
if ($lines[3] eq "!fortune") {
-
}
Quite simply it sets a database variable (in-case you call it in other subs to add to or whatever)
then opens the database if the proper command is given (or errors if it can’t
open the database) picks a random line (removes any white spaces before the line)
then prints it to the channel that the command was in. closes the file and its done.
Now there are many thing you can do with these, the list goes on and on
and if you use different modules you can have sql databases of information or users
you can have it connect to a site with a socket and pull information.
The list goes on and on. Play around and see what you can come up with.
Enjoy!