75 lines
2.5 KiB
Python
75 lines
2.5 KiB
Python
|
import re
|
||
|
import json
|
||
|
|
||
|
USERREGEX = re.compile(r'!(=)+\[ (.+)\'s Adventure \](=)+!')
|
||
|
HPSREGEX = re.compile(r'[0-9,]+/[0-9,]+')
|
||
|
|
||
|
|
||
|
def read_adv(content):
|
||
|
try:
|
||
|
hps = HPSREGEX.findall(content)
|
||
|
hp = hps[1].replace(',', '').split("/")
|
||
|
hppercent = int(hp[0]) / int(hp[1]) * 100
|
||
|
usr = USERREGEX.search(content)
|
||
|
usr = usr.group(2)
|
||
|
return usr, hppercent
|
||
|
except Exception:
|
||
|
pass
|
||
|
|
||
|
|
||
|
STATSUSERRE = re.compile(r'!=+ \[(.+)\'s Stats\] =+!')
|
||
|
LEVELRE = re.compile(r'Level (\d+)')
|
||
|
WEAPRE = re.compile(r'Weapon: (.+)')
|
||
|
with open('items/weapons.json') as f:
|
||
|
WEAPONS = json.loads(f.read())
|
||
|
|
||
|
|
||
|
def read_stats(content):
|
||
|
try:
|
||
|
user = STATSUSERRE.search(content).groups(0)[0]
|
||
|
weap = WEAPRE.search(content).groups(0)[0]
|
||
|
for i in WEAPONS:
|
||
|
if i['item'] == weap:
|
||
|
weap = i
|
||
|
break
|
||
|
level = LEVELRE.search(content).groups(0)[0]
|
||
|
for i in WEAPONS[::-1]:
|
||
|
if i['level'] <= int(level):
|
||
|
if i['level'] != weap['level']:
|
||
|
new_weap = i
|
||
|
break
|
||
|
else:
|
||
|
new_weap = None
|
||
|
break
|
||
|
if new_weap is not None:
|
||
|
out = f'```{user}\'s Weapon\n' \
|
||
|
f'Name: {weap["item"]} Maxhit: '\
|
||
|
f'{weap["max dmg"]} Minhit: {weap["min dmg"]}\n'\
|
||
|
f'You should upgrade to {new_weap["item"]} ' \
|
||
|
f'costing {new_weap["price"]}gold with ' \
|
||
|
f'a max hit of {new_weap["max dmg"]} and a ' \
|
||
|
f'min hit of {new_weap["min dmg"]}```'
|
||
|
else:
|
||
|
out = f'```{user}\'s Weapon\n' \
|
||
|
f'Name: {weap["item"]} ' \
|
||
|
f'Maxhit: {weap["max dmg"]} ' \
|
||
|
f'Minhit: {weap["min dmg"]}\n' \
|
||
|
f'Your weapon seems correct for your level```'
|
||
|
return out
|
||
|
except Exception:
|
||
|
pass
|
||
|
|
||
|
LOC_USR_RE = re.compile(r'(.+)\'s location')
|
||
|
CLEAN_DEST_RE = re.compile(r'([A-Za-z \']+) - (\d+)s')
|
||
|
|
||
|
def read_travel(title, fields, **kwargs):
|
||
|
if title.endswith('location') and fields[0]["name"] == "Kingdom":
|
||
|
rawdestinations = fields[1]["value"].split('\n')
|
||
|
desetinations = {i[0]: int(i[1])
|
||
|
for i in [CLEAN_DEST_RE.search(i).groups()
|
||
|
for i in rawdestinations]}
|
||
|
user = LOC_USR_RE.search(title).groups(0)[0]
|
||
|
return user, desetinations
|
||
|
|
||
|
DEST_RE = re.compile(r'started their journey to ([A-Za-z \']+)!')
|