Rewrote EightBall to be nicer.

This commit is contained in:
Elijah Perrault committed 2011-03-17 21:00:50 -06:00
1 parent e2afe403c0
commit 61fe399ac6
3 files changed
+41 -40

No files matched your search

+1
View File
@@ -17,6 +17,7 @@ In this alpha8 release, we have added:
* Support for installs to custom locations. * Support for installs to custom locations.
* Support for system-wide installs. (/usr or /usr/local) * Support for system-wide installs. (/usr or /usr/local)
* The `wizard` utility, for creating local Auto config directories. * The `wizard` utility, for creating local Auto config directories.
* EightBall rewritten to be much nicer.
Bug fixes: Bug fixes:
+1
View File
@@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log
3.0 Indev 3.0 Indev
=============================================================================== ===============================================================================
* EightBall module rewritten.
* Fixed a bug in LinkTitle that caused multi-line <title>'s to display * Fixed a bug in LinkTitle that caused multi-line <title>'s to display
wrong. wrong.
* Added `wizard`, for creating local Auto config directories. * Added `wizard`, for creating local Auto config directories.
+39 -40
View File
@@ -4,14 +4,27 @@
package M::EightBall; package M::EightBall;
use strict; use strict;
use warnings; use warnings;
use feature qw(switch);
use API::Std qw(cmd_add cmd_del trans); use API::Std qw(cmd_add cmd_del trans);
use API::IRC qw(privmsg notice); use API::IRC qw(privmsg notice);
our $ANSWER = 0; our $ANSWER = 0;
my @responses = (
'Yes!',
'No!',
'Yes... No... Yes... No... Hmm... No.',
'Hmm... it seems likely.',
'Very unlikely.',
'Heck no!',
'Definite yes!',
'Magic unavailable. Try again later.',
'Possibly, I wouldn\'t count on it though.',
'Outcome looks bad.',
'Outcome looks good.',
'Can\'t tell now. Maybe another time.',
'Sorry, but no.',
);
# Initialization subroutine. # Initialization subroutine.
sub _init sub _init {
{
# Create the 8BALL and RIGBALL commands. # Create the 8BALL and RIGBALL commands.
cmd_add('8BALL', 0, 0, \%M::EightBall::HELP_8BALL, \&M::EightBall::c_8ball) or return 0; cmd_add('8BALL', 0, 0, \%M::EightBall::HELP_8BALL, \&M::EightBall::c_8ball) or return 0;
cmd_add('RIGBALL', 1, 'cmd.rigball', \%M::EightBall::HELP_RIGBALL, \&M::EightBall::rigball) or return 0; cmd_add('RIGBALL', 1, 'cmd.rigball', \%M::EightBall::HELP_RIGBALL, \&M::EightBall::rigball) or return 0;
@@ -21,8 +34,7 @@ sub _init
} }
# Void subroutine. # Void subroutine.
sub _void sub _void {
{
# Delete the 8BALL and RIGBALL commands. # Delete the 8BALL and RIGBALL commands.
cmd_del('8BALL') or return 0; cmd_del('8BALL') or return 0;
cmd_del('RIGBALL') or return 0; cmd_del('RIGBALL') or return 0;
@@ -40,66 +52,53 @@ our %HELP_RIGBALL = (
); );
# Callback for 8BALL command. # Callback for 8BALL command.
sub c_8ball sub c_8ball {
{
my ($src, @argv) = @_; my ($src, @argv) = @_;
if (!defined $argv[0]) { if (!defined $argv[0]) {
notice($src->{svr}, $src->{nick}, trans("Not enough parameters")."."); notice($src->{svr}, $src->{nick}, trans('Not enough parameters').q{.});
return; return;
} }
privmsg($src->{svr}, $src->{chan}, "\002Question:\002 ".join(" ", @argv)); # Return the question.
privmsg($src->{svr}, $src->{chan}, "\2Question:\2 ".join q{ }, @argv);
my $a = '';
# Set answer.
my $answer;
if (!$ANSWER) { if (!$ANSWER) {
my $rn = int(rand(12)); $answer = $responses[int rand scalar @responses];
given ($rn) {
when (1) { $a = "Yes!"; }
when (2) { $a = "No!"; }
when (3) { $a = "Yes... No... Yes... No... No."; }
when (4) { $a = "Hmm... it seems likely."; }
when (5) { $a = "Very unlikely."; }
when (6) { $a = "Heck no!"; }
when (7) { $a = "Definite yes!"; }
when (8) { $a = "Magic unavailable. Try again later."; }
when (9) { $a = "Possibly, I wouldn't count on it though."; }
when (10) { $a = "Outcome looks bad."; }
when (11) { $a = "Outcome looks good."; }
when (12) { $a = "Can't tell now. Maybe another time."; }
default { $a = "Sorry, but no."; }
}
} }
else { else {
$a = $ANSWER; $answer = $ANSWER;
$ANSWER = 0; $ANSWER = 0;
} }
privmsg($src->{svr}, $src->{chan}, "\002Answer:\002 ".$a); # Return it.
privmsg($src->{svr}, $src->{chan}, "\2Answer:\2 $answer");
return 1; return 1;
} }
# Callback for RIGBALL command. # Callback for RIGBALL command.
sub rigball sub rigball {
{
my ($src, @argv) = @_; my ($src, @argv) = @_;
# Check for necessary parameters. # Check for necessary parameters.
if (!defined $argv[0]) { if (!defined $argv[0]) {
privmsg($src->{svr}, $src->{nick}, trans("Not enough parameters")."."); privmsg($src->{svr}, $src->{nick}, trans('Not enough parameters').q{.});
return; return;
} }
$ANSWER = join(" ", @argv); # Return result.
privmsg($src->{svr}, $src->{nick}, "Answer set to: ".$ANSWER); $ANSWER = join q{ }, @argv;
privmsg($src->{svr}, $src->{nick}, "Answer set to: $ANSWER");
return 1; return 1;
} }
# Start initialization. # Start initialization.
API::Std::mod_init('EightBall', 'Xelhua', '1.00', '3.0.0a7', __PACKAGE__); API::Std::mod_init('EightBall', 'Xelhua', '2.00', '3.0.0a8', __PACKAGE__);
# build: perl=5.010000 # build: perl=5.010000
__END__ __END__
@@ -110,7 +109,7 @@ EightBall - A magic eightball module.
=head1 VERSION =head1 VERSION
1.00 2.00
=head1 SYNOPSIS =head1 SYNOPSIS
@@ -124,9 +123,9 @@ EightBall - A magic eightball module.
=head1 DESCRIPTION =head1 DESCRIPTION
This module adds the 8BALL and RIGBALL commands, 8BALL is a channel This module adds the 8BALL and RIGBALL commands, 8BALL is a channel command for
command for asking the magic 8-Ball a question, RIGBALL is a private asking the magic 8-Ball a question, RIGBALL is a private command for setting
command for setting ("rigging") the 8-Ball's next answer. ("rigging") the 8-Ball's next answer.
=head1 AUTHOR =head1 AUTHOR