mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-23 19:44:20 +00:00
Improve dnditem command
This commit is contained in:
parent
fcc3bbe111
commit
2bdb6c7729
2 changed files with 22 additions and 11 deletions
|
@ -21,10 +21,20 @@ class DnditemCommand(Command):
|
||||||
interface.loop.create_task(self._fetch_dnddata())
|
interface.loop.create_task(self._fetch_dnddata())
|
||||||
|
|
||||||
async def _fetch_dnddata(self):
|
async def _fetch_dnddata(self):
|
||||||
|
self._dnddata = self._dnddata = sortedcontainers.SortedKeyList([], key=lambda i: i["name"].lower())
|
||||||
async with aiohttp.ClientSession() as session:
|
async with aiohttp.ClientSession() as session:
|
||||||
async with session.get("https://scaleway.steffo.eu/dnd/items.json") as response:
|
async with session.get("https://5e.tools/data/items.json") as response:
|
||||||
j = await response.json()
|
j = await response.json()
|
||||||
self._dnddata = sortedcontainers.SortedKeyList(j["item"], key=lambda i: i["name"].lower())
|
for item in j["item"]:
|
||||||
|
self._dnddata.add(item)
|
||||||
|
async with session.get("https://5e.tools/data/fluff-items.json") as response:
|
||||||
|
j = await response.json()
|
||||||
|
for item in j["item"]:
|
||||||
|
self._dnddata.add(item)
|
||||||
|
async with session.get("https://5e.tools/data/items-base.json") as response:
|
||||||
|
j = await response.json()
|
||||||
|
for item in j["baseitem"]:
|
||||||
|
self._dnddata.add(item)
|
||||||
|
|
||||||
def _parse_entry(self, entry):
|
def _parse_entry(self, entry):
|
||||||
if isinstance(entry, str):
|
if isinstance(entry, str):
|
||||||
|
@ -58,14 +68,15 @@ class DnditemCommand(Command):
|
||||||
return
|
return
|
||||||
search = args.joined().lower()
|
search = args.joined().lower()
|
||||||
result = self._dnddata[self._dnddata.bisect_key_left(search)]
|
result = self._dnddata[self._dnddata.bisect_key_left(search)]
|
||||||
string = f'[b]{result["name"]}[/b]\n' \
|
string = f'[b]{result["name"]}[/b]\n'
|
||||||
f'[i]{result["source"]}, page {result["page"]}[/i]\n' \
|
if "source" in result:
|
||||||
f'\n' \
|
string += f'[i]{result["source"]}, page {result["page"]}[/i]\n'
|
||||||
f'Type: [b]{result.get("type", "None")}[/b]\n' \
|
string += f'\n' \
|
||||||
f'Value: [b]{result.get("value", "Priceless")}[/b]\n' \
|
f'Type: [b]{result.get("type", "None")}[/b]\n' \
|
||||||
f'Weight: [b]{result.get("weight", "0")} lb[/b]\n' \
|
f'Value: [b]{result.get("value", "Priceless")}[/b]\n' \
|
||||||
f'Rarity: [b]{result["rarity"] if result["rarity"] != "None" else "Mundane"}[/b]\n' \
|
f'Weight: [b]{result.get("weight", "0")} lb[/b]\n' \
|
||||||
f'\n'
|
f'Rarity: [b]{result["rarity"] if result.get("rarity", "None") != "None" else "Mundane"}[/b]\n' \
|
||||||
|
f'\n'
|
||||||
for entry in result.get("entries", []):
|
for entry in result.get("entries", []):
|
||||||
string += self._parse_entry(entry)
|
string += self._parse_entry(entry)
|
||||||
string += "\n\n"
|
string += "\n\n"
|
||||||
|
|
|
@ -11,7 +11,7 @@ from royalnet.database.tables import Royal, Telegram, Discord
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
|
|
||||||
log = logging.root
|
log = logging.getLogger("royalnet.bots")
|
||||||
stream_handler = logging.StreamHandler()
|
stream_handler = logging.StreamHandler()
|
||||||
stream_handler.formatter = logging.Formatter("{asctime}\t{name}\t{levelname}\t{message}", style="{")
|
stream_handler.formatter = logging.Formatter("{asctime}\t{name}\t{levelname}\t{message}", style="{")
|
||||||
log.addHandler(stream_handler)
|
log.addHandler(stream_handler)
|
||||||
|
|
Loading…
Reference in a new issue