Created
June 30, 2009 02:28
-
-
Save sartak/137948 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use IM::Engine; | |
do { | |
package Rock::Paper::Scissors; | |
use Path::Dispatcher::Declarative -base; | |
my %beats = ( | |
rock => 'scissors', | |
paper => 'rock', | |
scissors => 'paper', | |
); | |
on [ ['rock', 'paper', 'scissors'] ] => sub { | |
my $human = $1; | |
my $computer = (qw/rock paper scissors/)[rand 3]; | |
my $result = "$human vs $computer: "; | |
$result .= "It's a draw!" if $human eq $computer; | |
$result .= "You win!" if $computer eq $beats{$human}; | |
$result .= "I win!" if $human eq $beats{$computer}; | |
return $result; | |
}; | |
}; | |
IM::Engine->new( | |
interface => { | |
protocol => 'IRC', | |
credentials => { | |
server => 'irc.perl.org', | |
channels => ['#im-engine'], | |
nick => 'IM_Engine', | |
}, | |
}, | |
plugins => [ | |
Dispatcher => { | |
dispatcher => 'Rock::Paper::Scissors', | |
}, | |
# If you're running a non-IRC bot, you probably want to tell the user | |
# about invalid commands with: | |
# 404 => {}, | |
], | |
)->run; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment