Skip to content

Commit

Permalink
Update extra.py
Browse files Browse the repository at this point in the history
  • Loading branch information
pieckenst committed Aug 29, 2024
1 parent 80308a6 commit f457f62
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion utils/extra.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,20 @@ async def rtfm(bot: JDBot, url: str) -> list[RtfmObject]:
header_lines = [line for line in lines[:10] if not line.startswith(b"#")]
content_lines = lines[10:]

full_data = zlib.decompress(b"\n".join(header_lines + content_lines))
try:
full_data = zlib.decompress(b"\n".join(header_lines + content_lines))
except zlib.error:
# If decompression fails, try to skip the first few lines
for i in range(len(lines)):
try:
full_data = zlib.decompress(b"\n".join(lines[i:]))
break
except zlib.error:
continue
else:
# If all attempts fail, raise an exception
raise ValueError("Unable to decompress data")

normal_data = full_data.decode()
new_list = normal_data.split("\n")

Expand All @@ -209,6 +222,7 @@ async def rtfm(bot: JDBot, url: str) -> list[RtfmObject]:
return results



async def asset_converter(ctx, assets):
assets = list(assets)
attachments = ctx.message.attachments
Expand Down

0 comments on commit f457f62

Please sign in to comment.