Added command aliasing.

This commit is contained in:
Elijah Perrault committed 2011-03-20 15:23:28 -06:00
1 parent 703f2c2ec8
commit 168266696a
6 files changed
+75 -8

No files matched your search

+1
View File
@@ -19,6 +19,7 @@ In this alpha8 release, we have added:
* The `wizard` utility, for creating local Auto config directories.
* EightBall rewritten to be much nicer.
* A module to translate English into LOLCAT (LOLCAT).
* Command aliasing via aliases blocks in the config.
Bug fixes:
+10
View File
@@ -483,6 +483,16 @@ API::Std::cmd_add('SHUTDOWN', 2, 'cmd.shutdown', \%Core::Cmd::HELP_SHUTDOWN, \&C
API::Std::cmd_add('RESTART', 2, 'cmd.restart', \%Core::Cmd::HELP_RESTART, \&Core::Cmd::cmd_restart);
API::Std::cmd_add('REHASH', 2, 'cmd.rehash', \%Core::Cmd::HELP_REHASH, \&Core::Cmd::cmd_rehash);
API::Std::cmd_add('HELP', 2, 0, \%Core::Cmd::HELP_HELP, \&Core::Cmd::cmd_help);
# Aliases, if any.
if (conf_get('aliases:alias')) {
my $aliases = (conf_get('aliases:alias'))[0];
foreach (@{$aliases}) {
if ($_ =~ m/\s/xsm) {
my @data = split /\s/xsm, $_;
API::Std::cmd_alias($data[0], join ' ', @data[1..$#data]);
}
}
}
# Infinite while loop.
while (1) {
+1
View File
@@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log
3.0 Indev
===============================================================================
* Added command aliasing.
* Moved botinfo to State::IRC.
* Added hook on_selfkick for when we are kicked from a channel.
* Moved chanusers to State::IRC.
+7
View File
@@ -86,6 +86,13 @@ user "#bot-ops" {
privs "op";
}
# Command aliases.
# These can be used to alias a shortcut to a longer command.
# Like so: alias "PL UNO PLAY";
aliases {
alias "RELOAD REHASH";
}
# Database.
database {
# Format. This can be one of the following:
+14 -1
View File
@@ -9,7 +9,7 @@ use Exporter;
use base qw(Exporter);
our (%LANGE, %MODULE, %EVENTS, %HOOKS, %CMDS, %RAWHOOKS);
our (%LANGE, %MODULE, %EVENTS, %HOOKS, %CMDS, %ALIASES, %RAWHOOKS);
our @EXPORT_OK = qw(conf_get trans err awarn timer_add timer_del cmd_add
cmd_del hook_add hook_del rchook_add rchook_del match_user
has_priv mod_exists ratelimit_check fpfmt);
@@ -123,6 +123,19 @@ sub cmd_add {
return 1;
}
# Alias a command to another.
sub cmd_alias {
my ($alias, $cmd) = @_;
# Prepare data.
$alias = uc $alias;
$cmd = uc $cmd;
# Create alias.
$ALIASES{$alias} = $cmd;
return 1;
}
# Delete a command from Auto.
sub cmd_del {
+42 -7
View File
@@ -26,6 +26,41 @@ hook_add("on_uprivmsg", "ctcp_version_reply", sub {
return 1;
});
# Command alias parsing.
hook_add('on_cprivmsg', 'irc.commands.aliases', sub {
my (($src, $chan, ($cmd, @args))) = @_;
# Check for valid length.
if (length $cmd >= 2) {
my $ipref = substr $cmd, 0, 1, q{};
my $upref = (conf_get('fantasy_pf'))[0][0];
# Check if the prefix is valid.
if ($upref eq $ipref) {
# It is, 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',
$chan,
q{:}.$upref.$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)) = @_;
@@ -55,7 +90,7 @@ hook_add("on_connect", "on_connect_modes", sub {
hook_add('on_connect', 'on_connect_selfwho', sub {
my ($svr) = @_;
API::IRC::who($svr, $Proto::IRC::botinfo{$svr}{nick});
API::IRC::who($svr, $State::IRC::botinfo{$svr}{nick});
return 1;
});
@@ -128,10 +163,10 @@ hook_add('on_whoreply', 'selfwho.getdata', sub {
my (($svr, $nick, undef, $user, $mask, undef, undef, undef, undef)) = @_;
# Check if it's for us.
if ($nick eq $Proto::IRC::botinfo{$svr}{nick}) {
if ($nick eq $State::IRC::botinfo{$svr}{nick}) {
# It is. Set data.
$Proto::IRC::botinfo{$svr}{user} = $user;
$Proto::IRC::botinfo{$svr}{mask} = $mask;
$State::IRC::botinfo{$svr}{user} = $user;
$State::IRC::botinfo{$svr}{mask} = $mask;
}
return 1;
@@ -194,7 +229,7 @@ hook_add('on_disconnect', 'core.irc.deldata', sub {
# Delete all data related to the server.
if (defined $Proto::IRC::got_001{$svr}) { delete $Proto::IRC::got_001{$svr} }
if (defined $Proto::IRC::botinfo{$svr}) { delete $Proto::IRC::botinfo{$svr} }
if (defined $State::IRC::botinfo{$svr}) { delete $State::IRC::botinfo{$svr} }
if (defined $Proto::IRC::botchans{$svr}) { delete $Proto::IRC::botchans{$svr} }
if (defined $State::IRC::chanusers{$svr}) { delete $State::IRC::chanusers{$svr} }
if (defined $Proto::IRC::csprefix{$svr}) { delete $Proto::IRC::csprefix{$svr} }
@@ -223,10 +258,10 @@ hook_add('on_umode', 'core.irc.state.umode', sub {
else {
# Adjust our modes.
if ($op) {
$Proto::IRC::botinfo{$svr}{modes} .= $_;
$State::IRC::botinfo{$svr}{modes} .= $_;
}
else {
$Proto::IRC::botinfo{$svr}{modes} =~ s/($_)//xsm;
$State::IRC::botinfo{$svr}{modes} =~ s/($_)//xsm;
}
}
}