moss-n-puddles/utils/word_list.py
2025-04-14 10:11:19 -07:00

57 lines
1.5 KiB
Python
Executable file

#!/usr/bin/env python
import random
import re
def squish(text):
"Remove series of spaces from the text."
return re.sub('[ \n\t]+', ' ', text).strip()
def routput(text, substitution=None):
"""
Return string with internal word choices replaced randomly.
For instance, the string:
'This feels [|very|quite] [nice|cozy|comfortable].'
Could return any of the following strings:
'This feels quite nice.'
'This feels cozy.'
'This feels very comfortable.'
"""
if text:
acc = []
for s in text.split("["):
selections, *rest = s.split("]")
choice = random.choice(selections.split('|'))
acc = acc + [choice] + rest
return squish(''.join(acc).format(substitution or ""))
def choices(text, substitution=None):
"""
Returns a section of 'text' based on separating semicolons.
"""
if text:
selections = text.split(';;')
return routput(random.choice(selections), substitution)
def split_party_msg(viewer, msg):
# First a message for the view:
viewer.msg(
re.sub("<You>", "You", re.sub("<you>", "you", msg))
)
# Then the message for the rest of the area:
viewer.location.msg_contents(re.sub("<[Yy]ou>",
viewer.name.title(), msg),
exclude=viewer)
# def searsonal(text, **kwargs):
# season = kwargs['season'] or kwargs['location'].get_season()
# time_of_day = kwargs['time_of_day'] or kwargs['location'].get_time_of_day()