Add chardelete command to ooc menu for MULTISESSION_MODEs > 1. Also strip the result string from get_input helper to get rid of the carriage return always sent due to the user committing the command string.

This commit is contained in:
Griatch 2016-08-28 23:15:46 +02:00
parent d3c2e5de9d
commit 46ac4d3928
4 changed files with 61 additions and 1 deletions

View file

@ -30,6 +30,7 @@ class PlayerCmdSet(CmdSet):
self.add(player.CmdIC())
self.add(player.CmdOOC())
self.add(player.CmdCharCreate())
self.add(player.CmdCharDelete())
#self.add(player.CmdSessions())
self.add(player.CmdWho())
self.add(player.CmdOption())

View file

@ -174,6 +174,57 @@ class CmdCharCreate(COMMAND_DEFAULT_CLASS):
self.msg("Created new character %s. Use {w@ic %s{n to enter the game as this character." % (new_character.key, new_character.key))
class CmdCharDelete(COMMAND_DEFAULT_CLASS):
"""
delete a character - this cannot be undone!
Usage:
@chardelete <charname>
Permanently deletes one of your characters.
"""
key = "@chardelete"
locks = "cmd:pperm(Players)"
help_category = "General"
def func(self):
"delete the character"
player = self.player
if not self.args:
self.msg("Usage: @chardelete <charactername>")
return
# use the playable_characters list to search
match = [char for char in utils.make_iter(player.db._playable_characters) if char.key.lower() == self.args.lower()]
if not match:
self.msg("You have no such character to delete.")
return
elif len(match) > 1:
self.msg("Aborting - there are two characters with the same name. Ask an admin to delete the right one.")
return
else: # one match
from evennia.utils.evmenu import get_input
def _callback(caller, prompt, result):
if result.lower() == "yes":
# only take action
delobj = caller.ndb._char_to_delete
key = delobj.key
caller.db._playable_characters = [char for char
in caller.db._playable_characters if char != delobj]
delobj.delete()
caller.msg("Character '%s' was permanently deleted." % key)
else:
caller.msg("Deletion was aborted.")
del caller.ndb._char_to_delete
match = match[0]
player.ndb._char_to_delete = match
prompt = "|rThis will permanently destroy '%s'. This cannot be undone.|n Continue yes/[no]?"
get_input(player, prompt % match.key, _callback)
class CmdIC(COMMAND_DEFAULT_CLASS):
"""
control an object you have permission to puppet

View file

@ -843,6 +843,7 @@ class DefaultPlayer(with_metaclass(TypeclassBase, PlayerDB)):
string += "\n\n You don't have any characters yet. See |whelp @charcreate|n for creating one."
else:
string += "\n |w@charcreate <name> [=description]|n - create new character"
string += "\n |w@chardelete <name>|n - delete a character (cannot be undone!)"
if characters:
string_s_ending = len(characters) > 1 and "s" or ""

View file

@ -792,7 +792,7 @@ class CmdGetInput(Command):
caller = self.caller
callback = caller.ndb._getinputcallback
prompt = caller.ndb._getinputprompt
result = self.raw_string
result = self.raw_string.strip() # we strip the ending line break caused by sending
ok = not callback(caller, prompt, result)
if ok:
@ -842,6 +842,13 @@ def get_input(caller, prompt, callback):
Raises:
RuntimeError: If the given callback is not callable.
Notes:
The result value sent to the callback is raw and not
processed in any way. This means that you will get
the ending line return character from most types of
client inputs. So make sure to strip that before
doing a comparison.
"""
if not callable(callback):
raise RuntimeError("get_input: input callback is not callable.")