Skip to content

Instantly share code, notes, and snippets.

@arodland
Created April 14, 2009 00:29
Show Gist options
  • Save arodland/94850 to your computer and use it in GitHub Desktop.
Save arodland/94850 to your computer and use it in GitHub Desktop.
diff --git a/modules/decide.pl b/modules/decide.pl
index 95f7321..d66a810 100644
--- a/modules/decide.pl
+++ b/modules/decide.pl
@@ -1,38 +1,37 @@
#!/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+\"([\w\W]+)\"/i) {
- my @tokens = split /\"/, $1;
- if(scalar(@tokens) == 1) {
- $self->privmsg($send_to, "Figure it out yourself!");
- }
- else {
- my $choice = int(rand((scalar(@tokens)+1)/2));
- $self->privmsg($send_to, "I choose: " . $tokens[($choice*2)]);
- }
+ 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);
+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