Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions homeassistant/components/discord/notify.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def file_exists(self, filename):
"""Check if a file exists on disk and is in authorized path."""
if not self.hass.config.is_allowed_path(filename):
return False

return os.path.isfile(filename)

async def async_send_message(self, message, **kwargs):
Expand All @@ -52,7 +51,6 @@ async def async_send_message(self, message, **kwargs):
if ATTR_TARGET not in kwargs:
_LOGGER.error("No target specified")
return None

data = kwargs.get(ATTR_DATA) or {}

if ATTR_IMAGES in data:
Expand All @@ -67,27 +65,26 @@ async def async_send_message(self, message, **kwargs):
images.append(image)
else:
_LOGGER.warning("Image not found: %s", image)

# pylint: disable=unused-variable
@discord_bot.event
async def on_ready():
"""Send the messages when the bot is ready."""
try:
for channelid in kwargs[ATTR_TARGET]:
channelid = int(channelid)
channel = discord_bot.get_channel(channelid)
channel = discord_bot.get_channel(
channelid
) or discord_bot.get_user(channelid)

if channel is None:
_LOGGER.warning("Channel not found for id: %s", channelid)
continue

# Must create new instances of File for each channel.
files = None
if images:
files = []
for image in images:
files.append(discord.File(image))

await channel.send(message, files=files)
except (discord.errors.HTTPException, discord.errors.NotFound) as error:
_LOGGER.warning("Communication error: %s", error)
Expand Down