Compare commits

...

4 Commits

Author SHA1 Message Date
Michal Kunc
ec6a94f18e
Move localization parsing earlier than macro and compendium 2021-11-18 23:39:05 +01:00
Michal Kunc
3982850dd3
Add support for long roll command 2021-11-18 23:36:34 +01:00
Michal Kunc
9641173758
Add todo 2021-11-18 23:32:01 +01:00
Michal Kunc
41a32accfd
Add support for localization lookup 2021-11-18 17:59:38 +01:00
2 changed files with 4581 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import json
import urllib.parse
import os
import re
@ -10,16 +11,32 @@ app = Flask(__name__)
app.config["MONGO_URI"] = os.environ["MONGO_URI"]
mongo = PyMongo(app)
LOCALIZATION_JSON = {}
with open("./db_explorer/en.json") as f:
LOCALIZATION_JSON = json.load(f)
@app.template_filter('filter_vtt')
def filter_vtt(text):
compendium_re = re.compile(r"@Compendium\[([^\]]+)\]\{([^\}]+)\}")
def compendium_return(m):
# TODO: Actually add links
return f"<a>{m.group(2)}</a>"
macro_re = re.compile(r"\[\[\/\S?r\s(?:(?P<sdice>[^\{\] ]+)[^\{\]]*|(?:\{(?P<ldice>[^\}]+)\}\[[^\]]+\])?)\]\](?:\{(?P<alt>[^\}]+)\})?")
macro_re = re.compile(r"\[\[\/\S+?r(?:oll)?\s(?:(?P<sdice>[^\{\] ]+)[^\{\]]*|(?:\{(?P<ldice>[^\}]+)\}\[[^\]]+\])?)\]\](?:\{(?P<alt>[^\}]+)\})?")
def macro_return(m):
if m.group('alt') is not None:
return m.group('alt')
return m.group('sdice')
localize_re = re.compile(r"@Localize\[([^\]]+)\]")
def localize_return(m):
path = m.group(1)
output = LOCALIZATION_JSON
for chunk in path.split('.'):
output = output.get(chunk, {})
if type(output) != str:
output = f"[LOCALIZATION LOOKUP ERROR - {m.group(0)}]"
return output
# Template
text = localize_re.sub(localize_return, text) # Has to be run before Compendium and Macro replacement
text = compendium_re.sub(compendium_return, text)
text = macro_re.sub(macro_return, text)
return text

File diff suppressed because it is too large Load Diff