nakedmud-mod/
nakedmud-mod/html/tutorials/
nakedmud-mod/html/tutorials/building_extras/
nakedmud-mod/html/tutorials/c/
nakedmud-mod/html/tutorials/reference/
nakedmud-mod/html/tutorials/scripting/
nakedmud-mod/html/tutorials/scripting_extras/
nakedmud-mod/lib/
nakedmud-mod/lib/help/A/
nakedmud-mod/lib/help/B/
nakedmud-mod/lib/help/C/
nakedmud-mod/lib/help/D/
nakedmud-mod/lib/help/G/
nakedmud-mod/lib/help/H/
nakedmud-mod/lib/help/J/
nakedmud-mod/lib/help/L/
nakedmud-mod/lib/help/M/
nakedmud-mod/lib/help/O/
nakedmud-mod/lib/help/P/
nakedmud-mod/lib/help/R/
nakedmud-mod/lib/help/S/
nakedmud-mod/lib/help/W/
nakedmud-mod/lib/logs/
nakedmud-mod/lib/misc/
nakedmud-mod/lib/players/
nakedmud-mod/lib/pymodules/polc/
nakedmud-mod/lib/txt/
nakedmud-mod/lib/world/
nakedmud-mod/lib/world/zones/examples/
nakedmud-mod/lib/world/zones/examples/mproto/
nakedmud-mod/lib/world/zones/examples/oproto/
nakedmud-mod/lib/world/zones/examples/reset/
nakedmud-mod/lib/world/zones/examples/rproto/
nakedmud-mod/lib/world/zones/examples/trigger/
nakedmud-mod/lib/world/zones/limbo/
nakedmud-mod/lib/world/zones/limbo/room/
nakedmud-mod/lib/world/zones/limbo/rproto/
nakedmud-mod/src/alias/
nakedmud-mod/src/dyn_vars/
nakedmud-mod/src/editor/
nakedmud-mod/src/example_module/
nakedmud-mod/src/help2/
nakedmud-mod/src/set_val/
nakedmud-mod/src/socials/
nakedmud-mod/src/time/
'''
cmd_misc.c

a collection of miscellaneous commands that come with NakedMud(tm)
'''
import mudsys, mud, hooks, event, mudsys



def cmd_stop(ch, cmd, arg):
    '''If you are currently performing an action (for example, a delayed
       command), make an attempt to stop performing that action.'''
    if not ch.isActing():
        ch.send("But you're not currently performing an action!\r\n")
    else:
        ch.interrupt()

def cmd_clear(ch, cmd, arg):
    '''This command will clear your display screen.'''
    ch.send_raw("\033[H\033[J")

def event_delayed_cmd(ch, filler, cmd):
    '''used to perform delayed commands'''
    ch.act(cmd, True)

def cmd_delay(ch, cmd, arg):
    '''Usage: delay <seconds> <command>

       Allows the user to prepare a command to be executed in the future. For
       example:

       > delay 2 say hello, world!

       Will make you say \'hello, world!\' two seconds after entering the
       delayed command.'''
    try:
        secs, to_delay = mud.parse_args(ch, True, cmd, arg, "double string")
    except: return

    if secs < 1:
        ch.send("You can only delay commands for positive amounts of time.")
    else:
        ch.send("You delay '%s' for %.2f seconds" % (to_delay, secs))
        event.start_event(ch, secs, event_delayed_cmd, None, to_delay)

def cmd_motd(ch, cmd, arg):
    '''This command will display to you the mud\'s message of the day.'''
    ch.page(get_motd())

def cmd_save(ch, cmd, arg):
    '''Attempt to save your character and all recent changes made to it, to
       disk. This automatically happens when logging out.'''
    if mudsys.do_save(ch):
        ch.send("Saved.")
    else:
        ch.send("Your character was not saved.")
    

def cmd_quit(ch, cmd, arg):
    '''Attempts to save and log out of the game.'''
    mud.log_string(ch.name + " has left the game.")
    mudsys.do_save(ch)
    mudsys.do_quit(ch)



################################################################################
# add our commands
################################################################################
mudsys.add_cmd("stop",  None, cmd_stop,  "player", False)
mudsys.add_cmd("clear", None, cmd_clear, "player", False)
mudsys.add_cmd("delay", None, cmd_delay, "player", False)
mudsys.add_cmd("motd",  None, cmd_motd,  "player", False)
mudsys.add_cmd("save",  None, cmd_save,  "player", False)
mudsys.add_cmd("quit",  None, cmd_quit,  "player", True)

chk_can_save = lambda ch, cmd: not ch.is_npc
mudsys.add_cmd_check("save", chk_can_save)
mudsys.add_cmd_check("quit", chk_can_save)