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.


In reply to Newbie playing with Bot::BasicBot by yuppie

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.