cmd_alias.rb
znmud-0.0.1/cmd/zombie/cmd_alias.rb · 1.3 KB
From the archive znmud-minimal-0.0.1.tar.gz
Download the archive « Back to the archive contents
#
# file:: cmd_alias.rb
# This source code copyright (C) 2009 Craig Smith
# All rights reserved.
#
# Released under the terms of the TeensyMUD Public License
# See LICENSE file for additional information.
#
module Cmd
bindtextdomain("cmd")
# The alias command
def cmd_alias(args)
# fix backwards compatibility
self.cmdaliases = {} if not self.cmdaliases
case args
when /^(\w+)\s*(.*)/
aliascmd = $1
arg = $2
exists = false
cmds = world.cmds.find(aliascmd)
cmds.each do |c|
exists = true if c.name == aliascmd
end
if exists
sendto _("Alias command already exists as a real command")
else
if self.cmdaliases.has_key? aliascmd
if arg.size > 0
self.cmdaliases[aliascmd] = arg
sendto _("Alias `%{alias}' redefined." % {:alias => aliascmd})
else
self.cmdaliases.delete aliascmd
sendto _("Alias '%{alias}' deleted." % {:alias => aliascmd})
end
else
self.cmdaliases[aliascmd] = arg
sendto _("Alias `%{alias}' set." % {:alias => aliascmd})
end
end
when nil, ""
if self.cmdaliases.size > 0
self.cmdaliases.each do |a, cmd|
sendto("#{a} - \"#{cmd}\"")
end
else
sendto _("You have no aliases defined.")
end
else
sendto _("Syntax: alias 'cmd' 'expanded command'")
end
end
end