62 lines
1.9 KiB
Python
62 lines
1.9 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
|
||
|
|