diff --git a/assets/error/image_not_found.png b/assets/error/image_not_found.png new file mode 100644 index 0000000..8a717b3 Binary files /dev/null and b/assets/error/image_not_found.png differ diff --git a/src/api/discord_embeds.py b/src/api/discord_embeds.py index 5fce000..4516155 100644 --- a/src/api/discord_embeds.py +++ b/src/api/discord_embeds.py @@ -2,6 +2,7 @@ from .generic_api import GenericApi from config import Config import cv2 import datetime +import traceback import discord from version import __version__ import numpy as np @@ -17,8 +18,10 @@ class DiscordEmbeds(GenericApi): def send_item(self, item: str, image: np.ndarray, location: str): imgName = item.replace('_', '-') + _, w, _ = image.shape + image = image[:, (w//2):,:] cv2.imwrite(f"./loot_screenshots/{item}.png", image) - file = discord.File(f"./loot_screenshots/{item}.png", filename=f"{imgName}.png") + file = self._add_file(f"./loot_screenshots/{item}.png", f"{imgName}.png") e = discord.Embed( title="Item Stashed!", description=f"{item} at {location}", @@ -29,7 +32,7 @@ class DiscordEmbeds(GenericApi): self._send_embed(e, file) def send_death(self, location, image_path): - file = discord.File(image_path, filename="death.png") + file = self._add_file(image_path, "death.png") e = discord.Embed(title=f"{self._config.general['name']} has died at {location}", color=Color.dark_red()) e.title=(f"{self._config.general['name']} died") e.description=(f"Died at {location}") @@ -38,7 +41,7 @@ class DiscordEmbeds(GenericApi): self._send_embed(e, file) def send_chicken(self, location, image_path): - file = discord.File(image_path, filename="chicken.png") + file = self._add_file(image_path, "chicken.png") e = discord.Embed(title=f"{self._config.general['name']} has chickened at {location}", color=Color.dark_grey()) e.title=(f"{self._config.general['name']} ran away") e.description=(f"chickened at {location}") @@ -84,4 +87,11 @@ class DiscordEmbeds(GenericApi): elif "gray_" in item: return Color.darker_grey() else: - return Color.blue() \ No newline at end of file + return Color.blue() + + def _add_file(self, image_path, image_name): + try: + return discord.File(image_path, filename=image_name) + except: + traceback.print_exc() + return discord.File("./assets/error/image_not_found.png", filename=image_name) diff --git a/src/main.py b/src/main.py index d3e0d21..014967a 100644 --- a/src/main.py +++ b/src/main.py @@ -59,7 +59,7 @@ def main(): # Create folder for debug screenshots if they dont exist yet if not os.path.exists("stats"): os.system("mkdir stats") - if not os.path.exists("info_screenshots") and config.general["info_screenshots"]: + if not os.path.exists("info_screenshots") and (config.general["info_screenshots"] or config.general["message_api_type"] == "discord"): os.system("mkdir info_screenshots") if not os.path.exists("loot_screenshots") and (config.general["loot_screenshots"] or config.general["message_api_type"] == "discord"): os.system("mkdir loot_screenshots")