3 dialogc.py -- Crossfire dialog compiler
5 Complies simple dialogs into CFDialog-compatible JSON. Works on standard input
6 and output when called from the command-line.
20 "Reset local variables when entering a new @match block."
21 nonlocal pre, msgbuilder, replies, post
28 "Add the current block to the rules dict."
32 if len(msgbuilder) > 0:
37 block[
'match'] = matches
40 block[
'msg'] = [
"\n".join(msgbuilder)]
42 block[
'replies'] = replies
50 if line.startswith(
'@match'):
52 parts = line.split(
' ', maxsplit=1)
53 matches = parts[1].
split(
'|')
55 elif line.startswith(
'@reply'):
56 parts = line.split(
' ', maxsplit=2)
59 replies.append([key, msg])
60 elif line.startswith(
'@identify'):
61 post.append([
"identify"])
62 elif line.startswith(
'@pre'):
63 parts = line.split(
' ')
65 elif line.startswith(
'@post'):
66 parts = line.split(
' ')
67 post.append(parts[1:])
69 msgbuilder.append(line)
73 dialog[
'rules'] = rules
76 if __name__ ==
'__main__':
80 json.dump(dialog, sys.stdout)