Tanner M. Young <mozilla.bugs@alyoung.com>, r=Wolf git-svn-id: svn://10.0.0.236/trunk@261762 18797224-902f-48f8-a5cc-f745e15eee43
69 lines
1.9 KiB
Plaintext
69 lines
1.9 KiB
Plaintext
################################
|
|
# UUIDGen Module #
|
|
################################
|
|
|
|
# "uuidgen" should be installed on the path somewhere.
|
|
# you can get the source of uuidgen from CVS, see:
|
|
# http://mxr.mozilla.org/webtools/source/mozbot/uuidgen/
|
|
|
|
package BotModules::UUIDGen;
|
|
use vars qw(@ISA);
|
|
@ISA = qw(BotModules);
|
|
1;
|
|
|
|
sub Help {
|
|
my $self = shift;
|
|
my ($event) = @_;
|
|
return {
|
|
'' => 'This module is an interface to the uuidgen application.',
|
|
'uuid' => 'Generates a UUID.',
|
|
'cid' => 'Generates a UUID but outputs format suitable for components (CID).',
|
|
};
|
|
}
|
|
|
|
sub Told {
|
|
my $self = shift;
|
|
my ($event, $message) = @_;
|
|
if ($message =~ /^\s*uuid(?:[\s,!?]+please)?[\s,!?]*\s*$/osi) {
|
|
$self->spawnChild($event, 'uuidgen', [], 'UUID', []);
|
|
} elsif ($message =~ /^\s*cid(?:[\s,!?]+please)?[\s,!?]*\s*$/osi) {
|
|
$self->spawnChild($event, 'uuidgen', [], 'CID', []);
|
|
} else {
|
|
return $self->SUPER::Told(@_);
|
|
}
|
|
return 0; # we've dealt with it, no need to do anything else.
|
|
}
|
|
|
|
# ChildCompleted - Called when a child process has quit
|
|
sub ChildCompleted {
|
|
my $self = shift;
|
|
my ($event, $type, $output, @data) = @_;
|
|
if ($type eq 'UUID') {
|
|
chop($output);
|
|
$output .= " (/msg $nicks[$nick] cid for CID form)";
|
|
$self->say($event, $output);
|
|
} elsif ($type eq 'CID') {
|
|
# remove newline
|
|
chop($output);
|
|
my @split = split(/-/, $output);
|
|
$output = "{0x$split[0], 0x$split[1], 0x$split[2], {";
|
|
|
|
my @rest = $split[3] =~ m/(..)(..)/;
|
|
push(@rest, $split[4] =~ m/(..)(..)(..)(..)(..)(..)/);
|
|
|
|
foreach (@rest) {
|
|
$output .= "0x$_, ";
|
|
}
|
|
|
|
# remove the space and comma
|
|
chop($output);
|
|
chop($output);
|
|
|
|
$output .= "}}\n";
|
|
$self->say($event, $output);
|
|
} else {
|
|
return $self->SUPER::ChildCompleted(@_);
|
|
}
|
|
}
|
|
|