Created
July 28, 2010 00:58
-
-
Save jsocol/493135 to your computer and use it in GitHub Desktop.
Dungeon.bm - A dice-rolling module for MozBot
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
########################### | |
# Dungeon Module # | |
########################### | |
package BotModules::Dungeon; | |
use vars qw(@ISA); | |
@ISA = qw(BotModules); | |
use DBI; | |
use strict; | |
1; | |
sub Help { | |
my $self = shift; | |
my ($event) = @_; | |
return { | |
'' => 'A dungeon master module.', | |
'!roll' => 'Roll the dice.', | |
}; | |
} | |
sub Heard { | |
my $self = shift; | |
my ($event, $message) = @_; | |
my $user = substr $event->{'user'}, 0, index($event->{'user'}, '@'); | |
if ($message =~ /^!roll$/i) { | |
my $rand = int(rand(100))+1; | |
$self->say($event, "$user rolled a $rand (1-100)"); | |
return 0; | |
} elsif ($message =~ /^!roll\s+(\d*)d(\d+)(?:\+(\d+))?\s*$/i) { | |
my $count = int($1); if ($count == 0) {$count = 1;} | |
my $size = int($2); | |
my $offset = int($3) or 0; | |
my $total = $offset; | |
my $i; | |
for ($i = 0; $i < $count; $i++) { | |
$total += int(rand($size))+1; | |
} | |
$self->say($event, "$user rolled a $total (${count}d${size}+$offset)"); | |
return 0; | |
} elsif ($message =~ /^!roll\s+(\d+)\s*$/i) { | |
my $range = int($1); | |
my $rand = int(rand($range))+1; | |
$self->say($event, "$user rolled a $rand (1-$range)"); | |
return 0; | |
} elsif ($message =~ /^!roll\s+(\d+)-(\d+)\s*$/i) { | |
my $low = int($1); | |
my $high = int($2); | |
my $range = $high - $low + 1; | |
my $rand = int(rand($range)) + $low; | |
$self->say($event, "$user rolled a $rand ($low-$high)"); | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment