def create_character(self, name, owner=""): '''Create an in-world character if one does not already exist. If one exists, return it.''' # TODO: This is pretty dumb and needs reorganized. charobj = self.get_character(name) if not charobj: # No character in the db named that, # So create an object for the player and save it. charobj = Character() charobj.name = name charobj.owner = owner charobj.states.append('player') return charobj
def get_character(self, character): '''Gets a character from the database by name. Returns the Character object, or False if it isn't a well-formed character object.''' try: charobj = Character.objects(name=character).first() return charobj if charobj.states else False except(IndexError, AttributeError): return False
def is_owner(self, username, character): charobj = Character.objects(name=character).first() if charobj: return charobj.owner == username else: return None