Add check to create info_screenshots folder and try-catch adding image to discord embed (#416)

This commit is contained in:
egut125
2022-01-09 16:34:04 +01:00
committed by GitHub
parent 8dfe8a2163
commit 39f65ab1fb
3 changed files with 15 additions and 5 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

+14 -4
View File
@@ -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()
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)
+1 -1
View File
@@ -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")