From 21fb5d49740523be0e6eda19b1149dd55e9c6b03 Mon Sep 17 00:00:00 2001 From: Elijah Perrault Date: Wed, 20 Apr 2011 20:37:31 -0600 Subject: [PATCH] Commands now work with prefixes even in PM. --- doc/CHANGELOG | 1 + lib/Core/IRC.pm | 5 +++-- lib/Proto/IRC.pm | 8 ++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/doc/CHANGELOG b/doc/CHANGELOG index f345dac..1406e83 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev =============================================================================== + * Commands now work with prefixes even in PM. * Ping: Determines end by numeric 315 instead of a 3-second timer now. * Werewolf: Fixed a GUARD issue and made it possible to VISIT yourself. * Possibly fixed a rare fatal error. diff --git a/lib/Core/IRC.pm b/lib/Core/IRC.pm index cba8c0b..1b1fde3 100644 --- a/lib/Core/IRC.pm +++ b/lib/Core/IRC.pm @@ -64,6 +64,8 @@ hook_add('on_cprivmsg', 'irc.commands.aliases', sub { # Command alias parsing for private messages. hook_add('on_uprivmsg', 'irc.commands.aliases', sub { my (($src, ($cmd, @args))) = @_; + my $cprefix = (conf_get('fantasy_pf'))[0][0]; + $cmd =~ s/^$cprefix//xsm; # Check for an alias. if (defined $API::Std::ALIASES{uc $cmd}) { @@ -233,8 +235,7 @@ hook_add('on_isupport', 'core.prefixchanmode.getdata', sub { return 1; }); -sub clear_usercmd_timer -{ +sub clear_usercmd_timer { # If ratelimit is set to 1 in config, add this timer. if ((conf_get('ratelimit'))[0][0] eq 1) { # Clear usercmd hash every X seconds. diff --git a/lib/Proto/IRC.pm b/lib/Proto/IRC.pm index d1817a5..684fecd 100644 --- a/lib/Proto/IRC.pm +++ b/lib/Proto/IRC.pm @@ -624,9 +624,13 @@ sub privmsg { if (lc($ex[2]) eq lc($State::IRC::botinfo{$svr}{nick})) { # It is coming to us in a private message. + # Check for a prefix. + $cprefix = (conf_get('fantasy_pf'))[0][0]; + # Ensure it's a valid length. - if (length($ex[3]) > 1) { - $cmd = uc(substr($ex[3], 1)); + if (length($ex[3]) > 2) { + $cmd = uc substr $ex[3], 1; + $cmd =~ s/^$cprefix//xsm; if (defined $API::Std::CMDS{$cmd}) { # If this is indeed a command, continue. if ($API::Std::CMDS{$cmd}{lvl} == 1 or $API::Std::CMDS{$cmd}{lvl} == 2) {