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_bug.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 bug command
  def cmd_bug(args)
    case args
    when nil, ""
	sendto _("==== [ BUGS ] ====")
	if not File.exists? options["bugfile"]
		sendto _(" * No bugs reported *")
		return
	end
	cnt = 1
	msg = ""
	File.open(options["bugfile"], "r").each do |l| 
		line = l.chomp
		msg << "#{cnt}) #{line}\n" 
		cnt += 1
	end
	msg << _(" * No bugs reported *") if cnt == 1
	msg = Msg.new(msg)
	msg.no_parse = true
	sendto(msg)
    when /^del\s+all/, /^clear$/
	if not world.can_build? id
		sendto _("You can not delete bugs.")
		return
	end
	if not File.exists? options["bugfile"]
		sendto _("No bugs to delete.")
		return
	end
	File.unlink(options["bugfile"])
	sendto _("Bug list cleared.")
    when /^del\s+(\d+)/
	if not world.can_build? id
		sendto _("You can not delete bugs.")
		return
	end
	if not File.exists? options["bugfile"]
		sendto _("No bugs to delete.")
		return
	end
	num = $1.to_i
	lines = []
	File.open(options["bugfile"], "r").each { |l| lines << l }
	cnt = 1
	if num > lines.size or num <= 0
		sendto _("Invalid line number.")
	else
		File.open(options["bugfile"], "w") do |f|
			lines.each do |l|
				f.write l if not cnt == num
				cnt += 1
			end
		end
		sendto _("Bug deleted.")
	end
    when /(.+)/
    	todo = File.open(options["bugfile"], "a+")
	todo.puts "#{name} (#{location}) #{$1}"
	todo.close
	sendto _("Ok")
    end
  end

end