Added command aliasing.
This commit is contained in:
1 parent
703f2c2ec8
commit
168266696a
6 files changed
+75
-8
No files matched your search
@@ -19,6 +19,7 @@ In this alpha8 release, we have added:
|
|||||||
* The `wizard` utility, for creating local Auto config directories.
|
* The `wizard` utility, for creating local Auto config directories.
|
||||||
* EightBall rewritten to be much nicer.
|
* EightBall rewritten to be much nicer.
|
||||||
* A module to translate English into LOLCAT (LOLCAT).
|
* A module to translate English into LOLCAT (LOLCAT).
|
||||||
|
* Command aliasing via aliases blocks in the config.
|
||||||
|
|
||||||
Bug fixes:
|
Bug fixes:
|
||||||
|
|
||||||
|
|||||||
@@ -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('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('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);
|
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.
|
# Infinite while loop.
|
||||||
while (1) {
|
while (1) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ Auto IRC Bot 3.0: Change Log
|
|||||||
|
|
||||||
3.0 Indev
|
3.0 Indev
|
||||||
===============================================================================
|
===============================================================================
|
||||||
|
* Added command aliasing.
|
||||||
* Moved botinfo to State::IRC.
|
* Moved botinfo to State::IRC.
|
||||||
* Added hook on_selfkick for when we are kicked from a channel.
|
* Added hook on_selfkick for when we are kicked from a channel.
|
||||||
* Moved chanusers to State::IRC.
|
* Moved chanusers to State::IRC.
|
||||||
|
|||||||
@@ -86,6 +86,13 @@ user "#bot-ops" {
|
|||||||
privs "op";
|
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.
|
||||||
database {
|
database {
|
||||||
# Format. This can be one of the following:
|
# Format. This can be one of the following:
|
||||||
|
|||||||
+14
-1
@@ -9,7 +9,7 @@ use Exporter;
|
|||||||
use base qw(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
|
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
|
cmd_del hook_add hook_del rchook_add rchook_del match_user
|
||||||
has_priv mod_exists ratelimit_check fpfmt);
|
has_priv mod_exists ratelimit_check fpfmt);
|
||||||
@@ -123,6 +123,19 @@ sub cmd_add {
|
|||||||
return 1;
|
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.
|
# Delete a command from Auto.
|
||||||
sub cmd_del {
|
sub cmd_del {
|
||||||
|
|||||||
+42
-7
@@ -26,6 +26,41 @@ hook_add("on_uprivmsg", "ctcp_version_reply", sub {
|
|||||||
return 1;
|
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.
|
# QUIT hook; delete user from chanusers.
|
||||||
hook_add("on_quit", "quit_update_chanusers", sub {
|
hook_add("on_quit", "quit_update_chanusers", sub {
|
||||||
my (($src, undef)) = @_;
|
my (($src, undef)) = @_;
|
||||||
@@ -55,7 +90,7 @@ hook_add("on_connect", "on_connect_modes", sub {
|
|||||||
hook_add('on_connect', 'on_connect_selfwho', sub {
|
hook_add('on_connect', 'on_connect_selfwho', sub {
|
||||||
my ($svr) = @_;
|
my ($svr) = @_;
|
||||||
|
|
||||||
API::IRC::who($svr, $Proto::IRC::botinfo{$svr}{nick});
|
API::IRC::who($svr, $State::IRC::botinfo{$svr}{nick});
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
});
|
});
|
||||||
@@ -128,10 +163,10 @@ hook_add('on_whoreply', 'selfwho.getdata', sub {
|
|||||||
my (($svr, $nick, undef, $user, $mask, undef, undef, undef, undef)) = @_;
|
my (($svr, $nick, undef, $user, $mask, undef, undef, undef, undef)) = @_;
|
||||||
|
|
||||||
# Check if it's for us.
|
# 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.
|
# It is. Set data.
|
||||||
$Proto::IRC::botinfo{$svr}{user} = $user;
|
$State::IRC::botinfo{$svr}{user} = $user;
|
||||||
$Proto::IRC::botinfo{$svr}{mask} = $mask;
|
$State::IRC::botinfo{$svr}{mask} = $mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -194,7 +229,7 @@ hook_add('on_disconnect', 'core.irc.deldata', sub {
|
|||||||
|
|
||||||
# Delete all data related to the server.
|
# Delete all data related to the server.
|
||||||
if (defined $Proto::IRC::got_001{$svr}) { delete $Proto::IRC::got_001{$svr} }
|
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 $Proto::IRC::botchans{$svr}) { delete $Proto::IRC::botchans{$svr} }
|
||||||
if (defined $State::IRC::chanusers{$svr}) { delete $State::IRC::chanusers{$svr} }
|
if (defined $State::IRC::chanusers{$svr}) { delete $State::IRC::chanusers{$svr} }
|
||||||
if (defined $Proto::IRC::csprefix{$svr}) { delete $Proto::IRC::csprefix{$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 {
|
else {
|
||||||
# Adjust our modes.
|
# Adjust our modes.
|
||||||
if ($op) {
|
if ($op) {
|
||||||
$Proto::IRC::botinfo{$svr}{modes} .= $_;
|
$State::IRC::botinfo{$svr}{modes} .= $_;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$Proto::IRC::botinfo{$svr}{modes} =~ s/($_)//xsm;
|
$State::IRC::botinfo{$svr}{modes} =~ s/($_)//xsm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user