use Net::IRC; use Getopt::Long; use Pod::Usage; use strict; my $VERSION = "1.1.0"; my $server = ""; my @room; my $room; my $port = 6667; my $help = 0; my $versions = 0; my $pass = ''; my $name = "Roller"; GetOptions( 'help|h' => \$help, 'port|p=i' => \$port, 'versions|v' => \$versions, 'pass|p=s' => \$pass, 'name|n=s' => \$name, ) or (pod2usage() && die); if($help){ pod2usage(-verbose=>1); exit; } if($versions){ print "\nModules, Perl, OS, Program info:\n", " Net::IRC $Net::IRC::VERSION\n", " Pod::Usage $Pod::Usage::VERSION\n", " Getopt::Long $Getopt::Long::VERSION\n", " strict $strict::VERSION\n", " Perl $]\n", " OS $^O\n", " irc.pl $VERSION\n", " $0\n\n"; exit; } { local $@; eval{ $server = shift(@ARGV) or (pod2usage() && die); @room = @ARGV or (pod2usage() && die); }; if($@ =~ m#Can't open -e for reading#){ #Used with tinyperl pod2usage(-verbose=>1); exit; }elsif($@){ die($@); } } my $irc = new Net::IRC; my $conn = $irc->newconn( Nick => $name, Server => $server, Port => $port, Ircname => 'Dice Roler Bot', ($pass ? (Password => $pass) : ()), ); $conn->add_handler('376',\&on_connect); $conn->add_handler('msg',\&on_msg); $conn->add_handler('public',\&on_public); $irc->start; sub on_connect{ my $self = shift; for(@room){ print "Joining $_\n"; $self->join($_); } print "Connection phase complete... Waiting...\n"; } sub on_public{ my $self = shift; my $event = shift; my $cmd = $event->{'args'}[0]; return unless($cmd =~ m/^~(\d+)d(\d+)(?:(?:(?=-)|\+)(-?\d+))?$/); my @list; print "Rolling...\n"; if($1 > 50){ $self->privmsg($event->{'to'}[0],"Error: You cannot roll more th +an 50 dice."); return; } my $total = $3; #Set the bonus to the base! for(1..$1){ my $num = int(rand($2)+1); $total += $num; push(@list,$num); } $self->privmsg($event->{'to'}[0],$event->{'nick'}. ' rolled '. $1.'d'.$2.($3 ? ($3 > 0 ? "+$3" : "$3") : ''). ' for '. join(', ',@list). ": $total" ); } sub on_msg{ my $self = shift; my $event = shift; print "Private message detected... processing/explaining\n"; if($event->{'args'}[0] eq 'quit'){ warn($event->{'nick'}); exit; } $self->privmsg($event->{'nick'},"This is $name, a dice roller."); $self->privmsg($event->{'nick'},"Summery of use: type ~xdy+b into t +he chat and I will roll the dice as specified, adding b to the total +and reporting the results."); } __END__ =head1 NAME D&D - Dice Roller =head1 SYNOPSIS perl irc.pl [options] server room Options: --help|-h brief help message --port|-p=PORT# specify the port --versions|-v version information --name|n=botname specify the name of the bot --pass|p=password specify a password =head1 OPTIONS =over 8 =item B<--help> Prints a brief help message and then quits =item B<--port> Allows for specifying the port. =item B<--versions> Prints out a list of versions for the modules used by the program, and + the program itself. =item B<--name> Specify a name for the bot =item B<--pass> If the server is password protected, set this. =back =head1 DESCRIPTION B<This program> connects to the specified server and joins the request +ed room. Once connected, it waits for anyone in that room to say "~xdy+b" each +variable representing the following. =over 8 =item B<x> B<x> = the number of dice =item B<d> B<d> = a seperator common to D&D and other dice-based games. =item B<y> B<y> = the number of sides on the dice =item B<b> B<b> = something to arbitraraly add to the sum of the rolls, it is not + necessary =back This program will then reply to the current chat-room something to the + effect of "E<lt>NAMEE<gt> rolls 4d10+2 and got the following: 4, 6, 10, 9: 31 +" This program automatically terminates when private messaged the word " +quit". =head1 AUTHOR This program was written by Stephen "Flame" Couchman E<lt>guildms@user +s.sourceforge.netE<gt> =head1 COPYRIGHT and REDISTRIBUTION This program is copyright 2003 Stephen Couchman and may be freely modi +fied and redistributed under the same terms as Perl itself. =cut
Edit: Some changes made to properly apply the bonus, now only applys to the total rather than to each roll... thought it looked a little funny. Also expanded docs a little more... could still be better documented but for now...

In reply to IRC Dice Roller by Flame

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.