diff --git a/pgbotlib/api.py b/pgbotlib/api.py index 28f5909..ee0b0ca 100644 --- a/pgbotlib/api.py +++ b/pgbotlib/api.py @@ -1,6 +1,7 @@ import json import random import re +import sys import typing import bs4 @@ -26,18 +27,21 @@ class ApiWrapper: # this is the entry point for the api calls # if you add another api, make sure there is a match here - # this could have used match - case statement, but python 3.9 def call(self, api: str, data: typing.Union[str, None], message: str) -> str: - match api: - case 'img_url': return self.format_img(data) - case 'gif': return self.get_gif() - case 'kmp': return self.get_kmp() - case 'fga': return self.get_fga() - case 'fakenews': return self.get_fakenews() - case 'anek': return self.get_anek() - case 'y_search': return self.y_search(message) - case _: return self.FAILED + try: + match api: + case 'img_url': return self.format_img(data) + case 'gif': return self.get_gif() + case 'kmp': return self.get_kmp() + case 'fga': return self.get_fga() + case 'fakenews': return self.get_fakenews() + case 'anek': return self.get_anek() + case 'y_search': return self.y_search(message) + case _: return self.FAILED + except Exception as e: + sys.stderr.write(e) + return self.FAILED def __sanitize_search(self, message: str) -> str: """Removes one of each of the search tokens from the query