-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmbot.pl
executable file
·49 lines (40 loc) · 1.06 KB
/
dmbot.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/perl
use strict;
use warnings;
package DMBot;
use base qw(Bot::BasicBot);
use utf8;
use Data::Dumper;
use YAML::Tiny;
my $yaml = YAML::Tiny->read('config.yml');
my $dm = DMBot->new(
server => $yaml->[0]->{server},
port => $yaml->[0]->{port},
channels => $yaml->[0]->{channels},
nick => $yaml->[0]->{nick},
alt_nicks => $yaml->[0]->{alt_nicks},
username => $yaml->[0]->{username},
name => $yaml->[0]->{name},
ignore_list => [qw(RepBot ChanServ)],
);
sub said {
my ($self, $message) = @_;
if ($message->{body} =~ /^!roll[\s]+(?<num>\d+)?d(?<sides>\d+)/){
my $dice = (defined $+{num}) ? int($+{num}) : 1;
my $sides = $+{sides};
if ($sides == 0 || $dice == 0){
return 0;
}
my $val = int(rand($dice*$sides))+$dice;
if ($val == $dice*$sides){
return "$val!";
}
elsif ($val == $dice){
return "$val!";
}
else{
return "$val";
}
}
}
$dm->run();