1 ================================================================================
5 In this challenge, we will modify our original dicebot.pl to convert it
6 into a bot that checks the person who messages it.
8 Every time the owner messages the channel, it will say, "You're the boss!"
9 Every time another user messages it, it will say, "I don't recognize you!"
11 ================================================================================
15 Let's start with our original dicebot.pl. With just a few modifications, we
16 can make the bot chat in new and interactive ways.
18 Let's edit the subroutine said:
22 my $arguments = shift;
23 if ($arguments->{body} =~ /^!roll/) {
24 my $dice = int(rand(12))+1;
25 return "You rolled $dice!";
29 Let's change the if test. Instead of testing if the body of the message
30 starts with !roll, let's test if the sender has the right nick:
34 if ($arguments->{body} =~ /^!roll/) {
38 if ($arguments->{who} =~ /^yournick$/) {
40 Replace yournick with your nick on IRC.
42 The if (...) conditional tests whether the expression inside is true.
43 Here, we check the sender of the message with $arguments->{who}.
44 We use =~ to test if it matches the string yournick. The carat
45 symbol ^ marks the beginning of the string and the dollar symbol $
46 marks the end of the string.
48 Now that we're no longer rolling dice, we can delete this line:
50 my $dice = int(rand(12))+1;
52 Next, we should change the message. We replace:
54 return "You rolled $dice!";
58 return "You're the boss!";
60 We now have this snippet of code:
62 if ($arguments->{who} =~ /^yournick$/) {
63 return "You're the boss!";
66 This means: If the message comes from yournick, say "You're the boss!"
67 in the same channel that the message came from.
69 Let's use an else statement to send a message for users
70 that do not match yournick:
73 return "I don't recognize you!";
76 Finally, we will replace DiceBot on lines 5 and 20 with IDBot (because
77 this bot checks our ID):
87 my $bot = DiceBot->new(
93 (Hint: the answer is in /home/perl102/idbot.pl)
95 ================================================================================
102 ================================================================================