]> git.somenet.org - irc/bugbot.git/blob - BotModules/UUIDGen.bm
some old base
[irc/bugbot.git] / BotModules / UUIDGen.bm
1 ################################
2 # UUIDGen Module               #
3 ################################
4
5 # "uuidgen" should be installed on the path somewhere.
6 # you can get the source of uuidgen from CVS, see:
7 # http://lxr.mozilla.org/mozilla/source/webtools/mozbot/uuidgen/
8
9 package BotModules::UUIDGen;
10 use vars qw(@ISA);
11 @ISA = qw(BotModules);
12 1;
13
14 sub Help {
15     my $self = shift;
16     my ($event) = @_;
17     return {
18         '' => 'This module is an interface to the uuidgen application.',
19         'uuid' => 'Generates a UUID.',
20         'cid'  => 'Generates a UUID but outputs format suitable for components (CID).',
21     };
22 }
23
24 sub Told {
25     my $self = shift;
26     my ($event, $message) = @_;
27     if ($message =~ /^\s*uuid(?:[\s,!?]+please)?[\s,!?]*\s*$/osi) {
28         $self->spawnChild($event, 'uuidgen', [], 'UUID', []);
29     } elsif ($message =~ /^\s*cid(?:[\s,!?]+please)?[\s,!?]*\s*$/osi) {
30         $self->spawnChild($event, 'uuidgen', [], 'CID', []);
31     } else {
32         return $self->SUPER::Told(@_);
33     }
34     return 0; # we've dealt with it, no need to do anything else.
35 }
36
37 # ChildCompleted - Called when a child process has quit
38 sub ChildCompleted {
39     my $self = shift;
40     my ($event, $type, $output, @data) = @_;
41     if ($type eq 'UUID') {
42         chop($output);
43         $output .= " (/msg $nicks[$nick] cid for CID form)";
44         $self->say($event, $output);
45     } elsif ($type eq 'CID') {
46         # remove newline
47         chop($output);
48         my @split = split(/-/, $output);
49         $output = "{0x$split[0], 0x$split[1], 0x$split[2], {";
50
51         my @rest = $split[3] =~ m/(..)(..)/;
52         push(@rest, $split[4] =~ m/(..)(..)(..)(..)(..)(..)/);
53
54         foreach (@rest) {
55             $output .= "0x$_, ";
56         }
57
58         # remove the space and comma
59         chop($output);
60         chop($output);
61
62         $output .= "}}\n";
63         $self->say($event, $output);
64     } else {
65         return $self->SUPER::ChildCompleted(@_);
66     }
67 }
68