yuppie has asked for the wisdom of the Perl Monks concerning the following question:

So, I'm a big newb. Decided it would be fun to hack an IRC bot in perl.

This is what I have so far: https://github.com/internaught/perl/blob/master/yuppie.pl

#!/usr/bin/env perl -w # use strict; use diagnostics; package yuppie; use base qw(Bot::BasicBot); use v5.20.1; my $ticked = 0; sub said { my $self = shift; my $message = shift; #exit if $ticked; print q(Called said); if ($message->{body} =~ /\bperl\b/) { $self->say( { channel => ( $self->channels ), #[0], body => "I heard python is better...\n", } ); } } yuppie->new( server => "irc.freenode.net", port => "6667", channels => ["##bikes"], ssl => 0, nick => "yuppie", alt_nicks => ["yuppy", "yuppieee"], username => "yuppie", ignore_list => [qw("what?" "huh?" lactose)], )->run();
Basically, the subroutine starting at line 12 listens for anyone to say "perl" anywhere in the channel and then replies with "I heard python is better..."

Now, there are quite a few things I'd like to implement in this bot, eventually. But, the first is going to be simple, building on what I already have in place: Reading input from the channel and writing output to the channel.

Now, whenever someone mentions the word "perl" only one thing happens, but I'd like for there to be many choices and have the bot randomly pick one.

So, upon hearing "perl" the bot responds, at random, with either:

"I heard python is better..." or "Silly $nick, perl is for kids!" or things like that. Where $nick is the nickname of the person in channel that said it.

How would I do that? Also...

This list could become quite lengthy and I think that using "use lib;" where I have certain categories broken up by files would be a good route to go in order to keep track of and maintain all the possibilities of what could be heard and how the bot will respond to what has been said. (This was suggested to me by another perler.)

Also, whenever the bot is addressed by it's nickname, there could be a wide array (pun intended) of responses. e.g.: "yuppie, what's up?" bot responds: "Nothing much! What's up with you, $nick?" or if someone -only- says the name of the bot, the bot could respond with: "What?" or "Yes, $nick?" or "That's me."

That should be good for starters but I'd also like to implement being able to pass commands to the bot within the channel. For instance, searching google by typing in the channel: "!g Laser Cats" youtube: "!yt @ARGV" wikipedia: "!wiki @ARGV" urbandictionary: "!ud @ARGV" and so on... Where the bot would output either a link to the search result, along with the page title or, in the case of urban dictionary, a snippet of the page containing the search result itself.

Also... logging. I'm going to be running the bot directly from a CentOS server and I'd like to have some logging for the bot in place. Most likely putting everything that could possibly be logged into "/var/log/bot/yuppie.log".

This is my vision for my IRC bot. I would like to learn by doing and I'm coming here seeking suggestions, advice and constructive criticism on how to accomplish these goals.

Thanks in advance.

Replies are listed 'Best First'.
Re: Newbie playing with Bot::BasicBot
by roboticus (Chancellor) on Dec 23, 2014 at 03:39 UTC

    yuppie:

    Perhaps you should write it in Python? I heard it's better...

    ...roboticus

    When your only tool is a hammer, all problems look like your thumb.

      At least, it would teach the OP to indent code.
      لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Newbie playing with Bot::BasicBot
by LanX (Saint) on Dec 23, 2014 at 12:56 UTC