From bc287589bb0b0a61303455e1b01c514b9662eeba Mon Sep 17 00:00:00 2001 From: Elijah Perrault Date: Thu, 7 Apr 2011 14:54:30 -0600 Subject: [PATCH] Aliases now work in PM's to the bot too. --- NEWS | 1 + doc/CHANGELOG | 1 + lib/Core/IRC.pm | 29 ++++++++++++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/NEWS b/NEWS index deff39d..00ddc2e 100644 --- a/NEWS +++ b/NEWS @@ -22,6 +22,7 @@ In this alpha10 release, we have added: * German translation for FML command help. * German translation for Greet command help. * Werewolf module for the Werewolf party game. +* Aliases now work in PM's to the bot too. Bug fixes: diff --git a/doc/CHANGELOG b/doc/CHANGELOG index 214cf14..2e0b70d 100644 --- a/doc/CHANGELOG +++ b/doc/CHANGELOG @@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log 3.0 Indev =============================================================================== + * Aliases now work in PM's to the bot too. * Added an epic, Werewolf module. * Made slog() saner. * Syntax for mod_init() changed. Package name is no longer required. diff --git a/lib/Core/IRC.pm b/lib/Core/IRC.pm index adcd2cd..cba8c0b 100644 --- a/lib/Core/IRC.pm +++ b/lib/Core/IRC.pm @@ -26,7 +26,7 @@ hook_add("on_uprivmsg", "ctcp_version_reply", sub { return 1; }); -# Command alias parsing. +# Command alias parsing for channel messages. hook_add('on_cprivmsg', 'irc.commands.aliases', sub { my (($src, $chan, ($cmd, @args))) = @_; @@ -61,6 +61,33 @@ hook_add('on_cprivmsg', 'irc.commands.aliases', sub { return 1; }); +# Command alias parsing for private messages. +hook_add('on_uprivmsg', 'irc.commands.aliases', sub { + my (($src, ($cmd, @args))) = @_; + + # Check for an alias. + if (defined $API::Std::ALIASES{uc $cmd}) { + # Get aliased command. + my @actual; + if ($API::Std::ALIASES{uc $cmd} =~ m/ /xsm) { @actual = split /\s/xsm, $API::Std::ALIASES{uc $cmd} } + else { @actual = ($API::Std::ALIASES{uc $cmd}) } + # Prepare data. + my @msg = ( + q{:}.$src->{nick}.q{!}.$src->{user}.q{@}.$src->{host}, + 'PRIVMSG', + $State::IRC::botinfo{$src->{svr}}{nick}, + q{:}.$actual[0], + ); + # Rest of the data. + if (scalar @actual > 1) { for (1..$#actual) { push @msg, $actual[$_] } } + if (defined $args[0]) { foreach (@args) { push @msg, $_ } } + # Simulate a PRIVMSG. + Proto::IRC::privmsg($src->{svr}, @msg); + } + + return 1; +}); + # QUIT hook; delete user from chanusers. hook_add("on_quit", "quit_update_chanusers", sub { my (($src, undef)) = @_;