cmd_misc.py 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. '''
  2. cmd_misc.c
  3. a collection of miscellaneous commands that come with NakedMud(tm)
  4. '''
  5. import mudsys, mud, hooks, event, mudsys
  6. def cmd_stop(ch, cmd, arg):
  7. '''If you are currently performing an action (for example, a delayed
  8. command), make an attempt to stop performing that action.'''
  9. if not ch.isActing():
  10. ch.send("But you're not currently performing an action!\r\n")
  11. else:
  12. ch.interrupt()
  13. def cmd_clear(ch, cmd, arg):
  14. '''This command will clear your display screen.'''
  15. ch.send_raw("\033[H\033[J")
  16. def event_delayed_cmd(ch, filler, cmd):
  17. '''used to perform delayed commands'''
  18. ch.act(cmd, True)
  19. def cmd_delay(ch, cmd, arg):
  20. '''Usage: delay <seconds> <command>
  21. Allows the user to prepare a command to be executed in the future. For
  22. example:
  23. > delay 2 say hello, world!
  24. Will make you say \'hello, world!\' two seconds after entering the
  25. delayed command.'''
  26. try:
  27. secs, to_delay = mud.parse_args(ch, True, cmd, arg, "double string")
  28. except: return
  29. if secs < 1:
  30. ch.send("You can only delay commands for positive amounts of time.")
  31. else:
  32. ch.send("You delay '%s' for %.2f seconds" % (to_delay, secs))
  33. event.start_event(ch, secs, event_delayed_cmd, None, to_delay)
  34. def cmd_motd(ch, cmd, arg):
  35. '''This command will display to you the mud\'s message of the day.'''
  36. ch.page(mud.get_motd())
  37. def cmd_save(ch, cmd, arg):
  38. '''Attempt to save your character and all recent changes made to it, to
  39. disk. This automatically happens when logging out.'''
  40. if mudsys.do_save(ch):
  41. ch.send("Saved.")
  42. else:
  43. ch.send("Your character was not saved.")
  44. def cmd_quit(ch, cmd, arg):
  45. '''Attempts to save and log out of the game.'''
  46. mud.log_string(ch.name + " has left the game.")
  47. mudsys.do_save(ch)
  48. mudsys.do_quit(ch)
  49. ################################################################################
  50. # add our commands
  51. ################################################################################
  52. mudsys.add_cmd("stop", None, cmd_stop, "player", False)
  53. mudsys.add_cmd("clear", None, cmd_clear, "player", False)
  54. mudsys.add_cmd("delay", None, cmd_delay, "player", False)
  55. mudsys.add_cmd("motd", None, cmd_motd, "player", False)
  56. mudsys.add_cmd("save", None, cmd_save, "player", False)
  57. mudsys.add_cmd("quit", None, cmd_quit, "player", True)
  58. chk_can_save = lambda ch, cmd: not ch.is_npc
  59. mudsys.add_cmd_check("save", chk_can_save)
  60. mudsys.add_cmd_check("quit", chk_can_save)