moss-n-puddles/utils/word_list.py
2025-04-07 22:44:56 -07:00

47 lines
1.2 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.'
"""
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.
"""
selections = text.split(';;')
return routput(random.choice(selections), substitution)
def split_party(text, viewer):
return text.sub(r"<you>", viewer.name)
# 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()