Skip to content

Commit

Permalink
fixing generator issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Cybergenik committed Mar 26, 2022
1 parent 6d9bb5f commit feaea13
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bot/runemaster.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ async def on_message(message):
await message.channel.send('Ready for the Rift? type >commands for a list of all commands')
elif re.search('^>[a-zA-Z]', message.content, flags=re.IGNORECASE):
_in = message.content.split(' ', 1)
command = _in[0].lower()
command = _in[0].lkower()
if len(_in) == 1:
#region Generic commands
if command == ">hello":
Expand Down
15 changes: 8 additions & 7 deletions bot/screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
from datetime import datetime, timedelta

async def init_browser():
playwright = await async_playwright().start()
browser = await playwright.chromium.launch()
while True:
yield await browser.new_page()
async with async_playwright() as p:
browser = await p.chromium.launch()
return await browser.new_page()

class Browser:
"""Singleton class to represent Playwright Browser for screenshots"""
def __init__(self):
self.__browser = init_browser()
self.__browser = init_browser
self.__cache = TTLCache(maxsize=500, ttl=timedelta(hours=6), timer=datetime.now)

async def __new_page(self) -> Coroutine[Any, Any, Page]:
Expand Down Expand Up @@ -55,7 +54,8 @@ async def __cached_screenshot(self, name:str, action:str) -> BytesIO:
return None
except Exception as e:
print(f'Error in Cached Screenshot at: {url} :\n {e}')

await page.close()
return None
screenshot_bytes = BytesIO(await page.screenshot())
await page.close()
screenshot_bytes.seek(0)
Expand Down Expand Up @@ -87,7 +87,8 @@ async def get_screenshot(self, name:str, action:str, prefix: str) -> BytesIO:
return None
except Exception as e:
print(f'Error in Screenshot at: {url} :\n {e}')

await page.close()
return None
screenshot_bytes = BytesIO(await page.screenshot())
await page.close()
screenshot_bytes.seek(0)
Expand Down

0 comments on commit feaea13

Please sign in to comment.