The shrub now records a transcript.
The show notes now work lovely.
This commit is contained in:
parent
5a1ef48ce5
commit
45d591403c
3 changed files with 122 additions and 1 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -58,3 +58,4 @@ nosetests.xml
|
|||
.DS_Store
|
||||
/server/ssh-private.key
|
||||
/server/ssh-public.key
|
||||
/transcripts/202*.html
|
||||
|
|
|
|||
34
transcripts/header-template.html
Normal file
34
transcripts/header-template.html
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
<html>
|
||||
<head>
|
||||
<title>Wyldwood Bar Transcript</title>
|
||||
<style type="text/css" media="screen">
|
||||
@import url('https://fonts.googleapis.com/css2?family=Cormorant+Garamond:ital,wght@0,300;0,400;0,500;0,600;0,700;1,300;1,400;1,500;1,600;1,700&family=Goudy+Bookletter+1911&family=Merienda:wght@300..900&display=swap');
|
||||
|
||||
html {
|
||||
background-color: #FCF5E5;
|
||||
color: #26201a;
|
||||
|
||||
font-family: "Goudy Bookletter 1911", serif;
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
font-size: 21px;
|
||||
line-height: 1.4em;
|
||||
|
||||
padding: 40px;
|
||||
}
|
||||
|
||||
p {
|
||||
margin: auto;
|
||||
margin-bottom: .5em;
|
||||
}
|
||||
|
||||
.special {
|
||||
margin: 20px;
|
||||
padding: 2px 20px;
|
||||
border: 2px solid brown;
|
||||
border-radius: 12px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Wyldwood Bar Transcript</h1>
|
||||
|
|
@ -1,6 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
from re import split, match, IGNORECASE
|
||||
from os.path import exists
|
||||
from datetime import datetime
|
||||
from re import split, match, sub, IGNORECASE
|
||||
from shutil import copyfile
|
||||
|
||||
from evennia import CmdSet
|
||||
from evennia.utils import logger
|
||||
|
|
@ -146,6 +149,7 @@ class CmdShrubSay(Command):
|
|||
msg = routput("The shrub uses a branch to << brush ^ wipe >> << off ^ >> << the chalk from ^ >> its << small ^ >> chalkboard, and with another branch, << slowly ^ carefully ^ deliberately ^ >> starts to write << something ^ a message ^ >>.")
|
||||
here.msg_contents(msg)
|
||||
self.caller.db.inside = self.args.strip()
|
||||
self.caller.record_msg(f"The chalkboard reads: |w{self.args}|n")
|
||||
|
||||
|
||||
class CmdSetShrubSay(CmdSet):
|
||||
|
|
@ -164,3 +168,85 @@ class Shrub(Puppet):
|
|||
def at_object_creation(self):
|
||||
"Called when a character is first created."
|
||||
self.cmdset.add(CmdSetShrubSay, persistent=True)
|
||||
|
||||
def find_actor(self, msg, default=None):
|
||||
"""
|
||||
Extract the character performing the action from the text.
|
||||
"""
|
||||
if default:
|
||||
return default
|
||||
|
||||
m = match(r".*\|b(.*?)\|n.*", msg)
|
||||
if m:
|
||||
return m.group(1)
|
||||
|
||||
def capitalize_msg(self, msg, msg_type=None):
|
||||
"""
|
||||
If msg is lowercase, capitalize it.
|
||||
|
||||
Maybe prepend a 'The' to the front.
|
||||
"""
|
||||
if msg_type == 'traverse' or msg_type == 'teleport':
|
||||
if match(r"^(\|[A-z])?[aeiou]", msg):
|
||||
return "An " + msg
|
||||
else:
|
||||
return "A " + msg
|
||||
elif msg_type == 'say' and match(r"^\|b[a-z]", msg):
|
||||
return "The " + msg
|
||||
elif match(r"^(\|[A-z])[a-z]", msg) and len(msg) > 2:
|
||||
return msg[0:1] + msg[2].upper() + msg[3:]
|
||||
elif match(r"^(\|[A-z])?[a-z]", msg) and len(msg) > 2:
|
||||
return msg[0].upper() + msg[1:]
|
||||
return msg
|
||||
|
||||
def to_html(self, msg, msg_type=None):
|
||||
"""
|
||||
Convert the 'msg' to an HTML formatted string.
|
||||
"""
|
||||
# Bold anything white:
|
||||
msg = sub(r"\|w(.*?)\|n", '<b>\\1</b>', msg)
|
||||
# Remove the rest:
|
||||
msg = sub(r"\|[A-z]", '', msg)
|
||||
# Remove initial or final carriage returns:
|
||||
msg = sub(r"^\n", '', msg)
|
||||
msg = sub(r"\n$", '', msg)
|
||||
# Convert the carriage returns:
|
||||
msg = sub(r"\n", ' <br/>\n', msg)
|
||||
|
||||
if msg_type == 'look':
|
||||
msg = msg[0].upper + msg[1:]
|
||||
return f"<div class=\"special\"><p>{msg}</p></div>\n"
|
||||
return f"<p>{msg}</p>\n"
|
||||
|
||||
def record_msg(self, text, actor=None):
|
||||
msg_type = None
|
||||
|
||||
if isinstance(text, tuple):
|
||||
if text[1] and isinstance(text[1], dict):
|
||||
msg_type = text[1]['type']
|
||||
msg = self.capitalize_msg(text[0], msg_type)
|
||||
else:
|
||||
msg = self.capitalize_msg(str(text))
|
||||
|
||||
actor = self.find_actor(msg, actor)
|
||||
msg = self.to_html(msg, msg_type)
|
||||
filename = datetime.today().strftime('transcripts/%Y-%m-%d.html')
|
||||
if not exists(filename):
|
||||
copyfile("transcripts/header-template.html", filename)
|
||||
|
||||
with open(filename, "a") as myfile:
|
||||
myfile.write(msg)
|
||||
|
||||
# Follow-up Actions ...
|
||||
if match(r".* arrives .*", msg) and actor and \
|
||||
msg_type in ('traverse', 'teleport'):
|
||||
self.execute_cmd(f"look {actor}")
|
||||
|
||||
def msg(self, text=None, from_obj=None, session=None, **kwargs):
|
||||
"""
|
||||
Record everything that happens in the room for a transcript.
|
||||
|
||||
Some key events may trigger more actions to get more information.
|
||||
"""
|
||||
self.record_msg(text, from_obj)
|
||||
super().msg(text, from_obj, session)
|
||||
|
|
|
|||
Loading…
Reference in a new issue