Blame


1 8f7f2f4a 2021-12-17 jrmu ================================================================================
2 8f7f2f4a 2021-12-17 jrmu
3 8f7f2f4a 2021-12-17 jrmu Creating a DiceBot
4 8f7f2f4a 2021-12-17 jrmu
5 8f7f2f4a 2021-12-17 jrmu In our first lesson, we'll create an IRC bot that rolls the
6 8f7f2f4a 2021-12-17 jrmu dice for you.
7 8f7f2f4a 2021-12-17 jrmu
8 8f7f2f4a 2021-12-17 jrmu Copy the code for dicebot.pl to your home folder:
9 8f7f2f4a 2021-12-17 jrmu
10 8f7f2f4a 2021-12-17 jrmu $ cp dicebot.pl ~/dicebot.pl
11 8f7f2f4a 2021-12-17 jrmu
12 8f7f2f4a 2021-12-17 jrmu Next, open up dicebot.pl using a text editor and make a few changes.
13 8f7f2f4a 2021-12-17 jrmu (We recommend vim because it provides syntax highlighting)
14 8f7f2f4a 2021-12-17 jrmu
15 8f7f2f4a 2021-12-17 jrmu 1. Edit the server in line 20. Replace irc.example.com with the server's
16 8f7f2f4a 2021-12-17 jrmu real address. NOTE: Only IPv4 is supported.
17 8f7f2f4a 2021-12-17 jrmu 2. Edit line 23 to replace nickname with the nickname you want for the bot.
18 8f7f2f4a 2021-12-17 jrmu WARNING: The nickname must not already be taken, or else the bot will
19 8f7f2f4a 2021-12-17 jrmu fail to connect.
20 8f7f2f4a 2021-12-17 jrmu 3. Edit line 24 to replace username with the username you want for the bot.
21 8f7f2f4a 2021-12-17 jrmu The username is what appears in a /whois on IRC; it can be different
22 8f7f2f4a 2021-12-17 jrmu from the nickname.
23 8f7f2f4a 2021-12-17 jrmu
24 8f7f2f4a 2021-12-17 jrmu Next, you'll want to make the perl script executable:
25 8f7f2f4a 2021-12-17 jrmu
26 8f7f2f4a 2021-12-17 jrmu $ chmod u+x ~/dicebot.pl
27 8f7f2f4a 2021-12-17 jrmu
28 8f7f2f4a 2021-12-17 jrmu Then run the script:
29 8f7f2f4a 2021-12-17 jrmu
30 8f7f2f4a 2021-12-17 jrmu $ perl ~/dicebot.pl
31 8f7f2f4a 2021-12-17 jrmu
32 8f7f2f4a 2021-12-17 jrmu On IRC, /join #perl101
33 8f7f2f4a 2021-12-17 jrmu
34 8f7f2f4a 2021-12-17 jrmu Type !roll and you'll see the bot rolls a pair of virtual dice.
35 8f7f2f4a 2021-12-17 jrmu
36 8f7f2f4a 2021-12-17 jrmu In less than 5 minutes, you've created your first IRC bot with perl.
37 8f7f2f4a 2021-12-17 jrmu
38 8f7f2f4a 2021-12-17 jrmu ================================================================================
39 8f7f2f4a 2021-12-17 jrmu
40 8f7f2f4a 2021-12-17 jrmu Understanding DiceBot
41 8f7f2f4a 2021-12-17 jrmu
42 8f7f2f4a 2021-12-17 jrmu Next, take a look at the file called ~/comments to see an explanation of
43 8f7f2f4a 2021-12-17 jrmu key lines in the program.
44 8f7f2f4a 2021-12-17 jrmu
45 8f7f2f4a 2021-12-17 jrmu ================================================================================