Fix the automated gift from puppets
This commit is contained in:
parent
d242489c71
commit
dca4048acf
6 changed files with 44 additions and 22 deletions
|
|
@ -137,7 +137,7 @@ class CmdGift(MuxCommand):
|
|||
m = match(r"([A-z]+) *?( to|=)? *(.+)( *: *[A-z]+( *: *[A-z]+)?)?",
|
||||
self.args.strip())
|
||||
if m:
|
||||
logger.info(f"Groups: {m.group(1)}, {m.group(2)}, {m.group(3)}")
|
||||
# logger.info(f"Gift: {m.group(1)} to {m.group(3)}")
|
||||
self.caller.do_gift(m.group(3), m.group(1), m.group(4), m.group(5))
|
||||
else:
|
||||
self.caller.msg("Usage: gift <gift> to <char> [ : name : desc ]")
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ from evennia.prototypes.spawner import spawn
|
|||
from evennia.utils import delay, logger, int2str
|
||||
from evennia.utils.search import search_object, search_objects_by_typeclass
|
||||
|
||||
from utils.word_list import routput, choices
|
||||
from utils.word_list import routput, choices, fix_msg
|
||||
from .objects import Object
|
||||
from .tutorial import TutorBird, TutorialState
|
||||
|
||||
|
|
@ -112,22 +112,7 @@ class Character(Object, GenderCharacter, ContribRPCharacter):
|
|||
Capitalizes messages sent to the user.
|
||||
This just looks better to me.
|
||||
"""
|
||||
def capitalize_line(line):
|
||||
if not line or line.strip() == "":
|
||||
return line
|
||||
elif match(r"^\|[bm][a-z].*", line):
|
||||
logger.info(f"Adding The! {line}")
|
||||
return "The " + line
|
||||
elif match(r"^\|[A-z][a-z].*", line):
|
||||
logger.info(f"Capitalizes: {line}")
|
||||
return line[0:2] + line[2].upper() + line[3:]
|
||||
else:
|
||||
return line[0].upper() + line[1:]
|
||||
|
||||
if text and isinstance(text, str) and len(text) > 0:
|
||||
text = capitalize_line(text)
|
||||
elif text and isinstance(text, tuple):
|
||||
text = (capitalize_line(text[0]), text[1])
|
||||
text = fix_msg(text)
|
||||
super().msg(text, from_obj=from_obj, session=session, **kwargs)
|
||||
|
||||
def create_pouch(self, name="pouch", desc="leather pouch", giver=None):
|
||||
|
|
|
|||
|
|
@ -310,7 +310,6 @@ class Object(ObjectParent, ContribRPObject):
|
|||
delay(pause, self.location.msg_contents, routput(m.group(2), *args))
|
||||
else:
|
||||
cmd = routput(line, *args)
|
||||
logger.info(f"Executing: {cmd}")
|
||||
delay(pause, self.do_cmd, cmd)
|
||||
|
||||
delay(pause, self.attributes.remove, "current_sequence")
|
||||
|
|
@ -411,6 +410,7 @@ class Listener:
|
|||
"""
|
||||
Like 'execute_cmd', but for objects.
|
||||
"""
|
||||
logger.info(f"Executing: {cmd}")
|
||||
m = match(r"teleport +(.*?) *= *(.*)", cmd)
|
||||
if m:
|
||||
o = self.global_search(m.group(1))
|
||||
|
|
@ -430,6 +430,12 @@ class Listener:
|
|||
c.tags.add(tag, category="mp")
|
||||
return
|
||||
|
||||
m = match(r"gift ([A-z]+) *?( to|=)? *(.+)( *: *[A-z]+( *: *[A-z]+)?)?", cmd)
|
||||
if m:
|
||||
logger.info(f"Higher Gift: {m.group(1)} to {m.group(3)}")
|
||||
self.do_gift(m.group(3), m.group(1), m.group(4), m.group(5))
|
||||
return
|
||||
|
||||
if self.is_typeclass("typeclasses.characters.Character"):
|
||||
self.execute_cmd(cmd)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -126,14 +126,16 @@ class Puppet(Character, Listener):
|
|||
}
|
||||
},
|
||||
}
|
||||
|
||||
receiver = self.search(recipient)
|
||||
receiver = self.search(recipient, global_search=True)
|
||||
if not receiver:
|
||||
logger.info(f"Didn't find {recipient}.")
|
||||
return None
|
||||
|
||||
if gift in gifts.keys() and \
|
||||
not receiver.attributes.get(f"received_{gift}"):
|
||||
details = gifts[gift]
|
||||
logger.info(f"Giving {details['key']} to {receiver.key}")
|
||||
|
||||
obj = spawn(details)[0]
|
||||
for attr, value in enumerate(details.get("attr", {})):
|
||||
obj.attributes.add(attr, value)
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ from django.conf import settings
|
|||
|
||||
from typeclasses.pets import Hunger
|
||||
from typeclasses.objects import ObjectParent
|
||||
from utils.word_list import fix_msg
|
||||
|
||||
_SEARCH_AT_RESULT = utils.object_from_module(settings.SEARCH_AT_RESULT)
|
||||
|
||||
|
|
@ -127,6 +128,12 @@ class Room(ObjectParent, ExtendedRoom, ContribRPRoom):
|
|||
else:
|
||||
return ''
|
||||
|
||||
def msg_contents(self, message, exclude=None, from_obj=None, mapping=None,
|
||||
raise_funcparse_errors=False, **kwargs):
|
||||
message = fix_msg(message)
|
||||
super().msg_contents(message, exclude, from_obj, mapping,
|
||||
raise_funcparse_errors)
|
||||
|
||||
|
||||
class DabblersRoom(Room):
|
||||
def get_display_desc(self, looker):
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
from itertools import batched
|
||||
from random import choice
|
||||
from re import compile, sub, split
|
||||
from re import compile, sub, split, match
|
||||
|
||||
from evennia.utils import logger, dedent
|
||||
|
||||
|
|
@ -18,6 +18,28 @@ def paragraph(text):
|
|||
sub(r"\n\n+", ";;",
|
||||
dedent(text)))).strip()
|
||||
|
||||
def fix_msg(text):
|
||||
if text and isinstance(text, str) and len(text) > 0:
|
||||
return capitalize_line(text)
|
||||
elif text and isinstance(text, tuple):
|
||||
return (capitalize_line(text[0]), text[1])
|
||||
else:
|
||||
return text
|
||||
|
||||
def capitalize_line(line):
|
||||
"""
|
||||
Return a capitalized version of 'line'.
|
||||
"""
|
||||
# logger.info(f"Fixing {line}")
|
||||
if not line or line.strip() == "":
|
||||
return line
|
||||
elif match(r"^\|[bm][a-z].*", line):
|
||||
return "The " + line
|
||||
elif match(r"^\|[A-z][a-z].*", line):
|
||||
return line[0:2] + line[2].upper() + line[3:]
|
||||
else:
|
||||
return line[0].upper() + line[1:]
|
||||
|
||||
def squish(text):
|
||||
"Remove series of spaces from the text."
|
||||
return sub('[ \t]+', ' ', text).strip()
|
||||
|
|
|
|||
Loading…
Reference in a new issue