Skip to content

Instantly share code, notes, and snippets.

@arodland
Created June 11, 2009 00:03
Show Gist options
  • Save arodland/127608 to your computer and use it in GitHub Desktop.
Save arodland/127608 to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
use strict;
use Text::ParseWords;
sub decide {
my $self = shift;
my $event = shift;
my (@args) = ( $event->args );
my $message = shift(@args);
my $send_to;
if ( $event->type eq "public" ) {
$send_to = ( $event->to )[0];
} elsif ( $event->type eq "msg" ) {
$send_to = $event->nick;
} else {
print STDERR "Got an unexpected type\n";
return;
}
if ( $message =~ /^\.decide\s+(.*)/i ) {
my @tokens = shellwords($lines);
if ( @tokens == 1 ) {
$self->privmsg( $send_to, "Figure it out yourself!" );
} else {
my $choice = $tokens[ rand @tokens ];
$self->privmsg( $send_to, "I choose: $choice" );
}
}
}
register_function( "pubmsg", \&decide );
register_function( "privmsg", \&decide );
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment