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]+)?)?",
|
m = match(r"([A-z]+) *?( to|=)? *(.+)( *: *[A-z]+( *: *[A-z]+)?)?",
|
||||||
self.args.strip())
|
self.args.strip())
|
||||||
if m:
|
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))
|
self.caller.do_gift(m.group(3), m.group(1), m.group(4), m.group(5))
|
||||||
else:
|
else:
|
||||||
self.caller.msg("Usage: gift <gift> to <char> [ : name : desc ]")
|
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 import delay, logger, int2str
|
||||||
from evennia.utils.search import search_object, search_objects_by_typeclass
|
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 .objects import Object
|
||||||
from .tutorial import TutorBird, TutorialState
|
from .tutorial import TutorBird, TutorialState
|
||||||
|
|
||||||
|
|
@ -112,22 +112,7 @@ class Character(Object, GenderCharacter, ContribRPCharacter):
|
||||||
Capitalizes messages sent to the user.
|
Capitalizes messages sent to the user.
|
||||||
This just looks better to me.
|
This just looks better to me.
|
||||||
"""
|
"""
|
||||||
def capitalize_line(line):
|
text = fix_msg(text)
|
||||||
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])
|
|
||||||
super().msg(text, from_obj=from_obj, session=session, **kwargs)
|
super().msg(text, from_obj=from_obj, session=session, **kwargs)
|
||||||
|
|
||||||
def create_pouch(self, name="pouch", desc="leather pouch", giver=None):
|
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))
|
delay(pause, self.location.msg_contents, routput(m.group(2), *args))
|
||||||
else:
|
else:
|
||||||
cmd = routput(line, *args)
|
cmd = routput(line, *args)
|
||||||
logger.info(f"Executing: {cmd}")
|
|
||||||
delay(pause, self.do_cmd, cmd)
|
delay(pause, self.do_cmd, cmd)
|
||||||
|
|
||||||
delay(pause, self.attributes.remove, "current_sequence")
|
delay(pause, self.attributes.remove, "current_sequence")
|
||||||
|
|
@ -411,6 +410,7 @@ class Listener:
|
||||||
"""
|
"""
|
||||||
Like 'execute_cmd', but for objects.
|
Like 'execute_cmd', but for objects.
|
||||||
"""
|
"""
|
||||||
|
logger.info(f"Executing: {cmd}")
|
||||||
m = match(r"teleport +(.*?) *= *(.*)", cmd)
|
m = match(r"teleport +(.*?) *= *(.*)", cmd)
|
||||||
if m:
|
if m:
|
||||||
o = self.global_search(m.group(1))
|
o = self.global_search(m.group(1))
|
||||||
|
|
@ -430,6 +430,12 @@ class Listener:
|
||||||
c.tags.add(tag, category="mp")
|
c.tags.add(tag, category="mp")
|
||||||
return
|
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"):
|
if self.is_typeclass("typeclasses.characters.Character"):
|
||||||
self.execute_cmd(cmd)
|
self.execute_cmd(cmd)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -126,14 +126,16 @@ class Puppet(Character, Listener):
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
receiver = self.search(recipient, global_search=True)
|
||||||
receiver = self.search(recipient)
|
|
||||||
if not receiver:
|
if not receiver:
|
||||||
|
logger.info(f"Didn't find {recipient}.")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if gift in gifts.keys() and \
|
if gift in gifts.keys() and \
|
||||||
not receiver.attributes.get(f"received_{gift}"):
|
not receiver.attributes.get(f"received_{gift}"):
|
||||||
details = gifts[gift]
|
details = gifts[gift]
|
||||||
|
logger.info(f"Giving {details['key']} to {receiver.key}")
|
||||||
|
|
||||||
obj = spawn(details)[0]
|
obj = spawn(details)[0]
|
||||||
for attr, value in enumerate(details.get("attr", {})):
|
for attr, value in enumerate(details.get("attr", {})):
|
||||||
obj.attributes.add(attr, value)
|
obj.attributes.add(attr, value)
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ from django.conf import settings
|
||||||
|
|
||||||
from typeclasses.pets import Hunger
|
from typeclasses.pets import Hunger
|
||||||
from typeclasses.objects import ObjectParent
|
from typeclasses.objects import ObjectParent
|
||||||
|
from utils.word_list import fix_msg
|
||||||
|
|
||||||
_SEARCH_AT_RESULT = utils.object_from_module(settings.SEARCH_AT_RESULT)
|
_SEARCH_AT_RESULT = utils.object_from_module(settings.SEARCH_AT_RESULT)
|
||||||
|
|
||||||
|
|
@ -127,6 +128,12 @@ class Room(ObjectParent, ExtendedRoom, ContribRPRoom):
|
||||||
else:
|
else:
|
||||||
return ''
|
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):
|
class DabblersRoom(Room):
|
||||||
def get_display_desc(self, looker):
|
def get_display_desc(self, looker):
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
from itertools import batched
|
from itertools import batched
|
||||||
from random import choice
|
from random import choice
|
||||||
from re import compile, sub, split
|
from re import compile, sub, split, match
|
||||||
|
|
||||||
from evennia.utils import logger, dedent
|
from evennia.utils import logger, dedent
|
||||||
|
|
||||||
|
|
@ -18,6 +18,28 @@ def paragraph(text):
|
||||||
sub(r"\n\n+", ";;",
|
sub(r"\n\n+", ";;",
|
||||||
dedent(text)))).strip()
|
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):
|
def squish(text):
|
||||||
"Remove series of spaces from the text."
|
"Remove series of spaces from the text."
|
||||||
return sub('[ \t]+', ' ', text).strip()
|
return sub('[ \t]+', ' ', text).strip()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue