znmud-0.0.1/benchmark/
znmud-0.0.1/cmd/
znmud-0.0.1/cmd/emotes/
znmud-0.0.1/cmd/objects/
znmud-0.0.1/cmd/tiny/
znmud-0.0.1/doc/
znmud-0.0.1/farts/
znmud-0.0.1/lib/
znmud-0.0.1/lib/combat/
znmud-0.0.1/lib/core/bodytypes/
znmud-0.0.1/lib/engine/
znmud-0.0.1/lib/farts/
znmud-0.0.1/logs/
#
# 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